From 7beaa30e4e95eef2f1c1d23d21c45b7a159912f4 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 21 Sep 2018 17:47:58 +0000 Subject: [PATCH] [WebAssembly] Made assembler only use stack instruction tablegen defs Summary: This ensures we have the non-register version of the instruction. The stack version of call_indirect now wants a type index argument, so that has been added in the existing tests. Tested: llvm-lit -v `find test -name WebAssembly` Reviewers: dschuff Subscribers: sbc100, jgravelle-google, aheejin, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D51662 llvm-svn: 342753 --- llvm/test/MC/WebAssembly/basic-assembly.s | 4 ++-- llvm/utils/TableGen/AsmMatcherEmitter.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/llvm/test/MC/WebAssembly/basic-assembly.s b/llvm/test/MC/WebAssembly/basic-assembly.s index c562917..cf52776 100644 --- a/llvm/test/MC/WebAssembly/basic-assembly.s +++ b/llvm/test/MC/WebAssembly/basic-assembly.s @@ -29,7 +29,7 @@ test0: i64.const 1234 i32.call something2@FUNCTION i32.const 0 - call_indirect + call_indirect 0 i32.const 1 i32.add tee_local 0 @@ -68,7 +68,7 @@ test0: # CHECK-NEXT: i64.const 1234 # CHECK-NEXT: i32.call something2@FUNCTION # CHECK-NEXT: i32.const 0 -# CHECK-NEXT: call_indirect +# CHECK-NEXT: call_indirect 0 # CHECK-NEXT: i32.const 1 # CHECK-NEXT: i32.add # CHECK-NEXT: tee_local 0 diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp index e808661..a0283fc 100644 --- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp +++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp @@ -1479,6 +1479,8 @@ void AsmMatcherInfo::buildInfo() { bool ReportMultipleNearMisses = AsmParser->getValueAsBit("ReportMultipleNearMisses"); + bool IsWebAssemblyTarget = Target.getName() == "WebAssembly"; + // Parse the instructions; we need to do this first so that we can gather the // singleton register classes. SmallPtrSet SingletonRegisters; @@ -1514,6 +1516,14 @@ void AsmMatcherInfo::buildInfo() { if (!V.empty() && V != Variant.Name) continue; + // [WebAssembly] Ignore non-stack instructions. + if (IsWebAssemblyTarget) { + auto Bit = CGI->TheDef->getValue("StackBased")->getValue()-> + getCastTo(BitRecTy::get()); + if (!Bit || !reinterpret_cast(Bit)->getValue()) + continue; + } + auto II = llvm::make_unique(*CGI); II->initialize(*this, SingletonRegisters, Variant, HasMnemonicFirst); -- 2.7.4