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

Side by Side Diff: src/compiler/code-assembler.h

Issue 1875583003: Separate CodeAssembler and CodeStubAssembler (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix gn build. Again. Created 4 years, 8 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
« no previous file with comments | « src/code-stubs.cc ('k') | src/compiler/code-assembler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_CODE_ASSEMBLER_H_
6 #define V8_COMPILER_CODE_ASSEMBLER_H_
7
8 #include <map>
9
10 // Clients of this interface shouldn't depend on lots of compiler internals.
11 // Do not include anything from src/compiler here!
12 #include "src/allocation.h"
13 #include "src/builtins.h"
14 #include "src/heap/heap.h"
15 #include "src/machine-type.h"
16 #include "src/runtime/runtime.h"
17 #include "src/zone-containers.h"
18
19 namespace v8 {
20 namespace internal {
21
22 class Callable;
23 class CallInterfaceDescriptor;
24 class Isolate;
25 class Factory;
26 class Zone;
27
28 namespace compiler {
29
30 class CallDescriptor;
31 class Graph;
32 class Node;
33 class Operator;
34 class RawMachineAssembler;
35 class RawMachineLabel;
36 class Schedule;
37
38 #define CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \
39 V(Float32Equal) \
40 V(Float32LessThan) \
41 V(Float32LessThanOrEqual) \
42 V(Float32GreaterThan) \
43 V(Float32GreaterThanOrEqual) \
44 V(Float64Equal) \
45 V(Float64LessThan) \
46 V(Float64LessThanOrEqual) \
47 V(Float64GreaterThan) \
48 V(Float64GreaterThanOrEqual) \
49 V(Int32GreaterThan) \
50 V(Int32GreaterThanOrEqual) \
51 V(Int32LessThan) \
52 V(Int32LessThanOrEqual) \
53 V(IntPtrLessThan) \
54 V(IntPtrLessThanOrEqual) \
55 V(Uint32LessThan) \
56 V(UintPtrGreaterThanOrEqual) \
57 V(WordEqual) \
58 V(WordNotEqual) \
59 V(Word32Equal) \
60 V(Word32NotEqual) \
61 V(Word64Equal) \
62 V(Word64NotEqual)
63
64 #define CODE_ASSEMBLER_BINARY_OP_LIST(V) \
65 CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \
66 V(Float64Add) \
67 V(Float64Sub) \
68 V(Float64Mul) \
69 V(Float64Div) \
70 V(Float64Mod) \
71 V(Float64InsertLowWord32) \
72 V(Float64InsertHighWord32) \
73 V(IntPtrAdd) \
74 V(IntPtrAddWithOverflow) \
75 V(IntPtrSub) \
76 V(IntPtrSubWithOverflow) \
77 V(IntPtrMul) \
78 V(Int32Add) \
79 V(Int32AddWithOverflow) \
80 V(Int32Sub) \
81 V(Int32Mul) \
82 V(Int32Div) \
83 V(WordOr) \
84 V(WordAnd) \
85 V(WordXor) \
86 V(WordShl) \
87 V(WordShr) \
88 V(WordSar) \
89 V(WordRor) \
90 V(Word32Or) \
91 V(Word32And) \
92 V(Word32Xor) \
93 V(Word32Shl) \
94 V(Word32Shr) \
95 V(Word32Sar) \
96 V(Word32Ror) \
97 V(Word64Or) \
98 V(Word64And) \
99 V(Word64Xor) \
100 V(Word64Shr) \
101 V(Word64Sar) \
102 V(Word64Ror)
103
104 #define CODE_ASSEMBLER_UNARY_OP_LIST(V) \
105 V(Float64Neg) \
106 V(Float64Sqrt) \
107 V(Float64ExtractLowWord32) \
108 V(Float64ExtractHighWord32) \
109 V(TruncateInt64ToInt32) \
110 V(ChangeFloat64ToUint32) \
111 V(ChangeInt32ToFloat64) \
112 V(ChangeInt32ToInt64) \
113 V(ChangeUint32ToFloat64) \
114 V(ChangeUint32ToUint64) \
115 V(Float64RoundDown) \
116 V(Float64RoundUp) \
117 V(Float64RoundTruncate) \
118 V(Word32Clz)
119
120 // A "public" interface used by components outside of compiler directory to
121 // create code objects with TurboFan's backend. This class is mostly a thin shim
122 // around the RawMachineAssembler, and its primary job is to ensure that the
123 // innards of the RawMachineAssembler and other compiler implementation details
124 // don't leak outside of the the compiler directory..
125 //
126 // V8 components that need to generate low-level code using this interface
127 // should include this header--and this header only--from the compiler directory
128 // (this is actually enforced). Since all interesting data structures are
129 // forward declared, it's not possible for clients to peek inside the compiler
130 // internals.
131 //
132 // In addition to providing isolation between TurboFan and code generation
133 // clients, CodeAssembler also provides an abstraction for creating variables
134 // and enhanced Label functionality to merge variable values along paths where
135 // they have differing values, including loops.
136 class CodeAssembler {
137 public:
138 // Create with CallStub linkage.
139 // |result_size| specifies the number of results returned by the stub.
140 // TODO(rmcilroy): move result_size to the CallInterfaceDescriptor.
141 CodeAssembler(Isolate* isolate, Zone* zone,
142 const CallInterfaceDescriptor& descriptor, Code::Flags flags,
143 const char* name, size_t result_size = 1);
144
145 // Create with JSCall linkage.
146 CodeAssembler(Isolate* isolate, Zone* zone, int parameter_count,
147 Code::Flags flags, const char* name);
148
149 virtual ~CodeAssembler();
150
151 Handle<Code> GenerateCode();
152
153 bool Is64() const;
154 bool IsFloat64RoundUpSupported() const;
155 bool IsFloat64RoundDownSupported() const;
156 bool IsFloat64RoundTruncateSupported() const;
157
158 class Label;
159 class Variable {
160 public:
161 explicit Variable(CodeAssembler* assembler, MachineRepresentation rep);
162 void Bind(Node* value);
163 Node* value() const;
164 MachineRepresentation rep() const;
165 bool IsBound() const;
166
167 private:
168 friend class CodeAssembler;
169 class Impl;
170 Impl* impl_;
171 };
172
173 enum AllocationFlag : uint8_t {
174 kNone = 0,
175 kDoubleAlignment = 1,
176 kPretenured = 1 << 1
177 };
178
179 typedef base::Flags<AllocationFlag> AllocationFlags;
180
181 // ===========================================================================
182 // Base Assembler
183 // ===========================================================================
184
185 // Constants.
186 Node* Int32Constant(int value);
187 Node* IntPtrConstant(intptr_t value);
188 Node* NumberConstant(double value);
189 Node* SmiConstant(Smi* value);
190 Node* HeapConstant(Handle<HeapObject> object);
191 Node* BooleanConstant(bool value);
192 Node* ExternalConstant(ExternalReference address);
193 Node* Float64Constant(double value);
194 Node* BooleanMapConstant();
195 Node* EmptyStringConstant();
196 Node* HeapNumberMapConstant();
197 Node* NaNConstant();
198 Node* NoContextConstant();
199 Node* NullConstant();
200 Node* UndefinedConstant();
201
202 Node* Parameter(int value);
203 void Return(Node* value);
204
205 void Bind(Label* label);
206 void Goto(Label* label);
207 void GotoIf(Node* condition, Label* true_label);
208 void GotoUnless(Node* condition, Label* false_label);
209 void Branch(Node* condition, Label* true_label, Label* false_label);
210
211 void Switch(Node* index, Label* default_label, int32_t* case_values,
212 Label** case_labels, size_t case_count);
213
214 // Access to the frame pointer
215 Node* LoadFramePointer();
216 Node* LoadParentFramePointer();
217
218 // Access to the stack pointer
219 Node* LoadStackPointer();
220
221 // Load raw memory location.
222 Node* Load(MachineType rep, Node* base);
223 Node* Load(MachineType rep, Node* base, Node* index);
224
225 // Store value to raw memory location.
226 Node* Store(MachineRepresentation rep, Node* base, Node* value);
227 Node* Store(MachineRepresentation rep, Node* base, Node* index, Node* value);
228 Node* StoreNoWriteBarrier(MachineRepresentation rep, Node* base, Node* value);
229 Node* StoreNoWriteBarrier(MachineRepresentation rep, Node* base, Node* index,
230 Node* value);
231
232 // Basic arithmetic operations.
233 #define DECLARE_CODE_ASSEMBLER_BINARY_OP(name) Node* name(Node* a, Node* b);
234 CODE_ASSEMBLER_BINARY_OP_LIST(DECLARE_CODE_ASSEMBLER_BINARY_OP)
235 #undef DECLARE_CODE_ASSEMBLER_BINARY_OP
236
237 Node* WordShl(Node* value, int shift);
238
239 // Unary
240 #define DECLARE_CODE_ASSEMBLER_UNARY_OP(name) Node* name(Node* a);
241 CODE_ASSEMBLER_UNARY_OP_LIST(DECLARE_CODE_ASSEMBLER_UNARY_OP)
242 #undef DECLARE_CODE_ASSEMBLER_UNARY_OP
243
244 Node* TruncateFloat64ToInt32RoundToZero(Node* a);
245 Node* TruncateFloat64ToInt32JavaScript(Node* a);
246
247 // Projections
248 Node* Projection(int index, Node* value);
249
250 // Calls
251 Node* CallRuntime(Runtime::FunctionId function_id, Node* context);
252 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1);
253 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1,
254 Node* arg2);
255 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1,
256 Node* arg2, Node* arg3);
257 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1,
258 Node* arg2, Node* arg3, Node* arg4);
259 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1,
260 Node* arg2, Node* arg3, Node* arg4, Node* arg5);
261
262 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context);
263 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
264 Node* arg1);
265 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
266 Node* arg1, Node* arg2);
267 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
268 Node* arg1, Node* arg2, Node* arg3);
269 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
270 Node* arg1, Node* arg2, Node* arg3, Node* arg4);
271
272 Node* CallStub(Callable const& callable, Node* context, Node* arg1,
273 size_t result_size = 1);
274 Node* CallStub(Callable const& callable, Node* context, Node* arg1,
275 Node* arg2, size_t result_size = 1);
276 Node* CallStub(Callable const& callable, Node* context, Node* arg1,
277 Node* arg2, Node* arg3, size_t result_size = 1);
278
279 Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target,
280 Node* context, Node* arg1, size_t result_size = 1);
281 Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target,
282 Node* context, Node* arg1, Node* arg2, size_t result_size = 1);
283 Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target,
284 Node* context, Node* arg1, Node* arg2, Node* arg3,
285 size_t result_size = 1);
286 Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target,
287 Node* context, Node* arg1, Node* arg2, Node* arg3, Node* arg4,
288 size_t result_size = 1);
289 Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target,
290 Node* context, Node* arg1, Node* arg2, Node* arg3, Node* arg4,
291 Node* arg5, size_t result_size = 1);
292
293 Node* TailCallStub(Callable const& callable, Node* context, Node* arg1,
294 Node* arg2, size_t result_size = 1);
295 Node* TailCallStub(const CallInterfaceDescriptor& descriptor, Node* target,
296 Node* context, Node* arg1, Node* arg2,
297 size_t result_size = 1);
298
299 Node* TailCallBytecodeDispatch(const CallInterfaceDescriptor& descriptor,
300 Node* code_target_address, Node** args);
301
302 // ===========================================================================
303 // Macros
304 // ===========================================================================
305
306 // Tag a Word as a Smi value.
307 Node* SmiTag(Node* value);
308 // Untag a Smi value as a Word.
309 Node* SmiUntag(Node* value);
310
311 // Load a value from the root array.
312 Node* LoadRoot(Heap::RootListIndex root_index);
313
314 // Allocate an object of the given size.
315 Node* Allocate(int size, AllocationFlags flags = kNone);
316 Node* InnerAllocate(Node* previous, int offset);
317
318 // Branching helpers.
319 void BranchIf(Node* condition, Label* if_true, Label* if_false);
320
321 #define BRANCH_HELPER(name) \
322 void BranchIf##name(Node* a, Node* b, Label* if_true, Label* if_false) { \
323 BranchIf(name(a, b), if_true, if_false); \
324 }
325 CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(BRANCH_HELPER)
326 #undef BRANCH_HELPER
327
328 // Helpers which delegate to RawMachineAssembler.
329 Factory* factory() const;
330 Isolate* isolate() const;
331 Zone* zone() const;
332
333 protected:
334 // Protected helpers which delegate to RawMachineAssembler.
335 Graph* graph() const;
336
337 Node* SmiShiftBitsConstant();
338
339 // Enables subclasses to perform operations before and after a call.
340 virtual void CallPrologue();
341 virtual void CallEpilogue();
342
343 private:
344 friend class CodeAssemblerTester;
345
346 CodeAssembler(Isolate* isolate, Zone* zone, CallDescriptor* call_descriptor,
347 Code::Flags flags, const char* name);
348
349 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args);
350 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args);
351
352 Node* AllocateRawAligned(Node* size_in_bytes, AllocationFlags flags,
353 Node* top_address, Node* limit_address);
354 Node* AllocateRawUnaligned(Node* size_in_bytes, AllocationFlags flags,
355 Node* top_adddress, Node* limit_address);
356
357 base::SmartPointer<RawMachineAssembler> raw_assembler_;
358 Code::Flags flags_;
359 const char* name_;
360 bool code_generated_;
361 ZoneVector<Variable::Impl*> variables_;
362
363 DISALLOW_COPY_AND_ASSIGN(CodeAssembler);
364 };
365
366 DEFINE_OPERATORS_FOR_FLAGS(CodeAssembler::AllocationFlags);
367
368 class CodeAssembler::Label {
369 public:
370 enum Type { kDeferred, kNonDeferred };
371
372 explicit Label(
373 CodeAssembler* assembler,
374 CodeAssembler::Label::Type type = CodeAssembler::Label::kNonDeferred)
375 : CodeAssembler::Label(assembler, 0, nullptr, type) {}
376 Label(CodeAssembler* assembler, CodeAssembler::Variable* merged_variable,
377 CodeAssembler::Label::Type type = CodeAssembler::Label::kNonDeferred)
378 : CodeAssembler::Label(assembler, 1, &merged_variable, type) {}
379 Label(CodeAssembler* assembler, int merged_variable_count,
380 CodeAssembler::Variable** merged_variables,
381 CodeAssembler::Label::Type type = CodeAssembler::Label::kNonDeferred);
382 ~Label() {}
383
384 private:
385 friend class CodeAssembler;
386
387 void Bind();
388 void MergeVariables();
389
390 bool bound_;
391 size_t merge_count_;
392 CodeAssembler* assembler_;
393 RawMachineLabel* label_;
394 // Map of variables that need to be merged to their phi nodes (or placeholders
395 // for those phis).
396 std::map<Variable::Impl*, Node*> variable_phis_;
397 // Map of variables to the list of value nodes that have been added from each
398 // merge path in their order of merging.
399 std::map<Variable::Impl*, std::vector<Node*>> variable_merges_;
400 };
401
402 } // namespace compiler
403 } // namespace internal
404 } // namespace v8
405
406 #endif // V8_COMPILER_CODE_ASSEMBLER_H_
OLDNEW
« no previous file with comments | « src/code-stubs.cc ('k') | src/compiler/code-assembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698