diff options
author | Dan Gohman <gohman@apple.com> | 2008-09-23 18:22:58 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2008-09-23 18:22:58 +0000 |
commit | 8b746969baee26237e4c52de9862d06795eabcda (patch) | |
tree | a02b00e3e3d886e096047bcba43437faf20a9c65 /lib/Target/X86/X86InstrInfo.cpp | |
parent | 3ee8fc964952a65bcb3668b85938c46f90631e42 (diff) | |
download | external_llvm-8b746969baee26237e4c52de9862d06795eabcda.zip external_llvm-8b746969baee26237e4c52de9862d06795eabcda.tar.gz external_llvm-8b746969baee26237e4c52de9862d06795eabcda.tar.bz2 |
Move the code for initializing the global base reg out of
X86ISelDAGToDAG.cpp and into X86InstrInfo.cpp. This will allow
it to be reused by FastISel.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56494 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86/X86InstrInfo.cpp')
-rw-r--r-- | lib/Target/X86/X86InstrInfo.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index 4c597ed..0864fa0 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -2935,3 +2935,32 @@ 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. +/// +unsigned X86InstrInfo::initializeGlobalBaseReg(MachineFunction *MF) const { + // Insert the set of GlobalBaseReg into the first MBB of the function + MachineBasicBlock &FirstMBB = MF->front(); + MachineBasicBlock::iterator MBBI = FirstMBB.begin(); + MachineRegisterInfo &RegInfo = MF->getRegInfo(); + unsigned PC = RegInfo.createVirtualRegister(X86::GR32RegisterClass); + + const TargetInstrInfo *TII = TM.getInstrInfo(); + // Operand of MovePCtoStack is completely ignored by asm printer. It's + // only used in JIT code emission as displacement to pc. + BuildMI(FirstMBB, MBBI, TII->get(X86::MOVPC32r), PC).addImm(0); + + // If we're using vanilla 'GOT' PIC style, we should use relative addressing + // not to pc, but to _GLOBAL_ADDRESS_TABLE_ external + if (TM.getRelocationModel() == Reloc::PIC_ && + TM.getSubtarget<X86Subtarget>().isPICStyleGOT()) { + unsigned GlobalBaseReg = + RegInfo.createVirtualRegister(X86::GR32RegisterClass); + BuildMI(FirstMBB, MBBI, TII->get(X86::ADD32ri), GlobalBaseReg) + .addReg(PC).addExternalSymbol("_GLOBAL_OFFSET_TABLE_"); + return GlobalBaseReg; + } + + return PC; +} |