diff --git a/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp b/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp --- a/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp +++ b/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp @@ -22,17 +22,13 @@ #include "llvm/ADT/Twine.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" #include "llvm/TableGen/TableGenBackend.h" using namespace llvm; using namespace mlir; -static LogicalResult emitError(const Twine &message) { - llvm::errs() << message << "\n"; - return failure(); -} - namespace { // Helper structure to return a position of the substring in a string. struct StringLoc { @@ -118,7 +114,7 @@ auto op = tblgen::Operator(record); if (!record.getValue("llvmBuilder")) - return emitError("no 'llvmBuilder' field for op " + op.getOperationName()); + PrintFatalError(record.getLoc(), "expected 'llvmBuilder' field"); // Return early if there is no builder specified. StringRef builderStrRef = record.getValueAsString("llvmBuilder"); @@ -158,8 +154,8 @@ } else if (name == "$") { bs << '$'; } else { - return emitError(name + " is neither an argument nor a result of " + - op.getOperationName()); + PrintFatalError(record.getLoc(), + "expected keyword, argument, or result, but got " + name); } // Finally, only keep the untraversed part of the string. builderStrRef = builderStrRef.substr(loc.pos + loc.length); @@ -197,7 +193,7 @@ auto op = tblgen::Operator(record); if (!record.getValue("mlirBuilder")) - return emitError("no 'mlirBuilder' field for op " + op.getOperationName()); + PrintFatalError(record.getLoc(), "expected 'mlirBuilder' field"); // Return early if there is no builder specified. StringRef builderStrRef = record.getValueAsString("mlirBuilder"); @@ -212,9 +208,9 @@ if (llvmArgIndices.empty()) append_range(llvmArgIndices, seq(0, op.getNumArgs())); if (llvmArgIndices.size() != static_cast(op.getNumArgs())) { - return emitError( - "'llvmArgIndices' does not match the number of arguments for op " + - op.getOperationName()); + PrintFatalError( + record.getLoc(), + "expected 'llvmArgIndices' size to match the number of arguments"); } // Progressively create the builder string by replacing $-variables. Keep only @@ -233,12 +229,13 @@ // the provided argument indices mapping. // FIXME: support trailing variadic arguments. int64_t operandIdx = llvmArgIndices[*argIndex]; - assert(operandIdx >= 0 && "expected argument to have a mapping"); + if (operandIdx < 0) + PrintFatalError(record.getLoc(), "expected non-negative operand index"); assert(!isVariadicOperandName(op, name) && "unexpected variadic operand"); bs << formatv("processValue(llvmOperands[{0}])", operandIdx); } else if (isResultName(op, name)) { - assert(op.getNumResults() == 1 && - "expected operation to have one result"); + if (op.getNumResults() != 1) + PrintFatalError(record.getLoc(), "expected op to have one result"); bs << formatv("mapValue(inst)"); } else if (name == "_int_attr") { bs << "matchIntegerAttr"; @@ -253,9 +250,8 @@ } else if (name == "$") { bs << '$'; } else { - return emitError(name + - " is not a known keyword, argument, or result of " + - op.getOperationName()); + PrintFatalError(record.getLoc(), + "expected keyword, argument, or result, but got " + name); } // Finally, only keep the untraversed part of the string. builderStrRef = builderStrRef.substr(loc.pos + loc.length);