Chromium Code Reviews| 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 <limits> | |
| 9 #include <vector> | |
| 10 | |
| 8 // Clients of this interface shouldn't depend on lots of compiler internals. | 11 // Clients of this interface shouldn't depend on lots of compiler internals. |
| 9 // Do not include anything from src/compiler here! | 12 // Do not include anything from src/compiler here! |
| 10 #include "src/allocation.h" | 13 #include "src/allocation.h" |
| 11 #include "src/builtins.h" | 14 #include "src/builtins.h" |
| 15 #include "src/machine-type.h" | |
| 12 #include "src/runtime/runtime.h" | 16 #include "src/runtime/runtime.h" |
| 13 | 17 |
| 14 namespace v8 { | 18 namespace v8 { |
| 15 namespace internal { | 19 namespace internal { |
| 16 | 20 |
| 17 class CallInterfaceDescriptor; | 21 class CallInterfaceDescriptor; |
| 18 class Isolate; | 22 class Isolate; |
| 19 class Zone; | 23 class Zone; |
| 20 | 24 |
| 21 namespace compiler { | 25 namespace compiler { |
| 22 | 26 |
| 23 class CallDescriptor; | 27 class CallDescriptor; |
| 24 class Graph; | 28 class Graph; |
| 25 class Node; | 29 class Node; |
| 26 class Operator; | 30 class Operator; |
| 27 class RawMachineAssembler; | 31 class RawMachineAssembler; |
| 32 class RawMachineLabel; | |
| 28 class Schedule; | 33 class Schedule; |
| 29 | 34 |
| 30 class CodeStubAssembler { | 35 class CodeStubAssembler { |
| 31 public: | 36 public: |
| 37 class Label; | |
| 38 | |
| 39 // Create with CallStub linkage. | |
| 32 CodeStubAssembler(Isolate* isolate, Zone* zone, | 40 CodeStubAssembler(Isolate* isolate, Zone* zone, |
| 33 const CallInterfaceDescriptor& descriptor, | 41 const CallInterfaceDescriptor& descriptor, |
| 34 Code::Flags flags, const char* name); | 42 Code::Flags flags, const char* name); |
| 43 | |
| 44 // Create with JSCall linkage. | |
| 45 CodeStubAssembler(Isolate* isolate, Zone* zone, int parameter_count, | |
| 46 Code::Flags flags, const char* name); | |
| 47 | |
| 35 virtual ~CodeStubAssembler(); | 48 virtual ~CodeStubAssembler(); |
| 36 | 49 |
| 37 Handle<Code> GenerateCode(); | 50 Handle<Code> GenerateCode(); |
| 38 | 51 |
| 39 // Constants. | 52 // Constants. |
| 40 Node* Int32Constant(int value); | 53 Node* Int32Constant(int value); |
| 41 Node* IntPtrConstant(intptr_t value); | 54 Node* IntPtrConstant(intptr_t value); |
| 42 Node* NumberConstant(double value); | 55 Node* NumberConstant(double value); |
| 43 Node* HeapConstant(Handle<HeapObject> object); | 56 Node* HeapConstant(Handle<HeapObject> object); |
| 57 Node* UndefinedConstant(); | |
| 44 Node* BooleanConstant(bool value); | 58 Node* BooleanConstant(bool value); |
| 45 | 59 |
| 60 // Memory Operations. | |
| 61 Node* Load(MachineType rep, Node* base); | |
| 62 Node* Load(MachineType rep, Node* base, Node* index); | |
| 63 | |
| 46 Node* Parameter(int value); | 64 Node* Parameter(int value); |
| 47 void Return(Node* value); | |
| 48 | 65 |
| 49 // Tag and untag Smi values. | 66 // Tag and untag Smi values. |
| 50 Node* SmiTag(Node* value); | 67 Node* SmiTag(Node* value); |
| 51 Node* SmiUntag(Node* value); | 68 Node* SmiUntag(Node* value); |
| 52 | 69 |
| 53 // Basic arithmetic operations. | 70 // Basic arithmetic operations. |
| 54 Node* IntPtrAdd(Node* a, Node* b); | 71 Node* IntPtrAdd(Node* a, Node* b); |
| 55 Node* IntPtrSub(Node* a, Node* b); | 72 Node* IntPtrSub(Node* a, Node* b); |
| 56 Node* WordShl(Node* value, int shift); | 73 Node* WordShl(Node* value, int shift); |
| 74 Node* WordEqual(Node* a, Node* b); | |
| 75 Node* WordOr(Node* a, Node* b); | |
| 76 Node* WordAnd(Node* a, Node* b); | |
| 77 Node* Int32GreaterThanOrEqual(Node* a, Node* b); | |
| 78 Node* Int32LessThan(Node* a, Node* b); | |
| 57 | 79 |
| 58 // Load a field from an object on the heap. | 80 // Heap objects. |
| 59 Node* LoadObjectField(Node* object, int offset); | 81 Node* LoadObjectField(Node* object, int offset); |
| 82 Node* IsHeapObject(Node* tagged); | |
| 83 Node* InstanceType(Node* object); | |
| 84 | |
| 85 // Returns a node that is true if the given bit is set in |word32|. | |
| 86 template <typename T> | |
| 87 Node* BitFieldValue(Node* word32) { | |
| 88 return BitFieldValue(word32, T::kShift, T::kMask); | |
| 89 } | |
| 90 | |
| 91 Node* BitFieldValue(Node* word32, uint32_t shift, uint32_t mask); | |
| 60 | 92 |
| 61 // Call runtime function. | 93 // Call runtime function. |
| 62 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1); | 94 Node* CallRuntime(Runtime::FunctionId function_id, Node* arg1); |
| 63 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1, | 95 Node* CallRuntime(Runtime::FunctionId function_id, Node* arg1, Node* arg2); |
| 64 Node* arg2); | |
| 65 | 96 |
| 66 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, | 97 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* arg1); |
| 67 Node* arg1); | 98 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* arg1, |
| 68 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, | 99 Node* arg2); |
| 69 Node* arg1, Node* arg2); | 100 |
| 101 // Control flow. | |
| 102 void Goto(Label* label); | |
| 103 void Branch(Node* cond, Label* true_label, Label* false_label); | |
| 104 void Bind(Label* label); | |
| 105 void Return(Node* value); | |
| 106 | |
| 107 // Variables. | |
| 108 Node* Phi(MachineRepresentation rep, Node* n1, Node* n2); | |
| 70 | 109 |
| 71 private: | 110 private: |
| 72 friend class CodeStubAssemblerTester; | 111 friend class CodeStubAssemblerTester; |
| 73 | 112 |
| 113 Node* Context(); | |
| 74 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); | 114 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); |
| 75 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args); | 115 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args); |
| 76 | 116 |
| 77 Node* SmiShiftBitsConstant(); | 117 Node* SmiShiftBitsConstant(); |
| 118 RawMachineLabel* GetOrCreateRawMachineLabel(Label* label); | |
| 78 | 119 |
| 79 // Private helpers which delegate to RawMachineAssembler. | 120 // Private helpers which delegate to RawMachineAssembler. |
| 80 Graph* graph(); | 121 Graph* graph(); |
| 81 Isolate* isolate(); | 122 Isolate* isolate(); |
| 82 Zone* zone(); | 123 Zone* zone(); |
| 83 | 124 |
| 125 enum class LinkageDescriptorType { kStubCall, kJSCall }; | |
| 126 | |
| 84 base::SmartPointer<RawMachineAssembler> raw_assembler_; | 127 base::SmartPointer<RawMachineAssembler> raw_assembler_; |
| 85 Code::Flags flags_; | 128 Code::Flags flags_; |
| 86 const char* name_; | 129 const char* name_; |
| 87 bool code_generated_; | 130 bool code_generated_; |
| 131 std::vector<RawMachineLabel*> labels_; | |
| 132 LinkageDescriptorType linkage_type_; | |
| 133 int parameter_count_; | |
| 88 | 134 |
| 89 DISALLOW_COPY_AND_ASSIGN(CodeStubAssembler); | 135 DISALLOW_COPY_AND_ASSIGN(CodeStubAssembler); |
| 90 }; | 136 }; |
| 91 | 137 |
| 138 | |
| 139 class CodeStubAssembler::Label { | |
| 140 public: | |
| 141 Label() : raw_label_(nullptr) {} | |
| 142 | |
| 143 private: | |
| 144 friend class CodeStubAssembler; | |
| 145 | |
| 146 RawMachineLabel* raw_label_; | |
|
Jarin
2016/02/08 10:25:04
Why is this a pointer? Can't it be an embedded fie
| |
| 147 }; | |
| 148 | |
| 149 | |
| 92 } // namespace compiler | 150 } // namespace compiler |
| 93 } // namespace internal | 151 } // namespace internal |
| 94 } // namespace v8 | 152 } // namespace v8 |
| 95 | 153 |
| 96 #endif // V8_COMPILER_CODE_STUB_ASSEMBLER_H_ | 154 #endif // V8_COMPILER_CODE_STUB_ASSEMBLER_H_ |
| OLD | NEW |