[llvm] r255782 - [WebAssembly] Support more kinds of inline asm operands

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 09:15:17 PST 2015


Author: djg
Date: Wed Dec 16 11:15:17 2015
New Revision: 255782

URL: http://llvm.org/viewvc/llvm-project?rev=255782&view=rev
Log:
[WebAssembly] Support more kinds of inline asm operands

Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
    llvm/trunk/test/CodeGen/WebAssembly/inline-asm.ll

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp?rev=255782&r1=255781&r2=255782&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp Wed Dec 16 11:15:17 2015
@@ -219,16 +219,36 @@ bool WebAssemblyAsmPrinter::PrintAsmOper
   if (AsmVariant != 0)
     report_fatal_error("There are no defined alternate asm variants");
 
+  // First try the generic code, which knows about modifiers like 'c' and 'n'.
+  if (!AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS))
+    return false;
+
   if (!ExtraCode) {
     const MachineOperand &MO = MI->getOperand(OpNo);
-    if (MO.isImm())
+    switch (MO.getType()) {
+    case MachineOperand::MO_Immediate:
       OS << MO.getImm();
-    else
+      return false;
+    case MachineOperand::MO_Register:
       OS << regToString(MO);
-    return false;
+      return false;
+    case MachineOperand::MO_GlobalAddress:
+      getSymbol(MO.getGlobal())->print(OS, MAI);
+      printOffset(MO.getOffset(), OS);
+      return false;
+    case MachineOperand::MO_ExternalSymbol:
+      GetExternalSymbolSymbol(MO.getSymbolName())->print(OS, MAI);
+      printOffset(MO.getOffset(), OS);
+      return false;
+    case MachineOperand::MO_MachineBasicBlock:
+      MO.getMBB()->getSymbol()->print(OS, MAI);
+      return false;
+    default:
+      break;
+    }
   }
 
-  return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS);
+  return true;
 }
 
 bool WebAssemblyAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,

Modified: llvm/trunk/test/CodeGen/WebAssembly/inline-asm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/inline-asm.ll?rev=255782&r1=255781&r2=255782&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/inline-asm.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/inline-asm.ll Wed Dec 16 11:15:17 2015
@@ -72,6 +72,21 @@ define void @X_ptr(i16 ** %t) {
   ret void
 }
 
+; CHECK-LABEL: funcname:
+; CHECK: foo funcname{{$}}
+define void @funcname() {
+  tail call void asm sideeffect "foo $0", "i"(void ()* nonnull @funcname) #0, !srcloc !0
+  ret void
+}
+
+; CHECK-LABEL: varname:
+; CHECK: foo gv+37{{$}}
+ at gv = global [0 x i8] zeroinitializer
+define void @varname() {
+  tail call void asm sideeffect "foo $0", "i"(i8* getelementptr inbounds ([0 x i8], [0 x i8]* @gv, i64 0, i64 37)) #0, !srcloc !0
+  ret void
+}
+
 attributes #0 = { nounwind }
 
 !0 = !{i32 47}




More information about the llvm-commits mailing list