5#ifndef RUNTIME_VM_COMPILER_BACKEND_IL_TEST_HELPER_H_
6#define RUNTIME_VM_COMPILER_BACKEND_IL_TEST_HELPER_H_
77 bool is_optimizing =
true)
79 thread_(
Thread::Current()),
80 compiler_state_(thread_,
84 hierarchy_info_(thread_),
108 std::unique_ptr<SpeculativeInliningPolicy> speculative_policy_;
119#define DEFINE_MATCH_OPCODES(Instruction, _) \
120 kMatch##Instruction, kMatchAndMove##Instruction, \
121 kMatchAndMoveOptional##Instruction,
124#undef DEFINE_MATCH_OPCODES
156 : opcode_(
opcode), capture_(nullptr) {}
159 : opcode_(
opcode), capture_(capture) {}
161#define DEFINE_TYPED_CONSTRUCTOR(Type, ignored) \
162 MatchCode(MatchOpCode opcode, Type##Instr** capture) \
163 : opcode_(opcode), capture_(reinterpret_cast<Instruction**>(capture)) { \
164 RELEASE_ASSERT(opcode == kMatch##Type || opcode == kMatchAndMove##Type); \
168#undef DEFINE_TYPED_CONSTRUCTOR
214 : flow_graph_(flow_graph),
216 parallel_moves_handling_(parallel_moves_handling),
234 bool TryMatch(std::initializer_list<MatchCode> match_codes,
238 Instruction* MatchInternal(std::vector<MatchCode> match_codes,
242 const char* MatchOpCodeToCString(
MatchOpCode code);
251#define ENTITY_TOCSTRING(v) ((v)->ToCString())
253#define ENTITY_TOCSTRING(v) "<?>"
261#define EXPECT_PROPERTY(entity, property) \
263 auto& it = *entity; \
265 dart::Expect(__FILE__, __LINE__) \
266 .Fail("expected " #property " for " #entity " which is %s.\n", \
267 ENTITY_TOCSTRING(entity)); \
275 flow_graph_(MakeDummyGraph(
Thread::Current(),
277 state_.is_optimizing())) {
306 new LocalVariable(TokenPosition::kNoSource, TokenPosition::kNoSource,
327 template <
typename T,
328 typename =
typename std::enable_if<
329 std::is_base_of<Definition, T>::value>
::type>
350 std::initializer_list<IncomingDef> incoming) {
351 auto phi =
new PhiInstr(join, incoming.size());
352 for (
size_t i = 0; i < incoming.size(); i++) {
354 phi->SetInputAt(i, input);
355 input->definition()->AddInputUse(input);
357 for (
auto def : incoming) {
358 pending_phis_.
Add({phi, def});
368 for (
auto& pending : pending_phis_) {
369 auto join = pending.phi->block();
370 EXPECT(pending.phi->InputCount() == join->PredecessorCount());
371 auto pred_index = join->IndexOfPredecessor(pending.incoming.from());
373 pending.phi->InputAt(pred_index)->BindTo(pending.incoming.defn());
381 intptr_t num_parameters,
382 bool is_optimizing) {
388 UntaggedFunction::kRegularFunction,
395 TokenPosition::kNoSource));
405 const intptr_t block_id = 1;
406 graph_entry->set_normal_entry(
409 return *
new FlowGraph(*parsed_function, graph_entry, block_id,
414 CompilerState& state_;
415 FlowGraph& flow_graph_;
417 struct PendingPhiInput {
419 IncomingDef incoming;
421 GrowableArray<PendingPhiInput> pending_phis_;
static constexpr bool kCannotBeSentinel
static constexpr bool kCanBeNull
static CompileType FromAbstractType(const AbstractType &type, bool can_be_null, bool can_be_sentinel)
intptr_t GetNextDeoptId()
static CompilerState & Current()
static constexpr intptr_t kNoOSRDeoptId
static DoublePtr NewCanonical(double d)
IncomingDef(BlockEntryInstr *from, T **defn_source)
Definition * defn() const
IncomingDef(BlockEntryInstr *from, Definition *defn)
BlockEntryInstr * from() const
Definition ** defn_source_
JoinEntryInstr * JoinEntry(intptr_t try_index=kInvalidTryIndex) const
PhiInstr * Phi(JoinEntryInstr *join, std::initializer_list< IncomingDef > incoming)
void AddVariable(const char *name, const AbstractType &static_type, CompileType *inferred_arg_type=nullptr)
ConstantInstr * IntConstant(int64_t value) const
TargetEntryInstr * TargetEntry(intptr_t try_index=kInvalidTryIndex) const
ConstantInstr * DoubleConstant(double value)
FlowGraphBuilderHelper(intptr_t num_parameters=0)
ConstantInstr * GetConstant(const Object &object, Representation representation=kTagged)
static constexpr CompilationMode CompilationModeFrom(bool is_optimizing)
ConstantInstr * constant_dead() const
void CreateCommonConstants()
void ComputeDominators(GrowableArray< BitVector * > *dominance_frontier)
const ParsedFunction & parsed_function() const
intptr_t allocate_block_id()
void set_num_fixed_parameters(intptr_t value) const
static FunctionTypePtr New(intptr_t num_parent_type_arguments=0, Nullability nullability=Nullability::kLegacy, Heap::Space space=Heap::kOld)
static FunctionPtr New(const FunctionType &signature, const String &name, UntaggedFunction::Kind kind, bool is_static, bool is_const, bool is_abstract, bool is_external, bool is_native, const Object &owner, TokenPosition token_pos, Heap::Space space=Heap::kOld)
ILMatcher(FlowGraph *flow_graph, Instruction *cursor, bool trace=true, ParallelMovesHandling parallel_moves_handling=ParallelMovesHandling::kDefault)
bool TryMatch(std::initializer_list< MatchCode > match_codes, MatchOpCode insert_before=kInvalidMatchOpCode)
static IntegerPtr NewCanonical(const String &str)
ObjectStore * object_store() const
bool AddVariable(LocalVariable *variable)
void set_type_check_mode(TypeCheckMode mode)
static constexpr intptr_t kNoKernelOffset
MatchCode(MatchOpCode opcode, Instruction **capture)
MatchCode(MatchOpCode opcode)
static Object & ZoneHandle()
LocalScope * scope() const
void set_scope(LocalScope *scope)
static StringPtr New(Thread *thread, const char *cstr)
void RunAdditionalPasses(std::initializer_list< CompilerPass::Id > passes)
FlowGraph * RunPasses(std::initializer_list< CompilerPass::Id > passes)
void CompileGraphAndAttachFunction()
TestPipeline(const Function &function, CompilerPass::PipelineMode mode, bool is_optimizing=true)
void RunForcedOptimizedAfterSSAPasses()
static Thread * Current()
IsolateGroup * isolate_group() const
Dart_NativeFunction(* Dart_NativeEntryResolver)(Dart_Handle name, int num_of_arguments, bool *auto_setup_scope)
Dart_NativeFunction function
#define FOR_EACH_INSTRUCTION(M)
#define FOR_EACH_ABSTRACT_INSTRUCTION(M)
#define DEFINE_MATCH_OPCODES(Instruction, _)
#define DEFINE_TYPED_CONSTRUCTOR(Type, ignored)
LibraryPtr LoadTestScript(const char *script, Dart_NativeEntryResolver resolver, const char *lib_uri)
@ kMatchAndMoveBranchFalse
@ kMatchAndMoveBranchTrue
ObjectPtr Invoke(const Library &lib, const char *name)
FunctionPtr GetFunction(const Library &lib, const char *name)
LibraryPtr ReloadTestScript(const char *script)
ClassPtr GetClass(const Library &lib, const char *name)
TypeParameterPtr GetClassTypeParameter(const Class &klass, intptr_t index)
TypeParameterPtr GetFunctionTypeParameter(const Function &fun, intptr_t index)
InstructionsPtr BuildInstructions(std::function< void(compiler::Assembler *assembler)> fun)
static constexpr intptr_t kInvalidTryIndex
#define RESOLVED_USER_TEST_URI
#define NOT_IN_PRODUCT(code)