OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_CODE_STUB_ASSEMBLER_H_ | 5 #ifndef V8_COMPILER_CODE_STUB_ASSEMBLER_H_ |
6 #define V8_COMPILER_CODE_STUB_ASSEMBLER_H_ | 6 #define V8_COMPILER_CODE_STUB_ASSEMBLER_H_ |
7 | 7 |
8 #include <map> | |
9 | |
8 // Clients of this interface shouldn't depend on lots of compiler internals. | 10 // Clients of this interface shouldn't depend on lots of compiler internals. |
9 // Do not include anything from src/compiler here! | 11 // Do not include anything from src/compiler here! |
10 #include "src/allocation.h" | 12 #include "src/allocation.h" |
11 #include "src/builtins.h" | 13 #include "src/builtins.h" |
14 #include "src/heap/heap.h" | |
15 #include "src/machine-type.h" | |
12 #include "src/runtime/runtime.h" | 16 #include "src/runtime/runtime.h" |
17 #include "src/zone-containers.h" | |
13 | 18 |
14 namespace v8 { | 19 namespace v8 { |
15 namespace internal { | 20 namespace internal { |
16 | 21 |
17 class CallInterfaceDescriptor; | 22 class CallInterfaceDescriptor; |
18 class Isolate; | 23 class Isolate; |
19 class Zone; | 24 class Zone; |
20 | 25 |
21 namespace compiler { | 26 namespace compiler { |
22 | 27 |
23 class CallDescriptor; | 28 class CallDescriptor; |
24 class Graph; | 29 class Graph; |
25 class Node; | 30 class Node; |
26 class Operator; | 31 class Operator; |
27 class RawMachineAssembler; | 32 class RawMachineAssembler; |
33 class RawMachineLabel; | |
28 class Schedule; | 34 class Schedule; |
29 | 35 |
36 #define CODE_STUB_ASSEMBLER_BINARY_OP_LIST(V) \ | |
37 V(IntPtrAdd) \ | |
38 V(IntPtrSub) \ | |
39 V(Int32Add) \ | |
40 V(Int32Sub) \ | |
41 V(Int32Mul) \ | |
42 V(WordEqual) \ | |
43 V(WordNotEqual) \ | |
44 V(WordOr) \ | |
45 V(WordAnd) \ | |
46 V(WordXor) \ | |
47 V(WordShl) \ | |
48 V(WordShr) \ | |
49 V(WordSar) \ | |
50 V(WordRor) \ | |
51 V(Word32Equal) \ | |
52 V(Word32NotEqual) \ | |
53 V(Word32Or) \ | |
54 V(Word32And) \ | |
55 V(Word32Xor) \ | |
56 V(Word32Shr) \ | |
57 V(Word32Sar) \ | |
58 V(Word32Ror) \ | |
59 V(Word64Equal) \ | |
60 V(Word64NotEqual) \ | |
61 V(Word64Or) \ | |
62 V(Word64And) \ | |
63 V(Word64Xor) \ | |
64 V(Word64Shr) \ | |
65 V(Word64Sar) \ | |
66 V(Word64Ror) | |
67 | |
30 class CodeStubAssembler { | 68 class CodeStubAssembler { |
31 public: | 69 public: |
32 CodeStubAssembler(Isolate* isolate, Zone* zone, | 70 CodeStubAssembler(Isolate* isolate, Zone* zone, |
33 const CallInterfaceDescriptor& descriptor, | 71 const CallInterfaceDescriptor& descriptor, |
34 Code::Flags flags, const char* name); | 72 Code::Flags flags, const char* name); |
35 virtual ~CodeStubAssembler(); | 73 virtual ~CodeStubAssembler(); |
36 | 74 |
37 Handle<Code> GenerateCode(); | 75 Handle<Code> GenerateCode(); |
38 | 76 |
77 class Label; | |
78 class Variable { | |
79 public: | |
80 explicit Variable(CodeStubAssembler* assembler, MachineRepresentation rep); | |
81 void Bind(Node* value) { impl_->value_ = value; } | |
82 Node* value() const { | |
83 DCHECK(impl_->value_ != nullptr); | |
Michael Starzinger
2016/02/01 16:04:12
nit: DCHECK_NOT_NULL
danno
2016/02/02 07:52:55
Done.
| |
84 return impl_->value_; | |
85 } | |
86 MachineRepresentation rep() const { return impl_->rep_; } | |
87 bool IsBound() const { return impl_->value_ != nullptr; } | |
88 | |
89 private: | |
90 friend class CodeStubAssembler; | |
91 // The core implementation of Variable is stored through an indirection so | |
92 // that it can outlive the often block-scoped Variable declarations. This is | |
93 // needed to ensure that variable binding and merging through phis can | |
94 // properly be verified. | |
95 class Impl : public ZoneObject { | |
Michael Starzinger
2016/02/01 16:04:12
nit: Does this need to be a nested class within th
danno
2016/02/02 07:52:55
Done.
| |
96 public: | |
97 explicit Impl(MachineRepresentation rep) : value_(nullptr), rep_(rep) {} | |
98 Node* value_; | |
99 MachineRepresentation rep_; | |
100 }; | |
101 Impl* impl_; | |
102 }; | |
103 | |
104 // | |
Michael Starzinger
2016/02/01 16:04:12
nit: A loon separator line could have a higher vis
danno
2016/02/02 07:52:55
Done.
| |
105 // BASE ASSEMBLER | |
106 // | |
107 | |
39 // Constants. | 108 // Constants. |
40 Node* Int32Constant(int value); | 109 Node* Int32Constant(int value); |
41 Node* IntPtrConstant(intptr_t value); | 110 Node* IntPtrConstant(intptr_t value); |
42 Node* NumberConstant(double value); | 111 Node* NumberConstant(double value); |
43 Node* HeapConstant(Handle<HeapObject> object); | 112 Node* HeapConstant(Handle<HeapObject> object); |
44 Node* BooleanConstant(bool value); | 113 Node* BooleanConstant(bool value); |
114 Node* ExternalConstant(ExternalReference address); | |
45 | 115 |
46 Node* Parameter(int value); | 116 Node* Parameter(int value); |
47 void Return(Node* value); | 117 void Return(Node* value); |
48 | 118 |
119 void Bind(Label* label); | |
120 void Goto(Label* label); | |
121 void Branch(Node* condition, Label* true_label, Label* false_label); | |
122 | |
123 void Switch(Node* index, Label* default_label, int32_t* case_values, | |
124 Label** case_labels, size_t case_count); | |
125 | |
126 // Access to the frame pointer | |
127 Node* LoadFramePointer(); | |
128 Node* LoadParentFramePointer(); | |
129 | |
130 // Basic arithmetic operations. | |
131 #define DECLARE_CODE_STUB_ASSEMBER_BINARY_OP(name) Node* name(Node* a, Node* b); | |
132 CODE_STUB_ASSEMBLER_BINARY_OP_LIST(DECLARE_CODE_STUB_ASSEMBER_BINARY_OP) | |
133 #undef DECLARE_CODE_STUB_ASSEMBER_BINARY_OP | |
134 | |
135 Node* WordShl(Node* value, int shift); | |
136 | |
137 // Calls | |
138 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1); | |
139 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1, | |
140 Node* arg2); | |
141 | |
142 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* arg1, | |
143 Node* context); | |
144 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* arg1, Node* arg2, | |
145 Node* context); | |
146 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* arg1, Node* arg2, | |
147 Node* arg3, Node* context); | |
148 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* arg1, Node* arg2, | |
149 Node* arg3, Node* arg4, Node* context); | |
150 | |
151 Node* TailCallStub(CodeStub& stub, Node** args); | |
152 Node* TailCall(const CallInterfaceDescriptor& descriptor, Node* target, | |
153 Node** args); | |
154 | |
155 // | |
156 // MACROS | |
Michael Starzinger
2016/02/01 16:04:12
nit: Likewise.
danno
2016/02/02 07:52:55
Done.
| |
157 // | |
158 | |
49 // Tag and untag Smi values. | 159 // Tag and untag Smi values. |
50 Node* SmiTag(Node* value); | 160 Node* SmiTag(Node* value); |
51 Node* SmiUntag(Node* value); | 161 Node* SmiUntag(Node* value); |
52 | 162 |
53 // Basic arithmetic operations. | 163 // Load a value from the root array. |
54 Node* IntPtrAdd(Node* a, Node* b); | 164 Node* LoadRoot(Heap::RootListIndex root_index); |
55 Node* IntPtrSub(Node* a, Node* b); | |
56 Node* WordShl(Node* value, int shift); | |
57 | 165 |
166 // Check a value for smi-ness | |
167 Node* WordIsSmi(Node* a); | |
168 | |
169 // Load an object pointer from a buffer that isn't in the heap. | |
170 Node* LoadBufferObject(Node* buffer, int offset); | |
58 // Load a field from an object on the heap. | 171 // Load a field from an object on the heap. |
59 Node* LoadObjectField(Node* object, int offset); | 172 Node* LoadObjectField(Node* object, int offset); |
60 | 173 |
61 // Call runtime function. | 174 // Load an array element from a FixedArray. |
62 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1); | 175 Node* LoadFixedArrayElementSmiIndex(Node* object, Node* smi_index, |
63 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1, | 176 int additional_offset = 0); |
64 Node* arg2); | 177 Node* LoadFixedArrayElementConstantIndex(Node* object, int index); |
65 | |
66 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, | |
67 Node* arg1); | |
68 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, | |
69 Node* arg1, Node* arg2); | |
70 | 178 |
71 private: | 179 private: |
72 friend class CodeStubAssemblerTester; | 180 friend class CodeStubAssemblerTester; |
181 friend class Label; | |
Michael Starzinger
2016/02/01 16:04:12
nit: Are these friend declarations needed? I was a
danno
2016/02/02 07:52:55
Done.
| |
182 friend class Variable; | |
73 | 183 |
74 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); | 184 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); |
75 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args); | 185 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args); |
76 | 186 |
77 Node* SmiShiftBitsConstant(); | 187 Node* SmiShiftBitsConstant(); |
78 | 188 |
79 // Private helpers which delegate to RawMachineAssembler. | 189 // Private helpers which delegate to RawMachineAssembler. |
80 Graph* graph(); | 190 Graph* graph(); |
81 Isolate* isolate(); | 191 Isolate* isolate(); |
82 Zone* zone(); | 192 Zone* zone(); |
83 | 193 |
84 base::SmartPointer<RawMachineAssembler> raw_assembler_; | 194 base::SmartPointer<RawMachineAssembler> raw_assembler_; |
85 Code::Flags flags_; | 195 Code::Flags flags_; |
86 const char* name_; | 196 const char* name_; |
87 bool code_generated_; | 197 bool code_generated_; |
198 ZoneVector<Variable::Impl*> vars_; | |
Michael Starzinger
2016/02/01 16:04:12
nit: s/vars/variables/
danno
2016/02/02 07:52:55
Done.
| |
88 | 199 |
89 DISALLOW_COPY_AND_ASSIGN(CodeStubAssembler); | 200 DISALLOW_COPY_AND_ASSIGN(CodeStubAssembler); |
90 }; | 201 }; |
91 | 202 |
203 class CodeStubAssembler::Label { | |
204 public: | |
205 explicit Label(CodeStubAssembler* assembler); | |
206 Label(CodeStubAssembler* assembler, int merged_variable_count, | |
207 CodeStubAssembler::Variable** merged_variables); | |
208 Label(CodeStubAssembler* assembler, | |
209 CodeStubAssembler::Variable* merged_variable); | |
210 ~Label() {} | |
211 | |
212 private: | |
213 friend class CodeStubAssembler; | |
214 | |
215 void Bind(); | |
216 void MergeVariables(); | |
217 | |
218 bool bound_; | |
219 size_t merge_count_; | |
220 CodeStubAssembler* assembler_; | |
221 RawMachineLabel* label_; | |
222 // Map of variables that need to be merged to their phi nodes (or placeholders | |
223 // for those phis). | |
224 std::map<Variable::Impl*, Node*> variable_phis_; | |
225 // Map of variables to the list of value nodes that have been added from each | |
226 // merge path in their order of merging. | |
227 std::map<Variable::Impl*, std::vector<Node*>> variable_merges_; | |
228 }; | |
229 | |
92 } // namespace compiler | 230 } // namespace compiler |
93 } // namespace internal | 231 } // namespace internal |
94 } // namespace v8 | 232 } // namespace v8 |
95 | 233 |
96 #endif // V8_COMPILER_CODE_STUB_ASSEMBLER_H_ | 234 #endif // V8_COMPILER_CODE_STUB_ASSEMBLER_H_ |
OLD | NEW |