summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2004-06-28 18:20:59 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2004-06-28 18:20:59 +0000
commit2f0cda8b2a1d50a9530c07236d8dd5ac98f6ec34 (patch)
treebe9ed39e9d2304b1d32db23b2bca6a1a9e2f1944 /llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp
parent75985d725c2e3a28430d71a1c139834f71d4c38d (diff)
downloadbcm5719-llvm-2f0cda8b2a1d50a9530c07236d8dd5ac98f6ec34.tar.gz
bcm5719-llvm-2f0cda8b2a1d50a9530c07236d8dd5ac98f6ec34.zip
Fix loading and storing PC-relative static variables, courtesy of Nate Begeman.
llvm-svn: 14468
Diffstat (limited to 'llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp')
-rw-r--r--llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp b/llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp
index 4302beb79b3..6d7b585106d 100644
--- a/llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp
+++ b/llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp
@@ -365,10 +365,19 @@ unsigned ISel::getReg(Value *V, MachineBasicBlock *MBB,
copyConstantToRegister(MBB, IPt, C, Reg);
return Reg;
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
+ // GV is located at PC + distance
+ unsigned LRsave = makeAnotherReg(Type::IntTy);
+ unsigned CurPC = makeAnotherReg(Type::IntTy);
unsigned Reg1 = makeAnotherReg(V->getType());
unsigned Reg2 = makeAnotherReg(V->getType());
- // Move the address of the global into the register
- BuildMI(*MBB, IPt, PPC32::LOADHiAddr, 2, Reg1).addReg(PPC32::R0)
+ // Save the old LR
+ BuildMI(*MBB, IPt, PPC32::MFLR, 0, LRsave);
+ // Move PC to destination reg
+ BuildMI(*MBB, IPt, PPC32::MovePCtoLR, 0, CurPC);
+ // Restore the old LR
+ BuildMI(*MBB, IPt, PPC32::MTLR, 1).addReg(LRsave);
+ // Move value at PC + distance into return reg
+ BuildMI(*MBB, IPt, PPC32::LOADHiAddr, 2, Reg1).addReg(CurPC)
.addGlobalAddress(GV);
BuildMI(*MBB, IPt, PPC32::LOADLoAddr, 2, Reg2).addReg(Reg1)
.addGlobalAddress(GV);
OpenPOWER on IntegriCloud