aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target/X86/X86InstrInfo.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-09-30 00:58:23 +0000
committerDan Gohman <gohman@apple.com>2008-09-30 00:58:23 +0000
commit57c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37c (patch)
tree2918c6ebf974f9b46d0f53e515ce82f99b7e3a38 /lib/Target/X86/X86InstrInfo.cpp
parent9b66d73bb1a0279d86e9ba77807146146a07724f (diff)
downloadexternal_llvm-57c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37c.zip
external_llvm-57c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37c.tar.gz
external_llvm-57c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37c.tar.bz2
Move the GlobalBaseReg field out of X86ISelDAGToDAG.cpp
and X86FastISel.cpp into X86MachineFunction.h, so that it can be shared, instead of having each selector keep track of its own. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56825 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86/X86InstrInfo.cpp')
-rw-r--r--lib/Target/X86/X86InstrInfo.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp
index c275418..cac35b1 100644
--- a/lib/Target/X86/X86InstrInfo.cpp
+++ b/lib/Target/X86/X86InstrInfo.cpp
@@ -2947,10 +2947,19 @@ unsigned X86InstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const {
return Size;
}
-/// initializeGlobalBaseReg - Output the instructions required to put the
-/// base address to use for accessing globals into a register.
+/// getGlobalBaseReg - Return a virtual register initialized with the
+/// the global base register value. Output instructions required to
+/// initialize the register in the function entry block, if necessary.
///
-unsigned X86InstrInfo::initializeGlobalBaseReg(MachineFunction *MF) const {
+unsigned X86InstrInfo::getGlobalBaseReg(MachineFunction *MF) const {
+ assert(!TM.getSubtarget<X86Subtarget>().is64Bit() &&
+ "X86-64 PIC uses RIP relative addressing");
+
+ X86MachineFunctionInfo *X86FI = MF->getInfo<X86MachineFunctionInfo>();
+ unsigned GlobalBaseReg = X86FI->getGlobalBaseReg();
+ if (GlobalBaseReg != 0)
+ return GlobalBaseReg;
+
// Insert the set of GlobalBaseReg into the first MBB of the function
MachineBasicBlock &FirstMBB = MF->front();
MachineBasicBlock::iterator MBBI = FirstMBB.begin();
@@ -2966,12 +2975,14 @@ unsigned X86InstrInfo::initializeGlobalBaseReg(MachineFunction *MF) const {
// not to pc, but to _GLOBAL_ADDRESS_TABLE_ external
if (TM.getRelocationModel() == Reloc::PIC_ &&
TM.getSubtarget<X86Subtarget>().isPICStyleGOT()) {
- unsigned GlobalBaseReg =
+ GlobalBaseReg =
RegInfo.createVirtualRegister(X86::GR32RegisterClass);
BuildMI(FirstMBB, MBBI, TII->get(X86::ADD32ri), GlobalBaseReg)
.addReg(PC).addExternalSymbol("_GLOBAL_OFFSET_TABLE_");
- return GlobalBaseReg;
+ } else {
+ GlobalBaseReg = PC;
}
- return PC;
+ X86FI->setGlobalBaseReg(GlobalBaseReg);
+ return GlobalBaseReg;
}