From 3de3334800cac5947a0ef8a9d1e9be0bafeef401 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 16 Dec 2015 17:15:17 +0000 Subject: [PATCH] [WebAssembly] Support more kinds of inline asm operands git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255782 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../WebAssembly/WebAssemblyAsmPrinter.cpp | 28 ++++++++++++++++--- test/CodeGen/WebAssembly/inline-asm.ll | 15 ++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp index c1403fb0c9e..68cfee42802 100644 --- a/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ b/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -219,16 +219,36 @@ bool WebAssemblyAsmPrinter::PrintAsmOperand(const MachineInstr *MI, 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, diff --git a/test/CodeGen/WebAssembly/inline-asm.ll b/test/CodeGen/WebAssembly/inline-asm.ll index ba580028629..5eea83a771c 100644 --- a/test/CodeGen/WebAssembly/inline-asm.ll +++ b/test/CodeGen/WebAssembly/inline-asm.ll @@ -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{{$}} +@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} -- 2.34.1