OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/assembler.h" |
| 6 #include "src/code-stubs.h" |
| 7 #include "src/macro-assembler.h" |
| 8 |
| 9 #include "src/compiler/linkage.h" |
| 10 #include "src/compiler/linkage-impl.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 namespace compiler { |
| 15 |
| 16 namespace { |
| 17 MachineType reptyp(Representation representation) { |
| 18 switch (representation.kind()) { |
| 19 case Representation::kInteger8: |
| 20 return kMachInt8; |
| 21 case Representation::kUInteger8: |
| 22 return kMachUint8; |
| 23 case Representation::kInteger16: |
| 24 return kMachInt16; |
| 25 case Representation::kUInteger16: |
| 26 return kMachUint16; |
| 27 case Representation::kInteger32: |
| 28 return kMachInt32; |
| 29 case Representation::kSmi: |
| 30 case Representation::kTagged: |
| 31 case Representation::kHeapObject: |
| 32 return kMachAnyTagged; |
| 33 case Representation::kDouble: |
| 34 return kMachFloat64; |
| 35 case Representation::kExternal: |
| 36 return kMachPtr; |
| 37 case Representation::kNone: |
| 38 case Representation::kNumRepresentations: |
| 39 break; |
| 40 } |
| 41 UNREACHABLE(); |
| 42 return kMachNone; |
| 43 } |
| 44 } // namespace |
| 45 |
| 46 |
| 47 // TODO(all): Add support for return representations/locations to |
| 48 // CallInterfaceDescriptor. |
| 49 // TODO(turbofan): cache call descriptors for code stub calls. |
| 50 CallDescriptor* Linkage::GetStubCallDescriptor( |
| 51 Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor, |
| 52 int stack_parameter_count, CallDescriptor::Flags flags, |
| 53 Operator::Properties properties, MachineType return_type) { |
| 54 const int register_parameter_count = descriptor.GetRegisterParameterCount(); |
| 55 const int js_parameter_count = |
| 56 register_parameter_count + stack_parameter_count; |
| 57 const int context_count = 1; |
| 58 const size_t return_count = 1; |
| 59 const size_t parameter_count = |
| 60 static_cast<size_t>(js_parameter_count + context_count); |
| 61 |
| 62 LocationSignature::Builder locations(zone, return_count, parameter_count); |
| 63 MachineSignature::Builder types(zone, return_count, parameter_count); |
| 64 |
| 65 // Add return location. |
| 66 locations.AddReturn(regloc(kReturnRegister0)); |
| 67 types.AddReturn(return_type); |
| 68 |
| 69 // Add parameters in registers and on the stack. |
| 70 for (int i = 0; i < js_parameter_count; i++) { |
| 71 if (i < register_parameter_count) { |
| 72 // The first parameters go in registers. |
| 73 Register reg = descriptor.GetRegisterParameter(i); |
| 74 Representation rep = |
| 75 RepresentationFromType(descriptor.GetParameterType(i)); |
| 76 locations.AddParam(regloc(reg)); |
| 77 types.AddParam(reptyp(rep)); |
| 78 } else { |
| 79 // The rest of the parameters go on the stack. |
| 80 int stack_slot = i - register_parameter_count - stack_parameter_count; |
| 81 locations.AddParam(stackloc(stack_slot)); |
| 82 types.AddParam(kMachAnyTagged); |
| 83 } |
| 84 } |
| 85 // Add context. |
| 86 locations.AddParam(regloc(kContextRegister)); |
| 87 types.AddParam(kMachAnyTagged); |
| 88 |
| 89 // The target for stub calls is a code object. |
| 90 MachineType target_type = kMachAnyTagged; |
| 91 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(); |
| 92 return new (zone) CallDescriptor( // -- |
| 93 CallDescriptor::kCallCodeObject, // kind |
| 94 target_type, // target MachineType |
| 95 target_loc, // target location |
| 96 types.Build(), // machine_sig |
| 97 locations.Build(), // location_sig |
| 98 stack_parameter_count, // stack_parameter_count |
| 99 properties, // properties |
| 100 kNoCalleeSaved, // callee-saved registers |
| 101 kNoCalleeSaved, // callee-saved fp |
| 102 flags, // flags |
| 103 descriptor.DebugName(isolate)); |
| 104 } |
| 105 } |
| 106 } |
| 107 } |
OLD | NEW |