forked from OSchip/llvm-project
Update the dialect attribute verification hooks to return LogicalResult instead of bool. This updates Function::emitError to return LogicalResult as well.
-- PiperOrigin-RevId: 241598892
This commit is contained in:
parent
f457ab7fc9
commit
7fa2864954
|
@ -105,24 +105,24 @@ public:
|
|||
virtual void
|
||||
getTypeAliases(SmallVectorImpl<std::pair<StringRef, Type>> &aliases) {}
|
||||
|
||||
/// Verify an attribute from this dialect on the given function. Returns true
|
||||
/// if the verification failed, false otherwise.
|
||||
virtual bool verifyFunctionAttribute(Function *, NamedAttribute) {
|
||||
return false;
|
||||
/// Verify an attribute from this dialect on the given function. Returns
|
||||
/// failure if the verification failed, success otherwise.
|
||||
virtual LogicalResult verifyFunctionAttribute(Function *, NamedAttribute) {
|
||||
return success();
|
||||
}
|
||||
|
||||
/// Verify an attribute from this dialect on the argument at 'argIndex' for
|
||||
/// the given function. Returns true if the verification failed, false
|
||||
/// the given function. Returns failure if the verification failed, success
|
||||
/// otherwise.
|
||||
virtual bool verifyFunctionArgAttribute(Function *, unsigned argIndex,
|
||||
NamedAttribute) {
|
||||
return false;
|
||||
virtual LogicalResult
|
||||
verifyFunctionArgAttribute(Function *, unsigned argIndex, NamedAttribute) {
|
||||
return success();
|
||||
}
|
||||
|
||||
/// Verify an attribute from this dialect on the given operation. Returns
|
||||
/// true if the verification failed, false otherwise.
|
||||
virtual bool verifyOperationAttribute(Operation *, NamedAttribute) {
|
||||
return false;
|
||||
/// failure if the verification failed, success otherwise.
|
||||
virtual LogicalResult verifyOperationAttribute(Operation *, NamedAttribute) {
|
||||
return success();
|
||||
}
|
||||
|
||||
virtual ~Dialect();
|
||||
|
|
|
@ -264,9 +264,9 @@ public:
|
|||
|
||||
/// 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 emitError(const Twine &message);
|
||||
/// returns failure. NOTE: This may terminate the containing application,
|
||||
/// only use when the IR is in an inconsistent state.
|
||||
LogicalResult emitError(const Twine &message);
|
||||
|
||||
/// Emit a warning about this operation, reporting up to any diagnostic
|
||||
/// handlers that may be listening.
|
||||
|
|
|
@ -79,9 +79,9 @@ public:
|
|||
void printType(Type type, raw_ostream &os) const override;
|
||||
|
||||
/// Verify a function argument attribute registered to this dialect.
|
||||
/// Returns true if the verification failed, false otherwise.
|
||||
bool verifyFunctionArgAttribute(Function *func, unsigned argIdx,
|
||||
NamedAttribute argAttr) override;
|
||||
/// Returns failure if the verification failed, success otherwise.
|
||||
LogicalResult verifyFunctionArgAttribute(Function *func, unsigned argIdx,
|
||||
NamedAttribute argAttr) override;
|
||||
|
||||
private:
|
||||
llvm::LLVMContext llvmContext;
|
||||
|
|
|
@ -55,11 +55,11 @@ public:
|
|||
LogicalResult failure() { return mlir::failure(); }
|
||||
|
||||
LogicalResult failure(const Twine &message, Operation &value) {
|
||||
return value.emitError(message), failure();
|
||||
return value.emitError(message);
|
||||
}
|
||||
|
||||
LogicalResult failure(const Twine &message, Function &fn) {
|
||||
return fn.emitError(message), failure();
|
||||
return fn.emitError(message);
|
||||
}
|
||||
|
||||
LogicalResult failure(const Twine &message, Block &bb) {
|
||||
|
@ -153,7 +153,7 @@ LogicalResult FuncVerifier::verify() {
|
|||
|
||||
// Verify this attribute with the defining dialect.
|
||||
if (auto *dialect = getDialectForAttribute(attr))
|
||||
if (dialect->verifyFunctionAttribute(&fn, attr))
|
||||
if (failed(dialect->verifyFunctionAttribute(&fn, attr)))
|
||||
return failure();
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ LogicalResult FuncVerifier::verify() {
|
|||
|
||||
// Verify this attribute with the defining dialect.
|
||||
if (auto *dialect = getDialectForAttribute(attr))
|
||||
if (dialect->verifyFunctionArgAttribute(&fn, i, attr))
|
||||
if (failed(dialect->verifyFunctionArgAttribute(&fn, i, attr)))
|
||||
return failure();
|
||||
}
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ LogicalResult FuncVerifier::verifyOperation(Operation &op) {
|
|||
if (!attr.first.strref().contains('.'))
|
||||
continue;
|
||||
if (auto *dialect = getDialectForAttribute(attr))
|
||||
if (dialect->verifyOperationAttribute(&op, attr))
|
||||
if (failed(dialect->verifyOperationAttribute(&op, attr)))
|
||||
return failure();
|
||||
}
|
||||
|
||||
|
|
|
@ -131,10 +131,10 @@ void Function::emitWarning(const Twine &message) {
|
|||
|
||||
/// 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) {
|
||||
return getContext()->emitError(getLoc(), message);
|
||||
/// returns failure. NOTE: This may terminate the containing application, only
|
||||
/// use when the IR is in an inconsistent state.
|
||||
LogicalResult Function::emitError(const Twine &message) {
|
||||
return getContext()->emitError(getLoc(), message), failure();
|
||||
}
|
||||
|
||||
/// Clone the internal blocks from this function into dest and all attributes
|
||||
|
|
|
@ -95,13 +95,14 @@ void LLVMDialect::printType(Type type, raw_ostream &os) const {
|
|||
}
|
||||
|
||||
/// Verify LLVMIR function argument attributes.
|
||||
bool LLVMDialect::verifyFunctionArgAttribute(Function *func, unsigned argIdx,
|
||||
NamedAttribute argAttr) {
|
||||
LogicalResult LLVMDialect::verifyFunctionArgAttribute(Function *func,
|
||||
unsigned argIdx,
|
||||
NamedAttribute argAttr) {
|
||||
// Check that llvm.noalias is a boolean attribute.
|
||||
if (argAttr.first == "llvm.noalias" && !argAttr.second.isa<BoolAttr>())
|
||||
return func->emitError(
|
||||
"llvm.noalias argument attribute of non boolean type");
|
||||
return false;
|
||||
return success();
|
||||
}
|
||||
|
||||
static DialectRegistration<LLVMDialect> llvmDialect;
|
||||
|
|
Loading…
Reference in New Issue