5#ifndef RUNTIME_VM_COMPILER_FRONTEND_KERNEL_BINARY_FLOWGRAPH_H_
6#define RUNTIME_VM_COMPILER_FRONTEND_KERNEL_BINARY_FLOWGRAPH_H_
8#if defined(DART_PRECOMPILED_RUNTIME)
9#error "AOT runtime should not use compiler sources (including header files)"
27 intptr_t data_program_offset)
32 flow_graph_builder_(flow_graph_builder),
33 active_class_(&flow_graph_builder->active_class_),
34 constant_reader_(this, active_class_),
35 type_translator_(this,
39 direct_call_metadata_helper_(this),
40 inferred_type_metadata_helper_(this, &constant_reader_),
41 procedure_attributes_metadata_helper_(this),
42 call_site_attributes_metadata_helper_(this, &type_translator_),
43 closure_owner_(
Object::Handle(flow_graph_builder->
zone_)) {}
56 Thread* thread()
const {
return flow_graph_builder_->thread_; }
58 void ParseKernelASTFunction();
60 void SetupDefaultParameterValues();
62 FlowGraph* BuildGraphOfFieldInitializer();
63 Fragment BuildFieldInitializer(
const Field& field,
64 bool only_for_side_effects);
65 Fragment BuildLateFieldInitializer(
const Field& field,
bool has_initializer);
66 Fragment BuildInitializers(
const Class& parent_class);
67 FlowGraph* BuildGraphOfFunction(
bool constructor);
71 Fragment BuildStatementWithBranchCoverage(
TokenPosition* position =
nullptr);
75 Fragment BuildFunctionBody(
const Function& dart_function,
80 Fragment BuildRegularFunctionPrologue(
const Function& dart_function,
83 Fragment ClearRawParameters(
const Function& dart_function);
84 Fragment DebugStepCheckInPrologue(
const Function& dart_function,
86 Fragment CheckStackOverflowInPrologue(
const Function& dart_function);
87 Fragment SetupCapturedParameters(
const Function& dart_function);
88 Fragment InitSuspendableFunction(
const Function& dart_function,
90 Fragment ShortcutForUserDefinedEquals(
const Function& dart_function,
92 Fragment TypeArgumentsHandling(
const Function& dart_function);
95 if (active_class_ !=
nullptr) {
102 const Function& dart_function,
103 const Fragment& implicit_type_checks,
104 const Fragment& regular_function_prologue,
105 const Fragment& type_args_handling);
107 void loop_depth_inc();
108 void loop_depth_dec();
109 void catch_depth_inc();
110 void catch_depth_dec();
111 void try_depth_inc();
112 void try_depth_dec();
113 intptr_t block_expression_depth();
114 void block_expression_depth_inc();
115 void block_expression_depth_dec();
116 void synthetic_error_handler_depth_inc();
117 void synthetic_error_handler_depth_dec();
118 intptr_t CurrentTryIndex();
119 intptr_t AllocateTryIndex();
120 LocalVariable* CurrentException();
121 LocalVariable* CurrentStackTrace();
122 CatchBlock* catch_block();
123 ActiveClass* active_class();
124 ScopeBuildingResult* scopes();
125 void set_scopes(ScopeBuildingResult* scope);
126 ParsedFunction* parsed_function();
127 TryFinallyBlock* try_finally_block();
128 SwitchBlock* switch_block();
129 BreakableBlock* breakable_block();
131 void set_stack(
Value* top);
132 void Push(Definition* definition);
134 Class& GetSuperOrDie();
136 Tag PeekArgumentsFirstPositionalTag();
137 const TypeArguments& PeekArgumentsInstantiatedType(
const Class& klass);
138 intptr_t PeekArgumentsCount();
140 TokenPosition ReadPosition();
143 LocalVariable* MakeTemporary(
const char*
suffix =
nullptr);
144 Fragment DropTemporary(LocalVariable** variable);
146 LocalVariable* LookupVariable(intptr_t kernel_offset);
147 Function& FindMatchingFunction(
const Class& klass,
151 const Array& argument_names);
153 bool NeedsDebugStepCheck(
const Function&
function, TokenPosition position);
154 bool NeedsDebugStepCheck(
Value*
value, TokenPosition position);
156 void InlineBailout(
const char* reason);
157 Fragment DebugStepCheck(TokenPosition position);
158 Fragment LoadLocal(LocalVariable* variable);
159 IndirectGotoInstr* IndirectGoto(intptr_t target_count);
160 Fragment Return(TokenPosition position);
161 Fragment EvaluateAssertion();
162 Fragment RethrowException(TokenPosition position,
int catch_try_index);
163 Fragment ThrowNoSuchMethodError(TokenPosition position,
165 bool incompatible_arguments);
166 Fragment Constant(
const Object&
value);
167 Fragment IntConstant(int64_t
value);
168 Fragment LoadStaticField(
const Field& field,
bool calls_initializer);
169 Fragment RedefinitionWithType(
const AbstractType&
type);
170 Fragment CheckNull(TokenPosition position,
171 LocalVariable* receiver,
173 Fragment StaticCall(TokenPosition position,
177 Fragment StaticCall(TokenPosition position,
180 const Array& argument_names,
182 const InferredTypeMetadata* result_type =
nullptr,
183 intptr_t type_args_len = 0,
184 bool use_unchecked_entry =
false);
185 Fragment StaticCallMissing(TokenPosition position,
186 const String& selector,
190 Fragment InstanceCall(TokenPosition position,
194 intptr_t checked_argument_count = 1);
195 Fragment InstanceCall(
196 TokenPosition position,
199 intptr_t type_args_len,
201 const Array& argument_names,
202 intptr_t checked_argument_count,
203 const Function& interface_target,
204 const Function& tearoff_interface_target,
205 const InferredTypeMetadata* result_type =
nullptr,
206 bool use_unchecked_entry =
false,
207 const CallSiteAttributesMetadata* call_site_attrs =
nullptr,
208 bool receiver_is_not_smi =
false,
209 bool is_call_on_this =
false);
211 Fragment ThrowException(TokenPosition position);
212 Fragment BooleanNegate();
213 Fragment TranslateInstantiatedTypeArguments(
214 const TypeArguments& type_arguments);
215 Fragment StrictCompare(TokenPosition position,
217 bool number_check =
false);
218 Fragment AllocateObject(TokenPosition position,
221 Fragment AllocateContext(
const ZoneGrowableArray<const Slot*>& context_slots);
222 Fragment LoadNativeField(
const Slot& field,
225 Fragment StoreLocal(TokenPosition position, LocalVariable* variable);
226 Fragment StoreStaticField(TokenPosition position,
const Field& field);
227 Fragment StringInterpolate(TokenPosition position);
228 Fragment StringInterpolateSingle(TokenPosition position);
229 Fragment ThrowTypeError();
230 Fragment LoadInstantiatorTypeArguments();
231 Fragment LoadFunctionTypeArguments();
232 Fragment InstantiateType(
const AbstractType&
type);
233 Fragment CreateArray();
234 Fragment StoreIndexed(intptr_t class_id);
235 Fragment CheckStackOverflow(TokenPosition position);
236 Fragment CloneContext(
const ZoneGrowableArray<const Slot*>& context_slots);
237 Fragment TranslateFinallyFinalizers(TryFinallyBlock* outer_finally,
238 intptr_t target_context_depth);
239 Fragment BranchIfTrue(TargetEntryInstr** then_entry,
240 TargetEntryInstr** otherwise_entry,
242 Fragment BranchIfEqual(TargetEntryInstr** then_entry,
243 TargetEntryInstr** otherwise_entry,
244 bool negate =
false);
245 Fragment BranchIfNull(TargetEntryInstr** then_entry,
246 TargetEntryInstr** otherwise_entry,
247 bool negate =
false);
248 Fragment CatchBlockEntry(
const Array& handler_types,
249 intptr_t handler_index,
250 bool needs_stacktrace,
251 bool is_synthesized);
252 Fragment TryCatch(
int try_handler_index);
254 Fragment DropArguments(intptr_t
argument_count, intptr_t type_args_count);
257 Fragment DropTempsPreserveTop(intptr_t num_temps_to_drop);
260 Fragment NullConstant();
261 JoinEntryInstr* BuildJoinEntry();
262 JoinEntryInstr* BuildJoinEntry(intptr_t try_index);
263 Fragment Goto(JoinEntryInstr* destination);
264 Fragment CheckBoolean(TokenPosition position);
265 Fragment CheckArgumentType(LocalVariable* variable,
const AbstractType&
type);
266 Fragment RecordCoverage(TokenPosition position);
267 Fragment EnterScope(intptr_t kernel_offset,
268 const LocalScope** scope =
nullptr);
269 Fragment ExitScope(intptr_t kernel_offset);
271 TestFragment TranslateConditionForControl();
273 const TypeArguments& BuildTypeArguments();
274 Fragment BuildArguments(Array* argument_names,
276 intptr_t* positional_argument_count);
277 Fragment BuildArgumentsFromActualArguments(Array* argument_names);
279 Fragment BuildInvalidExpression(TokenPosition* position);
280 Fragment BuildVariableGet(TokenPosition* position);
281 Fragment BuildVariableGet(uint8_t payload, TokenPosition* position);
282 Fragment BuildVariableGetImpl(intptr_t variable_kernel_position,
283 TokenPosition position);
284 Fragment BuildVariableSet(TokenPosition* position);
285 Fragment BuildVariableSet(uint8_t payload, TokenPosition* position);
286 Fragment BuildVariableSetImpl(TokenPosition position,
287 intptr_t variable_kernel_position);
288 Fragment BuildInstanceGet(TokenPosition* position);
289 Fragment BuildDynamicGet(TokenPosition* position);
290 Fragment BuildInstanceTearOff(TokenPosition* position);
291 Fragment BuildInstanceSet(TokenPosition* position);
292 Fragment BuildDynamicSet(TokenPosition* position);
293 Fragment BuildAllocateInvocationMirrorCall(TokenPosition position,
295 intptr_t num_type_arguments,
296 intptr_t num_arguments,
297 const Array& argument_names,
298 LocalVariable* actuals_array,
299 Fragment build_rest_of_actuals);
300 Fragment BuildSuperPropertyGet(TokenPosition* position);
301 Fragment BuildSuperPropertySet(TokenPosition* position);
302 Fragment BuildStaticGet(TokenPosition* position);
303 Fragment BuildStaticSet(TokenPosition* position);
304 Fragment BuildMethodInvocation(TokenPosition* position,
bool is_dynamic);
305 Fragment BuildLocalFunctionInvocation(TokenPosition* position);
306 Fragment BuildFunctionInvocation(TokenPosition* position);
307 Fragment BuildEqualsCall(TokenPosition* position);
308 Fragment BuildEqualsNull(TokenPosition* position);
309 Fragment BuildSuperMethodInvocation(TokenPosition* position);
310 Fragment BuildStaticInvocation(TokenPosition* position);
311 Fragment BuildConstructorInvocation(TokenPosition* position);
312 Fragment BuildNot(TokenPosition* position);
313 Fragment BuildNullCheck(TokenPosition* position);
314 Fragment BuildLogicalExpression(TokenPosition* position);
315 Fragment TranslateLogicalExpressionForValue(
bool negated,
316 TestFragment* side_exits);
317 Fragment BuildConditionalExpression(TokenPosition* position);
318 Fragment BuildStringConcatenation(TokenPosition* position);
319 Fragment BuildIsTest(TokenPosition position,
const AbstractType&
type);
320 Fragment BuildRecordIsTest(TokenPosition position,
const RecordType&
type);
321 Fragment BuildIsExpression(TokenPosition* position);
322 Fragment BuildAsExpression(TokenPosition* position);
323 Fragment BuildTypeLiteral(TokenPosition* position);
324 Fragment BuildThisExpression(TokenPosition* position);
325 Fragment BuildRethrow(TokenPosition* position);
326 Fragment BuildThrow(TokenPosition* position);
327 Fragment BuildListLiteral(TokenPosition* position);
328 Fragment BuildMapLiteral(TokenPosition* position);
329 Fragment BuildRecordLiteral(TokenPosition* position);
330 Fragment BuildRecordFieldGet(TokenPosition* position,
bool is_named);
331 Fragment BuildFunctionExpression();
332 Fragment BuildLet(TokenPosition* position);
333 Fragment BuildBlockExpression();
334 Fragment BuildBigIntLiteral(TokenPosition* position);
335 Fragment BuildStringLiteral(TokenPosition* position);
336 Fragment BuildIntLiteral(uint8_t payload, TokenPosition* position);
337 Fragment BuildIntLiteral(
bool is_negative, TokenPosition* position);
338 Fragment BuildDoubleLiteral(TokenPosition* position);
339 Fragment BuildBoolLiteral(
bool value, TokenPosition* position);
340 Fragment BuildNullLiteral(TokenPosition* position);
341 Fragment BuildFutureNullValue(TokenPosition* position);
342 Fragment BuildConstantExpression(TokenPosition* position,
Tag tag);
343 Fragment BuildPartialTearoffInstantiation(TokenPosition* position);
344 Fragment BuildLibraryPrefixAction(TokenPosition* position,
345 const String& selector);
346 Fragment BuildAwaitExpression(TokenPosition* position);
347 Fragment BuildFileUriExpression(TokenPosition* position);
349 Fragment BuildExpressionStatement(TokenPosition* position);
350 Fragment BuildBlock(TokenPosition* position);
351 Fragment BuildEmptyStatement();
352 Fragment BuildAssertBlock(TokenPosition* position);
353 Fragment BuildAssertStatement(TokenPosition* position);
354 Fragment BuildLabeledStatement(TokenPosition* position);
355 Fragment BuildBreakStatement(TokenPosition* position);
356 Fragment BuildWhileStatement(TokenPosition* position);
357 Fragment BuildDoStatement(TokenPosition* position);
358 Fragment BuildForStatement(TokenPosition* position);
359 Fragment BuildSwitchStatement(TokenPosition* position);
360 Fragment BuildSwitchCase(SwitchHelper* helper, intptr_t case_index);
361 Fragment BuildLinearScanSwitch(SwitchHelper* helper);
362 Fragment BuildOptimizedSwitchPrelude(SwitchHelper* helper,
363 JoinEntryInstr*
join);
364 Fragment BuildBinarySearchSwitch(SwitchHelper* helper);
365 Fragment BuildJumpTableSwitch(SwitchHelper* helper);
366 Fragment BuildContinueSwitchStatement(TokenPosition* position);
367 Fragment BuildIfStatement(TokenPosition* position);
368 Fragment BuildReturnStatement(TokenPosition* position);
369 Fragment BuildTryCatch(TokenPosition* position);
370 Fragment BuildTryFinally(TokenPosition* position);
371 Fragment BuildYieldStatement(TokenPosition* position);
372 Fragment BuildVariableDeclaration(TokenPosition* position);
373 Fragment BuildFunctionDeclaration(TokenPosition* position);
374 Fragment BuildFunctionNode(intptr_t func_decl_offset);
377 Fragment BuildNativeEffect();
381 Fragment BuildReachabilityFence();
386 Fragment BuildLoadStoreAbiSpecificInt(
bool is_store,
bool at_index);
389 Fragment BuildFfiCall();
395 Fragment BuildFfiNativeAddressOf();
397 Fragment BuildArgumentsCachableIdempotentCall(intptr_t*
argument_count);
398 Fragment BuildCachableIdempotentCall(TokenPosition position,
405 const String* literal;
409 struct PiecesCollector {
410 explicit PiecesCollector(Zone* z, TranslationHelper* translation_helper)
413 translation_helper(translation_helper) {}
415 GrowableArray<ConcatPiece> pieces;
416 GrowableHandlePtrArray<const String> literal_run;
417 TranslationHelper* translation_helper;
419 void Add(
const ConcatPiece& piece) {
420 if (piece.literal !=
nullptr) {
421 literal_run.Add(*piece.literal);
429 switch (literal_run.length()) {
433 pieces.Add({-1, &literal_run[0]});
436 pieces.Add({-1, &translation_helper->DartString(literal_run)});
446 void FlattenStringConcatenation(PiecesCollector* collector);
448 FlowGraphBuilder* flow_graph_builder_;
449 ActiveClass*
const active_class_;
456 Object& closure_owner_;
457 intptr_t num_ast_nodes_ = 0;
458 intptr_t synthetic_error_handler_depth_ = 0;
friend class TypeTranslator
TranslationHelper & translation_helper_
friend class DirectCallMetadataHelper
friend class ProcedureAttributesMetadataHelper
friend class CallSiteAttributesMetadataHelper
friend class InferredTypeMetadataHelper
friend class ConstantReader
virtual ~StreamingFlowGraphBuilder()
void ReportUnexpectedTag(const char *variant, Tag tag) override
intptr_t num_ast_nodes() const
StreamingFlowGraphBuilder(FlowGraphBuilder *flow_graph_builder, const TypedDataView &data, intptr_t data_program_offset)
Fragment BuildStatementAt(intptr_t kernel_offset)
Dart_NativeFunction function
const char *const function_name
static int8_t data[kExtLength]
static SkString join(const CommandLineFlags::StringArray &)