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); |
| 82 Node* value() const; |
| 83 MachineRepresentation rep() const; |
| 84 bool IsBound() const; |
| 85 |
| 86 private: |
| 87 friend class CodeStubAssembler; |
| 88 class Impl; |
| 89 Impl* impl_; |
| 90 }; |
| 91 |
| 92 // =========================================================================== |
| 93 // Base Assembler |
| 94 // =========================================================================== |
| 95 |
39 // Constants. | 96 // Constants. |
40 Node* Int32Constant(int value); | 97 Node* Int32Constant(int value); |
41 Node* IntPtrConstant(intptr_t value); | 98 Node* IntPtrConstant(intptr_t value); |
42 Node* NumberConstant(double value); | 99 Node* NumberConstant(double value); |
43 Node* HeapConstant(Handle<HeapObject> object); | 100 Node* HeapConstant(Handle<HeapObject> object); |
44 Node* BooleanConstant(bool value); | 101 Node* BooleanConstant(bool value); |
| 102 Node* ExternalConstant(ExternalReference address); |
45 | 103 |
46 Node* Parameter(int value); | 104 Node* Parameter(int value); |
47 void Return(Node* value); | 105 void Return(Node* value); |
48 | 106 |
49 // Tag and untag Smi values. | 107 void Bind(Label* label); |
50 Node* SmiTag(Node* value); | 108 void Goto(Label* label); |
51 Node* SmiUntag(Node* value); | 109 void Branch(Node* condition, Label* true_label, Label* false_label); |
52 | 110 |
53 // Basic arithmetic operations. | 111 void Switch(Node* index, Label* default_label, int32_t* case_values, |
54 Node* IntPtrAdd(Node* a, Node* b); | 112 Label** case_labels, size_t case_count); |
55 Node* IntPtrSub(Node* a, Node* b); | 113 |
| 114 // Access to the frame pointer |
| 115 Node* LoadFramePointer(); |
| 116 Node* LoadParentFramePointer(); |
| 117 |
| 118 // Basic arithmetic operations. |
| 119 #define DECLARE_CODE_STUB_ASSEMBER_BINARY_OP(name) Node* name(Node* a, Node* b); |
| 120 CODE_STUB_ASSEMBLER_BINARY_OP_LIST(DECLARE_CODE_STUB_ASSEMBER_BINARY_OP) |
| 121 #undef DECLARE_CODE_STUB_ASSEMBER_BINARY_OP |
| 122 |
56 Node* WordShl(Node* value, int shift); | 123 Node* WordShl(Node* value, int shift); |
57 | 124 |
58 // Load a field from an object on the heap. | 125 // Calls |
59 Node* LoadObjectField(Node* object, int offset); | |
60 | |
61 // Call runtime function. | |
62 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1); | 126 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1); |
63 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1, | 127 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1, |
64 Node* arg2); | 128 Node* arg2); |
65 | 129 |
66 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, | 130 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, |
67 Node* arg1); | 131 Node* arg1); |
68 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, | 132 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, |
69 Node* arg1, Node* arg2); | 133 Node* arg1, Node* arg2); |
| 134 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, |
| 135 Node* arg1, Node* arg2, Node* arg3); |
| 136 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, |
| 137 Node* arg1, Node* arg2, Node* arg3, Node* arg4); |
| 138 |
| 139 Node* TailCallStub(CodeStub& stub, Node** args); |
| 140 Node* TailCall(const CallInterfaceDescriptor& descriptor, Node* target, |
| 141 Node** args); |
| 142 |
| 143 // =========================================================================== |
| 144 // Macros |
| 145 // =========================================================================== |
| 146 |
| 147 // Tag and untag Smi values. |
| 148 Node* SmiTag(Node* value); |
| 149 Node* SmiUntag(Node* value); |
| 150 |
| 151 // Load a value from the root array. |
| 152 Node* LoadRoot(Heap::RootListIndex root_index); |
| 153 |
| 154 // Check a value for smi-ness |
| 155 Node* WordIsSmi(Node* a); |
| 156 |
| 157 // Load an object pointer from a buffer that isn't in the heap. |
| 158 Node* LoadBufferObject(Node* buffer, int offset); |
| 159 // Load a field from an object on the heap. |
| 160 Node* LoadObjectField(Node* object, int offset); |
| 161 |
| 162 // Load an array element from a FixedArray. |
| 163 Node* LoadFixedArrayElementSmiIndex(Node* object, Node* smi_index, |
| 164 int additional_offset = 0); |
| 165 Node* LoadFixedArrayElementConstantIndex(Node* object, int index); |
70 | 166 |
71 private: | 167 private: |
72 friend class CodeStubAssemblerTester; | 168 friend class CodeStubAssemblerTester; |
73 | 169 |
74 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); | 170 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); |
75 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args); | 171 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args); |
76 | 172 |
77 Node* SmiShiftBitsConstant(); | 173 Node* SmiShiftBitsConstant(); |
78 | 174 |
79 // Private helpers which delegate to RawMachineAssembler. | 175 // Private helpers which delegate to RawMachineAssembler. |
80 Graph* graph(); | 176 Graph* graph(); |
81 Isolate* isolate(); | 177 Isolate* isolate(); |
82 Zone* zone(); | 178 Zone* zone(); |
83 | 179 |
84 base::SmartPointer<RawMachineAssembler> raw_assembler_; | 180 base::SmartPointer<RawMachineAssembler> raw_assembler_; |
85 Code::Flags flags_; | 181 Code::Flags flags_; |
86 const char* name_; | 182 const char* name_; |
87 bool code_generated_; | 183 bool code_generated_; |
| 184 ZoneVector<Variable::Impl*> variables_; |
88 | 185 |
89 DISALLOW_COPY_AND_ASSIGN(CodeStubAssembler); | 186 DISALLOW_COPY_AND_ASSIGN(CodeStubAssembler); |
90 }; | 187 }; |
91 | 188 |
| 189 class CodeStubAssembler::Label { |
| 190 public: |
| 191 explicit Label(CodeStubAssembler* assembler); |
| 192 Label(CodeStubAssembler* assembler, int merged_variable_count, |
| 193 CodeStubAssembler::Variable** merged_variables); |
| 194 Label(CodeStubAssembler* assembler, |
| 195 CodeStubAssembler::Variable* merged_variable); |
| 196 ~Label() {} |
| 197 |
| 198 private: |
| 199 friend class CodeStubAssembler; |
| 200 |
| 201 void Bind(); |
| 202 void MergeVariables(); |
| 203 |
| 204 bool bound_; |
| 205 size_t merge_count_; |
| 206 CodeStubAssembler* assembler_; |
| 207 RawMachineLabel* label_; |
| 208 // Map of variables that need to be merged to their phi nodes (or placeholders |
| 209 // for those phis). |
| 210 std::map<Variable::Impl*, Node*> variable_phis_; |
| 211 // Map of variables to the list of value nodes that have been added from each |
| 212 // merge path in their order of merging. |
| 213 std::map<Variable::Impl*, std::vector<Node*>> variable_merges_; |
| 214 }; |
| 215 |
92 } // namespace compiler | 216 } // namespace compiler |
93 } // namespace internal | 217 } // namespace internal |
94 } // namespace v8 | 218 } // namespace v8 |
95 | 219 |
96 #endif // V8_COMPILER_CODE_STUB_ASSEMBLER_H_ | 220 #endif // V8_COMPILER_CODE_STUB_ASSEMBLER_H_ |
OLD | NEW |