summaryrefslogtreecommitdiffstats
path: root/compiler/optimizing/code_generator_arm.cc
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2014-04-03 10:38:37 +0100
committerNicolas Geoffray <ngeoffray@google.com>2014-04-03 17:09:22 +0100
commit4a34a428c6a2588e0857ef6baf88f1b73ce65958 (patch)
treea9f025c17752a175c4e6a203c01e935cb438efb1 /compiler/optimizing/code_generator_arm.cc
parent8549cf9d83688f7decbbea2a8de761ce29e95f3c (diff)
downloadart-4a34a428c6a2588e0857ef6baf88f1b73ce65958.zip
art-4a34a428c6a2588e0857ef6baf88f1b73ce65958.tar.gz
art-4a34a428c6a2588e0857ef6baf88f1b73ce65958.tar.bz2
Support passing arguments to invoke-static* instructions.
- Stop using the frame pointer for accessing locals. - Stop emulating a stack when doing code generation. Instead, rely on dex register model, where instructions only reference registers. Change-Id: Id51bd7d33ac430cb87a53c9f4b0c864eeb1006f9
Diffstat (limited to 'compiler/optimizing/code_generator_arm.cc')
-rw-r--r--compiler/optimizing/code_generator_arm.cc102
1 files changed, 70 insertions, 32 deletions
diff --git a/compiler/optimizing/code_generator_arm.cc b/compiler/optimizing/code_generator_arm.cc
index 68c997b..09d6f7b 100644
--- a/compiler/optimizing/code_generator_arm.cc
+++ b/compiler/optimizing/code_generator_arm.cc
@@ -26,40 +26,50 @@
namespace art {
namespace arm {
+static constexpr int kNumberOfPushedRegistersAtEntry = 1;
+static constexpr int kCurrentMethodStackOffset = 0;
+
+InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
+ : HGraphVisitor(graph),
+ assembler_(codegen->GetAssembler()),
+ codegen_(codegen) {}
+
void CodeGeneratorARM::GenerateFrameEntry() {
core_spill_mask_ |= (1 << LR);
- // We're currently always using FP, which is callee-saved in Quick.
- core_spill_mask_ |= (1 << FP);
+ __ PushList((1 << LR));
- __ PushList((1 << FP) | (1 << LR));
- __ mov(FP, ShifterOperand(SP));
-
- // Add the current ART method to the frame size, the return pc, and FP.
- SetFrameSize(RoundUp(GetFrameSize() + 3 * kWordSize, kStackAlignment));
- // PC and FP have already been pushed on the stack.
- __ AddConstant(SP, -(GetFrameSize() - 2 * kWordSize));
+ // Add the current ART method to the frame size and the return PC.
+ SetFrameSize(RoundUp(GetFrameSize() + 2 * kWordSize, kStackAlignment));
+ // The retrn PC has already been pushed on the stack.
+ __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kWordSize));
__ str(R0, Address(SP, 0));
}
void CodeGeneratorARM::GenerateFrameExit() {
- __ mov(SP, ShifterOperand(FP));
- __ PopList((1 << FP) | (1 << PC));
+ __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kWordSize);
+ __ PopList((1 << PC));
}
void CodeGeneratorARM::Bind(Label* label) {
__ Bind(label);
}
-void CodeGeneratorARM::Push(HInstruction* instruction, Location location) {
- __ Push(location.reg<Register>());
+int32_t CodeGeneratorARM::GetStackSlot(HLocal* local) const {
+ return (GetGraph()->GetMaximumNumberOfOutVRegs() + local->GetRegNumber()) * kWordSize;
}
-void CodeGeneratorARM::Move(HInstruction* instruction, Location location) {
- HIntConstant* constant = instruction->AsIntConstant();
- if (constant != nullptr) {
- __ LoadImmediate(location.reg<Register>(), constant->GetValue());
+void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
+ if (instruction->AsIntConstant() != nullptr) {
+ __ LoadImmediate(location.reg<Register>(), instruction->AsIntConstant()->GetValue());
+ } else if (instruction->AsLoadLocal() != nullptr) {
+ __ LoadFromOffset(kLoadWord, location.reg<Register>(),
+ SP, GetStackSlot(instruction->AsLoadLocal()->GetLocal()));
} else {
- __ Pop(location.reg<Register>());
+ // This can currently only happen when the instruction that requests the move
+ // is the next to be compiled.
+ DCHECK_EQ(instruction->GetNext(), move_for);
+ __ mov(location.reg<Register>(),
+ ShifterOperand(instruction->GetLocations()->Out().reg<Register>()));
}
}
@@ -128,20 +138,11 @@ void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
}
void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
- LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load);
- locations->SetOut(Location(R0));
- load->SetLocations(locations);
-}
-
-static int32_t GetStackSlot(HLocal* local) {
- // We are currently using FP to access locals, so the offset must be negative.
- return (local->GetRegNumber() + 1) * -kWordSize;
+ load->SetLocations(nullptr);
}
void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
- LocationSummary* locations = load->GetLocations();
- __ LoadFromOffset(kLoadWord, locations->Out().reg<Register>(),
- FP, GetStackSlot(load->GetLocal()));
+ // Nothing to do, this is driven by the code generator.
}
void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
@@ -153,7 +154,7 @@ void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
LocationSummary* locations = store->GetLocations();
__ StoreToOffset(kStoreWord, locations->InAt(1).reg<Register>(),
- FP, GetStackSlot(store->GetLocal()));
+ SP, codegen_->GetStackSlot(store->GetLocal()));
}
void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
@@ -183,15 +184,52 @@ void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
codegen_->GenerateFrameExit();
}
+static constexpr Register kParameterCoreRegisters[] = { R1, R2, R3 };
+static constexpr int kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters);
+
+class InvokeStaticCallingConvention : public CallingConvention<Register> {
+ public:
+ InvokeStaticCallingConvention()
+ : CallingConvention(kParameterCoreRegisters, kParameterCoreRegistersLength) {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(InvokeStaticCallingConvention);
+};
+
+void LocationsBuilderARM::VisitPushArgument(HPushArgument* argument) {
+ LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(argument);
+ InvokeStaticCallingConvention calling_convention;
+ if (argument->GetArgumentIndex() < calling_convention.GetNumberOfRegisters()) {
+ Location location = Location(calling_convention.GetRegisterAt(argument->GetArgumentIndex()));
+ locations->SetInAt(0, location);
+ locations->SetOut(location);
+ } else {
+ locations->SetInAt(0, Location(R0));
+ }
+ argument->SetLocations(locations);
+}
+
+void InstructionCodeGeneratorARM::VisitPushArgument(HPushArgument* argument) {
+ uint8_t argument_index = argument->GetArgumentIndex();
+ InvokeStaticCallingConvention calling_convention;
+ size_t parameter_registers = calling_convention.GetNumberOfRegisters();
+ LocationSummary* locations = argument->GetLocations();
+ if (argument_index >= parameter_registers) {
+ uint8_t offset = calling_convention.GetStackOffsetOf(argument_index);
+ __ StoreToOffset(kStoreWord, locations->InAt(0).reg<Register>(), SP, offset);
+ } else {
+ DCHECK_EQ(locations->Out().reg<Register>(), locations->InAt(0).reg<Register>());
+ }
+}
+
void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(invoke);
- CHECK_EQ(invoke->InputCount(), 0);
locations->AddTemp(Location(R0));
invoke->SetLocations(locations);
}
void InstructionCodeGeneratorARM::LoadCurrentMethod(Register reg) {
- __ ldr(reg, Address(SP, 0));
+ __ ldr(reg, Address(SP, kCurrentMethodStackOffset));
}
void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {