[PATCH] D64039: [WebAssembly] tablegen: distinguish float/int immediate operands.

Wouter van Oortmerssen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 1 14:57:18 PDT 2019


aardappel updated this revision to Diff 207415.
aardappel added a comment.

added test


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64039/new/

https://reviews.llvm.org/D64039

Files:
  lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
  lib/Target/WebAssembly/WebAssemblyInstrInfo.td
  test/MC/WebAssembly/basic-assembly-errors.s


Index: test/MC/WebAssembly/basic-assembly-errors.s
===================================================================
--- test/MC/WebAssembly/basic-assembly-errors.s
+++ test/MC/WebAssembly/basic-assembly-errors.s
@@ -1,5 +1,9 @@
 # RUN: not llvm-mc -triple=wasm32-unknown-unknown -mattr=+simd128,+nontrapping-fptoint,+exception-handling < %s 2>&1 | FileCheck %s
 
+# CHECK: invalid operand for instruction
+# (must be 0.0 or similar)
+    f32.const 0
+
 # CHECK: End of block construct with no start: end_try
     end_try
 test0:
Index: lib/Target/WebAssembly/WebAssemblyInstrInfo.td
===================================================================
--- lib/Target/WebAssembly/WebAssemblyInstrInfo.td
+++ lib/Target/WebAssembly/WebAssemblyInstrInfo.td
@@ -118,6 +118,17 @@
 // WebAssembly-specific Operands.
 //===----------------------------------------------------------------------===//
 
+// Default Operand has AsmOperandClass "Imm" which is for integers (and
+// symbols), so specialize one for floats:
+def FPImmAsmOperand : AsmOperandClass {
+  let Name = "FPImm";
+  let PredicateMethod = "isFPImm";
+}
+
+class FPOperand<ValueType ty> : Operand<ty> {
+  AsmOperandClass ParserMatchClass = FPImmAsmOperand;
+}
+
 let OperandNamespace = "WebAssembly" in {
 
 let OperandType = "OPERAND_BASIC_BLOCK" in
@@ -136,10 +147,10 @@
 def i64imm_op : Operand<i64>;
 
 let OperandType = "OPERAND_F32IMM" in
-def f32imm_op : Operand<f32>;
+def f32imm_op : FPOperand<f32>;
 
 let OperandType = "OPERAND_F64IMM" in
-def f64imm_op : Operand<f64>;
+def f64imm_op : FPOperand<f64>;
 
 let OperandType = "OPERAND_VEC_I8IMM" in
 def vec_i8imm_op : Operand<i32>;
Index: lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
===================================================================
--- lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -89,9 +89,8 @@
   }
 
   bool isToken() const override { return Kind == Token; }
-  bool isImm() const override {
-    return Kind == Integer || Kind == Float || Kind == Symbol;
-  }
+  bool isImm() const override { return Kind == Integer || Kind == Symbol; }
+  bool isFPImm() const { return Kind == Float; }
   bool isMem() const override { return false; }
   bool isReg() const override { return false; }
   bool isBrList() const { return Kind == BrList; }
@@ -118,12 +117,18 @@
     assert(N == 1 && "Invalid number of operands!");
     if (Kind == Integer)
       Inst.addOperand(MCOperand::createImm(Int.Val));
-    else if (Kind == Float)
-      Inst.addOperand(MCOperand::createFPImm(Flt.Val));
     else if (Kind == Symbol)
       Inst.addOperand(MCOperand::createExpr(Sym.Exp));
     else
-      llvm_unreachable("Should be immediate or symbol!");
+      llvm_unreachable("Should be integer immediate or symbol!");
+  }
+
+  void addFPImmOperands(MCInst &Inst, unsigned N) const {
+    assert(N == 1 && "Invalid number of operands!");
+    if (Kind == Float)
+      Inst.addOperand(MCOperand::createFPImm(Flt.Val));
+    else
+      llvm_unreachable("Should be float immediate!");
   }
 
   void addBrListOperands(MCInst &Inst, unsigned N) const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64039.207415.patch
Type: text/x-patch
Size: 3173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190701/8e91a675/attachment.bin>


More information about the llvm-commits mailing list