[PATCH] D60428: [Aarch64AsmPrinter] support %c output template for global addresses
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 16:45:02 PDT 2019
nickdesaulniers created this revision.
nickdesaulniers added reviewers: olista01, kristof.beyls, peter.smith.
Herald added subscribers: llvm-commits, hiraditya, eraman, javed.absar.
Herald added a project: LLVM.
The Linux kernel makes use of %c<digit> "output template" in extended
inline assembly, particularly with asm goto for static key runtime
patching. The inline assembly uses the address of a global variable as
input to the extended inline assembly.
There's generic handling of %c in AsmPrinter::PrintAsmOperand() for
immediates. I considered extending support for global addresses there,
but it seems that X86AsmPrinter::PrintAsmOperand() has quite a bit of
custom logic for printing global addresses (see printSymbolOperand() in
X86AsmPrinter.cpp).
Fixes: https://bugs.llvm.org/show_bug.cgi?id=41402
Link: https://gcc.gnu.org/onlinedocs/gccint/Output-Template.html#Output-Template
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D60428
Files:
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/test/CodeGen/AArch64/inline-asm-globaladdress.ll
Index: llvm/test/CodeGen/AArch64/inline-asm-globaladdress.ll
===================================================================
--- llvm/test/CodeGen/AArch64/inline-asm-globaladdress.ll
+++ llvm/test/CodeGen/AArch64/inline-asm-globaladdress.ll
@@ -1,5 +1,5 @@
-; RUN: llc < %s -mtriple aarch64-gnu-linux | FileCheck %s
-; RUN: llc < %s -mtriple arm64-apple-darwin | FileCheck %s
+; RUN: llc < %s -mtriple aarch64-gnu-linux | FileCheck %s --check-prefixes=CHECK,CHECK-LINUX
+; RUN: llc < %s -mtriple arm64-apple-darwin | FileCheck %s --check-prefixes=CHECK,CHECK-DARWIN
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
@@ -18,3 +18,12 @@
}
declare void @test_symbol()
+
+; CHECK-LABEL: test_inlineasm_c_output_template:
+; CHECK-LINUX: .xword baz
+; CHECK-DARWIN: .quad _baz
+ at baz = internal global i32 0, align 4
+define dso_local i32 @test_inlineasm_c_output_template() {
+ tail call void asm sideeffect ".quad ${0:c}", "i"(i32* nonnull @baz)
+ ret i32 43
+}
Index: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -551,6 +551,12 @@
}
printOperand(MI, OpNum, O);
return false;
+ case 'c':
+ if (MO.getType() == MachineOperand::MO_GlobalAddress) {
+ printOperand(MI, OpNum, O);
+ return false;
+ }
+ return true;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60428.194221.patch
Type: text/x-patch
Size: 1467 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190408/b982860b/attachment.bin>
More information about the llvm-commits
mailing list