17 const char* kScript = R
"(
29 Invoke(root_library,
"test");
33 CompilerPass::kComputeSSA,
44 kMatchAndMoveFunctionEntry,
45 kMatchAndMoveCheckStackOverflow,
47 {kMatchDartReturn, &ret},
51 EXPECT(ret->value()->BindsToConstant());
52 EXPECT(ret->value()->BoundConstant().IsString());
53 const String& ret_str = String::Cast(ret->value()->BoundConstant());
54 EXPECT(ret_str.Equals(
"aaaabbbbcccc"));
59 const char* kScript = R
"(
61 return '$s' '${'d' 'e'}';
66 const auto& root_library = Library::Handle(
LoadTestScript(kScript));
69 Invoke(root_library,
"main");
73 CompilerPass::kComputeSSA,
85 kMatchAndMoveFunctionEntry,
86 kMatchAndMoveCheckStackOverflow,
88 kMatchAndMoveCreateArray,
89 {kMatchAndMoveStoreIndexed, &store1},
90 {kMatchAndMoveStoreIndexed, &store2},
91 kMatchAndMoveRecordCoverage,
92 kMatchAndMoveStaticCall,
99 EXPECT(store1->index()->BindsToConstant());
100 EXPECT(store1->index()->BoundConstant().IsInteger());
101 EXPECT(Integer::Cast(store1->index()->BoundConstant()).AsInt64Value() == 0);
103 EXPECT(!store1->value()->BindsToConstant());
108 EXPECT(Integer::Cast(
store2->index()->BoundConstant()).AsInt64Value() == 1);
112 EXPECT(String::Cast(
store2->value()->BoundConstant()).Equals(
"de"));
117 const char* kScript = R
"(
119 return '' 'a' '$s' '' 'b' '';
124 const auto& root_library = Library::Handle(
LoadTestScript(kScript));
127 Invoke(root_library,
"main");
131 CompilerPass::kComputeSSA,
144 kMatchAndMoveFunctionEntry,
145 kMatchAndMoveCheckStackOverflow,
146 kMoveDebugStepChecks,
147 kMatchAndMoveCreateArray,
148 {kMatchAndMoveStoreIndexed, &store1},
149 {kMatchAndMoveStoreIndexed, &store2},
150 {kMatchAndMoveStoreIndexed, &store3},
151 kMatchAndMoveRecordCoverage,
152 kMatchAndMoveStaticCall,
159 EXPECT(store1->index()->BindsToConstant());
160 EXPECT(store1->index()->BoundConstant().IsInteger());
161 EXPECT(Integer::Cast(store1->index()->BoundConstant()).AsInt64Value() == 0);
163 EXPECT(store1->value()->BindsToConstant());
164 EXPECT(store1->value()->BoundConstant().IsString());
165 EXPECT(String::Cast(store1->value()->BoundConstant()).Equals(
"a"));
170 EXPECT(Integer::Cast(
store2->index()->BoundConstant()).AsInt64Value() == 1);
175 EXPECT(store3->index()->BindsToConstant());
176 EXPECT(store3->index()->BoundConstant().IsInteger());
177 EXPECT(Integer::Cast(store3->index()->BoundConstant()).AsInt64Value() == 2);
179 EXPECT(store3->value()->BindsToConstant());
180 EXPECT(store3->value()->BoundConstant().IsString());
181 EXPECT(String::Cast(store3->value()->BoundConstant()).Equals(
"b"));
186 const char* kScript = R
"(
188 return '' 'a' '' 'b' '$s' '' 'c' '' 'd' '';
193 const auto& root_library = Library::Handle(
LoadTestScript(kScript));
196 Invoke(root_library,
"main");
200 CompilerPass::kComputeSSA,
213 kMatchAndMoveFunctionEntry,
214 kMatchAndMoveCheckStackOverflow,
215 kMoveDebugStepChecks,
216 kMatchAndMoveCreateArray,
217 {kMatchAndMoveStoreIndexed, &store1},
218 {kMatchAndMoveStoreIndexed, &store2},
219 {kMatchAndMoveStoreIndexed, &store3},
220 kMatchAndMoveRecordCoverage,
221 kMatchAndMoveStaticCall,
228 EXPECT(store1->index()->BindsToConstant());
229 EXPECT(store1->index()->BoundConstant().IsInteger());
230 EXPECT(Integer::Cast(store1->index()->BoundConstant()).AsInt64Value() == 0);
232 EXPECT(store1->value()->BindsToConstant());
233 EXPECT(store1->value()->BoundConstant().IsString());
234 EXPECT(String::Cast(store1->value()->BoundConstant()).Equals(
"ab"));
239 EXPECT(Integer::Cast(
store2->index()->BoundConstant()).AsInt64Value() == 1);
244 EXPECT(store3->index()->BindsToConstant());
245 EXPECT(store3->index()->BoundConstant().IsInteger());
246 EXPECT(Integer::Cast(store3->index()->BoundConstant()).AsInt64Value() == 2);
248 EXPECT(store3->value()->BindsToConstant());
249 EXPECT(store3->value()->BoundConstant().IsString());
250 EXPECT(String::Cast(store3->value()->BoundConstant()).Equals(
"cd"));
254 const char* kScript = R
"(
260 const auto& root_library = Library::Handle(
LoadTestScript(kScript));
263 Invoke(root_library,
"test");
267 CompilerPass::kComputeSSA,
278 kMatchAndMoveFunctionEntry,
279 kMatchAndMoveCheckStackOverflow,
280 kMoveDebugStepChecks,
281 kMatchAndMoveRecordCoverage,
282 kMatchAndMoveStaticCall,
283 kMatchAndMoveRecordCoverage,
284 kMatchAndMoveStaticCall,
285 kMatchAndMoveRecordCoverage,
286 {kMatchAndMoveInstanceCall, &call_add},
292 EXPECT(call_add !=
nullptr);
293 EXPECT(call_add->function_name().Equals(
"add"));
294 EXPECT(call_add->entry_kind() == Code::EntryKind::kUnchecked);
315 const char* kScript = R
"(
316 int callClosure(int Function(int) fun, int value) => fun(value);
317 test() => callClosure((int a) => a + 1, 10);
320 const auto& root_library = Library::Handle(
LoadTestScript(kScript));
321 Invoke(root_library,
"test");
323 const auto& callClosureFunction =
324 Function::Handle(
GetFunction(root_library,
"callClosure"));
325 TestPipeline pipeline(callClosureFunction, CompilerPass::kJIT);
327 CompilerPass::kComputeSSA,
333 ILMatcher cursor(flow_graph, entry,
true);
335 std::initializer_list<MatchCode> expected = {
336 kMatchAndMoveFunctionEntry,
337 kMatchAndMoveCheckStackOverflow,
339 kMatchAndMoveCheckNull,
340 kMatchAndMoveLoadField,
343 kMatchAndMoveRecordCoverage,
345 kMatchAndMoveClosureCall,
354 StreamingFlowGraphBuilder_StaticGetFinalFieldWithTrivialInitializer) {
355 const char* kScript = R
"(
356 final int x = 0xFEEDFEED;
362 const auto& root_library = Library::Handle(
LoadTestScript(kScript));
365 Invoke(root_library,
"test");
369 CompilerPass::kComputeSSA,
379 kMatchAndMoveFunctionEntry,
380 kMatchAndMoveCheckStackOverflow,
381 kMoveDebugStepChecks,
382 {kMatchDartReturn, &return_instr},
385 EXPECT(return_instr !=
nullptr);
386 ConstantInstr* const_value =
387 return_instr->value()->definition()->AsConstant();
388 EXPECT(const_value !=
nullptr);
389 EXPECT(const_value->value().IsInteger());
390 EXPECT_EQ(0xFEEDFEED, Integer::Cast(const_value->value()).AsInt64Value());
#define RELEASE_ASSERT(cond)
GraphEntryInstr * graph_entry() const
FunctionEntryInstr * normal_entry() const
bool TryMatch(std::initializer_list< MatchCode > match_codes, MatchOpCode insert_before=kInvalidMatchOpCode)
FlowGraph * RunPasses(std::initializer_list< CompilerPass::Id > passes)
Dart_NativeFunction function
SI void store2(uint16_t *ptr, U16 r, U16 g)
LibraryPtr LoadTestScript(const char *script, Dart_NativeEntryResolver resolver, const char *lib_uri)
ObjectPtr Invoke(const Library &lib, const char *name)
FunctionPtr GetFunction(const Library &lib, const char *name)
ISOLATE_UNIT_TEST_CASE(StackAllocatedDestruction)
#define ISOLATE_UNIT_TEST_CASE(name)