diff options
| author | Smit Hinsu <hinsu@google.com> | 2018-12-07 09:30:25 -0800 |
|---|---|---|
| committer | jpienaar <jpienaar@google.com> | 2019-03-29 14:22:06 -0700 |
| commit | adca59e4f7d2e5e1038e0491ecc840fb04911d97 (patch) | |
| tree | 67bfe391234a08d3ce365db3798a1e6287d4fbab | |
| parent | d2d7c11f197e3e93af390dc9a9cc3ba82c152b10 (diff) | |
| download | bcm5719-llvm-adca59e4f7d2e5e1038e0491ecc840fb04911d97.tar.gz bcm5719-llvm-adca59e4f7d2e5e1038e0491ecc840fb04911d97.zip | |
Return bool from all emitError methods similar to Operation::emitOpError
This simplifies call-sites returning true after emitting an error. After the
conversion, dropped braces around single statement blocks as that seems more
common.
Also, switched to emitError method instead of emitting Error kind using the
emitDiagnostic method.
TESTED with existing unit tests
PiperOrigin-RevId: 224527868
| -rw-r--r-- | mlir/include/mlir/IR/Function.h | 8 | ||||
| -rw-r--r-- | mlir/include/mlir/IR/Instructions.h | 8 | ||||
| -rw-r--r-- | mlir/include/mlir/IR/MLIRContext.h | 10 | ||||
| -rw-r--r-- | mlir/include/mlir/IR/OpDefinition.h | 8 | ||||
| -rw-r--r-- | mlir/include/mlir/IR/OpImplementation.h | 12 | ||||
| -rw-r--r-- | mlir/include/mlir/IR/Operation.h | 8 | ||||
| -rw-r--r-- | mlir/include/mlir/IR/Statement.h | 8 | ||||
| -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 |
19 files changed, 130 insertions, 190 deletions
diff --git a/mlir/include/mlir/IR/Function.h b/mlir/include/mlir/IR/Function.h index f4f807b2ed0..7ba9b2a248f 100644 --- a/mlir/include/mlir/IR/Function.h +++ b/mlir/include/mlir/IR/Function.h @@ -80,10 +80,10 @@ public: void dump() 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 emitError(const Twine &message) const; + /// 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 emitError(const Twine &message) const; /// Emit a warning about this operation, reporting up to any diagnostic /// handlers that may be listening. diff --git a/mlir/include/mlir/IR/Instructions.h b/mlir/include/mlir/IR/Instructions.h index d33bfd0c7d5..2c89722f2c8 100644 --- a/mlir/include/mlir/IR/Instructions.h +++ b/mlir/include/mlir/IR/Instructions.h @@ -313,10 +313,10 @@ public: void dropAllReferences(); /// 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 emitError(const Twine &message) const; + /// 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 emitError(const Twine &message) const; /// Emit a warning about this operation, reporting up to any diagnostic /// handlers that may be listening. diff --git a/mlir/include/mlir/IR/MLIRContext.h b/mlir/include/mlir/IR/MLIRContext.h index 5532c4db89b..3dbf6dc3c37 100644 --- a/mlir/include/mlir/IR/MLIRContext.h +++ b/mlir/include/mlir/IR/MLIRContext.h @@ -79,15 +79,15 @@ public: /// Return the current diagnostic handler, or null if none is present. DiagnosticHandlerTy getDiagnosticHandler() const; - /// This emits an diagnostic using the registered issue handle if present, or - /// with the default behavior if not. The MLIR compiler should not generally + /// Emit a diagnostic using the registered issue handle if present, or with + /// the default behavior if not. The MLIR compiler should not generally /// interact with this, it should use methods on Operation instead. void emitDiagnostic(Location location, const Twine &message, DiagnosticKind kind) const; - /// Emits an error message using the registered issue handle if present, or to - /// the standard error stream otherwise. - void emitError(Location location, const Twine &message) const; + /// Emit an error message using the registered issue handle if present, or to + /// the standard error stream otherwise and return true. + bool emitError(Location location, const Twine &message) const; // This is effectively private given that only MLIRContext.cpp can see the // MLIRContextImpl type. diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index 6fad0154bec..e2157646014 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -169,10 +169,10 @@ public: void erase() { state->erase(); } /// 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 emitError(const Twine &message) const; + /// 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 emitError(const Twine &message) const; /// Emit an error with the op name prefixed, like "'dim' op " which is /// convenient for verifiers. This always returns true. diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index 3a2f633c88c..df714e00e1f 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -185,10 +185,8 @@ public: // Check for the right kind of attribute. result = type.dyn_cast<TypeType>(); - if (!result) { - emitError(loc, "invalid kind of type specified"); - return true; - } + if (!result) + return emitError(loc, "invalid kind of type specified"); return false; } @@ -241,10 +239,8 @@ public: // Check for the right kind of attribute. result = attr.dyn_cast<AttrType>(); - if (!result) { - emitError(loc, "invalid kind of constant specified"); - return true; - } + if (!result) + return emitError(loc, "invalid kind of constant specified"); return false; } diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h index 361db4e0e12..f7d040647bd 100644 --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -184,10 +184,10 @@ public: RemoveResult removeAttr(Identifier name); /// 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 emitError(const Twine &message) const; + /// 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 emitError(const Twine &message) const; /// Emit an error with the op name prefixed, like "'dim' op " which is /// convenient for verifiers. This function always returns true. diff --git a/mlir/include/mlir/IR/Statement.h b/mlir/include/mlir/IR/Statement.h index 99ab86f5865..8b5dce7aad8 100644 --- a/mlir/include/mlir/IR/Statement.h +++ b/mlir/include/mlir/IR/Statement.h @@ -169,10 +169,10 @@ public: } /// 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 emitError(const Twine &message) const; + /// 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 emitError(const Twine &message) const; /// Emit a warning about this operation, reporting up to any diagnostic /// handlers that may be listening. 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) { |

