[PATCH] [AArch64] Teach AsmPrinter about GlobalAddress operands.
Ahmed Bougacha
ahmed.bougacha at gmail.com
Tue Mar 3 14:19:28 PST 2015
Basic fix for http://llvm.org/bugs/show_bug.cgi?id=22761.
Looking at the ARM counterpart, it handles stuff like ":lower16:" and more interestingly "(PLT)". Even more interestingly, removing those doesn't break any tests.
I tried to get some more interesting testcases, but I settled on an assert on the target flags, as I couldn't come up with a case where any of those would be set in inline asm (the other way to get to printOperand is the DEBUG_VALUE comment printer, but that's even more constrained).
Examples and pointers welcome!
I don't have a clear picture of the place of AsmPrinter in the grand scheme of things - yet -, so I'll have a second look and update if necessary (to the ARM version as well, smells like dead code to me).
Thanks,
-Ahmed
http://reviews.llvm.org/D8042
Files:
lib/Target/AArch64/AArch64AsmPrinter.cpp
test/CodeGen/AArch64/inline-asm-globaladdress.ll
Index: lib/Target/AArch64/AArch64AsmPrinter.cpp
===================================================================
--- lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -34,6 +34,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;
@@ -219,6 +220,17 @@
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;
+ }
}
}
Index: test/CodeGen/AArch64/inline-asm-globaladdress.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AArch64/inline-asm-globaladdress.ll
@@ -0,0 +1,22 @@
+; RUN: llc < %s -mtriple aarch64-gnu-linux | FileCheck %s --check-prefix=CHECK --check-prefix=LINUX
+; RUN: llc < %s -mtriple arm64-apple-darwin | FileCheck %s --check-prefix=CHECK --check-prefix=DARWIN
+
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+
+; CHECK-LABEL: test_inlineasm_globaladdress:
+; LINUX: b test_symbol
+; DARWIN: 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:
+; LINUX: b test_symbol+4
+; DARWIN: 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()
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8042.21139.patch
Type: text/x-patch
Size: 1919 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150303/daf7a3f0/attachment.bin>
More information about the llvm-commits
mailing list