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/v8.h" | 8 #include "src/base/flags.h" |
9 | |
10 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
11 #include "src/compiler/frame.h" | 10 #include "src/compiler/frame.h" |
12 #include "src/compiler/machine-operator.h" | 11 #include "src/compiler/machine-operator.h" |
13 #include "src/compiler/node.h" | 12 #include "src/compiler/node.h" |
14 #include "src/compiler/operator.h" | 13 #include "src/compiler/operator.h" |
15 #include "src/zone.h" | 14 #include "src/zone.h" |
16 | 15 |
17 namespace v8 { | 16 namespace v8 { |
18 namespace internal { | 17 namespace internal { |
19 namespace compiler { | 18 namespace compiler { |
(...skipping 10 matching lines...) Expand all Loading... | |
30 static const int16_t ANY_REGISTER = 32767; | 29 static const int16_t ANY_REGISTER = 32767; |
31 | 30 |
32 private: | 31 private: |
33 friend class CallDescriptor; | 32 friend class CallDescriptor; |
34 friend class OperandGenerator; | 33 friend class OperandGenerator; |
35 MachineType rep_; | 34 MachineType rep_; |
36 int16_t location_; // >= 0 implies register, otherwise stack slot. | 35 int16_t location_; // >= 0 implies register, otherwise stack slot. |
37 }; | 36 }; |
38 | 37 |
39 | 38 |
40 class CallDescriptor : public ZoneObject { | 39 class CallDescriptor V8_FINAL : public ZoneObject { |
41 public: | 40 public: |
42 // Describes whether the first parameter is a code object, a JSFunction, | 41 // Describes whether the first parameter is a code object, a JSFunction, |
43 // or an address--all of which require different machine sequences to call. | 42 // or an address--all of which require different machine sequences to call. |
44 enum Kind { kCallCodeObject, kCallJSFunction, kCallAddress }; | 43 enum Kind { kCallCodeObject, kCallJSFunction, kCallAddress }; |
45 | 44 |
46 // TODO(jarin) kLazyDeoptimization and kNeedsFrameState should be unified. | 45 enum Flag { |
Michael Starzinger
2014/08/27 12:50:11
nit: I think the TODO for Jaro still applies, bett
Benedikt Meurer
2014/08/28 11:46:57
Ups, didn't mean to remove that.
| |
47 enum DeoptimizationSupport { | 46 kNoFlags = 0u, |
48 kNoDeoptimization = 0, | 47 kLazyDeoptimization = 1u << 0, |
49 kLazyDeoptimization = 1, | 48 kNeedsFrameState = 1u << 1, |
50 kNeedsFrameState = 2 | 49 kPatchableCallSite = 1u << 2, |
50 kNeedsNopAfterCall = 1u << 3, | |
51 kPatchableCallSiteWithNop = kPatchableCallSite | kNeedsNopAfterCall | |
51 }; | 52 }; |
53 DEFINE_FLAGS(Flags, Flag); | |
52 | 54 |
53 CallDescriptor(Kind kind, int8_t return_count, int16_t parameter_count, | 55 CallDescriptor(Kind kind, int8_t return_count, int16_t parameter_count, |
54 int16_t input_count, LinkageLocation* locations, | 56 int16_t input_count, LinkageLocation* locations, |
55 Operator::Property properties, RegList callee_saved_registers, | 57 Operator::Property properties, RegList callee_saved_registers, |
56 DeoptimizationSupport deoptimization_support, | 58 Flags flags, const char* debug_name = "") |
57 const char* debug_name = "") | |
58 : kind_(kind), | 59 : kind_(kind), |
59 return_count_(return_count), | 60 return_count_(return_count), |
60 parameter_count_(parameter_count), | 61 parameter_count_(parameter_count), |
61 input_count_(input_count), | 62 input_count_(input_count), |
62 locations_(locations), | 63 locations_(locations), |
63 properties_(properties), | 64 properties_(properties), |
64 callee_saved_registers_(callee_saved_registers), | 65 callee_saved_registers_(callee_saved_registers), |
65 deoptimization_support_(deoptimization_support), | 66 flags_(flags), |
66 debug_name_(debug_name) {} | 67 debug_name_(debug_name) {} |
67 // Returns the kind of this call. | 68 // Returns the kind of this call. |
68 Kind kind() const { return kind_; } | 69 Kind kind() const { return kind_; } |
69 | 70 |
70 // Returns {true} if this descriptor is a call to a JSFunction. | 71 // Returns {true} if this descriptor is a call to a JSFunction. |
71 bool IsJSFunctionCall() const { return kind_ == kCallJSFunction; } | 72 bool IsJSFunctionCall() const { return kind_ == kCallJSFunction; } |
72 | 73 |
73 // The number of return values from this call, usually 0 or 1. | 74 // The number of return values from this call, usually 0 or 1. |
74 int ReturnCount() const { return return_count_; } | 75 int ReturnCount() const { return return_count_; } |
75 | 76 |
76 // The number of JavaScript parameters to this call, including receiver, | 77 // The number of JavaScript parameters to this call, including receiver, |
77 // but not the context. | 78 // but not the context. |
78 int ParameterCount() const { return parameter_count_; } | 79 int ParameterCount() const { return parameter_count_; } |
79 | 80 |
80 int InputCount() const { return input_count_; } | 81 int InputCount() const { return input_count_; } |
81 | 82 |
82 int FrameStateCount() const { return NeedsFrameState() ? 1 : 0; } | 83 int FrameStateCount() const { return NeedsFrameState() ? 1 : 0; } |
83 | 84 |
84 bool CanLazilyDeoptimize() const { | 85 Flags flags() const { return flags_; } |
85 return (deoptimization_support() & kLazyDeoptimization) != 0; | |
86 } | |
87 | 86 |
88 bool NeedsFrameState() const { | 87 bool CanLazilyDeoptimize() const { return flags() & kLazyDeoptimization; } |
89 return (deoptimization_support() & kNeedsFrameState) != 0; | 88 bool NeedsFrameState() const { return flags() & kNeedsFrameState; } |
90 } | |
91 | |
92 DeoptimizationSupport deoptimization_support() const { | |
93 return deoptimization_support_; | |
94 } | |
95 | 89 |
96 LinkageLocation GetReturnLocation(int index) { | 90 LinkageLocation GetReturnLocation(int index) { |
97 DCHECK(index < return_count_); | 91 DCHECK(index < return_count_); |
98 return locations_[0 + index]; // return locations start at 0. | 92 return locations_[0 + index]; // return locations start at 0. |
99 } | 93 } |
100 | 94 |
101 LinkageLocation GetInputLocation(int index) { | 95 LinkageLocation GetInputLocation(int index) { |
102 DCHECK(index < input_count_ + 1); // input_count + 1 is the context. | 96 DCHECK(index < input_count_ + 1); // input_count + 1 is the context. |
103 return locations_[return_count_ + index]; // inputs start after returns. | 97 return locations_[return_count_ + index]; // inputs start after returns. |
104 } | 98 } |
105 | 99 |
106 // Operator properties describe how this call can be optimized, if at all. | 100 // Operator properties describe how this call can be optimized, if at all. |
107 Operator::Property properties() const { return properties_; } | 101 Operator::Property properties() const { return properties_; } |
108 | 102 |
109 // Get the callee-saved registers, if any, across this call. | 103 // Get the callee-saved registers, if any, across this call. |
110 RegList CalleeSavedRegisters() { return callee_saved_registers_; } | 104 RegList CalleeSavedRegisters() { return callee_saved_registers_; } |
111 | 105 |
112 const char* debug_name() const { return debug_name_; } | 106 const char* debug_name() const { return debug_name_; } |
113 | 107 |
114 private: | 108 private: |
115 friend class Linkage; | 109 friend class Linkage; |
116 | 110 |
117 Kind kind_; | 111 Kind kind_; |
118 int8_t return_count_; | 112 int8_t return_count_; |
119 int16_t parameter_count_; | 113 int16_t parameter_count_; |
120 int16_t input_count_; | 114 int16_t input_count_; |
121 LinkageLocation* locations_; | 115 LinkageLocation* locations_; |
122 Operator::Property properties_; | 116 Operator::Property properties_; |
123 RegList callee_saved_registers_; | 117 RegList callee_saved_registers_; |
124 DeoptimizationSupport deoptimization_support_; | 118 Flags flags_; |
125 const char* debug_name_; | 119 const char* debug_name_; |
126 }; | 120 }; |
127 | 121 |
122 DEFINE_OPERATORS_FOR_FLAGS(CallDescriptor::Flags) | |
123 | |
128 OStream& operator<<(OStream& os, const CallDescriptor& d); | 124 OStream& operator<<(OStream& os, const CallDescriptor& d); |
129 OStream& operator<<(OStream& os, const CallDescriptor::Kind& k); | 125 OStream& operator<<(OStream& os, const CallDescriptor::Kind& k); |
130 | 126 |
131 // Defines the linkage for a compilation, including the calling conventions | 127 // Defines the linkage for a compilation, including the calling conventions |
132 // for incoming parameters and return value(s) as well as the outgoing calling | 128 // for incoming parameters and return value(s) as well as the outgoing calling |
133 // convention for any kind of call. Linkage is generally architecture-specific. | 129 // convention for any kind of call. Linkage is generally architecture-specific. |
134 // | 130 // |
135 // Can be used to translate {arg_index} (i.e. index of the call node input) as | 131 // Can be used to translate {arg_index} (i.e. index of the call node input) as |
136 // well as {param_index} (i.e. as stored in parameter nodes) into an operator | 132 // well as {param_index} (i.e. as stored in parameter nodes) into an operator |
137 // representing the architecture-specific location. The following call node | 133 // representing the architecture-specific location. The following call node |
(...skipping 10 matching lines...) Expand all Loading... | |
148 : info_(info), incoming_(incoming) {} | 144 : info_(info), incoming_(incoming) {} |
149 | 145 |
150 // The call descriptor for this compilation unit describes the locations | 146 // The call descriptor for this compilation unit describes the locations |
151 // of incoming parameters and the outgoing return value(s). | 147 // of incoming parameters and the outgoing return value(s). |
152 CallDescriptor* GetIncomingDescriptor() { return incoming_; } | 148 CallDescriptor* GetIncomingDescriptor() { return incoming_; } |
153 CallDescriptor* GetJSCallDescriptor(int parameter_count); | 149 CallDescriptor* GetJSCallDescriptor(int parameter_count); |
154 static CallDescriptor* GetJSCallDescriptor(int parameter_count, Zone* zone); | 150 static CallDescriptor* GetJSCallDescriptor(int parameter_count, Zone* zone); |
155 CallDescriptor* GetRuntimeCallDescriptor( | 151 CallDescriptor* GetRuntimeCallDescriptor( |
156 Runtime::FunctionId function, int parameter_count, | 152 Runtime::FunctionId function, int parameter_count, |
157 Operator::Property properties, | 153 Operator::Property properties, |
158 CallDescriptor::DeoptimizationSupport can_deoptimize = | 154 CallDescriptor::Flags flags = CallDescriptor::kNoFlags); |
159 CallDescriptor::kNoDeoptimization); | 155 static CallDescriptor* GetRuntimeCallDescriptor(Runtime::FunctionId function, |
160 static CallDescriptor* GetRuntimeCallDescriptor( | 156 int parameter_count, |
161 Runtime::FunctionId function, int parameter_count, | 157 Operator::Property properties, |
162 Operator::Property properties, | 158 CallDescriptor::Flags flags, |
163 CallDescriptor::DeoptimizationSupport can_deoptimize, Zone* zone); | 159 Zone* zone); |
164 | 160 |
165 CallDescriptor* GetStubCallDescriptor( | 161 CallDescriptor* GetStubCallDescriptor( |
166 CodeStubInterfaceDescriptor* descriptor, int stack_parameter_count = 0, | 162 CodeStubInterfaceDescriptor* descriptor, int stack_parameter_count = 0, |
167 CallDescriptor::DeoptimizationSupport can_deoptimize = | 163 CallDescriptor::Flags flags = CallDescriptor::kNoFlags); |
168 CallDescriptor::kNoDeoptimization); | |
169 static CallDescriptor* GetStubCallDescriptor( | 164 static CallDescriptor* GetStubCallDescriptor( |
170 CodeStubInterfaceDescriptor* descriptor, int stack_parameter_count, | 165 CodeStubInterfaceDescriptor* descriptor, int stack_parameter_count, |
171 CallDescriptor::DeoptimizationSupport can_deoptimize, Zone* zone); | 166 CallDescriptor::Flags flags, Zone* zone); |
172 | 167 |
173 // Creates a call descriptor for simplified C calls that is appropriate | 168 // Creates a call descriptor for simplified C calls that is appropriate |
174 // for the host platform. This simplified calling convention only supports | 169 // for the host platform. This simplified calling convention only supports |
175 // integers and pointers of one word size each, i.e. no floating point, | 170 // integers and pointers of one word size each, i.e. no floating point, |
176 // structs, pointers to members, etc. | 171 // structs, pointers to members, etc. |
177 static CallDescriptor* GetSimplifiedCDescriptor( | 172 static CallDescriptor* GetSimplifiedCDescriptor( |
178 Zone* zone, int num_params, MachineType return_type, | 173 Zone* zone, int num_params, MachineType return_type, |
179 const MachineType* param_types); | 174 const MachineType* param_types); |
180 | 175 |
181 // Get the location of an (incoming) parameter to this function. | 176 // Get the location of an (incoming) parameter to this function. |
(...skipping 12 matching lines...) Expand all Loading... | |
194 // caller's frame. The {extra} parameter indicates an additional offset from | 189 // caller's frame. The {extra} parameter indicates an additional offset from |
195 // the frame offset, e.g. to index into part of a double slot. | 190 // the frame offset, e.g. to index into part of a double slot. |
196 FrameOffset GetFrameOffset(int spill_slot, Frame* frame, int extra = 0); | 191 FrameOffset GetFrameOffset(int spill_slot, Frame* frame, int extra = 0); |
197 | 192 |
198 CompilationInfo* info() const { return info_; } | 193 CompilationInfo* info() const { return info_; } |
199 | 194 |
200 private: | 195 private: |
201 CompilationInfo* info_; | 196 CompilationInfo* info_; |
202 CallDescriptor* incoming_; | 197 CallDescriptor* incoming_; |
203 }; | 198 }; |
204 } | 199 |
205 } | 200 } // namespace compiler |
206 } // namespace v8::internal::compiler | 201 } // namespace internal |
202 } // namespace v8 | |
207 | 203 |
208 #endif // V8_COMPILER_LINKAGE_H_ | 204 #endif // V8_COMPILER_LINKAGE_H_ |
OLD | NEW |