From 08d03168f2be9ee8139e4d2ba0923260df6e00b2 Mon Sep 17 00:00:00 2001 From: Justin Holewinski Date: Wed, 22 Jun 2011 16:07:03 +0000 Subject: [PATCH] PTX: Fix FrameIndex mapping bug git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133619 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/PTX/PTXAsmPrinter.cpp | 17 ++++++++++------- lib/Target/PTX/PTXInstrInfo.cpp | 6 +++--- lib/Target/PTX/PTXInstrInfo.h | 2 +- lib/Target/PTX/PTXRegisterInfo.cpp | 27 +++++++++++++++++++++++++++ lib/Target/PTX/PTXRegisterInfo.h | 6 ++---- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/lib/Target/PTX/PTXAsmPrinter.cpp b/lib/Target/PTX/PTXAsmPrinter.cpp index 855a092833a..b1f7c1e4b2b 100644 --- a/lib/Target/PTX/PTXAsmPrinter.cpp +++ b/lib/Target/PTX/PTXAsmPrinter.cpp @@ -204,15 +204,18 @@ void PTXAsmPrinter::EmitFunctionBodyStart() { } const MachineFrameInfo* FrameInfo = MF->getFrameInfo(); - DEBUG(dbgs() << "Have " << FrameInfo->getNumObjects() << " frame object(s)\n"); + DEBUG(dbgs() << "Have " << FrameInfo->getNumObjects() + << " frame object(s)\n"); for (unsigned i = 0, e = FrameInfo->getNumObjects(); i != e; ++i) { DEBUG(dbgs() << "Size of object: " << FrameInfo->getObjectSize(i) << "\n"); - std::string def = "\t.reg .b"; - def += utostr(FrameInfo->getObjectSize(i)*8); // Convert to bits - def += " s"; - def += utostr(i); - def += ";"; - OutStreamer.EmitRawText(Twine(def)); + if (FrameInfo->getObjectSize(i) > 0) { + std::string def = "\t.reg .b"; + def += utostr(FrameInfo->getObjectSize(i)*8); // Convert to bits + def += " s"; + def += utostr(i); + def += ";"; + OutStreamer.EmitRawText(Twine(def)); + } } } diff --git a/lib/Target/PTX/PTXInstrInfo.cpp b/lib/Target/PTX/PTXInstrInfo.cpp index c4f6cbdfd95..5bdac8917e4 100644 --- a/lib/Target/PTX/PTXInstrInfo.cpp +++ b/lib/Target/PTX/PTXInstrInfo.cpp @@ -291,7 +291,7 @@ InsertBranch(MachineBasicBlock &MBB, // Memory operand folding for spills void PTXInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MII, - unsigned SrcReg, bool isKill, int FrameIdx, + unsigned SrcReg, bool isKill, int FrameIdx, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const { MachineInstr& MI = *MII; @@ -318,7 +318,7 @@ void PTXInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB, // Build the store instruction (really a mov) MachineInstrBuilder MIB = BuildMI(MBB, MII, DL, get(OpCode)); - MIB.addImm(FrameIdx); + MIB.addFrameIndex(FrameIdx); MIB.addReg(SrcReg); AddDefaultPredicate(MIB); @@ -354,7 +354,7 @@ void PTXInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, // Build the load instruction (really a mov) MachineInstrBuilder MIB = BuildMI(MBB, MII, DL, get(OpCode)); MIB.addReg(DestReg); - MIB.addImm(FrameIdx); + MIB.addFrameIndex(FrameIdx); AddDefaultPredicate(MIB); } diff --git a/lib/Target/PTX/PTXInstrInfo.h b/lib/Target/PTX/PTXInstrInfo.h index b08c1597412..a2eea25da97 100644 --- a/lib/Target/PTX/PTXInstrInfo.h +++ b/lib/Target/PTX/PTXInstrInfo.h @@ -93,7 +93,7 @@ public: // efficient code anyway. // virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF, // MachineInstr* MI, - // const SmallVectorImpl &Ops, + // const SmallVectorImpl &Ops, // int FrameIndex) const; virtual void storeRegToStackSlot(MachineBasicBlock& MBB, diff --git a/lib/Target/PTX/PTXRegisterInfo.cpp b/lib/Target/PTX/PTXRegisterInfo.cpp index 0f3e7bc2c3a..b7c7ee5d3ad 100644 --- a/lib/Target/PTX/PTXRegisterInfo.cpp +++ b/lib/Target/PTX/PTXRegisterInfo.cpp @@ -13,7 +13,34 @@ #include "PTX.h" #include "PTXRegisterInfo.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; #include "PTXGenRegisterInfo.inc" + + +void PTXRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, + int SPAdj, + RegScavenger *RS) const { + unsigned Index; + MachineInstr& MI = *II; + + Index = 0; + while (!MI.getOperand(Index).isFI()) { + ++Index; + assert(Index < MI.getNumOperands() && + "Instr does not have a FrameIndex operand!"); + } + + int FrameIndex = MI.getOperand(Index).getIndex(); + + DEBUG(dbgs() << "eliminateFrameIndex: " << MI); + DEBUG(dbgs() << "- SPAdj: " << SPAdj << "\n"); + DEBUG(dbgs() << "- FrameIndex: " << FrameIndex << "\n"); + + // This frame index is post stack slot re-use assignments + MI.getOperand(Index).ChangeToImmediate(FrameIndex); +} diff --git a/lib/Target/PTX/PTXRegisterInfo.h b/lib/Target/PTX/PTXRegisterInfo.h index dc563523810..223e965f2aa 100644 --- a/lib/Target/PTX/PTXRegisterInfo.h +++ b/lib/Target/PTX/PTXRegisterInfo.h @@ -38,11 +38,9 @@ struct PTXRegisterInfo : public PTXGenRegisterInfo { return Reserved; // reserve no regs } - virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI, + virtual void eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, - RegScavenger *RS = NULL) const { - llvm_unreachable("PTX does not support general function call"); - } + RegScavenger *RS = NULL) const; virtual unsigned getFrameRegister(const MachineFunction &MF) const { llvm_unreachable("PTX does not have a frame register"); -- 2.34.1