#include "src/codegen/assembler-inl.h"
#include "src/codegen/macro-assembler.h"
#include "src/compiler/globals.h"
#include "src/compiler/linkage.h"
#include "src/zone/zone.h"
namespace v8 {
namespace internal {
namespace compiler {
namespace {
#if V8_TARGET_ARCH_IA32
#define CALLEE_SAVE_REGISTERS …
#define CALLEE_SAVE_FP_REGISTERS
#elif V8_TARGET_ARCH_X64
#ifdef V8_TARGET_OS_WIN
#define STACK_SHADOW_WORDS …
#define PARAM_REGISTERS …
#define FP_PARAM_REGISTERS …
#define FP_RETURN_REGISTER …
#define CALLEE_SAVE_REGISTERS …
#define CALLEE_SAVE_FP_REGISTERS …
#else
#define PARAM_REGISTERS …
#define FP_PARAM_REGISTERS …
#define FP_RETURN_REGISTER …
#define CALLEE_SAVE_REGISTERS …
#define CALLEE_SAVE_FP_REGISTERS
#endif
#elif V8_TARGET_ARCH_ARM
#define PARAM_REGISTERS …
#define CALLEE_SAVE_REGISTERS …
#define CALLEE_SAVE_FP_REGISTERS …
#elif V8_TARGET_ARCH_ARM64
#define PARAM_REGISTERS …
#define FP_PARAM_REGISTERS …
#define FP_RETURN_REGISTER …
#define CALLEE_SAVE_REGISTERS …
#define CALLEE_SAVE_FP_REGISTERS …
#elif V8_TARGET_ARCH_MIPS64
#define PARAM_REGISTERS …
#define FP_PARAM_REGISTERS …
#define FP_RETURN_REGISTER …
#define CALLEE_SAVE_REGISTERS …
#define CALLEE_SAVE_FP_REGISTERS …
#elif V8_TARGET_ARCH_LOONG64
#define PARAM_REGISTERS …
#define FP_PARAM_REGISTERS …
#define FP_RETURN_REGISTER …
#define CALLEE_SAVE_REGISTERS …
#define CALLEE_SAVE_FP_REGISTERS …
#elif V8_TARGET_ARCH_PPC64
#ifdef V8_TARGET_LITTLE_ENDIAN
#define STACK_SHADOW_WORDS …
#else
#define STACK_SHADOW_WORDS …
#endif
#define PARAM_REGISTERS …
#define CALLEE_SAVE_REGISTERS …
#define CALLEE_SAVE_FP_REGISTERS …
#elif V8_TARGET_ARCH_S390X
#define STACK_SHADOW_WORDS …
#define PARAM_REGISTERS …
#define CALLEE_SAVE_REGISTERS …
#define CALLEE_SAVE_FP_REGISTERS …
#elif V8_TARGET_ARCH_RISCV32 || V8_TARGET_ARCH_RISCV64
#define PARAM_REGISTERS …
#define FP_PARAM_REGISTERS …
#define CALLEE_SAVE_REGISTERS …
#define CALLEE_SAVE_FP_REGISTERS …
#else
#define UNSUPPORTED_C_LINKAGE …
#endif
}
#if (defined(V8_TARGET_OS_WIN) && defined(V8_TARGET_ARCH_X64)) || \
defined(V8_TARGET_ARCH_MIPS64)
void BuildParameterLocations(const MachineSignature* msig,
size_t kFPParamRegisterCount,
size_t kParamRegisterCount,
const DoubleRegister* kFPParamRegisters,
const v8::internal::Register* kParamRegisters,
LocationSignature::Builder* out_locations) {
#ifdef STACK_SHADOW_WORDS
int stack_offset = STACK_SHADOW_WORDS;
#else
int stack_offset = 0;
#endif
CHECK_EQ(kFPParamRegisterCount, kParamRegisterCount);
for (size_t i = 0; i < msig->parameter_count(); i++) {
MachineType type = msig->GetParam(i);
bool spill = (i >= kParamRegisterCount);
if (spill) {
out_locations->AddParam(
LinkageLocation::ForCallerFrameSlot(-1 - stack_offset, type));
stack_offset++;
} else {
if (IsFloatingPoint(type.representation())) {
out_locations->AddParam(
LinkageLocation::ForRegister(kFPParamRegisters[i].code(), type));
} else {
out_locations->AddParam(
LinkageLocation::ForRegister(kParamRegisters[i].code(), type));
}
}
}
}
#elif defined(V8_TARGET_ARCH_LOONG64)
void BuildParameterLocations(const MachineSignature* msig,
size_t kFPParamRegisterCount,
size_t kParamRegisterCount,
const DoubleRegister* kFPParamRegisters,
const v8::internal::Register* kParamRegisters,
LocationSignature::Builder* out_locations) {
#ifdef STACK_SHADOW_WORDS
int stack_offset = STACK_SHADOW_WORDS;
#else
int stack_offset = 0;
#endif
size_t num_params = 0;
size_t num_fp_params = 0;
for (size_t i = 0; i < msig->parameter_count(); i++) {
MachineType type = msig->GetParam(i);
if (IsFloatingPoint(type.representation())) {
if (num_fp_params < kFPParamRegisterCount) {
out_locations->AddParam(LinkageLocation::ForRegister(
kFPParamRegisters[num_fp_params].code(), type));
++num_fp_params;
} else if (num_params < kParamRegisterCount) {
out_locations->AddParam(LinkageLocation::ForNullRegister(
-kParamRegisters[num_params].code(), type));
++num_params;
} else {
out_locations->AddParam(
LinkageLocation::ForCallerFrameSlot(-1 - stack_offset, type));
stack_offset++;
}
} else {
if (num_params < kParamRegisterCount) {
out_locations->AddParam(LinkageLocation::ForRegister(
kParamRegisters[num_params].code(), type));
++num_params;
} else {
out_locations->AddParam(
LinkageLocation::ForCallerFrameSlot(-1 - stack_offset, type));
stack_offset++;
}
}
}
}
#else
void BuildParameterLocations(const MachineSignature* msig,
size_t kFPParamRegisterCount,
size_t kParamRegisterCount,
const DoubleRegister* kFPParamRegisters,
const v8::internal::Register* kParamRegisters,
LocationSignature::Builder* out_locations) { … }
#endif
CallDescriptor* Linkage::GetSimplifiedCDescriptor(Zone* zone,
const MachineSignature* msig,
CallDescriptor::Flags flags) { … }
}
}
}