From 4e825336a0537c9e618d8011c9b1aad9a26e6dd8 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 31 Oct 2006 13:03:26 +0000 Subject: [PATCH] add support for calling functions when the caller has variable sized objects llvm-svn: 31312 --- llvm/lib/Target/ARM/ARMRegisterInfo.cpp | 20 +++++++++++++++++++- llvm/test/Regression/CodeGen/ARM/alloca.ll | 5 ++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/ARM/ARMRegisterInfo.cpp b/llvm/lib/Target/ARM/ARMRegisterInfo.cpp index 885c5a7b9eb1..817c9faf4510 100644 --- a/llvm/lib/Target/ARM/ARMRegisterInfo.cpp +++ b/llvm/lib/Target/ARM/ARMRegisterInfo.cpp @@ -19,6 +19,8 @@ #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineLocation.h" #include "llvm/Type.h" +#include "llvm/Target/TargetFrameInfo.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" #include "llvm/ADT/STLExtras.h" #include @@ -99,7 +101,23 @@ void ARMRegisterInfo:: eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const { if (hasFP(MF)) { - assert(0); + MachineInstr *Old = I; + unsigned Amount = Old->getOperand(0).getImmedValue(); + if (Amount != 0) { + unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment(); + Amount = (Amount+Align-1)/Align*Align; + + if (Old->getOpcode() == ARM::ADJCALLSTACKDOWN) { + // sub sp, sp, amount + BuildMI(MBB, I, ARM::SUB, 2, ARM::R13).addReg(ARM::R13).addImm(Amount) + .addImm(0).addImm(ARMShift::LSL); + } else { + // add sp, sp, amount + assert(Old->getOpcode() == ARM::ADJCALLSTACKUP); + BuildMI(MBB, I, ARM::ADD, 2, ARM::R13).addReg(ARM::R13).addImm(Amount) + .addImm(0).addImm(ARMShift::LSL); + } + } } MBB.erase(I); } diff --git a/llvm/test/Regression/CodeGen/ARM/alloca.ll b/llvm/test/Regression/CodeGen/ARM/alloca.ll index d5510d3e51f3..b77f234e1087 100644 --- a/llvm/test/Regression/CodeGen/ARM/alloca.ll +++ b/llvm/test/Regression/CodeGen/ARM/alloca.ll @@ -1,6 +1,9 @@ ; RUN: llvm-as < %s | llc -march=arm void %f(uint %a) { entry: - %tmp1032 = alloca ubyte, uint %a + %tmp = alloca sbyte, uint %a + call void %g( sbyte* %tmp, uint %a, uint 1, uint 2, uint 3 ) ret void } + +declare void %g(sbyte*, uint, uint, uint, uint)