Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(541)

Side by Side Diff: src/compiler/bytecode-graph-builder.h

Issue 1291693004: [Interpreter] Bytecode graph builder (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate comments on patch set 8. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/compiler.h"
9 #include "src/compiler/js-graph.h"
10 #include "src/interpreter/bytecode-array-iterator.h"
11 #include "src/interpreter/bytecodes.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);
23
24 // Creates a graph by visiting bytecodes.
25 bool CreateGraph(bool stack_check = true);
26
27 Graph* graph() const { return jsgraph_->graph(); }
28
29 private:
30 class Environment;
31
32 void CreateGraphBody(bool stack_check);
33 void VisitBytecodes();
34
35 Node* LoadAccumulator(Node* value);
36
37 Node* GetFunctionContext();
38
39 void set_environment(Environment* env) { environment_ = env; }
40 const Environment* environment() const { return environment_; }
41 Environment* environment() { return environment_; }
42
43 // Node creation helpers
44 Node* NewNode(const Operator* op, bool incomplete = false) {
45 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete);
46 }
47
48 Node* NewNode(const Operator* op, Node* n1) {
49 Node* buffer[] = {n1};
50 return MakeNode(op, arraysize(buffer), buffer, false);
51 }
52
53 Node* NewNode(const Operator* op, Node* n1, Node* n2) {
54 Node* buffer[] = {n1, n2};
55 return MakeNode(op, arraysize(buffer), buffer, false);
56 }
57
58 Node* MakeNode(const Operator* op, int value_input_count, Node** value_inputs,
59 bool incomplete);
60
61 Node* MergeControl(Node* control, Node* other);
62
63 Node** EnsureInputBufferSize(int size);
64
65 void UpdateControlDependencyToLeaveFunction(Node* exit);
66
67 void BuildBinaryOp(Node* node);
68
69 // Growth increment for the temporary buffer used to construct input lists to
70 // new nodes.
71 static const int kInputBufferSizeIncrement = 64;
72
73 // Field accessors
74 CommonOperatorBuilder* common() const { return jsgraph_->common(); }
75 Zone* graph_zone() const { return graph()->zone(); }
76 CompilationInfo* info() const { return info_; }
77 JSGraph* jsgraph() const { return jsgraph_; }
78 JSOperatorBuilder* javascript() const { return jsgraph_->javascript(); }
79 Zone* local_zone() const { return local_zone_; }
80 const Handle<BytecodeArray>& bytecode_array() const {
81 return bytecode_array_;
82 }
83
84 LanguageMode language_mode() const {
85 // TODO(oth): need to propagate language mode through
86 return LanguageMode::SLOPPY;
87 }
88
89 #define DECLARE_VISIT_BYTECODE(name, ...) \
90 void Visit##name(const interpreter::BytecodeArrayIterator& iterator);
91 BYTECODE_LIST(DECLARE_VISIT_BYTECODE)
92 #undef DECLARE_VISIT_BYTECODE
93
94 Zone* local_zone_;
95 CompilationInfo* info_;
96 JSGraph* jsgraph_;
97 Handle<BytecodeArray> bytecode_array_;
98 Environment* environment_;
99
100 // Temporary storage for building node input lists.
101 int input_buffer_size_;
102 Node** input_buffer_;
103
104 // Nodes representing values in the activation record.
105 SetOncePointer<Node> function_context_;
106
107 // Control nodes that exit the function body.
108 ZoneVector<Node*> exit_controls_;
109
110 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilder);
111 };
112
113
114 class BytecodeGraphBuilder::Environment : public ZoneObject {
115 public:
116 Environment(BytecodeGraphBuilder* builder, int register_count,
117 int parameter_count, Node* control_dependency, Node* context);
118
119 int parameter_count() const { return parameter_count_; }
120 int register_count() const { return register_count_; }
121
122 void BindRegister(interpreter::Register the_register, Node* node);
123 Node* LookupRegister(interpreter::Register the_register) const;
124
125 void BindAccumulator(Node* node);
126 Node* LookupAccumulator() const;
127
128 bool IsMarkedAsUnreachable() const;
129 void MarkAsUnreachable();
130
131 // Effect dependency tracked by this environment.
132 Node* GetEffectDependency() { return effect_dependency_; }
133 void UpdateEffectDependency(Node* dependency) {
134 effect_dependency_ = dependency;
135 }
136
137 // Control dependency tracked by this environment.
138 Node* GetControlDependency() const { return control_dependency_; }
139 void UpdateControlDependency(Node* dependency) {
140 control_dependency_ = dependency;
141 }
142
143 Node* Context() const { return context_; }
144
145 private:
146 static const int kParameterStartIndex;
147
148 BytecodeGraphBuilder* builder_;
149 int register_count_;
150 int parameter_count_;
151 Node* accumulator_;
152 Node* context_;
153 Node* control_dependency_;
154 Node* effect_dependency_;
155 NodeVector values_;
156 int register_base_;
157
158 Zone* zone() const { return builder_->local_zone(); }
159 Graph* graph() const { return builder_->graph(); }
160 CommonOperatorBuilder* common() const { return builder_->common(); }
161 BytecodeGraphBuilder* builder() const { return builder_; }
162 const NodeVector* values() const { return &values_; }
163 NodeVector* values() { return &values_; }
164 Node* accumulator() { return accumulator_; }
165 int register_base() const { return register_base_; }
166
167 int RegisterToValuesIndex(interpreter::Register the_register) const;
168 };
169
170
171 } // namespace compiler
172 } // namespace internal
173 } // namespace v8
174
175 #endif // V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698