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

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: More fixes for bots (tests w/ ASAN and tests w/ slow asserts enabled). 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(const Operator* op,
68 const interpreter::BytecodeArrayIterator& iterator);
69
70 // Growth increment for the temporary buffer used to construct input lists to
71 // new nodes.
72 static const int kInputBufferSizeIncrement = 64;
73
74 // Field accessors
75 CommonOperatorBuilder* common() const { return jsgraph_->common(); }
76 Zone* graph_zone() const { return graph()->zone(); }
77 CompilationInfo* info() const { return info_; }
78 JSGraph* jsgraph() const { return jsgraph_; }
79 JSOperatorBuilder* javascript() const { return jsgraph_->javascript(); }
80 Zone* local_zone() const { return local_zone_; }
81 const Handle<BytecodeArray>& bytecode_array() const {
82 return bytecode_array_;
83 }
84
85 LanguageMode language_mode() const {
86 // TODO(oth): need to propagate language mode through
87 return LanguageMode::SLOPPY;
88 }
89
90 #define DECLARE_VISIT_BYTECODE(name, ...) \
91 void Visit##name(const interpreter::BytecodeArrayIterator& iterator);
92 BYTECODE_LIST(DECLARE_VISIT_BYTECODE)
93 #undef DECLARE_VISIT_BYTECODE
94
95 Zone* local_zone_;
96 CompilationInfo* info_;
97 JSGraph* jsgraph_;
98 Handle<BytecodeArray> bytecode_array_;
99 Environment* environment_;
100
101 // Temporary storage for building node input lists.
102 int input_buffer_size_;
103 Node** input_buffer_;
104
105 // Nodes representing values in the activation record.
106 SetOncePointer<Node> function_context_;
107
108 // Control nodes that exit the function body.
109 ZoneVector<Node*> exit_controls_;
110
111 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilder);
112 };
113
114
115 class BytecodeGraphBuilder::Environment : public ZoneObject {
116 public:
117 Environment(BytecodeGraphBuilder* builder, int register_count,
118 int parameter_count, Node* control_dependency, Node* context);
119
120 int parameter_count() const { return parameter_count_; }
121 int register_count() const { return register_count_; }
122
123 void BindRegister(interpreter::Register the_register, Node* node);
124 Node* LookupRegister(interpreter::Register the_register) 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 Node* Context() const { return context_; }
145
146 private:
147 int RegisterToValuesIndex(interpreter::Register the_register) const;
148
149 Zone* zone() const { return builder_->local_zone(); }
150 Graph* graph() const { return builder_->graph(); }
151 CommonOperatorBuilder* common() const { return builder_->common(); }
152 BytecodeGraphBuilder* builder() const { return builder_; }
153 const NodeVector* values() const { return &values_; }
154 NodeVector* values() { return &values_; }
155 Node* accumulator() { return accumulator_; }
156 int register_base() const { return register_base_; }
157
158 BytecodeGraphBuilder* builder_;
159 int register_count_;
160 int parameter_count_;
161 Node* accumulator_;
162 Node* context_;
163 Node* control_dependency_;
164 Node* effect_dependency_;
165 NodeVector values_;
166 int register_base_;
167 };
168
169
170 } // namespace compiler
171 } // namespace internal
172 } // namespace v8
173
174 #endif // V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698