18#if defined(DART_PRECOMPILER)
25 import 'dart:typed_data';
27 foo(Uint8List list, int from) {
28 if (from >= list.length) {
38 FlowGraph* flow_graph = pipeline.RunPasses({});
40 auto entry = flow_graph->graph_entry()->normal_entry();
43 LoadFieldInstr* load_field =
nullptr;
44 GenericCheckBoundInstr* bounds_check =
nullptr;
45 LoadFieldInstr* load_untagged =
nullptr;
46 LoadIndexedInstr* load_indexed =
nullptr;
48 ILMatcher cursor(flow_graph, entry);
51 {kMatchAndMoveLoadField, &load_field},
55 {kMatchAndMoveGenericCheckBound, &bounds_check},
56 {kMatchAndMoveLoadField, &load_untagged},
58 {kMatchAndMoveLoadIndexed, &load_indexed},
63 EXPECT(load_field->InputAt(0)->definition()->IsParameter());
64 EXPECT(bounds_check->length()
66 ->OriginalDefinitionIgnoreBoxingAndConstraints() == load_field);
67 EXPECT(load_untagged->InputAt(0)->definition()->IsParameter());
68 EXPECT(load_indexed->InputAt(0)->definition() == load_untagged);
75 const char* kTemplate =
77 import 'dart:typed_data';
79 void reverse%s(%s list) {
80 final length = list.length;
81 final halfLength = length >> 1;
82 for (int i = 0; i < halfLength; ++i) {
83 final tmp = list[length-i-1];
84 list[length-i-1] = list[i];
90 char script_buffer[1024];
91 char uri_buffer[1024];
93 auto& lib = Library::Handle();
96 auto check_il = [&](
const char*
name) {
98 Utils::SNPrint(script_buffer,
sizeof(script_buffer), kTemplate,
name,
name);
99 Utils::SNPrint(uri_buffer,
sizeof(uri_buffer),
"file:///reverse-%s.dart",
107 TestPipeline pipeline(
function, CompilerPass::kAOT);
108 FlowGraph* flow_graph = pipeline.RunPasses({});
109 auto entry = flow_graph->graph_entry()->normal_entry();
112 ILMatcher cursor(flow_graph, entry);
116 kMatchAndMoveLoadField,
118 kMatchAndMoveBranchTrue,
123 kMatchAndMoveGenericCheckBound,
125 kMatchAndMoveLoadField,
127 kMatchAndMoveLoadIndexed,
130 kMatchAndMoveGenericCheckBound,
132 kMatchAndMoveLoadField,
134 kMatchAndMoveLoadIndexed,
137 kMatchAndMoveCheckWritable,
139 kMatchAndMoveLoadField,
141 kMatchAndMoveStoreIndexed,
145 kMatchAndMoveLoadField,
147 kMatchAndMoveStoreIndexed,
151 kMatchAndMoveBranchFalse,
157 check_il(
"Uint8List");
158 check_il(
"Int8List");
159 check_il(
"Uint8ClampedList");
160 check_il(
"Int16List");
161 check_il(
"Uint16List");
162 check_il(
"Int32List");
163 check_il(
"Uint32List");
164 check_il(
"Int64List");
165 check_il(
"Uint64List");
166 check_il(
"Float32List");
167 check_il(
"Float64List");
168 if (FlowGraphCompiler::SupportsUnboxedSimd128()) {
169 check_il(
"Int32x4List");
170 check_il(
"Float32x4List");
171 check_il(
"Float64x2List");
177 const char* kTemplate =
179 import 'dart:typed_data';
180 void set%s(%s list, int index, %s value) {
185 char script_buffer[1024];
186 char uri_buffer[1024];
188 auto& lib = Library::Handle();
189 auto&
function = Function::Handle();
190 auto& arguments = Array::Handle();
191 auto&
result = Object::Handle();
193 const intptr_t
kIndex = 1;
194 const intptr_t kLastStage = 3;
197 const TypedDataBase&
data,
const Object&
value,
200 Utils::SNPrint(script_buffer,
sizeof(script_buffer), kTemplate,
name,
name,
202 Utils::SNPrint(uri_buffer,
sizeof(uri_buffer),
"file:///set-%s.dart",
name);
209 TestPipeline pipeline(
function, CompilerPass::kAOT);
210 FlowGraph* flow_graph = pipeline.RunPasses({});
211 auto entry = flow_graph->graph_entry()->normal_entry();
214 ILMatcher cursor(flow_graph, entry,
true);
218 kMatchAndMoveLoadField,
222 kMatchAndMoveGenericCheckBound,
226 kMatchAndMoveLoadField,
228 kMatchAndMoveOptionalUnbox,
230 kMatchAndMoveStoreIndexed,
238 pipeline.CompileGraphAndAttachFunction();
240 arguments = Array::New(3);
241 arguments.SetAt(0, stage == 0 ? Object::null_object() :
data);
243 1, stage == 1 ? Object::null_object() : Smi::Handle(Smi::New(kIndex)));
244 arguments.SetAt(2, stage == 2 ? Object::null_object() :
value);
250 if (stage == kLastStage) {
260 const auto& uint8_list =
261 TypedData::Handle(TypedData::New(kTypedDataUint8ArrayCid, 16));
262 const auto& uint8c_list =
263 TypedData::Handle(TypedData::New(kTypedDataUint8ClampedArrayCid, 16));
264 const auto& int16_list =
265 TypedData::Handle(TypedData::New(kTypedDataInt16ArrayCid, 16));
266 const auto& uint16_list =
267 TypedData::Handle(TypedData::New(kTypedDataUint16ArrayCid, 16));
268 const auto& int32_list =
269 TypedData::Handle(TypedData::New(kTypedDataInt32ArrayCid, 16));
270 const auto& uint32_list =
271 TypedData::Handle(TypedData::New(kTypedDataUint32ArrayCid, 16));
272 const auto& int64_list =
273 TypedData::Handle(TypedData::New(kTypedDataInt64ArrayCid, 16));
274 const auto& uint64_list =
275 TypedData::Handle(TypedData::New(kTypedDataUint64ArrayCid, 16));
276 const auto& float32_list =
277 TypedData::Handle(TypedData::New(kTypedDataFloat32ArrayCid, 16));
278 const auto& float64_list =
279 TypedData::Handle(TypedData::New(kTypedDataFloat64ArrayCid, 16));
280 const auto& int8_list =
281 TypedData::Handle(TypedData::New(kTypedDataInt8ArrayCid, 16));
282 const auto& int_value = Integer::Handle(Integer::New(42));
283 const auto& float_value = Double::Handle(Double::New(4.2));
286 const intptr_t first_stage = kLastStage;
287 for (intptr_t stage = first_stage; stage <= kLastStage; ++stage) {
288 run_test(
"Uint8List",
"int", int8_list, int_value, stage);
289 run_test(
"Int8List",
"int", uint8_list, int_value, stage);
290 run_test(
"Uint8ClampedList",
"int", uint8c_list, int_value, stage);
291 run_test(
"Int16List",
"int", int16_list, int_value, stage);
292 run_test(
"Uint16List",
"int", uint16_list, int_value, stage);
293 run_test(
"Int32List",
"int", int32_list, int_value, stage);
294 run_test(
"Uint32List",
"int", uint32_list, int_value, stage);
295 run_test(
"Int64List",
"int", int64_list, int_value, stage);
296 run_test(
"Uint64List",
"int", uint64_list, int_value, stage);
297 run_test(
"Float32List",
"double", float32_list, float_value, stage);
298 run_test(
"Float64List",
"double", float64_list, float_value, stage);
static void run_test(GrDirectContext *dContext, skiatest::Reporter *reporter, BulkRectTest test)
#define RELEASE_ASSERT(cond)
Dart_NativeFunction function
LibraryPtr LoadTestScript(const char *script, Dart_NativeEntryResolver resolver, const char *lib_uri)
@ kMatchAndMoveBranchTrue
FunctionPtr GetFunction(const Library &lib, const char *name)
ISOLATE_UNIT_TEST_CASE(StackAllocatedDestruction)
const char *const function_name
DEF_SWITCHES_START aot vmservice shared library name
static Dart_Handle InvokeFunction(Dart_Handle builtin_library, const char *name)
std::shared_ptr< const fml::Mapping > data
#define ISOLATE_UNIT_TEST_CASE(name)