mirror of https://github.com/llvm/torch-mlir
[stablehlo] verify stablehlo backend contract (#3338)
parent
0ca88028cd
commit
405f884522
|
@ -11,10 +11,9 @@
|
||||||
|
|
||||||
#include "mlir/Dialect/Arith/IR/Arith.h"
|
#include "mlir/Dialect/Arith/IR/Arith.h"
|
||||||
#include "mlir/Dialect/Func/IR/FuncOps.h"
|
#include "mlir/Dialect/Func/IR/FuncOps.h"
|
||||||
|
#include "mlir/Dialect/Math/IR/Math.h"
|
||||||
#include "mlir/Dialect/Shape/IR/Shape.h"
|
#include "mlir/Dialect/Shape/IR/Shape.h"
|
||||||
#include "mlir/Dialect/Tensor/IR/Tensor.h"
|
#include "mlir/Dialect/Tensor/IR/Tensor.h"
|
||||||
#include "mlir/IR/BuiltinOps.h"
|
|
||||||
#include "mlir/IR/OpDefinition.h"
|
|
||||||
#include "mlir/Transforms/DialectConversion.h"
|
#include "mlir/Transforms/DialectConversion.h"
|
||||||
#include "stablehlo/dialect/ChloOps.h"
|
#include "stablehlo/dialect/ChloOps.h"
|
||||||
#include "stablehlo/dialect/StablehloOps.h"
|
#include "stablehlo/dialect/StablehloOps.h"
|
||||||
|
@ -47,13 +46,21 @@ class VerifyStablehloBackendContractPass
|
||||||
// Structural operations.
|
// Structural operations.
|
||||||
target.addDynamicallyLegalOp<ModuleOp, func::FuncOp, func::ReturnOp>(
|
target.addDynamicallyLegalOp<ModuleOp, func::FuncOp, func::ReturnOp>(
|
||||||
opHasLegalTypes);
|
opHasLegalTypes);
|
||||||
// Shape operations.
|
|
||||||
target.addDynamicallyLegalOp<shape::ShapeOfOp>(opHasLegalTypes);
|
|
||||||
|
|
||||||
target.addLegalDialect<chlo::ChloDialect>();
|
target.addLegalDialect<chlo::ChloDialect>();
|
||||||
target.addLegalDialect<stablehlo::StablehloDialect>();
|
target.addLegalDialect<stablehlo::StablehloDialect>();
|
||||||
target.addLegalDialect<tensor::TensorDialect>();
|
target.addLegalDialect<tensor::TensorDialect>();
|
||||||
target.addLegalDialect<arith::ArithDialect>();
|
target.addLegalDialect<arith::ArithDialect>();
|
||||||
|
target.addLegalDialect<math::MathDialect>();
|
||||||
|
target.addLegalDialect<shape::ShapeDialect>();
|
||||||
|
auto moduleOp = getOperation();
|
||||||
|
RewritePatternSet patterns(context);
|
||||||
|
if (failed(applyFullConversion(moduleOp, target, std::move(patterns)))) {
|
||||||
|
emitError(moduleOp.getLoc())
|
||||||
|
<< "Module does not conform to the Stablehlo backend contract. "
|
||||||
|
"See dialect conversion legality information above.";
|
||||||
|
return signalPassFailure();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in New Issue