aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmara Emerson <aemerson@apple.com>2020-02-07 01:07:57 -0800
committerAmara Emerson <aemerson@apple.com>2020-02-07 08:55:23 -0800
commit28d22c2c9c3199c60ba8ff0a06d06a6ff70b609d (patch)
tree2065e71cfdf94c06653993cdfd47e5533e7cda11
parent1ff411295f92cddfce21521594d58cf407a15189 (diff)
downloadllvm-28d22c2c9c3199c60ba8ff0a06d06a6ff70b609d.zip
llvm-28d22c2c9c3199c60ba8ff0a06d06a6ff70b609d.tar.gz
llvm-28d22c2c9c3199c60ba8ff0a06d06a6ff70b609d.tar.bz2
[GlobalISel][IRTranslator] Add special case support for ~memory inline asm clobber.
This is a one off special case, since actually implementing full inline asm support will be much more involved. This lets us compile a lot more code as a common simple case. Differential Revision: https://reviews.llvm.org/D74201
-rw-r--r--llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp24
-rw-r--r--llvm/test/CodeGen/AArch64/GlobalISel/translate-inline-asm.ll14
2 files changed, 33 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index d67279a..4398815 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -1559,8 +1559,16 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
bool IRTranslator::translateInlineAsm(const CallInst &CI,
MachineIRBuilder &MIRBuilder) {
const InlineAsm &IA = cast<InlineAsm>(*CI.getCalledValue());
- if (!IA.getConstraintString().empty())
- return false;
+ StringRef ConstraintStr = IA.getConstraintString();
+
+ bool HasOnlyMemoryClobber = false;
+ if (!ConstraintStr.empty()) {
+ // Until we have full inline assembly support, we just try to handle the
+ // very simple case of just "~{memory}" to avoid falling back so often.
+ if (ConstraintStr != "~{memory}")
+ return false;
+ HasOnlyMemoryClobber = true;
+ }
unsigned ExtraInfo = 0;
if (IA.hasSideEffects())
@@ -1568,9 +1576,15 @@ bool IRTranslator::translateInlineAsm(const CallInst &CI,
if (IA.getDialect() == InlineAsm::AD_Intel)
ExtraInfo |= InlineAsm::Extra_AsmDialect;
- MIRBuilder.buildInstr(TargetOpcode::INLINEASM)
- .addExternalSymbol(IA.getAsmString().c_str())
- .addImm(ExtraInfo);
+ // HACK: special casing for ~memory.
+ if (HasOnlyMemoryClobber)
+ ExtraInfo |= (InlineAsm::Extra_MayLoad | InlineAsm::Extra_MayStore);
+
+ auto Inst = MIRBuilder.buildInstr(TargetOpcode::INLINEASM)
+ .addExternalSymbol(IA.getAsmString().c_str())
+ .addImm(ExtraInfo);
+ if (const MDNode *SrcLoc = CI.getMetadata("srcloc"))
+ Inst.addMetadata(SrcLoc);
return true;
}
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/translate-inline-asm.ll b/llvm/test/CodeGen/AArch64/GlobalISel/translate-inline-asm.ll
new file mode 100644
index 0000000..337c05f
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/translate-inline-asm.ll
@@ -0,0 +1,14 @@
+; RUN: llc -mtriple=aarch64-darwin-ios13 -O0 -global-isel -stop-after=irtranslator -o - %s | FileCheck %s
+
+; The update_mir_test_checks script doesn't seem to handle INLINE_ASM well. Write this manually.
+
+define void @asm_simple_memory_clobber() {
+ ; CHECK-LABEL: name: asm_simple_memory_clobber
+ ; CHECK: INLINEASM &"", 25
+ ; CHECK: INLINEASM &"", 1
+ call void asm sideeffect "", "~{memory}"(), !srcloc !0
+ call void asm sideeffect "", ""(), !srcloc !0
+ ret void
+}
+
+!0 = !{i32 70}