[AArch64] Teach AsmPrinter about GlobalAddress operands.
authorAhmed Bougacha <ahmed.bougacha@gmail.com>
Thu, 5 Mar 2015 20:04:21 +0000 (20:04 +0000)
committerAhmed Bougacha <ahmed.bougacha@gmail.com>
Thu, 5 Mar 2015 20:04:21 +0000 (20:04 +0000)
Fixes PR22761, rdar://20024866.
Differential Revision: http://reviews.llvm.org/D8042

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231400 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AArch64/AArch64AsmPrinter.cpp
test/CodeGen/AArch64/inline-asm-globaladdress.ll [new file with mode: 0644]

index 5367f90f7c167869b11e5b12b5b1af5318254676..f8ebd66676b4cfc01922cea79861e54c0ab98b81 100644 (file)
@@ -36,6 +36,7 @@
 #include "llvm/MC/MCInstBuilder.h"
 #include "llvm/MC/MCLinkerOptimizationHint.h"
 #include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCSymbol.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/TargetRegistry.h"
 using namespace llvm;
@@ -221,6 +222,17 @@ void AArch64AsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNum,
     O << '#' << Imm;
     break;
   }
+  case MachineOperand::MO_GlobalAddress: {
+    const GlobalValue *GV = MO.getGlobal();
+    MCSymbol *Sym = getSymbol(GV);
+
+    // FIXME: Can we get anything other than a plain symbol here?
+    assert(!MO.getTargetFlags() && "Unknown operand target flag!");
+
+    O << *Sym;
+    printOffset(MO.getOffset(), O);
+    break;
+  }
   }
 }
 
diff --git a/test/CodeGen/AArch64/inline-asm-globaladdress.ll b/test/CodeGen/AArch64/inline-asm-globaladdress.ll
new file mode 100644 (file)
index 0000000..ba1bc40
--- /dev/null
@@ -0,0 +1,20 @@
+; RUN: llc < %s -mtriple aarch64-gnu-linux | FileCheck %s
+; RUN: llc < %s -mtriple arm64-apple-darwin | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+
+; CHECK-LABEL: test_inlineasm_globaladdress:
+; CHECK: b {{_?}}test_symbol
+define void @test_inlineasm_globaladdress() {
+  call void asm sideeffect "b $0", "i"(void ()* @test_symbol)
+  ret void
+}
+
+; CHECK-LABEL: test_inlineasm_globaladdress_offset:
+; CHECK: b {{_?}}test_symbol+4
+define void @test_inlineasm_globaladdress_offset() {
+  call void asm sideeffect "b $0", "i"(void ()* bitcast (i8* getelementptr (i8* bitcast (void ()* @test_symbol to i8*), i64 4) to void ()*))
+  ret void
+}
+
+declare void @test_symbol()