Chromium Code Reviews| 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); | |
| 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 // Convert values in bytecode_array to convenient to handle forms. | |
|
rmcilroy
2015/09/03 12:41:57
nit - I would just replace this with a comment des
oth
2015/09/04 11:06:36
Done.
| |
| 40 interpreter::Bytecode bytecode_at(int offset) const; | |
| 41 // Get constant from operand at position |offset| in bytecode array. | |
|
rmcilroy
2015/09/03 12:41:58
nit - could you make the comment clearer that this
oth
2015/09/04 11:06:36
Done.
| |
| 42 Handle<Object> constant_at(int offset) const; | |
| 43 // Get smi8 value from operand at position |offset| in bytecode array. | |
| 44 int8_t smi8_at(int offset) const; | |
| 45 // Get register from operand at position |offset| in bytecode array. | |
| 46 interpreter::Register register_at(int offset) const; | |
|
rmcilroy
2015/09/03 12:41:58
Optional suggestion (fine with doing this in a lat
oth
2015/09/04 11:06:36
Done with BytecodeArrayIterator.
| |
| 47 | |
| 48 void set_environment(Environment* env) { environment_ = env; } | |
| 49 const Environment* environment() const { return environment_; } | |
| 50 Environment* environment() { return environment_; } | |
| 51 | |
| 52 // Node creation helpers | |
| 53 Node* NewNode(const Operator* op, bool incomplete = false) { | |
| 54 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); | |
| 55 } | |
| 56 | |
| 57 Node* NewNode(const Operator* op, Node* n1) { | |
| 58 Node* buffer[] = {n1}; | |
| 59 return MakeNode(op, arraysize(buffer), buffer, false); | |
| 60 } | |
| 61 | |
| 62 Node* NewNode(const Operator* op, Node* n1, Node* n2) { | |
| 63 Node* buffer[] = {n1, n2}; | |
| 64 return MakeNode(op, arraysize(buffer), buffer, false); | |
| 65 } | |
| 66 | |
| 67 Node* MakeNode(const Operator* op, int value_input_count, Node** value_inputs, | |
| 68 bool incomplete); | |
| 69 | |
| 70 Node* MergeControl(Node* control, Node* other); | |
| 71 | |
| 72 Node** EnsureInputBufferSize(int size); | |
| 73 | |
| 74 void UpdateControlDependencyToLeaveFunction(Node* exit); | |
| 75 | |
| 76 void FinishBinaryOperation(Node* node); | |
|
rmcilroy
2015/09/03 12:41:57
How about we replace this with "Node* BuildBinaryO
oth
2015/09/04 11:06:36
Done.
| |
| 77 | |
| 78 // Growth increment for the temporary buffer used to construct input lists to | |
| 79 // new nodes. | |
| 80 static const int kInputBufferSizeIncrement = 64; | |
| 81 | |
| 82 // Field accessors | |
| 83 CommonOperatorBuilder* common() const { return jsgraph_->common(); } | |
| 84 Zone* graph_zone() const { return graph()->zone(); } | |
| 85 CompilationInfo* info() const { return info_; } | |
| 86 JSGraph* jsgraph() const { return jsgraph_; } | |
| 87 JSOperatorBuilder* javascript() const { return jsgraph_->javascript(); } | |
| 88 Zone* local_zone() const { return local_zone_; } | |
| 89 const Handle<BytecodeArray>& bytecode_array() const { | |
| 90 return bytecode_array_; | |
| 91 } | |
| 92 | |
| 93 LanguageMode language_mode() const { | |
| 94 // TODO(oth): need to propagate language mode through | |
| 95 return LanguageMode::SLOPPY; | |
| 96 } | |
| 97 | |
| 98 #define DECLARE_VISIT_BYTECODE(name, ...) void Visit##name(int operand_offset); | |
| 99 BYTECODE_LIST(DECLARE_VISIT_BYTECODE) | |
| 100 #undef DECLARE_VISIT_BYTECODE | |
| 101 | |
| 102 Zone* local_zone_; | |
| 103 CompilationInfo* info_; | |
| 104 JSGraph* jsgraph_; | |
| 105 Handle<BytecodeArray> bytecode_array_; | |
| 106 Environment* environment_; | |
| 107 | |
| 108 // Temporary storage for building node input lists. | |
| 109 int input_buffer_size_; | |
| 110 Node** input_buffer_; | |
| 111 | |
| 112 // Nodes representing values in the activation record. | |
| 113 SetOncePointer<Node> function_context_; | |
| 114 | |
| 115 // Control nodes that exit the function body. | |
| 116 ZoneVector<Node*> exit_controls_; | |
| 117 | |
| 118 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilder); | |
| 119 }; | |
| 120 | |
| 121 | |
| 122 class BytecodeGraphBuilder::Environment : public ZoneObject { | |
| 123 public: | |
| 124 Environment(BytecodeGraphBuilder* builder, int locals_count, | |
| 125 int parameter_count, Node* control_dependency, Node* context); | |
| 126 | |
| 127 int parameters_count() const { return parameters_count_; } | |
| 128 int locals_count() const { return locals_count_; } | |
| 129 | |
| 130 void BindRegister(interpreter::Register the_register, Node* node); | |
| 131 Node* LookupRegister(interpreter::Register the_register) const; | |
| 132 | |
| 133 void BindAccumulator(Node* node); | |
| 134 Node* LookupAccumulator() const; | |
| 135 | |
| 136 bool IsMarkedAsUnreachable() const; | |
| 137 void MarkAsUnreachable(); | |
| 138 | |
| 139 // Effect dependency tracked by this environment. | |
| 140 Node* GetEffectDependency() { return effect_dependency_; } | |
| 141 void UpdateEffectDependency(Node* dependency) { | |
| 142 effect_dependency_ = dependency; | |
| 143 } | |
| 144 | |
| 145 // Control dependency tracked by this environment. | |
| 146 Node* GetControlDependency() const { return control_dependency_; } | |
| 147 void UpdateControlDependency(Node* dependency) { | |
| 148 control_dependency_ = dependency; | |
| 149 } | |
| 150 | |
| 151 Node* Context() const { return context_; } | |
| 152 | |
| 153 private: | |
| 154 BytecodeGraphBuilder* builder_; | |
| 155 int locals_count_; | |
| 156 int parameters_count_; | |
| 157 Node* accumulator_; | |
| 158 Node* context_; | |
| 159 Node* control_dependency_; | |
| 160 Node* effect_dependency_; | |
| 161 NodeVector values_; | |
| 162 int register_base_; | |
| 163 | |
| 164 Zone* zone() const { return builder_->local_zone(); } | |
| 165 Graph* graph() const { return builder_->graph(); } | |
| 166 CommonOperatorBuilder* common() const { return builder_->common(); } | |
| 167 BytecodeGraphBuilder* builder() const { return builder_; } | |
| 168 const NodeVector* values() const { return &values_; } | |
| 169 NodeVector* values() { return &values_; } | |
| 170 Node* accumulator() { return accumulator_; } | |
| 171 int register_base() const { return register_base_; } | |
| 172 | |
| 173 int RegisterToValuesIndex(interpreter::Register the_register) const; | |
| 174 }; | |
| 175 | |
| 176 } // namespace compiler | |
| 177 } // namespace internal | |
| 178 } // namespace v8 | |
| 179 | |
| 180 #endif // V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ | |
| OLD | NEW |