OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_LINKAGE_H_ | 5 #ifndef V8_COMPILER_LINKAGE_H_ |
6 #define V8_COMPILER_LINKAGE_H_ | 6 #define V8_COMPILER_LINKAGE_H_ |
7 | 7 |
8 #include "src/base/flags.h" | 8 #include "src/base/flags.h" |
9 #include "src/compiler/frame.h" | 9 #include "src/compiler/frame.h" |
10 #include "src/compiler/machine-type.h" | 10 #include "src/compiler/machine-type.h" |
11 #include "src/compiler/operator.h" | 11 #include "src/compiler/operator.h" |
12 #include "src/frames.h" | 12 #include "src/frames.h" |
13 #include "src/runtime/runtime.h" | 13 #include "src/runtime/runtime.h" |
14 #include "src/zone.h" | 14 #include "src/zone.h" |
15 | 15 |
16 namespace v8 { | 16 namespace v8 { |
17 namespace internal { | 17 namespace internal { |
18 | 18 |
19 class CallInterfaceDescriptor; | 19 class CallInterfaceDescriptor; |
20 | 20 |
21 namespace compiler { | 21 namespace compiler { |
22 | 22 |
23 class OsrHelper; | 23 class OsrHelper; |
24 | 24 |
25 // Describes the location for a parameter or a return value to a call. | 25 // Describes the location for a parameter or a return value to a call. |
26 class LinkageLocation { | 26 class LinkageLocation { |
27 public: | 27 public: |
28 explicit LinkageLocation(int location) : location_(location) {} | 28 explicit LinkageLocation(int location) : location_(location) {} |
29 | 29 |
| 30 bool is_register() const { |
| 31 return 0 <= location_ && location_ <= ANY_REGISTER; |
| 32 } |
| 33 |
30 static const int16_t ANY_REGISTER = 1023; | 34 static const int16_t ANY_REGISTER = 1023; |
31 static const int16_t MAX_STACK_SLOT = 32767; | 35 static const int16_t MAX_STACK_SLOT = 32767; |
32 | 36 |
33 static LinkageLocation AnyRegister() { return LinkageLocation(ANY_REGISTER); } | 37 static LinkageLocation AnyRegister() { return LinkageLocation(ANY_REGISTER); } |
34 | 38 |
| 39 bool operator==(const LinkageLocation& other) const { |
| 40 return location_ == other.location_; |
| 41 } |
| 42 |
| 43 bool operator!=(const LinkageLocation& other) const { |
| 44 return !(*this == other); |
| 45 } |
| 46 |
35 private: | 47 private: |
36 friend class CallDescriptor; | 48 friend class CallDescriptor; |
37 friend class OperandGenerator; | 49 friend class OperandGenerator; |
38 // location < 0 -> a stack slot on the caller frame | 50 // location < 0 -> a stack slot on the caller frame |
39 // 0 <= location < 1023 -> a specific machine register | 51 // 0 <= location < 1023 -> a specific machine register |
40 // 1023 <= location < 1024 -> any machine register | 52 // 1023 <= location < 1024 -> any machine register |
41 // 1024 <= location -> a stack slot in the callee frame | 53 // 1024 <= location -> a stack slot in the callee frame |
42 int16_t location_; | 54 int16_t location_; |
43 }; | 55 }; |
44 | 56 |
45 typedef Signature<LinkageLocation> LocationSignature; | 57 typedef Signature<LinkageLocation> LocationSignature; |
46 | 58 |
47 // Describes a call to various parts of the compiler. Every call has the notion | 59 // Describes a call to various parts of the compiler. Every call has the notion |
48 // of a "target", which is the first input to the call. | 60 // of a "target", which is the first input to the call. |
49 class CallDescriptor final : public ZoneObject { | 61 class CallDescriptor final : public ZoneObject { |
50 public: | 62 public: |
51 // Describes the kind of this call, which determines the target. | 63 // Describes the kind of this call, which determines the target. |
52 enum Kind { | 64 enum Kind { |
53 kCallCodeObject, // target is a Code object | 65 kCallCodeObject, // target is a Code object |
54 kCallJSFunction, // target is a JSFunction object | 66 kCallJSFunction, // target is a JSFunction object |
55 kCallAddress // target is a machine pointer | 67 kCallAddress // target is a machine pointer |
56 }; | 68 }; |
57 | 69 |
58 enum Flag { | 70 enum Flag { |
59 kNoFlags = 0u, | 71 kNoFlags = 0u, |
60 kNeedsFrameState = 1u << 0, | 72 kNeedsFrameState = 1u << 0, |
61 kPatchableCallSite = 1u << 1, | 73 kPatchableCallSite = 1u << 1, |
62 kNeedsNopAfterCall = 1u << 2, | 74 kNeedsNopAfterCall = 1u << 2, |
63 kHasExceptionHandler = 1u << 3, | 75 kHasExceptionHandler = 1u << 3, |
| 76 kSupportsTailCalls = 1u << 4, |
64 kPatchableCallSiteWithNop = kPatchableCallSite | kNeedsNopAfterCall | 77 kPatchableCallSiteWithNop = kPatchableCallSite | kNeedsNopAfterCall |
65 }; | 78 }; |
66 typedef base::Flags<Flag> Flags; | 79 typedef base::Flags<Flag> Flags; |
67 | 80 |
68 CallDescriptor(Kind kind, MachineType target_type, LinkageLocation target_loc, | 81 CallDescriptor(Kind kind, MachineType target_type, LinkageLocation target_loc, |
69 const MachineSignature* machine_sig, | 82 const MachineSignature* machine_sig, |
70 LocationSignature* location_sig, size_t js_param_count, | 83 LocationSignature* location_sig, size_t js_param_count, |
71 Operator::Properties properties, | 84 Operator::Properties properties, |
72 RegList callee_saved_registers, Flags flags, | 85 RegList callee_saved_registers, Flags flags, |
73 const char* debug_name = "") | 86 const char* debug_name = "") |
(...skipping 27 matching lines...) Expand all Loading... |
101 // The total number of inputs to this call, which includes the target, | 114 // The total number of inputs to this call, which includes the target, |
102 // receiver, context, etc. | 115 // receiver, context, etc. |
103 // TODO(titzer): this should input the framestate input too. | 116 // TODO(titzer): this should input the framestate input too. |
104 size_t InputCount() const { return 1 + machine_sig_->parameter_count(); } | 117 size_t InputCount() const { return 1 + machine_sig_->parameter_count(); } |
105 | 118 |
106 size_t FrameStateCount() const { return NeedsFrameState() ? 1 : 0; } | 119 size_t FrameStateCount() const { return NeedsFrameState() ? 1 : 0; } |
107 | 120 |
108 Flags flags() const { return flags_; } | 121 Flags flags() const { return flags_; } |
109 | 122 |
110 bool NeedsFrameState() const { return flags() & kNeedsFrameState; } | 123 bool NeedsFrameState() const { return flags() & kNeedsFrameState; } |
| 124 bool SupportsTailCalls() const { return flags() & kSupportsTailCalls; } |
111 | 125 |
112 LinkageLocation GetReturnLocation(size_t index) const { | 126 LinkageLocation GetReturnLocation(size_t index) const { |
113 return location_sig_->GetReturn(index); | 127 return location_sig_->GetReturn(index); |
114 } | 128 } |
115 | 129 |
116 LinkageLocation GetInputLocation(size_t index) const { | 130 LinkageLocation GetInputLocation(size_t index) const { |
117 if (index == 0) return target_loc_; | 131 if (index == 0) return target_loc_; |
118 return location_sig_->GetParam(index - 1); | 132 return location_sig_->GetParam(index - 1); |
119 } | 133 } |
120 | 134 |
121 const MachineSignature* GetMachineSignature() const { return machine_sig_; } | 135 const MachineSignature* GetMachineSignature() const { return machine_sig_; } |
122 | 136 |
123 MachineType GetReturnType(size_t index) const { | 137 MachineType GetReturnType(size_t index) const { |
124 return machine_sig_->GetReturn(index); | 138 return machine_sig_->GetReturn(index); |
125 } | 139 } |
126 | 140 |
127 MachineType GetInputType(size_t index) const { | 141 MachineType GetInputType(size_t index) const { |
128 if (index == 0) return target_type_; | 142 if (index == 0) return target_type_; |
129 return machine_sig_->GetParam(index - 1); | 143 return machine_sig_->GetParam(index - 1); |
130 } | 144 } |
131 | 145 |
132 // Operator properties describe how this call can be optimized, if at all. | 146 // Operator properties describe how this call can be optimized, if at all. |
133 Operator::Properties properties() const { return properties_; } | 147 Operator::Properties properties() const { return properties_; } |
134 | 148 |
135 // Get the callee-saved registers, if any, across this call. | 149 // Get the callee-saved registers, if any, across this call. |
136 RegList CalleeSavedRegisters() const { return callee_saved_registers_; } | 150 RegList CalleeSavedRegisters() const { return callee_saved_registers_; } |
137 | 151 |
138 const char* debug_name() const { return debug_name_; } | 152 const char* debug_name() const { return debug_name_; } |
139 | 153 |
| 154 bool UsesOnlyRegisters() const; |
| 155 |
| 156 bool HasSameReturnLocationsAs(const CallDescriptor* other) const; |
| 157 |
140 private: | 158 private: |
141 friend class Linkage; | 159 friend class Linkage; |
142 | 160 |
143 const Kind kind_; | 161 const Kind kind_; |
144 const MachineType target_type_; | 162 const MachineType target_type_; |
145 const LinkageLocation target_loc_; | 163 const LinkageLocation target_loc_; |
146 const MachineSignature* const machine_sig_; | 164 const MachineSignature* const machine_sig_; |
147 const LocationSignature* const location_sig_; | 165 const LocationSignature* const location_sig_; |
148 const size_t js_param_count_; | 166 const size_t js_param_count_; |
149 const Operator::Properties properties_; | 167 const Operator::Properties properties_; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 CallDescriptor* const incoming_; | 256 CallDescriptor* const incoming_; |
239 | 257 |
240 DISALLOW_COPY_AND_ASSIGN(Linkage); | 258 DISALLOW_COPY_AND_ASSIGN(Linkage); |
241 }; | 259 }; |
242 | 260 |
243 } // namespace compiler | 261 } // namespace compiler |
244 } // namespace internal | 262 } // namespace internal |
245 } // namespace v8 | 263 } // namespace v8 |
246 | 264 |
247 #endif // V8_COMPILER_LINKAGE_H_ | 265 #endif // V8_COMPILER_LINKAGE_H_ |
OLD | NEW |