aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2009-05-03 13:09:57 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2009-05-03 13:09:57 +0000
commitaa29915b5822bd9af2a2b80eb95be59368743935 (patch)
treeed53b9645f44112849ae312a61d1b75998a5ac06 /lib/Target
parentcf14ae550051002283eabfb4dcbd67fa71f46f67 (diff)
downloadexternal_llvm-aa29915b5822bd9af2a2b80eb95be59368743935.zip
external_llvm-aa29915b5822bd9af2a2b80eb95be59368743935.tar.gz
external_llvm-aa29915b5822bd9af2a2b80eb95be59368743935.tar.bz2
First draft of stack slot loads / stores lowering
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70735 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
-rw-r--r--lib/Target/MSP430/MSP430InstrInfo.cpp40
-rw-r--r--lib/Target/MSP430/MSP430InstrInfo.h9
-rw-r--r--lib/Target/MSP430/MSP430RegisterInfo.cpp32
-rw-r--r--lib/Target/MSP430/MSP430RegisterInfo.h1
-rw-r--r--lib/Target/MSP430/MSP430TargetMachine.cpp2
5 files changed, 80 insertions, 4 deletions
diff --git a/lib/Target/MSP430/MSP430InstrInfo.cpp b/lib/Target/MSP430/MSP430InstrInfo.cpp
index dbbf29c..c32dbdc 100644
--- a/lib/Target/MSP430/MSP430InstrInfo.cpp
+++ b/lib/Target/MSP430/MSP430InstrInfo.cpp
@@ -16,10 +16,10 @@
#include "MSP430TargetMachine.h"
#include "MSP430GenInstrInfo.inc"
#include "llvm/Function.h"
-#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
-
+#include "llvm/CodeGen/PseudoSourceValue.h"
using namespace llvm;
@@ -27,6 +27,42 @@ MSP430InstrInfo::MSP430InstrInfo(MSP430TargetMachine &tm)
: TargetInstrInfoImpl(MSP430Insts, array_lengthof(MSP430Insts)),
RI(tm, *this), TM(tm) {}
+void MSP430InstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator MI,
+ unsigned SrcReg, bool isKill, int FrameIdx,
+ const TargetRegisterClass *RC) const {
+ DebugLoc DL = DebugLoc::getUnknownLoc();
+ if (MI != MBB.end()) DL = MI->getDebugLoc();
+
+ if (RC == &MSP430::GR16RegClass)
+ BuildMI(MBB, MI, DL, get(MSP430::MOV16mr))
+ .addFrameIndex(FrameIdx).addImm(0)
+ .addReg(SrcReg, false, false, isKill);
+ else if (RC == &MSP430::GR8RegClass)
+ BuildMI(MBB, MI, DL, get(MSP430::MOV8mr))
+ .addFrameIndex(FrameIdx).addImm(0)
+ .addReg(SrcReg, false, false, isKill);
+ else
+ assert(0 && "Cannot store this register to stack slot!");
+}
+
+void MSP430InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator MI,
+ unsigned DestReg, int FrameIdx,
+ const TargetRegisterClass *RC) const{
+ DebugLoc DL = DebugLoc::getUnknownLoc();
+ if (MI != MBB.end()) DL = MI->getDebugLoc();
+
+ if (RC == &MSP430::GR16RegClass)
+ BuildMI(MBB, MI, DL, get(MSP430::MOV16rm))
+ .addReg(DestReg).addFrameIndex(FrameIdx).addImm(0);
+ else if (RC == &MSP430::GR8RegClass)
+ BuildMI(MBB, MI, DL, get(MSP430::MOV8rm))
+ .addReg(DestReg).addFrameIndex(FrameIdx).addImm(0);
+ else
+ assert(0 && "Cannot store this register to stack slot!");
+}
+
bool MSP430InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator I,
unsigned DestReg, unsigned SrcReg,
diff --git a/lib/Target/MSP430/MSP430InstrInfo.h b/lib/Target/MSP430/MSP430InstrInfo.h
index 0ed2944..656e8df 100644
--- a/lib/Target/MSP430/MSP430InstrInfo.h
+++ b/lib/Target/MSP430/MSP430InstrInfo.h
@@ -41,6 +41,15 @@ public:
bool isMoveInstr(const MachineInstr& MI,
unsigned &SrcReg, unsigned &DstReg,
unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
+
+ virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator MI,
+ unsigned SrcReg, bool isKill, int FrameIndex,
+ const TargetRegisterClass *RC) const;
+ virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator MI,
+ unsigned DestReg, int FrameIdx,
+ const TargetRegisterClass *RC) const;
};
}
diff --git a/lib/Target/MSP430/MSP430RegisterInfo.cpp b/lib/Target/MSP430/MSP430RegisterInfo.cpp
index c7efa5e..be187fa 100644
--- a/lib/Target/MSP430/MSP430RegisterInfo.cpp
+++ b/lib/Target/MSP430/MSP430RegisterInfo.cpp
@@ -74,6 +74,11 @@ MSP430RegisterInfo::getReservedRegs(const MachineFunction &MF) const {
return Reserved;
}
+const TargetRegisterClass* MSP430RegisterInfo::getPointerRegClass() const {
+ return &MSP430::GR16RegClass;
+}
+
+
bool MSP430RegisterInfo::hasFP(const MachineFunction &MF) const {
return NoFramePointerElim || MF.getFrameInfo()->hasVarSizedObjects();
}
@@ -143,7 +148,32 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
void
MSP430RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
int SPAdj, RegScavenger *RS) const {
- assert(0 && "Not implemented yet!");
+ assert(SPAdj == 0 && "Unexpected");
+
+ unsigned i = 0;
+ MachineInstr &MI = *II;
+ MachineFunction &MF = *MI.getParent()->getParent();
+ while (!MI.getOperand(i).isFI()) {
+ ++i;
+ assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
+ }
+
+ int FrameIndex = MI.getOperand(i).getIndex();
+
+ unsigned BasePtr = (hasFP(MF) ? MSP430::FPW : MSP430::SPW);
+ int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex);
+
+ if (!hasFP(MF))
+ Offset += MF.getFrameInfo()->getStackSize();
+
+ // Skip the saved PC
+ Offset += 2;
+
+ MI.getOperand(i).ChangeToRegister(BasePtr, false);
+
+ // Fold imm into offset
+ Offset += MI.getOperand(i+1).getImm();
+ MI.getOperand(i+1).ChangeToImmediate(Offset);
}
void MSP430RegisterInfo::emitPrologue(MachineFunction &MF) const {
diff --git a/lib/Target/MSP430/MSP430RegisterInfo.h b/lib/Target/MSP430/MSP430RegisterInfo.h
index 0dc061c..6038af3 100644
--- a/lib/Target/MSP430/MSP430RegisterInfo.h
+++ b/lib/Target/MSP430/MSP430RegisterInfo.h
@@ -40,6 +40,7 @@ public:
getCalleeSavedRegClasses(const MachineFunction *MF = 0) const;
BitVector getReservedRegs(const MachineFunction &MF) const;
+ const TargetRegisterClass* getPointerRegClass() const;
bool hasFP(const MachineFunction &MF) const;
bool hasReservedCallFrame(MachineFunction &MF) const;
diff --git a/lib/Target/MSP430/MSP430TargetMachine.cpp b/lib/Target/MSP430/MSP430TargetMachine.cpp
index a2dee33..90819cf 100644
--- a/lib/Target/MSP430/MSP430TargetMachine.cpp
+++ b/lib/Target/MSP430/MSP430TargetMachine.cpp
@@ -41,7 +41,7 @@ MSP430TargetMachine::MSP430TargetMachine(const Module &M,
// FIXME: Check TargetData string.
DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"),
InstrInfo(*this), TLInfo(*this),
- FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0) { }
+ FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) { }
const TargetAsmInfo *MSP430TargetMachine::createTargetAsmInfo() const {
return new MSP430TargetAsmInfo(*this);