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