]> granicus.if.org Git - llvm/commitdiff
GlobalISel: support trivial inlineasm calls.
authorTim Northover <tnorthover@apple.com>
Thu, 9 Mar 2017 23:36:26 +0000 (23:36 +0000)
committerTim Northover <tnorthover@apple.com>
Thu, 9 Mar 2017 23:36:26 +0000 (23:36 +0000)
They're used for nefarious purposes by ObjC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297422 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/GlobalISel/IRTranslator.h
lib/CodeGen/GlobalISel/IRTranslator.cpp
test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
test/CodeGen/AArch64/GlobalISel/inline-asm.ll

index 74b0c8d63fd4a8a984a54b912a8d0220e4411e6c..174443d47a5614a59229a870260cf872be672b74 100644 (file)
@@ -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);
index e170b762ab890674c031c178a42575074e05e410..b2ab3c12bc15444138d3ee788eefb19574a7cfd4 100644 (file)
@@ -715,13 +715,32 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
   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);
index c0cbf69a2e64ba337bfc623ee0501d923b4b1c4e..21ce631cca318fb799c5c0667e90bde3acea8baf 100644 (file)
@@ -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
+}
index 3dc8f8cb7063b5f2cfc5bc4faac8e723666e9a2e..8ff7c4495dccb461aa287455f9e49bc6d70f56f3 100644 (file)
@@ -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
 }