Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
dart::FlowGraphAllocator Class Reference

#include <linearscan.h>

Inheritance diagram for dart::FlowGraphAllocator:
dart::ValueObject

Public Member Functions

 FlowGraphAllocator (const FlowGraph &flow_graph, bool intrinsic_mode=false)
 
void AllocateRegisters ()
 
LiveRangeGetLiveRange (intptr_t vreg)
 
- Public Member Functions inherited from dart::ValueObject
 ValueObject ()
 
 ~ValueObject ()
 

Static Public Member Functions

static DART_FORCE_INLINE void SetLifetimePosition (Instruction *instr, intptr_t pos)
 
static DART_FORCE_INLINE bool HasLifetimePosition (Instruction *instr)
 
static DART_FORCE_INLINE intptr_t GetLifetimePosition (const Instruction *instr)
 

Static Public Attributes

static constexpr intptr_t kDoubleSpillFactor
 

Detailed Description

Definition at line 55 of file linearscan.h.

Constructor & Destructor Documentation

◆ FlowGraphAllocator()

dart::FlowGraphAllocator::FlowGraphAllocator ( const FlowGraph flow_graph,
bool  intrinsic_mode = false 
)
explicit

Definition at line 88 of file linearscan.cc.

90 : flow_graph_(flow_graph),
91 reaching_defs_(flow_graph),
92 value_representations_(flow_graph.max_vreg()),
93 block_order_(BlockOrderForAllocation(flow_graph)),
94 postorder_(flow_graph.postorder()),
95 instructions_(),
96 block_entries_(),
97 extra_loop_info_(),
98 liveness_(flow_graph),
99 vreg_count_(flow_graph.max_vreg()),
100 live_ranges_(flow_graph.max_vreg()),
101 unallocated_cpu_(),
102 unallocated_fpu_(),
103 cpu_regs_(),
104 fpu_regs_(),
105 blocked_cpu_registers_(),
106 blocked_fpu_registers_(),
107 spilled_(),
108 safepoints_(),
109 register_kind_(),
110 number_of_registers_(0),
111 registers_(),
112 blocked_registers_(),
113 unallocated_(),
114 spill_slots_(),
115 quad_spill_slots_(),
116 untagged_spill_slots_(),
117 cpu_spill_slot_count_(0),
118 intrinsic_mode_(intrinsic_mode) {
119 for (intptr_t i = 0; i < vreg_count_; i++) {
120 live_ranges_.Add(nullptr);
121 }
122 for (intptr_t i = 0; i < vreg_count_; i++) {
123 value_representations_.Add(kNoRepresentation);
124 }
125
126 // All registers are marked as "not blocked" (array initialized to false).
127 // Mark the unavailable ones as "blocked" (true).
128 for (intptr_t i = 0; i < kNumberOfCpuRegisters; i++) {
129 if ((kDartAvailableCpuRegs & (1 << i)) == 0) {
130 blocked_cpu_registers_[i] = true;
131 }
132 }
133
134 // FpuTMP is used as scratch by optimized code and parallel move resolver.
135 blocked_fpu_registers_[FpuTMP] = true;
136
137 // Block additional registers needed preserved when generating intrinsics.
138 // TODO(fschneider): Handle saving and restoring these registers when
139 // generating intrinsic code.
140 if (intrinsic_mode) {
141 blocked_cpu_registers_[ARGS_DESC_REG] = true;
142
143#if !defined(TARGET_ARCH_IA32)
144 // Need to preserve CODE_REG to be able to store the PC marker
145 // and load the pool pointer.
146 blocked_cpu_registers_[CODE_REG] = true;
147#endif
148 }
149}
void Add(const T &value)
static const GrowableArray< BlockEntryInstr * > & BlockOrderForAllocation(const FlowGraph &flow_graph)
Definition: linearscan.cc:80
const FpuRegister FpuTMP
const Register CODE_REG
const Register ARGS_DESC_REG
@ kNumberOfCpuRegisters
Definition: constants_arm.h:98
constexpr RegList kDartAvailableCpuRegs

Member Function Documentation

◆ AllocateRegisters()

void dart::FlowGraphAllocator::AllocateRegisters ( )

Definition at line 3443 of file linearscan.cc.

