[llvm] r189002 - Fix ARM FastISel PIC function call.
Logan Chien
tzuhsiang.chien at gmail.com
Thu Aug 22 05:08:04 PDT 2013
Author: logan
Date: Thu Aug 22 07:08:04 2013
New Revision: 189002
URL: http://llvm.org/viewvc/llvm-project?rev=189002&view=rev
Log:
Fix ARM FastISel PIC function call.
The function call to external function should come with PLT relocation
type if the PIC relocation model is used.
Added:
llvm/trunk/test/CodeGen/ARM/pic.ll
Modified:
llvm/trunk/lib/Target/ARM/ARMFastISel.cpp
Modified: llvm/trunk/lib/Target/ARM/ARMFastISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMFastISel.cpp?rev=189002&r1=189001&r2=189002&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMFastISel.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMFastISel.cpp Thu Aug 22 07:08:04 2013
@@ -2460,15 +2460,22 @@ bool ARMFastISel::SelectCall(const Instr
MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
DL, TII.get(CallOpc));
+ unsigned char OpFlags = 0;
+
+ // Add MO_PLT for global address or external symbol in the PIC relocation
+ // model.
+ if (Subtarget->isTargetELF() && TM.getRelocationModel() == Reloc::PIC_)
+ OpFlags = ARMII::MO_PLT;
+
// ARM calls don't take a predicate, but tBL / tBLX do.
if(isThumb2)
AddDefaultPred(MIB);
if (UseReg)
MIB.addReg(CalleeReg);
else if (!IntrMemName)
- MIB.addGlobalAddress(GV, 0, 0);
+ MIB.addGlobalAddress(GV, 0, OpFlags);
else
- MIB.addExternalSymbol(IntrMemName, 0);
+ MIB.addExternalSymbol(IntrMemName, OpFlags);
// Add implicit physical register uses to the call.
for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
Added: llvm/trunk/test/CodeGen/ARM/pic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/pic.ll?rev=189002&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/pic.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/pic.ll Thu Aug 22 07:08:04 2013
@@ -0,0 +1,23 @@
+; Check the function call in PIC relocation model.
+
+; If the relocation model is PIC, then the "bl" instruction for the function
+; call to the external function should come with PLT fixup type.
+
+; RUN: llc < %s -mtriple=armv7-unknown-linux-gnueabi \
+; RUN: -relocation-model=pic -fast-isel \
+; RUN: | FileCheck %s
+
+define void @test() {
+entry:
+
+ %0 = call i32 @get()
+; CHECK: bl get(PLT)
+
+ call void @put(i32 %0)
+; CHECK: bl put(PLT)
+
+ ret void
+}
+
+declare i32 @get()
+declare void @put(i32)
More information about the llvm-commits
mailing list