Commit 282e9411 authored by ahaas's avatar ahaas Committed by Commit bot

[turbofan, arm64] Fix native stack parameters on arm64.

I added a flag to the CallDescriptor which indicates that the native
stack should be used for a CallObject instead of the js stack on arm64.

Additionally I removed the use of EmitPrepareArguments because the
current implementation does not work when float and int parameters are
mixed. I plan to fix it in a future CL, because currently I have a
problem figuring out the type of a parameter.

R=titzer@chromium.org, v8-arm-ports@googlegroups.com

Review URL: https://codereview.chromium.org/1494123002

Cr-Commit-Position: refs/heads/master@{#32577}
parent 9298b430
......@@ -2634,14 +2634,13 @@ void MacroAssembler::TruncateHeapNumberToI(Register result,
void MacroAssembler::StubPrologue() {
DCHECK(StackPointer().Is(jssp));
UseScratchRegisterScope temps(this);
Register temp = temps.AcquireX();
__ Mov(temp, Smi::FromInt(StackFrame::STUB));
// Compiled stubs don't age, and so they don't need the predictable code
// ageing sequence.
__ Push(lr, fp, cp, temp);
__ Add(fp, jssp, StandardFrameConstants::kFixedFrameSizeFromFp);
__ Add(fp, StackPointer(), StandardFrameConstants::kFixedFrameSizeFromFp);
}
......
......@@ -877,12 +877,22 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
}
case kArm64Poke: {
Operand operand(i.InputInt32(1) * kPointerSize);
__ Poke(i.InputRegister(0), operand);
if (instr->InputAt(0)->IsDoubleRegister()) {
__ Poke(i.InputFloat64Register(0), operand);
} else {
__ Poke(i.InputRegister(0), operand);
}
break;
}
case kArm64PokePair: {
int slot = i.InputInt32(2) - 1;
__ PokePair(i.InputRegister(1), i.InputRegister(0), slot * kPointerSize);
if (instr->InputAt(0)->IsDoubleRegister()) {
__ PokePair(i.InputFloat64Register(1), i.InputFloat64Register(0),
slot * kPointerSize);
} else {
__ PokePair(i.InputRegister(1), i.InputRegister(0),
slot * kPointerSize);
}
break;
}
case kArm64Clz:
......@@ -1292,9 +1302,18 @@ void CodeGenerator::AssemblePrologue() {
__ SetStackPointer(jssp);
__ Prologue(info->IsCodePreAgingActive());
} else if (frame()->needs_frame()) {
__ SetStackPointer(jssp);
if (descriptor->UseNativeStack()) {
__ SetStackPointer(csp);
} else {
__ SetStackPointer(jssp);
}
__ StubPrologue();
} else {
if (descriptor->UseNativeStack()) {
__ SetStackPointer(csp);
} else {
__ SetStackPointer(jssp);
}
frame()->SetElidedFrameSizeInSlots(0);
}
frame_access_state()->SetFrameAccessToDefault();
......@@ -1315,9 +1334,12 @@ void CodeGenerator::AssemblePrologue() {
stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots();
}
if (csp.Is(masm()->StackPointer())) {
// If frame()->needs_frame() is false, then
// frame()->AlignSavedCalleeRegisterSlots() is guaranteed to return 0.
if (csp.Is(masm()->StackPointer()) && frame()->needs_frame()) {
// The system stack pointer requires 16-byte alignment at function call
// boundaries.
stack_shrink_slots += frame()->AlignSavedCalleeRegisterSlots();
}
__ Claim(stack_shrink_slots);
......@@ -1374,9 +1396,15 @@ void CodeGenerator::AssembleReturn() {
return;
} else {
__ Bind(&return_label_);
__ Mov(jssp, fp);
if (descriptor->UseNativeStack()) {
__ Mov(csp, fp);
} else {
__ Mov(jssp, fp);
}
__ Pop(fp, lr);
}
} else if (descriptor->UseNativeStack()) {
pop_count += (pop_count & 1);
}
__ Drop(pop_count);
__ Ret();
......
......@@ -1535,7 +1535,14 @@ void InstructionSelector::EmitPrepareArguments(NodeVector* arguments,
// Push the arguments to the stack.
int aligned_push_count = static_cast<int>(arguments->size());
bool pushed_count_uneven = aligned_push_count & 1;
int claim_count = aligned_push_count;
if (pushed_count_uneven && descriptor->UseNativeStack()) {
// We can only claim for an even number of call arguments when we use the
// native stack.
claim_count++;
}
// TODO(dcarney): claim and poke probably take small immediates,
// loop here or whatever.
// Bump the stack pointer(s).
......@@ -1543,23 +1550,20 @@ void InstructionSelector::EmitPrepareArguments(NodeVector* arguments,
// TODO(dcarney): it would be better to bump the csp here only
// and emit paired stores with increment for non c frames.
Emit(kArm64ClaimForCallArguments, g.NoOutput(),
g.TempImmediate(aligned_push_count));
g.TempImmediate(claim_count));
}
// Move arguments to the stack.
{
int slot = aligned_push_count - 1;
// Emit the uneven pushes.
if (pushed_count_uneven) {
Node* input = (*arguments)[slot];
Emit(kArm64Poke, g.NoOutput(), g.UseRegister(input),
g.TempImmediate(slot));
slot--;
}
// Now all pushes can be done in pairs.
for (; slot >= 0; slot -= 2) {
Emit(kArm64PokePair, g.NoOutput(), g.UseRegister((*arguments)[slot]),
g.UseRegister((*arguments)[slot - 1]), g.TempImmediate(slot));
}
int slot = aligned_push_count - 1;
while (slot >= 0) {
Emit(kArm64Poke, g.NoOutput(), g.UseRegister((*arguments)[slot]),
g.TempImmediate(slot));
slot--;
// TODO(ahaas): Poke arguments in pairs if two subsequent arguments have the
// same type.
// Emit(kArm64PokePair, g.NoOutput(), g.UseRegister((*arguments)[slot]),
// g.UseRegister((*arguments)[slot - 1]), g.TempImmediate(slot));
// slot -= 2;
}
}
......
......@@ -153,6 +153,9 @@ class CallDescriptor final : public ZoneObject {
kHasLocalCatchHandler = 1u << 4,
kSupportsTailCalls = 1u << 5,
kCanUseRoots = 1u << 6,
// Indicates that the native stack should be used for a code object. This
// information is important for native calls on arm64.
kUseNativeStack = 1u << 7,
kPatchableCallSiteWithNop = kPatchableCallSite | kNeedsNopAfterCall
};
typedef base::Flags<Flag> Flags;
......@@ -218,6 +221,7 @@ class CallDescriptor final : public ZoneObject {
bool NeedsFrameState() const { return flags() & kNeedsFrameState; }
bool SupportsTailCalls() const { return flags() & kSupportsTailCalls; }
bool UseNativeStack() const { return flags() & kUseNativeStack; }
LinkageLocation GetReturnLocation(size_t index) const {
return location_sig_->GetReturn(index);
......
......@@ -21,13 +21,6 @@ namespace v8 {
namespace internal {
namespace compiler {
#if V8_TARGET_ARCH_ARM64
// TODO(titzer): fix native stack parameters on arm64
#define DISABLE_NATIVE_STACK_PARAMS true
#else
#define DISABLE_NATIVE_STACK_PARAMS false
#endif
namespace {
typedef float float32;
typedef double float64;
......@@ -221,7 +214,7 @@ class RegisterConfig {
compiler::Operator::kNoProperties, // properties
kCalleeSaveRegisters, // callee-saved registers
kCalleeSaveFPRegisters, // callee-saved fp regs
CallDescriptor::kNoFlags, // flags
CallDescriptor::kUseNativeStack, // flags
"c-call");
}
......@@ -559,8 +552,6 @@ static void TestInt32Sub(CallDescriptor* desc) {
static void CopyTwentyInt32(CallDescriptor* desc) {
if (DISABLE_NATIVE_STACK_PARAMS) return;
const int kNumParams = 20;
int32_t input[kNumParams];
int32_t output[kNumParams];
......@@ -672,7 +663,6 @@ TEST_INT32_SUB_WITH_RET(19)
TEST(Run_Int32Sub_all_allocatable_single) {
if (DISABLE_NATIVE_STACK_PARAMS) return;
Int32Signature sig(2);
RegisterPairs pairs;
while (pairs.More()) {
......@@ -690,7 +680,6 @@ TEST(Run_Int32Sub_all_allocatable_single) {
TEST(Run_CopyTwentyInt32_all_allocatable_pairs) {
if (DISABLE_NATIVE_STACK_PARAMS) return;
Int32Signature sig(20);
RegisterPairs pairs;
while (pairs.More()) {
......@@ -743,7 +732,6 @@ static int32_t Compute_Int32_WeightedSum(CallDescriptor* desc, int32_t* input) {
static void Test_Int32_WeightedSum_of_size(int count) {
if (DISABLE_NATIVE_STACK_PARAMS) return;
Int32Signature sig(count);
for (int p0 = 0; p0 < Register::kNumRegisters; p0++) {
if (Register::from_code(p0).IsAllocatable()) {
......@@ -805,8 +793,6 @@ static void RunSelect(CallDescriptor* desc) {
template <int which>
void Test_Int32_Select() {
if (DISABLE_NATIVE_STACK_PARAMS) return;
int parray[] = {
RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN)
->GetAllocatableGeneralCode(0)};
......@@ -930,7 +916,6 @@ TEST(Float64Select_registers) {
TEST(Float32Select_stack_params_return_reg) {
if (DISABLE_NATIVE_STACK_PARAMS) return;
int rarray[] = {
RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN)
->GetAllocatableDoubleCode(0)};
......@@ -953,7 +938,6 @@ TEST(Float32Select_stack_params_return_reg) {
TEST(Float64Select_stack_params_return_reg) {
if (DISABLE_NATIVE_STACK_PARAMS) return;
int rarray[] = {
RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN)
->GetAllocatableDoubleCode(0)};
......@@ -1008,8 +992,6 @@ static void Build_Select_With_Call(CallDescriptor* desc,
TEST(Float64StackParamsToStackParams) {
if (DISABLE_NATIVE_STACK_PARAMS) return;
int rarray[] = {
RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN)
->GetAllocatableDoubleCode(0)};
......@@ -1030,7 +1012,6 @@ TEST(Float64StackParamsToStackParams) {
void MixedParamTest(int start) {
if (DISABLE_NATIVE_STACK_PARAMS) return;
if (RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN)
->num_double_registers() < 2)
return;
......@@ -1045,7 +1026,7 @@ void MixedParamTest(int start) {
#else
static MachineType types[] = {
kMachInt32, kMachInt64, kMachFloat32, kMachFloat64, kMachInt32,
kMachFloat64, kMachFloat32, kMachInt64, kMachFloat64, kMachInt32,
kMachFloat64, kMachFloat32, kMachInt64, kMachInt64, kMachFloat32,
kMachFloat32, kMachInt32, kMachFloat64, kMachFloat64, kMachInt64,
kMachInt32, kMachFloat64, kMachInt32, kMachFloat32};
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment