OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ | |
6 #define V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ | |
7 | |
8 #include "src/interpreter/bytecodes.h" | |
9 | |
10 #include "src/compiler.h" | |
11 #include "src/compiler/js-graph.h" | |
12 | |
13 namespace v8 { | |
14 namespace internal { | |
15 namespace compiler { | |
16 | |
17 // The BytecodeGraphBuilder produces a high-level IR graph based on | |
18 // interpreter bytecodes. | |
19 class BytecodeGraphBuilder { | |
20 public: | |
21 BytecodeGraphBuilder(Zone* local_zone, CompilationInfo* info, | |
22 JSGraph* jsgraph); | |
rmcilroy
2015/09/01 14:00:06
Could we just have the one constructor and one Cre
oth
2015/09/01 15:25:57
Totally agree with the sentiment. Faking a compila
rmcilroy
2015/09/02 12:45:24
Yes, something like RawMachineAssemblerTester::Gen
Michael Starzinger
2015/09/02 12:46:52
+1
| |
23 BytecodeGraphBuilder(Zone* local_zone, Handle<BytecodeArray> bytecode_array, | |
24 JSGraph* jsgraph); | |
25 | |
26 // Creates a graph by visiting bytecodes. | |
27 bool CreateGraph(bool stack_check = true); | |
28 bool CreateGraphForTest(bool stack_check = true); | |
29 | |
30 Graph* graph() const { return jsgraph_->graph(); } | |
31 | |
32 private: | |
33 class Environment; | |
34 | |
35 void CreateGraphBody(bool stack_check); | |
36 void VisitBytecodes(); | |
37 | |
38 Node* LoadAccumulator(Node* value); | |
39 | |
40 // Convert values in bytecode_array to convenient to handle forms. | |
41 interpreter::Bytecode bytecode_at(int offset) const; | |
42 int8_t smi8_at(int offset) const; | |
43 int8_t register_at(int offset) const; | |
44 | |
45 void set_environment(Environment* env) { environment_ = env; } | |
46 const Environment* environment() const { return environment_; } | |
47 Environment* environment() { return environment_; } | |
48 | |
49 // Node creation helpers | |
50 Node* NewNode(const Operator* op, bool incomplete = false) { | |
51 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); | |
52 } | |
53 | |
54 Node* NewNode(const Operator* op, Node* n1) { | |
55 Node* buffer[] = {n1}; | |
56 return MakeNode(op, arraysize(buffer), buffer, false); | |
57 } | |
58 | |
59 Node* NewNode(const Operator* op, Node* n1, Node* n2) { | |
60 Node* buffer[] = {n1, n2}; | |
61 return MakeNode(op, arraysize(buffer), buffer, false); | |
62 } | |
63 | |
64 Node* MakeNode(const Operator* op, int value_input_count, Node** value_inputs, | |
65 bool incomplete); | |
66 | |
67 Node* MergeControl(Node* control, Node* other); | |
68 | |
69 Node** EnsureInputBufferSize(int size); | |
70 | |
71 void UpdateControlDependencyToLeaveFunction(Node* exit); | |
72 | |
73 void FinishBinaryOperation(Node* node); | |
74 | |
75 // Growth increment for the temporary buffer used to construct input lists to | |
76 // new nodes. | |
77 static const int kInputBufferSizeIncrement = 64; | |
78 | |
79 // Field accessors | |
80 CommonOperatorBuilder* common() const { return jsgraph_->common(); } | |
81 Zone* graph_zone() const { return graph()->zone(); } | |
82 CompilationInfo* info() const { return info_; } | |
83 JSGraph* jsgraph() const { return jsgraph_; } | |
84 JSOperatorBuilder* javascript() const { return jsgraph_->javascript(); } | |
85 Zone* local_zone() const { return local_zone_; } | |
86 const Handle<BytecodeArray>& bytecode_array() const { | |
87 return bytecode_array_; | |
88 } | |
89 | |
90 LanguageMode language_mode() const { | |
91 // TODO(oth): need to propagate language mode through | |
92 return LanguageMode::SLOPPY; | |
93 } | |
94 | |
95 #define DECLARE_VISIT_BYTECODE(name, ...) void Visit##name(int operand_offset); | |
96 BYTECODE_LIST(DECLARE_VISIT_BYTECODE) | |
97 #undef DECLARE_VISIT_BYTECODE | |
98 | |
99 Zone* local_zone_; | |
100 CompilationInfo* info_; | |
101 JSGraph* jsgraph_; | |
102 Handle<BytecodeArray> bytecode_array_; | |
103 Environment* environment_; | |
104 | |
105 // Temporary storage for building node input lists. | |
106 int input_buffer_size_; | |
107 Node** input_buffer_; | |
108 | |
109 // Control nodes that exit the function body. | |
110 ZoneVector<Node*> exit_controls_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilder); | |
113 }; | |
114 | |
115 | |
116 class BytecodeGraphBuilder::Environment : public ZoneObject { | |
117 public: | |
118 Environment(BytecodeGraphBuilder* builder, int locals_count, | |
119 Node* control_dependency); | |
120 | |
121 int locals_count() const { return locals_count_; } | |
122 | |
123 void BindRegister(size_t register_index, Node* node); | |
124 Node* LookupRegister(size_t register_index) const; | |
125 | |
126 void BindAccumulator(Node* node); | |
127 Node* LookupAccumulator() const; | |
128 | |
129 bool IsMarkedAsUnreachable() const; | |
130 void MarkAsUnreachable(); | |
131 | |
132 // Effect dependency tracked by this environment. | |
133 Node* GetEffectDependency() { return effect_dependency_; } | |
134 void UpdateEffectDependency(Node* dependency) { | |
135 effect_dependency_ = dependency; | |
136 } | |
137 | |
138 // Control dependency tracked by this environment. | |
139 Node* GetControlDependency() const { return control_dependency_; } | |
140 void UpdateControlDependency(Node* dependency) { | |
141 control_dependency_ = dependency; | |
142 } | |
143 | |
144 private: | |
145 BytecodeGraphBuilder* builder_; | |
146 int locals_count_; | |
147 Node* control_dependency_; | |
148 Node* effect_dependency_; | |
149 NodeVector values_; | |
150 size_t register_base_; | |
151 | |
152 Zone* zone() const { return builder_->local_zone(); } | |
153 Graph* graph() const { return builder_->graph(); } | |
154 CommonOperatorBuilder* common() const { return builder_->common(); } | |
155 BytecodeGraphBuilder* builder() const { return builder_; } | |
156 const NodeVector* values() const { return &values_; } | |
157 NodeVector* values() { return &values_; } | |
158 | |
159 size_t accumulator_pseudo_register() const { return locals_count_; } | |
160 size_t register_base() const { return register_base_; } | |
161 }; | |
162 | |
163 } // namespace compiler | |
164 } // namespace internal | |
165 } // namespace v8 | |
166 | |
167 #endif // V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ | |
OLD | NEW |