Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5 | #include "src/ast/scopes.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6 | #include "src/code-stubs.h" |
| 7 | #include "src/compiler.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8 | #include "src/compiler/common-operator.h" |
| 9 | #include "src/compiler/frame.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10 | #include "src/compiler/linkage.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/compiler/node.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 12 | #include "src/compiler/osr.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 13 | #include "src/compiler/pipeline.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | namespace compiler { |
| 18 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 19 | namespace { |
| 20 | LinkageLocation regloc(Register reg) { |
| 21 | return LinkageLocation::ForRegister(reg.code()); |
| 22 | } |
| 23 | |
| 24 | |
| 25 | MachineType reptyp(Representation representation) { |
| 26 | switch (representation.kind()) { |
| 27 | case Representation::kInteger8: |
| 28 | return MachineType::Int8(); |
| 29 | case Representation::kUInteger8: |
| 30 | return MachineType::Uint8(); |
| 31 | case Representation::kInteger16: |
| 32 | return MachineType::Int16(); |
| 33 | case Representation::kUInteger16: |
| 34 | return MachineType::Uint16(); |
| 35 | case Representation::kInteger32: |
| 36 | return MachineType::Int32(); |
| 37 | case Representation::kSmi: |
| 38 | case Representation::kTagged: |
| 39 | case Representation::kHeapObject: |
| 40 | return MachineType::AnyTagged(); |
| 41 | case Representation::kDouble: |
| 42 | return MachineType::Float64(); |
| 43 | case Representation::kExternal: |
| 44 | return MachineType::Pointer(); |
| 45 | case Representation::kNone: |
| 46 | case Representation::kNumRepresentations: |
| 47 | break; |
| 48 | } |
| 49 | UNREACHABLE(); |
| 50 | return MachineType::None(); |
| 51 | } |
| 52 | } // namespace |
| 53 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 54 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 55 | std::ostream& operator<<(std::ostream& os, const CallDescriptor::Kind& k) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 56 | switch (k) { |
| 57 | case CallDescriptor::kCallCodeObject: |
| 58 | os << "Code"; |
| 59 | break; |
| 60 | case CallDescriptor::kCallJSFunction: |
| 61 | os << "JS"; |
| 62 | break; |
| 63 | case CallDescriptor::kCallAddress: |
| 64 | os << "Addr"; |
| 65 | break; |
| 66 | } |
| 67 | return os; |
| 68 | } |
| 69 | |
| 70 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 71 | std::ostream& operator<<(std::ostream& os, const CallDescriptor& d) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 72 | // TODO(svenpanne) Output properties etc. and be less cryptic. |
| 73 | return os << d.kind() << ":" << d.debug_name() << ":r" << d.ReturnCount() |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 74 | << "s" << d.StackParameterCount() << "i" << d.InputCount() << "f" |
| 75 | << d.FrameStateCount() << "t" << d.SupportsTailCalls(); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | bool CallDescriptor::HasSameReturnLocationsAs( |
| 80 | const CallDescriptor* other) const { |
| 81 | if (ReturnCount() != other->ReturnCount()) return false; |
| 82 | for (size_t i = 0; i < ReturnCount(); ++i) { |
| 83 | if (GetReturnLocation(i) != other->GetReturnLocation(i)) return false; |
| 84 | } |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | bool CallDescriptor::CanTailCall(const Node* node, |
| 90 | int* stack_param_delta) const { |
| 91 | CallDescriptor const* other = OpParameter<CallDescriptor const*>(node); |
| 92 | size_t current_input = 0; |
| 93 | size_t other_input = 0; |
| 94 | *stack_param_delta = 0; |
| 95 | bool more_other = true; |
| 96 | bool more_this = true; |
| 97 | while (more_other || more_this) { |
| 98 | if (other_input < other->InputCount()) { |
| 99 | if (!other->GetInputLocation(other_input).IsRegister()) { |
| 100 | (*stack_param_delta)--; |
| 101 | } |
| 102 | } else { |
| 103 | more_other = false; |
| 104 | } |
| 105 | if (current_input < InputCount()) { |
| 106 | if (!GetInputLocation(current_input).IsRegister()) { |
| 107 | (*stack_param_delta)++; |
| 108 | } |
| 109 | } else { |
| 110 | more_this = false; |
| 111 | } |
| 112 | ++current_input; |
| 113 | ++other_input; |
| 114 | } |
| 115 | return HasSameReturnLocationsAs(OpParameter<CallDescriptor const*>(node)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 119 | CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 120 | DCHECK(!info->IsStub()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 121 | if (info->has_literal()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 122 | // If we already have the function literal, use the number of parameters |
| 123 | // plus the receiver. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 124 | return GetJSCallDescriptor(zone, info->is_osr(), |
| 125 | 1 + info->literal()->parameter_count(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 126 | CallDescriptor::kNoFlags); |
| 127 | } |
| 128 | if (!info->closure().is_null()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 129 | // If we are compiling a JS function, use a JS call descriptor, |
| 130 | // plus the receiver. |
| 131 | SharedFunctionInfo* shared = info->closure()->shared(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 132 | return GetJSCallDescriptor(zone, info->is_osr(), |
| 133 | 1 + shared->internal_formal_parameter_count(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 134 | CallDescriptor::kNoFlags); |
| 135 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 136 | return nullptr; // TODO(titzer): ? |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | |
| 140 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 141 | int Linkage::FrameStateInputCount(Runtime::FunctionId function) { |
| 142 | // Most runtime functions need a FrameState. A few chosen ones that we know |
| 143 | // not to call into arbitrary JavaScript, not to throw, and not to deoptimize |
| 144 | // are blacklisted here and can be called without a FrameState. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 145 | switch (function) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 146 | case Runtime::kAllocateInTargetSpace: |
| 147 | case Runtime::kCreateIterResultObject: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 148 | case Runtime::kDefineDataPropertyInLiteral: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 149 | case Runtime::kDefineGetterPropertyUnchecked: // TODO(jarin): Is it safe? |
| 150 | case Runtime::kDefineSetterPropertyUnchecked: // TODO(jarin): Is it safe? |
| 151 | case Runtime::kFinalizeClassDefinition: // TODO(conradw): Is it safe? |
| 152 | case Runtime::kForInDone: |
| 153 | case Runtime::kForInStep: |
| 154 | case Runtime::kGetSuperConstructor: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 155 | case Runtime::kIsFunction: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 156 | case Runtime::kNewClosure: |
| 157 | case Runtime::kNewClosure_Tenured: |
| 158 | case Runtime::kNewFunctionContext: |
| 159 | case Runtime::kPushBlockContext: |
| 160 | case Runtime::kPushCatchContext: |
| 161 | case Runtime::kReThrow: |
| 162 | case Runtime::kStringCompare: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 163 | case Runtime::kStringEqual: |
| 164 | case Runtime::kStringNotEqual: |
| 165 | case Runtime::kStringLessThan: |
| 166 | case Runtime::kStringLessThanOrEqual: |
| 167 | case Runtime::kStringGreaterThan: |
| 168 | case Runtime::kStringGreaterThanOrEqual: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 169 | case Runtime::kTraceEnter: |
| 170 | case Runtime::kTraceExit: |
| 171 | return 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 172 | case Runtime::kInlineGetPrototype: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 173 | case Runtime::kInlineNewObject: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 174 | case Runtime::kInlineRegExpConstructResult: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 175 | case Runtime::kInlineRegExpExec: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 176 | case Runtime::kInlineSubString: |
| 177 | case Runtime::kInlineToInteger: |
| 178 | case Runtime::kInlineToLength: |
| 179 | case Runtime::kInlineToName: |
| 180 | case Runtime::kInlineToNumber: |
| 181 | case Runtime::kInlineToObject: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 182 | case Runtime::kInlineToPrimitive: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 183 | case Runtime::kInlineToPrimitive_Number: |
| 184 | case Runtime::kInlineToPrimitive_String: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 185 | case Runtime::kInlineToString: |
| 186 | return 1; |
| 187 | case Runtime::kInlineCall: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 188 | case Runtime::kInlineDeoptimizeNow: |
| 189 | case Runtime::kInlineThrowNotDateError: |
| 190 | return 2; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 191 | default: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 192 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 193 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 194 | |
| 195 | // Most inlined runtime functions (except the ones listed above) can be called |
| 196 | // without a FrameState or will be lowered by JSIntrinsicLowering internally. |
| 197 | const Runtime::Function* const f = Runtime::FunctionForId(function); |
| 198 | if (f->intrinsic_type == Runtime::IntrinsicType::INLINE) return 0; |
| 199 | |
| 200 | return 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 204 | bool CallDescriptor::UsesOnlyRegisters() const { |
| 205 | for (size_t i = 0; i < InputCount(); ++i) { |
| 206 | if (!GetInputLocation(i).IsRegister()) return false; |
| 207 | } |
| 208 | for (size_t i = 0; i < ReturnCount(); ++i) { |
| 209 | if (!GetReturnLocation(i).IsRegister()) return false; |
| 210 | } |
| 211 | return true; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | |
| 215 | CallDescriptor* Linkage::GetRuntimeCallDescriptor( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 216 | Zone* zone, Runtime::FunctionId function_id, int js_parameter_count, |
| 217 | Operator::Properties properties, CallDescriptor::Flags flags) { |
| 218 | const size_t function_count = 1; |
| 219 | const size_t num_args_count = 1; |
| 220 | const size_t context_count = 1; |
| 221 | const size_t parameter_count = function_count + |
| 222 | static_cast<size_t>(js_parameter_count) + |
| 223 | num_args_count + context_count; |
| 224 | |
| 225 | const Runtime::Function* function = Runtime::FunctionForId(function_id); |
| 226 | const size_t return_count = static_cast<size_t>(function->result_size); |
| 227 | |
| 228 | LocationSignature::Builder locations(zone, return_count, parameter_count); |
| 229 | MachineSignature::Builder types(zone, return_count, parameter_count); |
| 230 | |
| 231 | // Add returns. |
| 232 | if (locations.return_count_ > 0) { |
| 233 | locations.AddReturn(regloc(kReturnRegister0)); |
| 234 | } |
| 235 | if (locations.return_count_ > 1) { |
| 236 | locations.AddReturn(regloc(kReturnRegister1)); |
| 237 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 238 | if (locations.return_count_ > 2) { |
| 239 | locations.AddReturn(regloc(kReturnRegister2)); |
| 240 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 241 | for (size_t i = 0; i < return_count; i++) { |
| 242 | types.AddReturn(MachineType::AnyTagged()); |
| 243 | } |
| 244 | |
| 245 | // All parameters to the runtime call go on the stack. |
| 246 | for (int i = 0; i < js_parameter_count; i++) { |
| 247 | locations.AddParam( |
| 248 | LinkageLocation::ForCallerFrameSlot(i - js_parameter_count)); |
| 249 | types.AddParam(MachineType::AnyTagged()); |
| 250 | } |
| 251 | // Add runtime function itself. |
| 252 | locations.AddParam(regloc(kRuntimeCallFunctionRegister)); |
| 253 | types.AddParam(MachineType::AnyTagged()); |
| 254 | |
| 255 | // Add runtime call argument count. |
| 256 | locations.AddParam(regloc(kRuntimeCallArgCountRegister)); |
| 257 | types.AddParam(MachineType::Pointer()); |
| 258 | |
| 259 | // Add context. |
| 260 | locations.AddParam(regloc(kContextRegister)); |
| 261 | types.AddParam(MachineType::AnyTagged()); |
| 262 | |
| 263 | if (Linkage::FrameStateInputCount(function_id) == 0) { |
| 264 | flags = static_cast<CallDescriptor::Flags>( |
| 265 | flags & ~CallDescriptor::kNeedsFrameState); |
| 266 | } |
| 267 | |
| 268 | // The target for runtime calls is a code object. |
| 269 | MachineType target_type = MachineType::AnyTagged(); |
| 270 | LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); |
| 271 | return new (zone) CallDescriptor( // -- |
| 272 | CallDescriptor::kCallCodeObject, // kind |
| 273 | target_type, // target MachineType |
| 274 | target_loc, // target location |
| 275 | types.Build(), // machine_sig |
| 276 | locations.Build(), // location_sig |
| 277 | js_parameter_count, // stack_parameter_count |
| 278 | properties, // properties |
| 279 | kNoCalleeSaved, // callee-saved |
| 280 | kNoCalleeSaved, // callee-saved fp |
| 281 | flags, // flags |
| 282 | function->name); // debug name |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 286 | CallDescriptor* Linkage::GetJSCallDescriptor(Zone* zone, bool is_osr, |
| 287 | int js_parameter_count, |
| 288 | CallDescriptor::Flags flags) { |
| 289 | const size_t return_count = 1; |
| 290 | const size_t context_count = 1; |
| 291 | const size_t new_target_count = 1; |
| 292 | const size_t num_args_count = 1; |
| 293 | const size_t parameter_count = |
| 294 | js_parameter_count + new_target_count + num_args_count + context_count; |
| 295 | |
| 296 | LocationSignature::Builder locations(zone, return_count, parameter_count); |
| 297 | MachineSignature::Builder types(zone, return_count, parameter_count); |
| 298 | |
| 299 | // All JS calls have exactly one return value. |
| 300 | locations.AddReturn(regloc(kReturnRegister0)); |
| 301 | types.AddReturn(MachineType::AnyTagged()); |
| 302 | |
| 303 | // All parameters to JS calls go on the stack. |
| 304 | for (int i = 0; i < js_parameter_count; i++) { |
| 305 | int spill_slot_index = i - js_parameter_count; |
| 306 | locations.AddParam(LinkageLocation::ForCallerFrameSlot(spill_slot_index)); |
| 307 | types.AddParam(MachineType::AnyTagged()); |
| 308 | } |
| 309 | |
| 310 | // Add JavaScript call new target value. |
| 311 | locations.AddParam(regloc(kJavaScriptCallNewTargetRegister)); |
| 312 | types.AddParam(MachineType::AnyTagged()); |
| 313 | |
| 314 | // Add JavaScript call argument count. |
| 315 | locations.AddParam(regloc(kJavaScriptCallArgCountRegister)); |
| 316 | types.AddParam(MachineType::Int32()); |
| 317 | |
| 318 | // Add context. |
| 319 | locations.AddParam(regloc(kContextRegister)); |
| 320 | types.AddParam(MachineType::AnyTagged()); |
| 321 | |
| 322 | // The target for JS function calls is the JSFunction object. |
| 323 | MachineType target_type = MachineType::AnyTagged(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 324 | // When entering into an OSR function from unoptimized code the JSFunction |
| 325 | // is not in a register, but it is on the stack in the marker spill slot. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 326 | LinkageLocation target_loc = is_osr |
| 327 | ? LinkageLocation::ForSavedCallerFunction() |
| 328 | : regloc(kJSFunctionRegister); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 329 | return new (zone) CallDescriptor( // -- |
| 330 | CallDescriptor::kCallJSFunction, // kind |
| 331 | target_type, // target MachineType |
| 332 | target_loc, // target location |
| 333 | types.Build(), // machine_sig |
| 334 | locations.Build(), // location_sig |
| 335 | js_parameter_count, // stack_parameter_count |
| 336 | Operator::kNoProperties, // properties |
| 337 | kNoCalleeSaved, // callee-saved |
| 338 | kNoCalleeSaved, // callee-saved fp |
| 339 | CallDescriptor::kCanUseRoots | // flags |
| 340 | flags, // flags |
| 341 | "js-call"); |
| 342 | } |
| 343 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 344 | // TODO(all): Add support for return representations/locations to |
| 345 | // CallInterfaceDescriptor. |
| 346 | // TODO(turbofan): cache call descriptors for code stub calls. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 347 | CallDescriptor* Linkage::GetStubCallDescriptor( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 348 | Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor, |
| 349 | int stack_parameter_count, CallDescriptor::Flags flags, |
| 350 | Operator::Properties properties, MachineType return_type, |
| 351 | size_t return_count) { |
| 352 | const int register_parameter_count = descriptor.GetRegisterParameterCount(); |
| 353 | const int js_parameter_count = |
| 354 | register_parameter_count + stack_parameter_count; |
| 355 | const int context_count = 1; |
| 356 | const size_t parameter_count = |
| 357 | static_cast<size_t>(js_parameter_count + context_count); |
| 358 | |
| 359 | LocationSignature::Builder locations(zone, return_count, parameter_count); |
| 360 | MachineSignature::Builder types(zone, return_count, parameter_count); |
| 361 | |
| 362 | // Add returns. |
| 363 | if (locations.return_count_ > 0) { |
| 364 | locations.AddReturn(regloc(kReturnRegister0)); |
| 365 | } |
| 366 | if (locations.return_count_ > 1) { |
| 367 | locations.AddReturn(regloc(kReturnRegister1)); |
| 368 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 369 | if (locations.return_count_ > 2) { |
| 370 | locations.AddReturn(regloc(kReturnRegister2)); |
| 371 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 372 | for (size_t i = 0; i < return_count; i++) { |
| 373 | types.AddReturn(return_type); |
| 374 | } |
| 375 | |
| 376 | // Add parameters in registers and on the stack. |
| 377 | for (int i = 0; i < js_parameter_count; i++) { |
| 378 | if (i < register_parameter_count) { |
| 379 | // The first parameters go in registers. |
| 380 | Register reg = descriptor.GetRegisterParameter(i); |
| 381 | Representation rep = |
| 382 | RepresentationFromType(descriptor.GetParameterType(i)); |
| 383 | locations.AddParam(regloc(reg)); |
| 384 | types.AddParam(reptyp(rep)); |
| 385 | } else { |
| 386 | // The rest of the parameters go on the stack. |
| 387 | int stack_slot = i - register_parameter_count - stack_parameter_count; |
| 388 | locations.AddParam(LinkageLocation::ForCallerFrameSlot(stack_slot)); |
| 389 | types.AddParam(MachineType::AnyTagged()); |
| 390 | } |
| 391 | } |
| 392 | // Add context. |
| 393 | locations.AddParam(regloc(kContextRegister)); |
| 394 | types.AddParam(MachineType::AnyTagged()); |
| 395 | |
| 396 | // The target for stub calls is a code object. |
| 397 | MachineType target_type = MachineType::AnyTagged(); |
| 398 | LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); |
| 399 | return new (zone) CallDescriptor( // -- |
| 400 | CallDescriptor::kCallCodeObject, // kind |
| 401 | target_type, // target MachineType |
| 402 | target_loc, // target location |
| 403 | types.Build(), // machine_sig |
| 404 | locations.Build(), // location_sig |
| 405 | stack_parameter_count, // stack_parameter_count |
| 406 | properties, // properties |
| 407 | kNoCalleeSaved, // callee-saved registers |
| 408 | kNoCalleeSaved, // callee-saved fp |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 409 | CallDescriptor::kCanUseRoots | // flags |
| 410 | flags, // flags |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 411 | descriptor.DebugName(isolate)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 415 | LinkageLocation Linkage::GetOsrValueLocation(int index) const { |
| 416 | CHECK(incoming_->IsJSFunctionCall()); |
| 417 | int parameter_count = static_cast<int>(incoming_->JSParameterCount() - 1); |
| 418 | int first_stack_slot = OsrHelper::FirstStackSlotIndex(parameter_count); |
| 419 | |
| 420 | if (index == kOsrContextSpillSlotIndex) { |
| 421 | // Context. Use the parameter location of the context spill slot. |
| 422 | // Parameter (arity + 2) is special for the context of the function frame. |
| 423 | // >> context_index = target + receiver + params + new_target + #args |
| 424 | int context_index = 1 + 1 + parameter_count + 1 + 1; |
| 425 | return incoming_->GetInputLocation(context_index); |
| 426 | } else if (index >= first_stack_slot) { |
| 427 | // Local variable stored in this (callee) stack. |
| 428 | int spill_index = |
| 429 | index - first_stack_slot + StandardFrameConstants::kFixedSlotCount; |
| 430 | return LinkageLocation::ForCalleeFrameSlot(spill_index); |
| 431 | } else { |
| 432 | // Parameter. Use the assigned location from the incoming call descriptor. |
| 433 | int parameter_index = 1 + index; // skip index 0, which is the target. |
| 434 | return incoming_->GetInputLocation(parameter_index); |
| 435 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 436 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 437 | |
| 438 | |
| 439 | bool Linkage::ParameterHasSecondaryLocation(int index) const { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 440 | if (!incoming_->IsJSFunctionCall()) return false; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 441 | LinkageLocation loc = GetParameterLocation(index); |
| 442 | return (loc == regloc(kJSFunctionRegister) || |
| 443 | loc == regloc(kContextRegister)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 444 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 445 | |
| 446 | LinkageLocation Linkage::GetParameterSecondaryLocation(int index) const { |
| 447 | DCHECK(ParameterHasSecondaryLocation(index)); |
| 448 | LinkageLocation loc = GetParameterLocation(index); |
| 449 | |
| 450 | if (loc == regloc(kJSFunctionRegister)) { |
| 451 | return LinkageLocation::ForCalleeFrameSlot(Frame::kJSFunctionSlot); |
| 452 | } else { |
| 453 | DCHECK(loc == regloc(kContextRegister)); |
| 454 | return LinkageLocation::ForCalleeFrameSlot(Frame::kContextSlot); |
| 455 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 456 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 457 | |
| 458 | |
| 459 | } // namespace compiler |
| 460 | } // namespace internal |
| 461 | } // namespace v8 |