diff options
| author | Eric Christopher <echristo@apple.com> | 2010-10-02 00:32:44 +0000 |
|---|---|---|
| committer | Eric Christopher <echristo@apple.com> | 2010-10-02 00:32:44 +0000 |
| commit | 7787f79f2135a35e767a4265226b865afae46a3a (patch) | |
| tree | 98d6c38e90e5913aaa592949d946bb22fc6e78a5 | |
| parent | a8d176866d9751757539684406e1b1cefa134726 (diff) | |
| download | bcm5719-llvm-7787f79f2135a35e767a4265226b865afae46a3a.tar.gz bcm5719-llvm-7787f79f2135a35e767a4265226b865afae46a3a.zip | |
Start on lowering global addresses.
llvm-svn: 115390
| -rw-r--r-- | llvm/lib/Target/ARM/ARMFastISel.cpp | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/llvm/lib/Target/ARM/ARMFastISel.cpp b/llvm/lib/Target/ARM/ARMFastISel.cpp index 3a716d321c1..5134d460b7e 100644 --- a/llvm/lib/Target/ARM/ARMFastISel.cpp +++ b/llvm/lib/Target/ARM/ARMFastISel.cpp @@ -449,8 +449,49 @@ unsigned ARMFastISel::ARMMaterializeInt(const Constant *C, EVT VT) { } unsigned ARMFastISel::ARMMaterializeGV(const GlobalValue *GV, EVT VT) { - // Disable currently... - return 0; + // For now 32-bit only. + if (VT.getSimpleVT().SimpleTy != MVT::i32) return 0; + + Reloc::Model RelocM = TM.getRelocationModel(); + + // TODO: No external globals for now. + if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) return 0; + + // TODO: Need more magic for ARM PIC. + if (!isThumb && (RelocM == Reloc::PIC_)) return 0; + + // MachineConstantPool wants an explicit alignment. + unsigned Align = TD.getPrefTypeAlignment(GV->getType()); + if (Align == 0) { + // TODO: Figure out if this is correct. + Align = TD.getTypeAllocSize(GV->getType()); + } + + // Grab index. + unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb() ? 4 : 8); + unsigned Id = AFI->createConstPoolEntryUId(); + ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, Id, + ARMCP::CPValue, PCAdj); + unsigned Idx = MCP.getConstantPoolIndex(CPV, Align); + + // Load value. + MachineInstrBuilder MIB; + unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); + if (isThumb) { + unsigned Opc = (RelocM != Reloc::PIC_) ? ARM::t2LDRpci : ARM::t2LDRpci_pic; + MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg) + .addConstantPoolIndex(Idx); + if (RelocM == Reloc::PIC_) + MIB.addImm(Id); + } else { + // The extra reg and immediate are for addrmode2. + MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(ARM::LDRcp), + DestReg) + .addConstantPoolIndex(Idx) + .addReg(0).addImm(0); + } + AddOptionalDefs(MIB); + return DestReg; } unsigned ARMFastISel::TargetMaterializeConstant(const Constant *C) { |

