[llvm] r297422 - GlobalISel: support trivial inlineasm calls.
Tim Northover via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 9 15:36:26 PST 2017
Author: tnorthover
Date: Thu Mar 9 17:36:26 2017
New Revision: 297422
URL: http://llvm.org/viewvc/llvm-project?rev=297422&view=rev
Log:
GlobalISel: support trivial inlineasm calls.
They're used for nefarious purposes by ObjC.
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
llvm/trunk/test/CodeGen/AArch64/GlobalISel/inline-asm.ll
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h?rev=297422&r1=297421&r2=297422&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h Thu Mar 9 17:36:26 2017
@@ -143,6 +143,8 @@ private:
bool translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
MachineIRBuilder &MIRBuilder);
+ bool translateInlineAsm(const CallInst &CI, MachineIRBuilder &MIRBuilder);
+
/// Translate call instruction.
/// \pre \p U is a call instruction.
bool translateCall(const User &U, MachineIRBuilder &MIRBuilder);
Modified: llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=297422&r1=297421&r2=297422&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp Thu Mar 9 17:36:26 2017
@@ -715,13 +715,32 @@ bool IRTranslator::translateKnownIntrins
return false;
}
+bool IRTranslator::translateInlineAsm(const CallInst &CI,
+ MachineIRBuilder &MIRBuilder) {
+ const InlineAsm &IA = cast<InlineAsm>(*CI.getCalledValue());
+ if (!IA.getConstraintString().empty())
+ return false;
+
+ unsigned ExtraInfo = 0;
+ if (IA.hasSideEffects())
+ ExtraInfo |= InlineAsm::Extra_HasSideEffects;
+ if (IA.getDialect() == InlineAsm::AD_Intel)
+ ExtraInfo |= InlineAsm::Extra_AsmDialect;
+
+ MIRBuilder.buildInstr(TargetOpcode::INLINEASM)
+ .addExternalSymbol(IA.getAsmString().c_str())
+ .addImm(ExtraInfo);
+
+ return true;
+}
+
bool IRTranslator::translateCall(const User &U, MachineIRBuilder &MIRBuilder) {
const CallInst &CI = cast<CallInst>(U);
auto TII = MF->getTarget().getIntrinsicInfo();
const Function *F = CI.getCalledFunction();
if (CI.isInlineAsm())
- return false;
+ return translateInlineAsm(CI, MIRBuilder);
if (!F || !F->isIntrinsic()) {
unsigned Res = CI.getType()->isVoidTy() ? 0 : getOrCreateVReg(CI);
Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll?rev=297422&r1=297421&r2=297422&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll Thu Mar 9 17:36:26 2017
@@ -1262,3 +1262,12 @@ define double @test_fneg_f64(double %x)
%neg = fsub double -0.000000e+00, %x
ret double %neg
}
+
+define void @test_trivial_inlineasm() {
+; CHECK-LABEL: name: test_trivial_inlineasm
+; CHECK: INLINEASM $wibble, 1
+; CHECK: INLINEASM $wibble, 0
+ call void asm sideeffect "wibble", ""()
+ call void asm "wibble", ""()
+ ret void
+}
Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/inline-asm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/inline-asm.ll?rev=297422&r1=297421&r2=297422&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/inline-asm.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/inline-asm.ll Thu Mar 9 17:36:26 2017
@@ -2,9 +2,9 @@
; CHECK-LABEL: test_asm:
; CHECK: {{APP|InlineAsm Start}}
-; CHECK: mov x0, x0
+; CHECK: mov x0, {{x[0-9]+}}
; CHECK: {{NO_APP|InlineAsm End}}
define void @test_asm() {
- call void asm sideeffect "mov x0, x0", ""()
+ call void asm sideeffect "mov x0, $0", "r"(i64 42)
ret void
}
More information about the llvm-commits
mailing list