diff options
Diffstat (limited to 'compiler/optimizing/nodes.h')
-rw-r--r-- | compiler/optimizing/nodes.h | 123 |
1 files changed, 68 insertions, 55 deletions
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index fef0c865ae..99fde755da 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -45,6 +45,7 @@ namespace art { +class ArenaStack; class GraphChecker; class HBasicBlock; class HConstructorFence; @@ -305,7 +306,8 @@ std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); // Control-flow graph of a method. Contains a list of basic blocks. class HGraph : public ArenaObject<kArenaAllocGraph> { public: - HGraph(ArenaAllocator* arena, + HGraph(ArenaAllocator* allocator, + ArenaStack* arena_stack, const DexFile& dex_file, uint32_t method_idx, InstructionSet instruction_set, @@ -313,10 +315,11 @@ class HGraph : public ArenaObject<kArenaAllocGraph> { bool debuggable = false, bool osr = false, int start_instruction_id = 0) - : arena_(arena), - blocks_(arena->Adapter(kArenaAllocBlockList)), - reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), - linear_order_(arena->Adapter(kArenaAllocLinearOrder)), + : allocator_(allocator), + arena_stack_(arena_stack), + blocks_(allocator->Adapter(kArenaAllocBlockList)), + reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), + linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), entry_block_(nullptr), exit_block_(nullptr), maximum_number_of_out_vregs_(0), @@ -337,22 +340,23 @@ class HGraph : public ArenaObject<kArenaAllocGraph> { number_of_cha_guards_(0), instruction_set_(instruction_set), cached_null_constant_(nullptr), - cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), - cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), - cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), - cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), + cached_int_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), + cached_float_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), + cached_long_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), + cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), cached_current_method_(nullptr), art_method_(nullptr), inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), osr_(osr), - cha_single_implementation_list_(arena->Adapter(kArenaAllocCHA)) { + cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { blocks_.reserve(kDefaultNumberOfBlocks); } // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); - ArenaAllocator* GetArena() const { return arena_; } + ArenaAllocator* GetAllocator() const { return allocator_; } + ArenaStack* GetArenaStack() const { return arena_stack_; } const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } bool IsInSsaForm() const { return in_ssa_form_; } @@ -613,7 +617,7 @@ class HGraph : public ArenaObject<kArenaAllocGraph> { // If not found or previously deleted, create and cache a new instruction. // Don't bother reviving a previously deleted instruction, for simplicity. if (constant == nullptr || constant->GetBlock() == nullptr) { - constant = new (arena_) InstructionType(value, dex_pc); + constant = new (allocator_) InstructionType(value, dex_pc); cache->Overwrite(value, constant); InsertConstant(constant); } @@ -629,7 +633,8 @@ class HGraph : public ArenaObject<kArenaAllocGraph> { // See CacheFloatConstant comment. void CacheDoubleConstant(HDoubleConstant* constant); - ArenaAllocator* const arena_; + ArenaAllocator* const allocator_; + ArenaStack* const arena_stack_; // List of blocks in insertion order. ArenaVector<HBasicBlock*> blocks_; @@ -751,9 +756,12 @@ class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { suspend_check_(nullptr), irreducible_(false), contains_irreducible_loop_(false), - back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), + back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), // Make bit vector growable, as the number of blocks may change. - blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { + blocks_(graph->GetAllocator(), + graph->GetBlocks().size(), + true, + kArenaAllocLoopInfoBackEdges) { back_edges_.reserve(kDefaultNumberOfBackEdges); } @@ -916,11 +924,11 @@ class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { public: explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) : graph_(graph), - predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), - successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), + predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), + successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), loop_information_(nullptr), dominator_(nullptr), - dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), + dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), block_id_(kInvalidBlockId), dex_pc_(dex_pc), lifetime_start_(kNoLifetime), @@ -972,7 +980,7 @@ class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { void AddBackEdge(HBasicBlock* back_edge) { if (loop_information_ == nullptr) { - loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); + loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); } DCHECK_EQ(loop_information_->GetHeader(), this); loop_information_->AddBackEdge(back_edge); @@ -1792,21 +1800,23 @@ class SideEffects : public ValueObject { // A HEnvironment object contains the values of virtual registers at a given location. class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { public: - ALWAYS_INLINE HEnvironment(ArenaAllocator* arena, + ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, size_t number_of_vregs, ArtMethod* method, uint32_t dex_pc, HInstruction* holder) - : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), - locations_(arena->Adapter(kArenaAllocEnvironmentLocations)), + : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), + locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), parent_(nullptr), method_(method), dex_pc_(dex_pc), holder_(holder) { } - ALWAYS_INLINE HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) - : HEnvironment(arena, + ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, + const HEnvironment& to_copy, + HInstruction* holder) + : HEnvironment(allocator, to_copy.Size(), to_copy.GetMethod(), to_copy.GetDexPc(), @@ -1925,7 +1935,7 @@ class HInstruction : public ArenaObject<kArenaAllocInstruction> { HInstruction* GetPreviousDisregardingMoves() const; HBasicBlock* GetBlock() const { return block_; } - ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } + ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } void SetBlock(HBasicBlock* block) { block_ = block; } bool IsInBlock() const { return block_ != nullptr; } bool IsInLoop() const { return block_->IsInLoop(); } @@ -2015,7 +2025,7 @@ class HInstruction : public ArenaObject<kArenaAllocInstruction> { // Note: fixup_end remains valid across push_front(). auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); HUseListNode<HInstruction*>* new_node = - new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); + new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HInstruction*>(user, index); uses_.push_front(*new_node); FixUpUserRecordsAfterUseInsertion(fixup_end); } @@ -2025,7 +2035,7 @@ class HInstruction : public ArenaObject<kArenaAllocInstruction> { // Note: env_fixup_end remains valid across push_front(). auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); HUseListNode<HEnvironment*>* new_node = - new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); + new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); env_uses_.push_front(*new_node); FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); } @@ -2108,7 +2118,7 @@ class HInstruction : public ArenaObject<kArenaAllocInstruction> { // copying, the uses lists are being updated. void CopyEnvironmentFrom(HEnvironment* environment) { DCHECK(environment_ == nullptr); - ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); + ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); environment_ = new (allocator) HEnvironment(allocator, *environment, this); environment_->CopyFrom(environment); if (environment->GetParent() != nullptr) { @@ -2119,7 +2129,7 @@ class HInstruction : public ArenaObject<kArenaAllocInstruction> { void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, HBasicBlock* block) { DCHECK(environment_ == nullptr); - ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); + ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); environment_ = new (allocator) HEnvironment(allocator, *environment, this); environment_->CopyFromWithLoopPhiAdjustment(environment, block); if (environment->GetParent() != nullptr) { @@ -2467,11 +2477,11 @@ class HVariableInputSizeInstruction : public HInstruction { protected: HVariableInputSizeInstruction(SideEffects side_effects, uint32_t dex_pc, - ArenaAllocator* arena, + ArenaAllocator* allocator, size_t number_of_inputs, ArenaAllocKind kind) : HInstruction(side_effects, dex_pc), - inputs_(number_of_inputs, arena->Adapter(kind)) {} + inputs_(number_of_inputs, allocator->Adapter(kind)) {} ArenaVector<HUserRecord<HInstruction*>> inputs_; @@ -2572,7 +2582,7 @@ class HReturn FINAL : public HTemplateInstruction<1> { class HPhi FINAL : public HVariableInputSizeInstruction { public: - HPhi(ArenaAllocator* arena, + HPhi(ArenaAllocator* allocator, uint32_t reg_number, size_t number_of_inputs, DataType::Type type, @@ -2580,7 +2590,7 @@ class HPhi FINAL : public HVariableInputSizeInstruction { : HVariableInputSizeInstruction( SideEffects::None(), dex_pc, - arena, + allocator, number_of_inputs, kArenaAllocPhiInputs), reg_number_(reg_number) { @@ -3019,11 +3029,14 @@ class HDeoptimize FINAL : public HVariableInputSizeInstruction { public: // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move // across. - HDeoptimize(ArenaAllocator* arena, HInstruction* cond, DeoptimizationKind kind, uint32_t dex_pc) + HDeoptimize(ArenaAllocator* allocator, + HInstruction* cond, + DeoptimizationKind kind, + uint32_t dex_pc) : HVariableInputSizeInstruction( SideEffects::All(), dex_pc, - arena, + allocator, /* number_of_inputs */ 1, kArenaAllocMisc) { SetPackedFlag<kFieldCanBeMoved>(false); @@ -3036,7 +3049,7 @@ class HDeoptimize FINAL : public HVariableInputSizeInstruction { // instead of `guard`. // We set CanTriggerGC to prevent any intermediate address to be live // at the point of the `HDeoptimize`. - HDeoptimize(ArenaAllocator* arena, + HDeoptimize(ArenaAllocator* allocator, HInstruction* cond, HInstruction* guard, DeoptimizationKind kind, @@ -3044,7 +3057,7 @@ class HDeoptimize FINAL : public HVariableInputSizeInstruction { : HVariableInputSizeInstruction( SideEffects::CanTriggerGC(), dex_pc, - arena, + allocator, /* number_of_inputs */ 2, kArenaAllocMisc) { SetPackedFlag<kFieldCanBeMoved>(true); @@ -3108,8 +3121,8 @@ class HShouldDeoptimizeFlag FINAL : public HVariableInputSizeInstruction { public: // CHA guards are only optimized in a separate pass and it has no side effects // with regard to other passes. - HShouldDeoptimizeFlag(ArenaAllocator* arena, uint32_t dex_pc) - : HVariableInputSizeInstruction(SideEffects::None(), dex_pc, arena, 0, kArenaAllocCHA) { + HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) + : HVariableInputSizeInstruction(SideEffects::None(), dex_pc, allocator, 0, kArenaAllocCHA) { } DataType::Type GetType() const OVERRIDE { return DataType::Type::kInt32; } @@ -4076,7 +4089,7 @@ class HInvoke : public HVariableInputSizeInstruction { using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; using ReturnTypeField = BitField<DataType::Type, kFieldReturnType, kFieldReturnTypeSize>; - HInvoke(ArenaAllocator* arena, + HInvoke(ArenaAllocator* allocator, uint32_t number_of_arguments, uint32_t number_of_other_inputs, DataType::Type return_type, @@ -4087,7 +4100,7 @@ class HInvoke : public HVariableInputSizeInstruction { : HVariableInputSizeInstruction( SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. dex_pc, - arena, + allocator, number_of_arguments + number_of_other_inputs, kArenaAllocInvokeInputs), number_of_arguments_(number_of_arguments), @@ -4114,13 +4127,13 @@ class HInvoke : public HVariableInputSizeInstruction { class HInvokeUnresolved FINAL : public HInvoke { public: - HInvokeUnresolved(ArenaAllocator* arena, + HInvokeUnresolved(ArenaAllocator* allocator, uint32_t number_of_arguments, DataType::Type return_type, uint32_t dex_pc, uint32_t dex_method_index, InvokeType invoke_type) - : HInvoke(arena, + : HInvoke(allocator, number_of_arguments, 0u /* number_of_other_inputs */, return_type, @@ -4138,12 +4151,12 @@ class HInvokeUnresolved FINAL : public HInvoke { class HInvokePolymorphic FINAL : public HInvoke { public: - HInvokePolymorphic(ArenaAllocator* arena, + HInvokePolymorphic(ArenaAllocator* allocator, uint32_t number_of_arguments, DataType::Type return_type, uint32_t dex_pc, uint32_t dex_method_index) - : HInvoke(arena, + : HInvoke(allocator, number_of_arguments, 0u /* number_of_other_inputs */, return_type, @@ -4215,7 +4228,7 @@ class HInvokeStaticOrDirect FINAL : public HInvoke { uint64_t method_load_data; }; - HInvokeStaticOrDirect(ArenaAllocator* arena, + HInvokeStaticOrDirect(ArenaAllocator* allocator, uint32_t number_of_arguments, DataType::Type return_type, uint32_t dex_pc, @@ -4225,7 +4238,7 @@ class HInvokeStaticOrDirect FINAL : public HInvoke { InvokeType invoke_type, MethodReference target_method, ClinitCheckRequirement clinit_check_requirement) - : HInvoke(arena, + : HInvoke(allocator, number_of_arguments, // There is potentially one extra argument for the HCurrentMethod node, and // potentially one other if the clinit check is explicit, and potentially @@ -4410,14 +4423,14 @@ std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckReq class HInvokeVirtual FINAL : public HInvoke { public: - HInvokeVirtual(ArenaAllocator* arena, + HInvokeVirtual(ArenaAllocator* allocator, uint32_t number_of_arguments, DataType::Type return_type, uint32_t dex_pc, uint32_t dex_method_index, ArtMethod* resolved_method, uint32_t vtable_index) - : HInvoke(arena, + : HInvoke(allocator, number_of_arguments, 0u, return_type, @@ -4458,14 +4471,14 @@ class HInvokeVirtual FINAL : public HInvoke { class HInvokeInterface FINAL : public HInvoke { public: - HInvokeInterface(ArenaAllocator* arena, + HInvokeInterface(ArenaAllocator* allocator, uint32_t number_of_arguments, DataType::Type return_type, uint32_t dex_pc, uint32_t dex_method_index, ArtMethod* resolved_method, uint32_t imt_index) - : HInvoke(arena, + : HInvoke(allocator, number_of_arguments, 0u, return_type, @@ -6637,7 +6650,7 @@ class HConstructorFence FINAL : public HVariableInputSizeInstruction { // about the associated object. HConstructorFence(HInstruction* fence_object, uint32_t dex_pc, - ArenaAllocator* arena) + ArenaAllocator* allocator) // We strongly suspect there is not a more accurate way to describe the fine-grained reordering // constraints described in the class header. We claim that these SideEffects constraints // enforce a superset of the real constraints. @@ -6661,7 +6674,7 @@ class HConstructorFence FINAL : public HVariableInputSizeInstruction { // we can refine the side effect to a smaller set of type reads (see above constraints). : HVariableInputSizeInstruction(SideEffects::AllReads(), dex_pc, - arena, + allocator, /* number_of_inputs */ 1, kArenaAllocConstructorFenceInputs) { DCHECK(fence_object != nullptr); @@ -6878,9 +6891,9 @@ static constexpr size_t kDefaultNumberOfMoves = 4; class HParallelMove FINAL : public HTemplateInstruction<0> { public: - explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) + explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc), - moves_(arena->Adapter(kArenaAllocMoveOperands)) { + moves_(allocator->Adapter(kArenaAllocMoveOperands)) { moves_.reserve(kDefaultNumberOfMoves); } |