[PATCH] D34622: [Linker] Add directives to support mixing ARM/Thumb module-level inline asm.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 26 07:45:12 PDT 2017


fhahn created this revision.
Herald added subscribers: kristof.beyls, eraman, javed.absar, aemerson.

By prepending `.text .thumb .balign 2` to the module-level inline
assembly from a Thumb module, the assembler will generate the assembly
from that module as Thumb, even if the destination module uses an ARM
triple. Similar directives are used for module-level inline assembly in
ARM modules.

The alignment and instruction set are reset based on the target triple
before emitting the first function label.


https://reviews.llvm.org/D34622

Files:
  lib/Linker/IRMover.cpp
  test/Linker/Inputs/thumb-module-inline-asm.ll
  test/Linker/link-arm-and-thumb-module-inline-asm.ll
  test/MC/ARM/inline-asm-switch-mode.ll


Index: test/MC/ARM/inline-asm-switch-mode.ll
===================================================================
--- /dev/null
+++ test/MC/ARM/inline-asm-switch-mode.ll
@@ -0,0 +1,14 @@
+; RUN: llc -mtriple=armv7-linux -filetype=asm < %s | FileCheck %s
+
+module asm ".thumb"
+module asm ".align 1"
+
+define i32 @inc1() {
+  ret i32 10
+}
+
+; CHECK: .code 16
+; CHECK-next: .p2align 1
+; CHECK: .code 32
+; CHECK: .p2align 2
+; CHECK-LABEL: @inc1
Index: test/Linker/link-arm-and-thumb-module-inline-asm.ll
===================================================================
--- /dev/null
+++ test/Linker/link-arm-and-thumb-module-inline-asm.ll
@@ -0,0 +1,17 @@
+; RUN: llvm-as %s -o %t1.bc
+; RUN: llvm-as %p/Inputs/thumb-module-inline-asm.ll -o %t2.bc
+; RUN: llvm-link %t1.bc %t2.bc -S 2> %t3.out | FileCheck %s
+
+target triple = "armv7-linux-gnueabihf"
+
+module asm "add r1, r2, r2"
+
+; CHECK: .text
+; CHECK-NEXT: .balign 4
+; CHECK-NEXT: .arm
+; CHECK-NEXT: add r1, r2, r2
+; CHECK-NEXT: module asm
+; CHECK-NEXT: .text
+; CHECK-NEXT: .balign 2
+; CHECK-NEXT: .thumb
+; CHECK-NEXT: orn r1, r2, r2
Index: test/Linker/Inputs/thumb-module-inline-asm.ll
===================================================================
--- /dev/null
+++ test/Linker/Inputs/thumb-module-inline-asm.ll
@@ -0,0 +1,3 @@
+target triple = "thumbv7-linux-gnueabihf"
+
+module asm "orn r1, r2, r2"
Index: lib/Linker/IRMover.cpp
===================================================================
--- lib/Linker/IRMover.cpp
+++ lib/Linker/IRMover.cpp
@@ -1293,11 +1293,20 @@
 
   // Append the module inline asm string.
   if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) {
+    std::string SrcModuleInlineAsm = SrcM->getModuleInlineAsm();
+    // Add directives to support mixing module-level inline assembly from ARM
+    // and Thumb modules.
+    if (SrcTriple.getArch() == Triple::thumb ||
+        SrcTriple.getArch() == Triple::thumbeb)
+      SrcModuleInlineAsm = ".text\n.balign 2\n.thumb\n" + SrcModuleInlineAsm;
+    else if (SrcTriple.getArch() == Triple::arm ||
+             SrcTriple.getArch() == Triple::armeb)
+      SrcModuleInlineAsm = ".text\n.balign 4\n.arm\n" + SrcModuleInlineAsm;
     if (DstM.getModuleInlineAsm().empty())
-      DstM.setModuleInlineAsm(SrcM->getModuleInlineAsm());
+      DstM.setModuleInlineAsm(SrcModuleInlineAsm);
     else
       DstM.setModuleInlineAsm(DstM.getModuleInlineAsm() + "\n" +
-                              SrcM->getModuleInlineAsm());
+                              SrcModuleInlineAsm);
   }
 
   // Loop over all of the linked values to compute type mappings.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34622.103950.patch
Type: text/x-patch
Size: 2620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170626/a869fe82/attachment.bin>


More information about the llvm-commits mailing list