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
5 #include "src/v8.h"
6
7 #include "src/assembler.h"
8 #include "src/code-stubs.h"
9 #include "src/compiler/linkage.h"
10 #include "src/compiler/linkage-impl.h"
11 #include "src/zone.h"
12
13 namespace v8 {
14 namespace internal {
15 namespace compiler {
16
17 #ifdef _WIN64
18 const bool kWin64 = true;
19 #else
20 const bool kWin64 = false;
21 #endif
22
23 struct X64LinkageHelperTraits {
ReturnValueRegv8::internal::compiler::X64LinkageHelperTraits24 static Register ReturnValueReg() { return rax; }
ReturnValue2Regv8::internal::compiler::X64LinkageHelperTraits25 static Register ReturnValue2Reg() { return rdx; }
JSCallFunctionRegv8::internal::compiler::X64LinkageHelperTraits26 static Register JSCallFunctionReg() { return rdi; }
ContextRegv8::internal::compiler::X64LinkageHelperTraits27 static Register ContextReg() { return rsi; }
RuntimeCallFunctionRegv8::internal::compiler::X64LinkageHelperTraits28 static Register RuntimeCallFunctionReg() { return rbx; }
RuntimeCallArgCountRegv8::internal::compiler::X64LinkageHelperTraits29 static Register RuntimeCallArgCountReg() { return rax; }
CCalleeSaveRegistersv8::internal::compiler::X64LinkageHelperTraits30 static RegList CCalleeSaveRegisters() {
31 if (kWin64) {
32 return rbx.bit() | rdi.bit() | rsi.bit() | r12.bit() | r13.bit() |
33 r14.bit() | r15.bit();
34 } else {
35 return rbx.bit() | r12.bit() | r13.bit() | r14.bit() | r15.bit();
36 }
37 }
CRegisterParameterv8::internal::compiler::X64LinkageHelperTraits38 static Register CRegisterParameter(int i) {
39 if (kWin64) {
40 static Register register_parameters[] = {rcx, rdx, r8, r9};
41 return register_parameters[i];
42 } else {
43 static Register register_parameters[] = {rdi, rsi, rdx, rcx, r8, r9};
44 return register_parameters[i];
45 }
46 }
CRegisterParametersLengthv8::internal::compiler::X64LinkageHelperTraits47 static int CRegisterParametersLength() { return kWin64 ? 4 : 6; }
48 };
49
50 typedef LinkageHelper<X64LinkageHelperTraits> LH;
51
GetJSCallDescriptor(int parameter_count,Zone * zone)52 CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone) {
53 return LH::GetJSCallDescriptor(zone, parameter_count);
54 }
55
56
GetRuntimeCallDescriptor(Runtime::FunctionId function,int parameter_count,Operator::Properties properties,Zone * zone)57 CallDescriptor* Linkage::GetRuntimeCallDescriptor(
58 Runtime::FunctionId function, int parameter_count,
59 Operator::Properties properties, Zone* zone) {
60 return LH::GetRuntimeCallDescriptor(zone, function, parameter_count,
61 properties);
62 }
63
64
GetStubCallDescriptor(CallInterfaceDescriptor descriptor,int stack_parameter_count,CallDescriptor::Flags flags,Zone * zone)65 CallDescriptor* Linkage::GetStubCallDescriptor(
66 CallInterfaceDescriptor descriptor, int stack_parameter_count,
67 CallDescriptor::Flags flags, Zone* zone) {
68 return LH::GetStubCallDescriptor(zone, descriptor, stack_parameter_count,
69 flags);
70 }
71
72
GetSimplifiedCDescriptor(Zone * zone,MachineSignature * sig)73 CallDescriptor* Linkage::GetSimplifiedCDescriptor(Zone* zone,
74 MachineSignature* sig) {
75 return LH::GetSimplifiedCDescriptor(zone, sig);
76 }
77
78 } // namespace compiler
79 } // namespace internal
80 } // namespace v8
81