summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gohman <dan433584@gmail.com>2015-12-16 17:15:17 +0000
committerDan Gohman <dan433584@gmail.com>2015-12-16 17:15:17 +0000
commit30a42bf585e3505e4f52ea191be41407ba5861e8 (patch)
tree859c924ef5c173174c0b4e9c585e216e970bdddb
parent279c73f9e05840df50232156d67645fddaaf3158 (diff)
downloadbcm5719-llvm-30a42bf585e3505e4f52ea191be41407ba5861e8.tar.gz
bcm5719-llvm-30a42bf585e3505e4f52ea191be41407ba5861e8.zip
[WebAssembly] Support more kinds of inline asm operands
llvm-svn: 255782
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp28
-rw-r--r--llvm/test/CodeGen/WebAssembly/inline-asm.ll15
2 files changed, 39 insertions, 4 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index c1403fb0c9e..68cfee42802 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/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/llvm/test/CodeGen/WebAssembly/inline-asm.ll b/llvm/test/CodeGen/WebAssembly/inline-asm.ll
index ba580028629..5eea83a771c 100644
--- a/llvm/test/CodeGen/WebAssembly/inline-asm.ll
+++ b/llvm/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}
OpenPOWER on IntegriCloud