Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
dart::AllocationSinking Class Reference

#include <redundancy_elimination.h>

Inheritance diagram for dart::AllocationSinking:
dart::ZoneAllocated

Public Member Functions

 AllocationSinking (FlowGraph *flow_graph)
 
const GrowableArray< Definition * > & candidates () const
 
MaterializeObjectInstrMaterializationFor (Definition *alloc, Instruction *exit)
 
void Optimize ()
 
void DetachMaterializations ()
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Detailed Description

Definition at line 19 of file redundancy_elimination.h.

Constructor & Destructor Documentation

◆ AllocationSinking()

dart::AllocationSinking::AllocationSinking ( FlowGraph flow_graph)
inlineexplicit

Definition at line 21 of file redundancy_elimination.h.

22 : flow_graph_(flow_graph), candidates_(5), materializations_(5) {}

Member Function Documentation

◆ candidates()

const GrowableArray< Definition * > & dart::AllocationSinking::candidates ( ) const
inline

Definition at line 24 of file redundancy_elimination.h.

24{ return candidates_; }

◆ DetachMaterializations()

void dart::AllocationSinking::DetachMaterializations ( )

Definition at line 3748 of file redundancy_elimination.cc.

3748 {
3749 for (MaterializeObjectInstr* mat : materializations_) {
3750 mat->previous()->LinkTo(mat->next());
3751 mat->set_next(nullptr);
3752 mat->set_previous(nullptr);
3753 }
3754}

◆ MaterializationFor()

MaterializeObjectInstr * dart::AllocationSinking::MaterializationFor ( Definition alloc,
Instruction exit 
)

Definition at line 3784 of file redundancy_elimination.cc.

3786 {
3787 if (exit->IsMaterializeObject()) {
3788 exit = ExitForMaterialization(exit->AsMaterializeObject());
3789 }
3790
3791 for (MaterializeObjectInstr* mat = exit->previous()->AsMaterializeObject();
3792 mat != nullptr; mat = mat->previous()->AsMaterializeObject()) {
3793 if (mat->allocation() == alloc) {
3794 return mat;
3795 }
3796 }
3797
3798 return nullptr;
3799}
exit(kErrorExitCode)
static Instruction * ExitForMaterialization(MaterializeObjectInstr *mat)

◆ Optimize()

void dart::AllocationSinking::Optimize ( )

Definition at line 3670 of file redundancy_elimination.cc.

3670 {
3671 // Allocation sinking depends on load forwarding, so give up early if load
3672 // forwarding is disabled.
3673 if (!FLAG_load_cse || flow_graph_->is_huge_method()) {
3674 return;
3675 }
3676
3677 CollectCandidates();
3678
3679 // Insert MaterializeObject instructions that will describe the state of the
3680 // object at all deoptimization points. Each inserted materialization looks
3681 // like this (where v_0 is allocation that we are going to eliminate):
3682 // v_1 <- LoadField(v_0, field_1)
3683 // ...
3684 // v_N <- LoadField(v_0, field_N)
3685 // v_{N+1} <- MaterializeObject(field_1 = v_1, ..., field_N = v_N)
3686 //
3687 // For typed data objects materialization looks like this:
3688 // v_1 <- LoadIndexed(v_0, index_1)
3689 // ...
3690 // v_N <- LoadIndexed(v_0, index_N)
3691 // v_{N+1} <- MaterializeObject([index_1] = v_1, ..., [index_N] = v_N)
3692 //
3693 // For arrays materialization looks like this:
3694 // v_1 <- LoadIndexed(v_0, index_1)
3695 // ...
3696 // v_N <- LoadIndexed(v_0, index_N)
3697 // v_{N+1} <- LoadField(v_0, Array.type_arguments)
3698 // v_{N+2} <- MaterializeObject([index_1] = v_1, ..., [index_N] = v_N,
3699 // type_arguments = v_{N+1})
3700 //
3701 for (intptr_t i = 0; i < candidates_.length(); i++) {
3702 InsertMaterializations(candidates_[i]);
3703 }
3704
3705 // Run load forwarding to eliminate LoadField/LoadIndexed instructions
3706 // inserted above.
3707 //
3708 // All loads will be successfully eliminated because:
3709 // a) they use fields/constant indices and thus provide precise aliasing
3710 // information
3711 // b) candidate does not escape and thus its fields/elements are not
3712 // affected by external effects from calls.
3713 LoadOptimizer::OptimizeGraph(flow_graph_);
3714
3715 NormalizeMaterializations();
3716
3717 RemoveUnusedMaterializations();
3718
3719 // If any candidates are no longer eligible for allocation sinking abort
3720 // the optimization for them and undo any changes we did in preparation.
3721 DiscoverFailedCandidates();
3722
3723 // At this point we have computed the state of object at each deoptimization
3724 // point and we can eliminate it. Loads inserted above were forwarded so there
3725 // are no uses of the allocation outside other candidates to eliminate, just
3726 // as in the beginning of the pass.
3727 for (intptr_t i = 0; i < candidates_.length(); i++) {
3728 EliminateAllocation(candidates_[i]);
3729 }
3730
3731 // Process materializations and unbox their arguments: materializations
3732 // are part of the environment and can materialize boxes for double/mint/simd
3733 // values when needed.
3734 // TODO(vegorov): handle all box types here.
3735 for (intptr_t i = 0; i < materializations_.length(); i++) {
3736 MaterializeObjectInstr* mat = materializations_[i];
3737 for (intptr_t j = 0; j < mat->InputCount(); j++) {
3738 Definition* defn = mat->InputAt(j)->definition();
3739 if (defn->IsBox()) {
3740 mat->InputAt(j)->BindTo(defn->InputAt(0)->definition());
3741 }
3742 }
3743 }
3744}
bool is_huge_method() const
Definition flow_graph.h:423
static bool OptimizeGraph(FlowGraph *graph)

The documentation for this class was generated from the following files: