43#ifndef RUNTIME_VM_COMPILER_BACKEND_LOCATIONS_HELPERS_H_
44#define RUNTIME_VM_COMPILER_BACKEND_LOCATIONS_HELPERS_H_
46#if defined(DART_PRECOMPILED_RUNTIME)
47#error "AOT runtime should not use compiler sources (including header files)"
55class FlowGraphCompiler;
57#define DEFINE_BACKEND(Name, Args) \
58 static void EmitterFor##Name(FlowGraphCompiler* compiler, \
59 Name##Instr* instr, PP_APPLY(PP_UNPACK, Args)); \
60 LocationSummary* Name##Instr::MakeLocationSummary(Zone* zone, bool opt) \
62 return MakeLocationSummaryFromEmitter(zone, this, &EmitterFor##Name); \
64 void Name##Instr::EmitNativeCode(FlowGraphCompiler* compiler) { \
65 InvokeEmitter(compiler, this, &EmitterFor##Name); \
67 static void EmitterFor##Name(FlowGraphCompiler* compiler, \
68 Name##Instr* instr, PP_APPLY(PP_UNPACK, Args))
70#define PP_UNPACK(...) __VA_ARGS__
71#define PP_APPLY(a, b) a b
91template <
typename R, R reg>
94 operator R() {
return reg; }
106 operator RegisterType() {
return reg_; }
118 static constexpr bool kIsTemp =
false;
122 template <
intptr_t arity,
intptr_t index>
124 return Unwrap(locs->
in(index));
127 template <
intptr_t arity,
intptr_t index>
129 locs->
set_in(index, ToConstraint());
142 static constexpr bool kIsTemp =
false;
146 template <
intptr_t arity,
intptr_t index>
148 return Unwrap(locs->
in(index));
151 template <
intptr_t arity,
intptr_t index>
153 locs->
set_in(index, ToConstraint());
162template <
typename R, R reg>
166 static constexpr bool kIsTemp =
false;
173 template <
intptr_t arity,
intptr_t index>
175 return Unwrap(locs->
in(index));
178 template <
intptr_t arity,
intptr_t index>
180 locs->
set_in(index, ToConstraint());
188template <
typename RegisterType>
190 static constexpr bool kIsTemp =
true;
196 template <
intptr_t arity,
intptr_t index>
198 return Unwrap(locs->
temp(index - arity));
201 template <
intptr_t arity,
intptr_t index>
203 locs->
set_temp(index - arity, ToConstraint());
213 static constexpr bool kIsTemp =
false;
224 static constexpr bool kIsTemp =
false;
236template <
typename T,
typename U>
239#define TYPE_LIST_0() Nil
240#define TYPE_LIST_1(T0) Cons<T0, TYPE_LIST_0()>
241#define TYPE_LIST_2(T0, T1) Cons<T0, TYPE_LIST_1(T1)>
242#define TYPE_LIST_3(T0, T1, T2) Cons<T0, TYPE_LIST_2(T1, T2)>
243#define TYPE_LIST_4(T0, T1, T2, T3) Cons<T0, TYPE_LIST_3(T1, T2, T3)>
244#define TYPE_LIST_5(T0, T1, T2, T3, T4) Cons<T0, TYPE_LIST_4(T1, T2, T3, T4)>
250#define SIGNATURE_TRAIT(Arity, Args) \
251 SignatureTrait<PP_APPLY(TYPE_LIST_##Arity, Args)>
258 enum { kArity = 0, kTempCount = 0, kInputCount = kArity - kTempCount };
260 template <
intptr_t kArity,
intptr_t kOffset>
264template <
typename T0,
typename Tx>
269 kArity = 1 + Tail::kArity,
271 kInputCount = kArity - kTempCount
274 template <
intptr_t kArity,
intptr_t kOffset>
277 Tail::template SetConstraints<kArity, kOffset + 1>(locs);
283template <
typename Instr,
typename Out>
290 ASSERT(instr->InputCount() == S::kInputCount);
297#define DEFINE_MAKE_LOCATION_SUMMARY_SPECIALIZATION(Arity, Types) \
298 LocationSummary* MakeLocationSummaryFromEmitter( \
299 Zone* zone, const Instr* instr, \
300 void (*Emit)(FlowGraphCompiler*, Instr*, Out, \
301 PP_APPLY(PP_UNPACK, Types))) { \
302 typedef SIGNATURE_TRAIT(Arity, Types) S; \
303 ASSERT(instr->InputCount() == S::kInputCount); \
304 LocationSummary* summary = new (zone) LocationSummary( \
305 zone, S::kInputCount, S::kTempCount, LocationSummary::kNoCall); \
306 S::template SetConstraints<S::kInputCount, 0>(summary); \
307 summary->set_out(0, LocationTrait<Out>::ToConstraint()); \
311template <
typename Instr,
typename Out,
typename T0>
314template <
typename Instr,
typename Out,
typename T0,
typename T1>
317template <
typename Instr,
typename Out,
typename T0,
typename T1,
typename T2>
320template <
typename Instr,
328template <
typename Instr,
339template <
typename Instr,
typename Out>
344 ASSERT(instr->InputCount() == S::kInputCount);
349template <
typename Instr,
typename Out,
typename T0>
354 ASSERT(instr->InputCount() == S::kInputCount);
360template <
typename Instr,
typename Out,
typename T0,
typename T1>
365 ASSERT(instr->InputCount() == S::kInputCount);
372template <
typename Instr,
typename Out,
typename T0,
typename T1,
typename T2>
377 ASSERT(instr->InputCount() == S::kInputCount);
385template <
typename Instr,
396 ASSERT(instr->InputCount() == S::kInputCount);
405template <
typename Instr,
417 ASSERT(instr->InputCount() == S::kInputCount);
429#if defined(TARGET_ARCH_IA32)
431#elif defined(TARGET_ARCH_X64)
433#elif defined(TARGET_ARCH_ARM)
435#elif defined(TARGET_ARCH_ARM64)
437#elif defined(TARGET_ARCH_RISCV32)
439#elif defined(TARGET_ARCH_RISCV64)
442#error Unknown architecture.
Location temp(intptr_t index) const
Location out(intptr_t index) const
void set_temp(intptr_t index, Location loc)
void set_out(intptr_t index, Location loc)
Location in(intptr_t index) const
void set_in(intptr_t index, Location loc)
static Location NoLocation()
static Location SameAsFirstInput()
static Location FpuRegisterLocation(FpuRegister reg)
static Location RegisterLocation(Register reg)
static Location RequiresRegister()
static Location RequiresFpuRegister()
FpuRegister fpu_reg() const
#define SIGNATURE_TRAIT(Arity, Args)
LocationSummary * MakeLocationSummaryFromEmitter(Zone *zone, const Instr *instr, void(*Emit)(FlowGraphCompiler *, Instr *, Out))
DEFINE_MAKE_LOCATION_SUMMARY_SPECIALIZATION(1,(T0))
void InvokeEmitter(FlowGraphCompiler *compiler, Instr *instr, void(*Emit)(FlowGraphCompiler *, Instr *, Out))
static Location ToConstraint()
static void SetInputConstraint(LocationSummary *locs)
static Fixed< R, reg > UnwrapInput(LocationSummary *locs)
static Fixed< R, reg > Unwrap(const Location &loc)
static FpuRegister UnwrapInput(LocationSummary *locs)
static Location ToFixedConstraint(FpuRegister reg)
static Location ToConstraint()
static FpuRegister Unwrap(const Location &loc)
static void SetInputConstraint(LocationSummary *locs)
static NoLocation Unwrap(const Location &loc)
static Location ToConstraint()
static void SetInputConstraint(LocationSummary *locs)
static Location ToFixedConstraint(Register reg)
static Location ToConstraint()
static Register Unwrap(const Location &loc)
static Register UnwrapInput(LocationSummary *locs)
static Temp< RegisterType > Unwrap(const Location &loc)
static Location ToConstraint()
static Temp< RegisterType > UnwrapInput(LocationSummary *locs)
static void SetInputConstraint(LocationSummary *locs)
static void SetConstraints(LocationSummary *locs)
SignatureTrait< Tx > Tail
static void SetConstraints(LocationSummary *locs)