Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
flow_graph_checker.h
Go to the documentation of this file.
1// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_COMPILER_BACKEND_FLOW_GRAPH_CHECKER_H_
6#define RUNTIME_VM_COMPILER_BACKEND_FLOW_GRAPH_CHECKER_H_
7
8#include "platform/globals.h"
9
10#if defined(DART_PRECOMPILED_RUNTIME)
11#error "AOT runtime should not use compiler sources (including header files)"
12#endif // defined(DART_PRECOMPILED_RUNTIME)
13
14#if defined(DEBUG)
15
18
19namespace dart {
20
21// Class responsible for performing sanity checks on the flow graph.
22// The intended use is running the checks after each compiler pass
23// in debug mode in order to detect graph inconsistencies as soon
24// as possible. This way, culprit passes are more easily identified.
25//
26// All important assumptions on the flow graph structure that can be
27// verified in reasonable time should be made explicit in this pass
28// so that we no longer rely on asserts that are dispersed throughout
29// the passes or, worse, unwritten assumptions once agreed upon but
30// so easily forgotten. Since the graph checker runs only in debug
31// mode, it is acceptable to perform slightly elaborate tests.
32class FlowGraphChecker : public FlowGraphVisitor {
33 public:
34 // Constructs graph checker. The checker uses some custom-made
35 // visitation to perform additional checks, and uses the
36 // FlowGraphVisitor structure for anything else.
37 FlowGraphChecker(FlowGraph* flow_graph,
38 const GrowableArray<const Function*>& inline_id_to_function)
39 : FlowGraphVisitor(flow_graph->preorder()),
40 flow_graph_(flow_graph),
41 inline_id_to_function_(inline_id_to_function),
42 script_(Script::Handle(flow_graph_->zone())),
43 current_block_(nullptr) {}
44
45 // Performs a sanity check on the flow graph.
46 void Check(const char* pass_name);
47
48 private:
49 // Custom-made visitors.
50 void VisitBlocks() override;
51 void VisitInstructions(BlockEntryInstr* block);
52 void VisitInstruction(Instruction* instruction);
53 void VisitDefinition(Definition* def);
54 void VisitUseDef(Instruction* instruction,
55 Value* use,
56 intptr_t index,
57 bool is_env);
58 void VisitDefUse(Definition* def, Value* use, Value* prev, bool is_env);
59
60 // Instruction visitors.
61 void VisitConstant(ConstantInstr* constant) override;
62 void VisitPhi(PhiInstr* phi) override;
63 void VisitGoto(GotoInstr* jmp) override;
64 void VisitIndirectGoto(IndirectGotoInstr* jmp) override;
65 void VisitBranch(BranchInstr* branch) override;
66 void VisitRedefinition(RedefinitionInstr* def) override;
67 void AssertArgumentsInEnv(Definition* call);
68 void VisitClosureCall(ClosureCallInstr* call) override;
69 void VisitStaticCall(StaticCallInstr* call) override;
70 void VisitInstanceCall(InstanceCallInstr* call) override;
71 void VisitPolymorphicInstanceCall(
72 PolymorphicInstanceCallInstr* call) override;
73
74 FlowGraph* const flow_graph_;
75 const GrowableArray<const Function*>& inline_id_to_function_;
76 Script& script_;
77 BlockEntryInstr* current_block_;
78};
79
80} // namespace dart
81
82#endif // defined(DEBUG)
83
84#endif // RUNTIME_VM_COMPILER_BACKEND_FLOW_GRAPH_CHECKER_H_
static float prev(float f)
Check(request)
Definition tester.py:24