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())
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;
}
--- /dev/null
+; 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}