[llvm-branch-commits] [llvm-branch] r295910 - Backport r293433, ARM: support `-mlong-calls` with AEABI TLS on ELF

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 22 16:14:14 PST 2017


Author: hans
Date: Wed Feb 22 18:14:14 2017
New Revision: 295910

URL: http://llvm.org/viewvc/llvm-project?rev=295910&view=rev
Log:
Backport r293433, ARM: support `-mlong-calls` with AEABI TLS on ELF

Support lowering AEABI TLS access (__aeabi_read_tp) with long calls.
This requires adjusting the call sequence to use an indirect call to get
full addressability.

Resolves PR31769!

By Saleem Abdulrasool!

Added:
    llvm/branches/release_40/test/CodeGen/ARM/aeabi-read-tp.ll
Modified:
    llvm/branches/release_40/lib/Target/ARM/ARMExpandPseudoInsts.cpp

Modified: llvm/branches/release_40/lib/Target/ARM/ARMExpandPseudoInsts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_40/lib/Target/ARM/ARMExpandPseudoInsts.cpp?rev=295910&r1=295909&r2=295910&view=diff
==============================================================================
--- llvm/branches/release_40/lib/Target/ARM/ARMExpandPseudoInsts.cpp (original)
+++ llvm/branches/release_40/lib/Target/ARM/ARMExpandPseudoInsts.cpp Wed Feb 22 18:14:14 2017
@@ -1225,16 +1225,36 @@ bool ARMExpandPseudo::ExpandMI(MachineBa
     }
     case ARM::tTPsoft:
     case ARM::TPsoft: {
+      const bool Thumb = Opcode == ARM::tTPsoft;
+
       MachineInstrBuilder MIB;
-      if (Opcode == ARM::tTPsoft)
+      if (STI->genLongCalls()) {
+        MachineFunction *MF = MBB.getParent();
+        MachineConstantPool *MCP = MF->getConstantPool();
+        unsigned PCLabelID = AFI->createPICLabelUId();
+        MachineConstantPoolValue *CPV =
+            ARMConstantPoolSymbol::Create(MF->getFunction()->getContext(),
+                                          "__aeabi_read_tp", PCLabelID, 0);
+        unsigned Reg = MI.getOperand(0).getReg();
+        MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
+                      TII->get(Thumb ? ARM::tLDRpci : ARM::LDRi12), Reg)
+                  .addConstantPoolIndex(MCP->getConstantPoolIndex(CPV, 4));
+        if (!Thumb)
+          MIB.addImm(0);
+        MIB.addImm(static_cast<unsigned>(ARMCC::AL)).addReg(0);
+
         MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
-                      TII->get( ARM::tBL))
-              .addImm((unsigned)ARMCC::AL).addReg(0)
-              .addExternalSymbol("__aeabi_read_tp", 0);
-      else
+                      TII->get(Thumb ? ARM::tBLXr : ARM::BLX));
+        if (Thumb)
+          MIB.addImm(static_cast<unsigned>(ARMCC::AL)).addReg(0);
+        MIB.addReg(Reg, RegState::Kill);
+      } else {
         MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
-                      TII->get( ARM::BL))
-              .addExternalSymbol("__aeabi_read_tp", 0);
+                      TII->get(Thumb ? ARM::tBL : ARM::BL));
+        if (Thumb)
+          MIB.addImm(static_cast<unsigned>(ARMCC::AL)).addReg(0);
+        MIB.addExternalSymbol("__aeabi_read_tp", 0);
+      }
 
       MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
       TransferImpOps(MI, MIB, MIB);

Added: llvm/branches/release_40/test/CodeGen/ARM/aeabi-read-tp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_40/test/CodeGen/ARM/aeabi-read-tp.ll?rev=295910&view=auto
==============================================================================
--- llvm/branches/release_40/test/CodeGen/ARM/aeabi-read-tp.ll (added)
+++ llvm/branches/release_40/test/CodeGen/ARM/aeabi-read-tp.ll Wed Feb 22 18:14:14 2017
@@ -0,0 +1,26 @@
+; RUN: llc -mtriple armv7---eabi -filetype asm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-SHORT
+; RUN: llc -mtriple thumbv7---eabi -filetype asm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-SHORT
+; RUN: llc -mtriple armv7---eabi -mattr=+long-calls -filetype asm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-LONG
+; RUN: llc -mtriple thumbv7---eabi -mattr=+long-calls -filetype asm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-LONG
+
+ at i = thread_local local_unnamed_addr global i32 0, align 4
+
+define i32 @f() local_unnamed_addr {
+entry:
+  %0 = load i32, i32* @i, align 4
+  ret i32 %0
+}
+
+; CHECK-LABEL: f:
+; CHECK-SHORT: ldr r1, [[VAR:.LCPI[0-9]+_[0-9]+]]
+; CHECK-SHORT-NEXT: bl __aeabi_read_tp
+; CHECK-SHORT: [[VAR]]:
+; CHECK-SHORT-NEXT: .long i(TPOFF)
+
+; CHECK-LONG: ldr [[REG:r[0-9]+]], [[FUN:.LCPI[0-9]+_[0-9]+]]
+; CHECK-LONG-NEXT: ldr r1, [[VAR:.LCPI[0-9]+_[0-9]+]]
+; CHECK-LONG-NEXT: blx [[REG]]
+; CHECK-LONG: [[VAR]]:
+; CHECK-LONG-NEXT: .long i(TPOFF)
+; CHECK-LONG: [[FUN]]:
+; CHECK-LONG-NEXT: .long __aeabi_read_tp




More information about the llvm-branch-commits mailing list