17#define GEN_PASS_DEF_GENERATERUNTIMEVERIFICATION
18#include "mlir/Transforms/Passes.h.inc"
24struct GenerateRuntimeVerificationPass
26 GenerateRuntimeVerificationPass> {
27 void runOnOperation()
override;
39class DefaultErrMsgGenerator {
45 DefaultErrMsgGenerator(
unsigned verboseLevel, AsmState &asmState)
46 : vLevel(verboseLevel), state(asmState) {}
48 std::string operator()(Operation *op, StringRef msg) {
50 llvm::raw_string_ostream stream(buffer);
51 stream <<
"ERROR: Runtime op verification failed\n";
53 op->
print(stream, state);
54 stream <<
"\n^ " << msg;
56 stream <<
"^ " << msg;
58 stream <<
"\nLocation: ";
63 unsigned getVerboseLevel()
const {
return vLevel; }
67void GenerateRuntimeVerificationPass::runOnOperation() {
69 if (verboseLevel > 1) {
70 getOperation()->emitError(
71 "generate-runtime-verification pass: set verboseLevel to 0 or 1");
79 SmallVector<RuntimeVerifiableOpInterface> ops;
80 getOperation()->walk([&](RuntimeVerifiableOpInterface verifiableOp) {
81 ops.push_back(verifiableOp);
86 OpPrintingFlags flags;
90 AsmState state(getOperation(), flags);
93 DefaultErrMsgGenerator defaultErrMsgGenerator(verboseLevel.getValue(), state);
95 OpBuilder builder(getOperation()->
getContext());
96 for (RuntimeVerifiableOpInterface verifiableOp : ops) {
97 builder.setInsertionPoint(verifiableOp);
98 verifiableOp.generateRuntimeVerification(builder, verifiableOp.getLoc(),
99 defaultErrMsgGenerator);
104 return std::make_unique<GenerateRuntimeVerificationPass>();
void print(raw_ostream &os) const
Print the location.
OpPrintingFlags & elideLargeElementsAttrs(int64_t largeElementLimit=16)
Enables the elision of large elements attributes by printing a lexically valid but otherwise meaningl...
OpPrintingFlags & useLocalScope(bool enable=true)
Use local scope when printing the operation.
OpPrintingFlags & skipRegions(bool skip=true)
Skip printing regions.
Location getLoc()
The source location the operation was defined or derived from.
void print(raw_ostream &os, const OpPrintingFlags &flags={})
Include the generated interface declarations.
std::unique_ptr< Pass > createGenerateRuntimeVerificationPass()
Creates a pass that generates IR to verify ops at runtime.