[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:37:14 PDT 2019
aardappel created this revision.
aardappel added a reviewer: dschuff.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, sbc100.
Herald added a project: LLVM.
Before, they were one category of operands which could cause
crashes in non-sensical combinations, e.g. "f32.const symbol".
Now these are forced to be an error.
Repository:
rL LLVM
https://reviews.llvm.org/D64039
Files:
lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
lib/Target/WebAssembly/WebAssemblyInstrInfo.td
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.207412.patch
Type: text/x-patch
Size: 2641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190701/6825f6bb/attachment.bin>
More information about the llvm-commits
mailing list