diff options
Diffstat (limited to 'mlir/lib')
| -rw-r--r-- | mlir/lib/Analysis/Verifier.cpp | 6 | ||||
| -rw-r--r-- | mlir/lib/IR/BuiltinOps.cpp | 8 | ||||
| -rw-r--r-- | mlir/lib/IR/Function.cpp | 13 | ||||
| -rw-r--r-- | mlir/lib/IR/Instructions.cpp | 13 | ||||
| -rw-r--r-- | mlir/lib/IR/MLIRContext.cpp | 3 | ||||
| -rw-r--r-- | mlir/lib/IR/Operation.cpp | 40 | ||||
| -rw-r--r-- | mlir/lib/IR/Statement.cpp | 13 | ||||
| -rw-r--r-- | mlir/lib/Parser/Lexer.cpp | 4 | ||||
| -rw-r--r-- | mlir/lib/Parser/Parser.cpp | 3 | ||||
| -rw-r--r-- | mlir/lib/StandardOps/StandardOps.cpp | 96 | ||||
| -rw-r--r-- | mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp | 35 | ||||
| -rw-r--r-- | mlir/lib/Transforms/MaterializeVectors.cpp | 24 |
12 files changed, 101 insertions, 157 deletions
diff --git a/mlir/lib/Analysis/Verifier.cpp b/mlir/lib/Analysis/Verifier.cpp index 3662692ccb4..d955bcd5edb 100644 --- a/mlir/lib/Analysis/Verifier.cpp +++ b/mlir/lib/Analysis/Verifier.cpp @@ -53,13 +53,11 @@ namespace { class Verifier { public: bool failure(const Twine &message, const Operation &value) { - value.emitError(message); - return true; + return value.emitError(message); } bool failure(const Twine &message, const Function &fn) { - fn.emitError(message); - return true; + return fn.emitError(message); } bool failure(const Twine &message, const BasicBlock &bb) { diff --git a/mlir/lib/IR/BuiltinOps.cpp b/mlir/lib/IR/BuiltinOps.cpp index dceaf3715c4..3eb0335a7aa 100644 --- a/mlir/lib/IR/BuiltinOps.cpp +++ b/mlir/lib/IR/BuiltinOps.cpp @@ -508,11 +508,9 @@ bool ReturnOp::verify() const { Twine(results.size())); for (unsigned i = 0, e = results.size(); i != e; ++i) - if (getOperand(i)->getType() != results[i]) { - emitError("type of return operand " + Twine(i) + - " doesn't match function result type"); - return true; - } + if (getOperand(i)->getType() != results[i]) + return emitError("type of return operand " + Twine(i) + + " doesn't match function result type"); return false; } diff --git a/mlir/lib/IR/Function.cpp b/mlir/lib/IR/Function.cpp index e7b30464597..b79e1596a65 100644 --- a/mlir/lib/IR/Function.cpp +++ b/mlir/lib/IR/Function.cpp @@ -147,13 +147,12 @@ void Function::emitWarning(const Twine &message) const { MLIRContext::DiagnosticKind::Warning); } -/// Emit an error about fatal conditions with this instruction, reporting up to -/// any diagnostic handlers that may be listening. NOTE: This may terminate -/// the containing application, only use when the IR is in an inconsistent -/// state. -void Function::emitError(const Twine &message) const { - getContext()->emitDiagnostic(getLoc(), message, - MLIRContext::DiagnosticKind::Error); +/// Emit an error about fatal conditions with this operation, reporting up to +/// any diagnostic handlers that may be listening. This function always +/// returns true. NOTE: This may terminate the containing application, only use +/// when the IR is in an inconsistent state. +bool Function::emitError(const Twine &message) const { + return getContext()->emitError(getLoc(), message); } //===----------------------------------------------------------------------===// // ExtFunction implementation. diff --git a/mlir/lib/IR/Instructions.cpp b/mlir/lib/IR/Instructions.cpp index 69fed425f62..9d65f4376b3 100644 --- a/mlir/lib/IR/Instructions.cpp +++ b/mlir/lib/IR/Instructions.cpp @@ -240,13 +240,12 @@ void Instruction::emitWarning(const Twine &message) const { MLIRContext::DiagnosticKind::Warning); } -/// Emit an error about fatal conditions with this instruction, reporting up to -/// any diagnostic handlers that may be listening. NOTE: This may terminate -/// the containing application, only use when the IR is in an inconsistent -/// state. -void Instruction::emitError(const Twine &message) const { - getContext()->emitDiagnostic(getLoc(), message, - MLIRContext::DiagnosticKind::Error); +/// Emit an error about fatal conditions with this operation, reporting up to +/// any diagnostic handlers that may be listening. This function always +/// returns true. NOTE: This may terminate the containing application, only use +/// when the IR is in an inconsistent state. +bool Instruction::emitError(const Twine &message) const { + return getContext()->emitError(getLoc(), message); } void Instruction::addSuccessorOperand(unsigned index, CFGValue *value) { diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp index b344f7475d8..7a27b9764dc 100644 --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -540,9 +540,10 @@ void MLIRContext::emitDiagnostic(Location location, const llvm::Twine &message, os.flush(); } -void MLIRContext::emitError(Location location, +bool MLIRContext::emitError(Location location, const llvm::Twine &message) const { emitDiagnostic(location, message, DiagnosticKind::Error); + return true; } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index 0da99c0bbf9..af295782718 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -278,19 +278,17 @@ void Operation::emitWarning(const Twine &message) const { } /// Emit an error about fatal conditions with this operation, reporting up to -/// any diagnostic handlers that may be listening. NOTE: This may terminate -/// the containing application, only use when the IR is in an inconsistent -/// state. -void Operation::emitError(const Twine &message) const { - getContext()->emitDiagnostic(getLoc(), message, - MLIRContext::DiagnosticKind::Error); +/// any diagnostic handlers that may be listening. This function always returns +/// true. NOTE: This may terminate the containing application, only use when +/// the IR is in an inconsistent state. +bool Operation::emitError(const Twine &message) const { + return getContext()->emitError(getLoc(), message); } /// Emit an error with the op name prefixed, like "'dim' op " which is /// convenient for verifiers. bool Operation::emitOpError(const Twine &message) const { - emitError(Twine('\'') + getName().getStringRef() + "' op " + message); - return true; + return emitError(Twine('\'') + getName().getStringRef() + "' op " + message); } /// Remove this operation from its parent block and delete it. @@ -380,8 +378,8 @@ void OpState::print(OpAsmPrinter *p) const { /// any diagnostic handlers that may be listening. NOTE: This may terminate /// the containing application, only use when the IR is in an inconsistent /// state. -void OpState::emitError(const Twine &message) const { - getOperation()->emitError(message); +bool OpState::emitError(const Twine &message) const { + return getOperation()->emitError(message); } /// Emit an error with the op name prefixed, like "'dim' op " which is @@ -557,19 +555,15 @@ static bool verifyBBArguments( llvm::iterator_range<Operation::const_operand_iterator> operands, const BasicBlock *destBB, const Operation *op) { unsigned operandCount = std::distance(operands.begin(), operands.end()); - if (operandCount != destBB->getNumArguments()) { - op->emitError("branch has " + Twine(operandCount) + - " operands, but target block has " + - Twine(destBB->getNumArguments())); - return true; - } + if (operandCount != destBB->getNumArguments()) + return op->emitError("branch has " + Twine(operandCount) + + " operands, but target block has " + + Twine(destBB->getNumArguments())); auto operandIt = operands.begin(); for (unsigned i = 0, e = operandCount; i != e; ++i, ++operandIt) { - if ((*operandIt)->getType() != destBB->getArgument(i)->getType()) { - op->emitError("type mismatch in bb argument #" + Twine(i)); - return true; - } + if ((*operandIt)->getType() != destBB->getArgument(i)->getType()) + return op->emitError("type mismatch in bb argument #" + Twine(i)); } return false; @@ -580,10 +574,8 @@ static bool verifyTerminatorSuccessors(const Operation *op) { const Function *fn = op->getOperationFunction(); for (unsigned i = 0, e = op->getNumSuccessors(); i != e; ++i) { auto *succ = op->getSuccessor(i); - if (succ->getFunction() != fn) { - op->emitError("reference to block defined in another function"); - return true; - } + if (succ->getFunction() != fn) + return op->emitError("reference to block defined in another function"); if (verifyBBArguments(op->getSuccessorOperands(i), succ, op)) return true; } diff --git a/mlir/lib/IR/Statement.cpp b/mlir/lib/IR/Statement.cpp index 225ede6315b..69afc5c1e98 100644 --- a/mlir/lib/IR/Statement.cpp +++ b/mlir/lib/IR/Statement.cpp @@ -164,13 +164,12 @@ void Statement::emitWarning(const Twine &message) const { MLIRContext::DiagnosticKind::Warning); } -/// Emit an error about fatal conditions with this statement, reporting up to -/// any diagnostic handlers that may be listening. NOTE: This may terminate -/// the containing application, only use when the IR is in an inconsistent -/// state. -void Statement::emitError(const Twine &message) const { - getContext()->emitDiagnostic(getLoc(), message, - MLIRContext::DiagnosticKind::Error); +/// Emit an error about fatal conditions with this operation, reporting up to +/// any diagnostic handlers that may be listening. This function always +/// returns true. NOTE: This may terminate the containing application, only +/// use when the IR is in an inconsistent state. +bool Statement::emitError(const Twine &message) const { + return getContext()->emitError(getLoc(), message); } //===----------------------------------------------------------------------===// // ilist_traits for Statement diff --git a/mlir/lib/Parser/Lexer.cpp b/mlir/lib/Parser/Lexer.cpp index 9d31f43179c..aa225c47822 100644 --- a/mlir/lib/Parser/Lexer.cpp +++ b/mlir/lib/Parser/Lexer.cpp @@ -55,8 +55,8 @@ Location Lexer::getEncodedSourceLocation(llvm::SMLoc loc) { /// emitError - Emit an error message and return an Token::error token. Token Lexer::emitError(const char *loc, const Twine &message) { - context->emitDiagnostic(getEncodedSourceLocation(SMLoc::getFromPointer(loc)), - message, MLIRContext::DiagnosticKind::Error); + context->emitError(getEncodedSourceLocation(SMLoc::getFromPointer(loc)), + message); return formToken(Token::error, loc); } diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 26e80eefb16..a4c5e8ed3e7 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -228,8 +228,7 @@ ParseResult Parser::emitError(SMLoc loc, const Twine &message) { if (getToken().is(Token::error)) return ParseFailure; - getContext()->emitDiagnostic(getEncodedSourceLocation(loc), message, - MLIRContext::DiagnosticKind::Error); + getContext()->emitError(getEncodedSourceLocation(loc), message); return ParseFailure; } diff --git a/mlir/lib/StandardOps/StandardOps.cpp b/mlir/lib/StandardOps/StandardOps.cpp index 1158213bb86..69a3370fafd 100644 --- a/mlir/lib/StandardOps/StandardOps.cpp +++ b/mlir/lib/StandardOps/StandardOps.cpp @@ -1486,39 +1486,27 @@ bool VectorTransferReadOp::parse(OpAsmParser *parser, OperationState *result) { // Resolution. auto funType = type.dyn_cast<FunctionType>(); - if (!funType) { - parser->emitError(parser->getNameLoc(), "Function type expected"); - return true; - } - if (funType.getNumInputs() < 1) { - parser->emitError(parser->getNameLoc(), - "Function type expects at least one input"); - return true; - } + if (!funType) + return parser->emitError(parser->getNameLoc(), "Function type expected"); + if (funType.getNumInputs() < 1) + return parser->emitError(parser->getNameLoc(), + "Function type expects at least one input"); MemRefType memrefType = funType.getInput(Offsets::MemRefOffset).dyn_cast<MemRefType>(); - if (!memrefType) { - parser->emitError(parser->getNameLoc(), - "MemRef type expected for first input"); - return true; - } - if (funType.getNumResults() < 1) { - parser->emitError(parser->getNameLoc(), - "Function type expects exactly one vector result"); - return true; - } + if (!memrefType) + return parser->emitError(parser->getNameLoc(), + "MemRef type expected for first input"); + if (funType.getNumResults() < 1) + return parser->emitError(parser->getNameLoc(), + "Function type expects exactly one vector result"); VectorType vectorType = funType.getResult(0).dyn_cast<VectorType>(); - if (!vectorType) { - parser->emitError(parser->getNameLoc(), - "Vector type expected for first result"); - return true; - } - if (parsedOperands.size() != funType.getNumInputs()) { - parser->emitError(parser->getNameLoc(), "requires " + - Twine(funType.getNumInputs()) + - " operands"); - return true; - } + if (!vectorType) + return parser->emitError(parser->getNameLoc(), + "Vector type expected for first result"); + if (parsedOperands.size() != funType.getNumInputs()) + return parser->emitError(parser->getNameLoc(), + "requires " + Twine(funType.getNumInputs()) + + " operands"); // Extract optional paddingValue. OpAsmParser::OperandType memrefInfo = parsedOperands[0]; @@ -1535,12 +1523,10 @@ bool VectorTransferReadOp::parse(OpAsmParser *parser, OperationState *result) { paddingType = funType.getInputs().back(); paddingValue = indexInfo.pop_back_val(); } - if (funType.getNumInputs() != expectedNumOperands) { - parser->emitError( + if (funType.getNumInputs() != expectedNumOperands) + return parser->emitError( parser->getNameLoc(), "requires actual number of operands to match function type"); - return true; - } auto indexType = parser->getBuilder().getIndexType(); return parser->resolveOperand(memrefInfo, memrefType, result->operands) || @@ -1693,36 +1679,28 @@ bool VectorTransferWriteOp::parse(OpAsmParser *parser, OperationState *result) { } // Resolution. - if (parsedOperands.size() != types.size()) { - parser->emitError(parser->getNameLoc(), - "requires number of operands and input types to match"); - return true; - } - if (parsedOperands.size() < Offsets::FirstIndexOffset) { - parser->emitError(parser->getNameLoc(), - "requires at least vector and memref operands"); - return true; - } + if (parsedOperands.size() != types.size()) + return parser->emitError( + parser->getNameLoc(), + "requires number of operands and input types to match"); + if (parsedOperands.size() < Offsets::FirstIndexOffset) + return parser->emitError(parser->getNameLoc(), + "requires at least vector and memref operands"); VectorType vectorType = types[Offsets::VectorOffset].dyn_cast<VectorType>(); - if (!vectorType) { - parser->emitError(parser->getNameLoc(), - "Vector type expected for first input type"); - return true; - } + if (!vectorType) + return parser->emitError(parser->getNameLoc(), + "Vector type expected for first input type"); MemRefType memrefType = types[Offsets::MemRefOffset].dyn_cast<MemRefType>(); - if (!memrefType) { - parser->emitError(parser->getNameLoc(), - "MemRef type expected for second input type"); - return true; - } + if (!memrefType) + return parser->emitError(parser->getNameLoc(), + "MemRef type expected for second input type"); unsigned expectedNumOperands = Offsets::FirstIndexOffset + memrefType.getRank(); - if (parsedOperands.size() != expectedNumOperands) { - parser->emitError(parser->getNameLoc(), - "requires " + Twine(expectedNumOperands) + " operands"); - return true; - } + if (parsedOperands.size() != expectedNumOperands) + return parser->emitError(parser->getNameLoc(), + "requires " + Twine(expectedNumOperands) + + " operands"); OpAsmParser::OperandType vectorInfo = parsedOperands[Offsets::VectorOffset]; OpAsmParser::OperandType memrefInfo = parsedOperands[Offsets::MemRefOffset]; diff --git a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp index 673485ade99..eb427c5c2b3 100644 --- a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp @@ -279,14 +279,10 @@ ModuleLowerer::linearizeSubscripts(ArrayRef<llvm::Value *> indices, // TODO(zinenko): this function should disappear when the conversion fully // supports MemRefs. static bool checkSupportedMemRefType(MemRefType type, const Operation &op) { - if (!type.getAffineMaps().empty()) { - op.emitError("NYI: memrefs with affine maps"); - return true; - } - if (type.getMemorySpace() != 0) { - op.emitError("NYI: non-default memory space"); - return true; - } + if (!type.getAffineMaps().empty()) + return op.emitError("NYI: memrefs with affine maps"); + if (type.getMemorySpace() != 0) + return op.emitError("NYI: non-default memory space"); return false; } @@ -494,10 +490,8 @@ bool ModuleLowerer::convertInstruction(const Instruction &inst) { return true; // TODO(somebody): float attributes have "double" semantics whatever the // type of the constant. This should be fixed at the parser level. - if (!type->isFloatTy()) { - inst.emitError("NYI: only floats are currently supported"); - return true; - } + if (!type->isFloatTy()) + return inst.emitError("NYI: only floats are currently supported"); bool unused; auto APvalue = constantOp->getValue(); APFloat::opStatus status = APvalue.convert( @@ -507,10 +501,8 @@ bool ModuleLowerer::convertInstruction(const Instruction &inst) { "Lossy conversion of a float constant to the float type"); // No return intended. } - if (status != APFloat::opOK) { - inst.emitError("Failed to convert a floating point constant"); - return true; - } + if (status != APFloat::opOK) + return inst.emitError("Failed to convert a floating point constant"); auto value = APvalue.convertToFloat(); valueMapping[constantOp->getResult()] = llvm::ConstantFP::get(type->getContext(), llvm::APFloat(value)); @@ -520,10 +512,8 @@ bool ModuleLowerer::convertInstruction(const Instruction &inst) { llvm::Type *type = convertType(constantOp->getType()); if (!type) return true; - if (!isa<llvm::IntegerType>(type)) { - inst.emitError("only integer types are supported"); - return true; - } + if (!isa<llvm::IntegerType>(type)) + return inst.emitError("only integer types are supported"); auto attr = (constantOp->getValue()).cast<IntegerAttr>(); // Create a new APInt even if we can extract one from the attribute, because // attributes are currently hardcoded to be 64-bit APInts and LLVM will @@ -569,7 +559,7 @@ bool ModuleLowerer::convertInstruction(const Instruction &inst) { const SSAValue *container = dimOp->getOperand(); MemRefType type = container->getType().dyn_cast<MemRefType>(); if (!type) - return dimOp->emitError("only memref types are supported"), true; + return dimOp->emitError("only memref types are supported"); auto shape = type.getShape(); auto index = dimOp->getIndex(); @@ -641,8 +631,7 @@ bool ModuleLowerer::convertInstruction(const Instruction &inst) { blockMapping[condBranchInst->getFalseDest()]); return false; } - inst.emitError("unsupported operation"); - return true; + return inst.emitError("unsupported operation"); } bool ModuleLowerer::convertBasicBlock(const BasicBlock &bb, diff --git a/mlir/lib/Transforms/MaterializeVectors.cpp b/mlir/lib/Transforms/MaterializeVectors.cpp index 3bf4305ca0c..b5e0f75406e 100644 --- a/mlir/lib/Transforms/MaterializeVectors.cpp +++ b/mlir/lib/Transforms/MaterializeVectors.cpp @@ -535,15 +535,11 @@ static bool instantiateMaterialization(Statement *stmt, MaterializationState *state) { LLVM_DEBUG(dbgs() << "\ninstantiate: " << *stmt); - if (isa<ForStmt>(stmt)) { - stmt->emitError("NYI path ForStmt"); - return true; - } + if (isa<ForStmt>(stmt)) + return stmt->emitError("NYI path ForStmt"); - if (isa<IfStmt>(stmt)) { - stmt->emitError("NYI path IfStmt"); - return true; - } + if (isa<IfStmt>(stmt)) + return stmt->emitError("NYI path IfStmt"); // Create a builder here for unroll-and-jam effects. MLFuncBuilder b(stmt); @@ -562,14 +558,10 @@ static bool instantiateMaterialization(Statement *stmt, // The only op with 0 results reaching this point must, by construction, be // VectorTransferWriteOps and have been caught above. Ops with >= 2 results // are not yet supported. So just support 1 result. - if (opStmt->getNumResults() != 1) { - stmt->emitError("NYI: ops with != 1 results"); - return true; - } - if (opStmt->getResult(0)->getType() != state->superVectorType) { - stmt->emitError("Op does not return a supervector."); - return true; - } + if (opStmt->getNumResults() != 1) + return stmt->emitError("NYI: ops with != 1 results"); + if (opStmt->getResult(0)->getType() != state->superVectorType) + return stmt->emitError("Op does not return a supervector."); auto *clone = instantiate(&b, opStmt, state->hwVectorType, state->substitutionsMap); if (!clone) { |

