aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target/NVPTX
diff options
context:
space:
mode:
authorJustin Holewinski <jholewinski@nvidia.com>2013-08-06 14:13:31 +0000
committerJustin Holewinski <jholewinski@nvidia.com>2013-08-06 14:13:31 +0000
commita3635eefc749389aed84d9791fab657297203e1b (patch)
tree613f5d28fe902b437c84eebdf89c60eb5f60c9ce /lib/Target/NVPTX
parent82767327c59ede1f8663ec9b9a64a668993d501f (diff)
downloadexternal_llvm-a3635eefc749389aed84d9791fab657297203e1b.zip
external_llvm-a3635eefc749389aed84d9791fab657297203e1b.tar.gz
external_llvm-a3635eefc749389aed84d9791fab657297203e1b.tar.bz2
[NVPTX] Fix bug in stack code generation causes by MC conversion
We do use a very small set of physical registers, so account for them in the virtual register encoding between MachineInstr and MC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187799 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/NVPTX')
-rw-r--r--lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp15
-rw-r--r--lib/Target/NVPTX/NVPTXAsmPrinter.cpp56
-rw-r--r--lib/Target/NVPTX/NVPTXFrameLowering.cpp41
-rw-r--r--lib/Target/NVPTX/NVPTXInstrInfo.td9
4 files changed, 68 insertions, 53 deletions
diff --git a/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp b/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp
index 1cb8a9a..c7b8aa4 100644
--- a/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp
+++ b/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp
@@ -41,21 +41,26 @@ void NVPTXInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
switch (RCId) {
default: report_fatal_error("Bad virtual register encoding");
case 0:
+ // This is actually a physical register, so defer to the autogenerated
+ // register printer
+ OS << getRegisterName(RegNo);
+ return;
+ case 1:
OS << "%p";
break;
- case 1:
+ case 2:
OS << "%rs";
break;
- case 2:
+ case 3:
OS << "%r";
break;
- case 3:
+ case 4:
OS << "%rl";
break;
- case 4:
+ case 5:
OS << "%f";
break;
- case 5:
+ case 6:
OS << "%fl";
break;
}
diff --git a/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index b417d64..fb4d4df 100644
--- a/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -368,33 +368,39 @@ bool NVPTXAsmPrinter::lowerOperand(const MachineOperand &MO,
}
unsigned NVPTXAsmPrinter::encodeVirtualRegister(unsigned Reg) {
- const TargetRegisterClass *RC = MRI->getRegClass(Reg);
-
- DenseMap<unsigned, unsigned> &RegMap = VRegMapping[RC];
- unsigned RegNum = RegMap[Reg];
-
- // Encode the register class in the upper 4 bits
- // Must be kept in sync with NVPTXInstPrinter::printRegName
- unsigned Ret = 0;
- if (RC == &NVPTX::Int1RegsRegClass) {
- Ret = 0;
- } else if (RC == &NVPTX::Int16RegsRegClass) {
- Ret = (1 << 28);
- } else if (RC == &NVPTX::Int32RegsRegClass) {
- Ret = (2 << 28);
- } else if (RC == &NVPTX::Int64RegsRegClass) {
- Ret = (3 << 28);
- } else if (RC == &NVPTX::Float32RegsRegClass) {
- Ret = (4 << 28);
- } else if (RC == &NVPTX::Float64RegsRegClass) {
- Ret = (5 << 28);
+ if (TargetRegisterInfo::isVirtualRegister(Reg)) {
+ const TargetRegisterClass *RC = MRI->getRegClass(Reg);
+
+ DenseMap<unsigned, unsigned> &RegMap = VRegMapping[RC];
+ unsigned RegNum = RegMap[Reg];
+
+ // Encode the register class in the upper 4 bits
+ // Must be kept in sync with NVPTXInstPrinter::printRegName
+ unsigned Ret = 0;
+ if (RC == &NVPTX::Int1RegsRegClass) {
+ Ret = (1 << 28);
+ } else if (RC == &NVPTX::Int16RegsRegClass) {
+ Ret = (2 << 28);
+ } else if (RC == &NVPTX::Int32RegsRegClass) {
+ Ret = (3 << 28);
+ } else if (RC == &NVPTX::Int64RegsRegClass) {
+ Ret = (4 << 28);
+ } else if (RC == &NVPTX::Float32RegsRegClass) {
+ Ret = (5 << 28);
+ } else if (RC == &NVPTX::Float64RegsRegClass) {
+ Ret = (6 << 28);
+ } else {
+ report_fatal_error("Bad register class");
+ }
+
+ // Insert the vreg number
+ Ret |= (RegNum & 0x0FFFFFFF);
+ return Ret;
} else {
- report_fatal_error("Bad register class");
+ // Some special-use registers are actually physical registers.
+ // Encode this as the register class ID of 0 and the real register ID.
+ return Reg & 0x0FFFFFFF;
}
-
- // Insert the vreg number
- Ret |= (RegNum & 0x0FFFFFFF);
- return Ret;
}
MCOperand NVPTXAsmPrinter::GetSymbolRef(const MachineOperand &MO,
diff --git a/lib/Target/NVPTX/NVPTXFrameLowering.cpp b/lib/Target/NVPTX/NVPTXFrameLowering.cpp
index 6533da5..9030584 100644
--- a/lib/Target/NVPTX/NVPTXFrameLowering.cpp
+++ b/lib/Target/NVPTX/NVPTXFrameLowering.cpp
@@ -20,6 +20,7 @@
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/MC/MachineLocation.h"
#include "llvm/Target/TargetInstrInfo.h"
@@ -36,30 +37,24 @@ void NVPTXFrameLowering::emitPrologue(MachineFunction &MF) const {
// in the BB, so giving it no debug location.
DebugLoc dl = DebugLoc();
- if (tm.getSubtargetImpl()->hasGenericLdSt()) {
- // mov %SPL, %depot;
- // cvta.local %SP, %SPL;
- if (is64bit) {
- MachineInstr *MI = BuildMI(
- MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::cvta_local_yes_64),
- NVPTX::VRFrame).addReg(NVPTX::VRFrameLocal);
- BuildMI(MBB, MI, dl, tm.getInstrInfo()->get(NVPTX::IMOV64rr),
- NVPTX::VRFrameLocal).addReg(NVPTX::VRDepot);
- } else {
- MachineInstr *MI = BuildMI(
- MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::cvta_local_yes),
- NVPTX::VRFrame).addReg(NVPTX::VRFrameLocal);
- BuildMI(MBB, MI, dl, tm.getInstrInfo()->get(NVPTX::IMOV32rr),
- NVPTX::VRFrameLocal).addReg(NVPTX::VRDepot);
- }
+ MachineRegisterInfo &MRI = MF.getRegInfo();
+
+ // mov %SPL, %depot;
+ // cvta.local %SP, %SPL;
+ if (is64bit) {
+ unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int64RegsRegClass);
+ MachineInstr *MI = BuildMI(
+ MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::cvta_local_yes_64),
+ NVPTX::VRFrame).addReg(LocalReg);
+ BuildMI(MBB, MI, dl, tm.getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR_64),
+ LocalReg).addImm(MF.getFunctionNumber());
} else {
- // mov %SP, %depot;
- if (is64bit)
- BuildMI(MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::IMOV64rr),
- NVPTX::VRFrame).addReg(NVPTX::VRDepot);
- else
- BuildMI(MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::IMOV32rr),
- NVPTX::VRFrame).addReg(NVPTX::VRDepot);
+ unsigned LocalReg = MRI.createVirtualRegister(&NVPTX::Int32RegsRegClass);
+ MachineInstr *MI = BuildMI(
+ MBB, MBBI, dl, tm.getInstrInfo()->get(NVPTX::cvta_local_yes),
+ NVPTX::VRFrame).addReg(LocalReg);
+ BuildMI(MBB, MI, dl, tm.getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR),
+ LocalReg).addImm(MF.getFunctionNumber());
}
}
}
diff --git a/lib/Target/NVPTX/NVPTXInstrInfo.td b/lib/Target/NVPTX/NVPTXInstrInfo.td
index 8ce16e9..db91eb0 100644
--- a/lib/Target/NVPTX/NVPTXInstrInfo.td
+++ b/lib/Target/NVPTX/NVPTXInstrInfo.td
@@ -1321,6 +1321,15 @@ def MOV_ADDR64 : NVPTXInst<(outs Int64Regs:$dst), (ins imem:$a),
"mov.u64 \t$dst, $a;",
[(set Int64Regs:$dst, (Wrapper tglobaladdr:$a))]>;
+// Get pointer to local stack
+def MOV_DEPOT_ADDR
+ : NVPTXInst<(outs Int32Regs:$d), (ins i32imm:$num),
+ "mov.u32 \t$d, __local_depot$num;", []>;
+def MOV_DEPOT_ADDR_64
+ : NVPTXInst<(outs Int64Regs:$d), (ins i32imm:$num),
+ "mov.u64 \t$d, __local_depot$num;", []>;
+
+
// copyPhysreg is hard-coded in NVPTXInstrInfo.cpp
let IsSimpleMove=1 in {
def IMOV1rr: NVPTXInst<(outs Int1Regs:$dst), (ins Int1Regs:$sss),