3443 {
3444 CollectRepresentations();
3445
3446 liveness_.Analyze();
3447
3448 NumberInstructions();
3449
3450 // Reserve spill slot for :suspend_state synthetic variable before
3451 // reserving spill slots for parameter variables.
3452 AllocateSpillSlotForSuspendState();
3453
3454 BuildLiveRanges();
3455
3456 // Update stackmaps after all safepoints are collected.
3457 UpdateStackmapsForSuspendState();
3458
3459 if (FLAG_print_ssa_liveranges && CompilerState::ShouldTrace()) {
3460 const Function& function = flow_graph_.function();
3461 THR_Print("-- [before ssa allocator] ranges [%s] ---------\n",
3462 function.ToFullyQualifiedCString());
3463 PrintLiveRanges();
3464 THR_Print("----------------------------------------------\n");
3465
3466 THR_Print("-- [before ssa allocator] ir [%s] -------------\n",
3467 function.ToFullyQualifiedCString());
3469#ifndef PRODUCT
3470 FlowGraphPrinter printer(flow_graph_, true);
3471 printer.PrintBlocks();
3472#endif
3473 }
3474 THR_Print("----------------------------------------------\n");
3475 }
3476
3477 PrepareForAllocation(Location::kRegister, kNumberOfCpuRegisters,
3478 unallocated_cpu_, cpu_regs_, blocked_cpu_registers_);
3479 AllocateUnallocatedRanges();
3480 // GraphEntryInstr::fixed_slot_count() stack slots are reserved for catch
3481 // entries. When allocating a spill slot, AllocateSpillSlotFor() accounts for
3482 // these reserved slots and allocates spill slots on top of them.
3483 // However, if there are no spill slots allocated, we still need to reserve
3484 // slots for catch entries in the spill area.
3485 cpu_spill_slot_count_ = Utils::Maximum(
3486 spill_slots_.length(), flow_graph_.graph_entry()->fixed_slot_count());
3487 spill_slots_.Clear();
3488 quad_spill_slots_.Clear();
3489 untagged_spill_slots_.Clear();
3490
3491 PrepareForAllocation(Location::kFpuRegister, kNumberOfFpuRegisters,
3492 unallocated_fpu_, fpu_regs_, blocked_fpu_registers_);
3493 AllocateUnallocatedRanges();
3494
3495 GraphEntryInstr* entry = block_order_[0]->AsGraphEntry();
3496 ASSERT(entry != nullptr);
3497 intptr_t double_spill_slot_count = spill_slots_.length() * kDoubleSpillFactor;
3498 entry->set_spill_slot_count(cpu_spill_slot_count_ + double_spill_slot_count +
3499 flow_graph_.max_argument_slot_count());
3500
3501 RemoveFrameIfNotNeeded();
3502
3503 AllocateOutgoingArguments();
3504
3505 ResolveControlFlow();
3506
3507 ScheduleParallelMoves();
3508
3509 if (FLAG_print_ssa_liveranges && CompilerState::ShouldTrace()) {
3510 const Function& function = flow_graph_.function();
3511
3512 THR_Print("-- [after ssa allocator] ranges [%s] ---------\n",
3513 function.ToFullyQualifiedCString());
3514 PrintLiveRanges();
3515 THR_Print("----------------------------------------------\n");
3516
3517 THR_Print("-- [after ssa allocator] ir [%s] -------------\n",
3518 function.ToFullyQualifiedCString());
3520#ifndef PRODUCT
3521 FlowGraphPrinter printer(flow_graph_, true);
3522 printer.PrintBlocks();
3523#endif
3524 }
3525 THR_Print("----------------------------------------------\n");
3526 }
3527}
intptr_t length() const
static bool ShouldTrace()
static constexpr intptr_t kDoubleSpillFactor
Definition: linearscan.h:58
GraphEntryInstr * graph_entry() const
Definition: flow_graph.h:268
intptr_t max_argument_slot_count() const
Definition: flow_graph.h:562
const Function & function() const
Definition: flow_graph.h:130
intptr_t fixed_slot_count() const
Definition: il.h:1996
static constexpr T Maximum(T x, T y)
Definition: utils.h:41
#define THR_Print(format,...)
Definition: log.h:20
#define ASSERT(E)
constexpr bool FLAG_support_il_printer
Definition: flag_list.h:48
Dart_NativeFunction function
Definition: fuchsia.cc:51
const int kNumberOfFpuRegisters

◆ GetLifetimePosition()

static DART_FORCE_INLINE intptr_t dart::FlowGraphAllocator::GetLifetimePosition ( const Instruction instr)
inlinestatic

Definition at line 78 of file linearscan.h.

79 {
80 return instr->GetPassSpecificId(CompilerPass::kAllocateRegisters);
81 }

◆ GetLiveRange()

LiveRange * dart::FlowGraphAllocator::GetLiveRange ( intptr_t  vreg)

Definition at line 431 of file linearscan.cc.

431 {
432 if (live_ranges_[vreg] == nullptr) {
433 Representation rep = value_representations_[vreg];
434 ASSERT(rep != kNoRepresentation);
435 live_ranges_[vreg] = new LiveRange(vreg, rep);
436 }
437 return live_ranges_[vreg];
438}
Representation
Definition: locations.h:66

◆ HasLifetimePosition()

static DART_FORCE_INLINE bool dart::FlowGraphAllocator::HasLifetimePosition ( Instruction instr)
inlinestatic

Definition at line 74 of file linearscan.h.

74 {
75 return instr->HasPassSpecificId(CompilerPass::kAllocateRegisters);
76 }

◆ SetLifetimePosition()

static DART_FORCE_INLINE void dart::FlowGraphAllocator::SetLifetimePosition ( Instruction instr,
intptr_t  pos 
)
inlinestatic

Definition at line 69 of file linearscan.h.

70 {
71 instr->SetPassSpecificId(CompilerPass::kAllocateRegisters, pos);
72 }
SkPoint pos

Member Data Documentation

◆ kDoubleSpillFactor

constexpr intptr_t dart::FlowGraphAllocator::kDoubleSpillFactor
staticconstexpr
Initial value:
=
static constexpr intptr_t kWordSize
Definition: runtime_api.h:274
constexpr intptr_t kDoubleSize
Definition: globals.h:456

Definition at line 58 of file linearscan.h.


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