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

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 review comments on patch set 5. 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/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);
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);
Michael Starzinger 2015/09/02 12:19:22 The only reason for the {stack_check} flags is for
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 // Get constant from operand at position |offset| in bytecode array.
43 Handle<Object> constant_at(int offset) const;
44 // Get smi8 value from operand at position |offset| in bytecode array.
45 int8_t smi8_at(int offset) const;
46 // Get register from operand at position |offset| in bytecode array.
47 int8_t register_at(int offset) const;
48
49 void set_environment(Environment* env) { environment_ = env; }
50 const Environment* environment() const { return environment_; }
51 Environment* environment() { return environment_; }
52
53 // Node creation helpers
54 Node* NewNode(const Operator* op, bool incomplete = false) {
Michael Starzinger 2015/09/02 12:19:22 The {incomplete} flag is only needed for merge poi
55 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete);
56 }
57
58 Node* NewNode(const Operator* op, Node* n1) {
59 Node* buffer[] = {n1};
60 return MakeNode(op, arraysize(buffer), buffer, false);
61 }
62
63 Node* NewNode(const Operator* op, Node* n1, Node* n2) {
64 Node* buffer[] = {n1, n2};
65 return MakeNode(op, arraysize(buffer), buffer, false);
66 }
67
68 Node* MakeNode(const Operator* op, int value_input_count, Node** value_inputs,
69 bool incomplete);
70
71 Node* MergeControl(Node* control, Node* other);
72
73 Node** EnsureInputBufferSize(int size);
74
75 void UpdateControlDependencyToLeaveFunction(Node* exit);
Michael Starzinger 2015/09/02 12:19:22 Again depends on how control flow is modeled. Only
76
77 void FinishBinaryOperation(Node* node);
78
79 // Growth increment for the temporary buffer used to construct input lists to
80 // new nodes.
81 static const int kInputBufferSizeIncrement = 64;
82
83 // Field accessors
84 CommonOperatorBuilder* common() const { return jsgraph_->common(); }
85 Zone* graph_zone() const { return graph()->zone(); }
86 CompilationInfo* info() const { return info_; }
87 JSGraph* jsgraph() const { return jsgraph_; }
88 JSOperatorBuilder* javascript() const { return jsgraph_->javascript(); }
89 Zone* local_zone() const { return local_zone_; }
90 const Handle<BytecodeArray>& bytecode_array() const {
91 return bytecode_array_;
92 }
93
94 LanguageMode language_mode() const {
95 // TODO(oth): need to propagate language mode through
96 return LanguageMode::SLOPPY;
97 }
98
99 #define DECLARE_VISIT_BYTECODE(name, ...) void Visit##name(int operand_offset);
100 BYTECODE_LIST(DECLARE_VISIT_BYTECODE)
101 #undef DECLARE_VISIT_BYTECODE
102
103 Zone* local_zone_;
104 CompilationInfo* info_;
105 JSGraph* jsgraph_;
106 Handle<BytecodeArray> bytecode_array_;
107 Environment* environment_;
108
109 // Temporary storage for building node input lists.
110 int input_buffer_size_;
111 Node** input_buffer_;
112
113 // Control nodes that exit the function body.
114 ZoneVector<Node*> exit_controls_;
115
116 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilder);
117 };
118
119
120 class BytecodeGraphBuilder::Environment : public ZoneObject {
121 public:
122 Environment(BytecodeGraphBuilder* builder, int locals_count,
123 int parameter_count, Node* control_dependency);
124
125 int parameters_count() const { return parameters_count_; }
126 int locals_count() const { return locals_count_; }
127
128 void BindRegister(int register_index, Node* node);
129 Node* LookupRegister(int register_index) const;
130
131 void BindAccumulator(Node* node);
132 Node* LookupAccumulator() const;
133
134 bool IsMarkedAsUnreachable() const;
135 void MarkAsUnreachable();
136
137 // Effect dependency tracked by this environment.
138 Node* GetEffectDependency() { return effect_dependency_; }
139 void UpdateEffectDependency(Node* dependency) {
140 effect_dependency_ = dependency;
141 }
142
143 // Control dependency tracked by this environment.
144 Node* GetControlDependency() const { return control_dependency_; }
145 void UpdateControlDependency(Node* dependency) {
146 control_dependency_ = dependency;
147 }
148
149 private:
150 BytecodeGraphBuilder* builder_;
151 int locals_count_;
152 int parameters_count_;
153 Node* accumulator_;
154 Node* control_dependency_;
155 Node* effect_dependency_;
156 NodeVector values_;
157 int register_base_;
158
159 Zone* zone() const { return builder_->local_zone(); }
160 Graph* graph() const { return builder_->graph(); }
161 CommonOperatorBuilder* common() const { return builder_->common(); }
162 BytecodeGraphBuilder* builder() const { return builder_; }
163 const NodeVector* values() const { return &values_; }
164 NodeVector* values() { return &values_; }
165 Node* accumulator() { return accumulator_; }
166
167 int register_base() const { return register_base_; }
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