17 #define GEN_PASS_DEF_GENERATERUNTIMEVERIFICATION
18 #include "mlir/Transforms/Passes.h.inc"
24 struct GenerateRuntimeVerificationPass
25 :
public impl::GenerateRuntimeVerificationBase<
26 GenerateRuntimeVerificationPass> {
27 void runOnOperation()
override;
39 class 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; }
67 void GenerateRuntimeVerificationPass::runOnOperation() {
69 if (verboseLevel > 1) {
70 getOperation()->emitError(
71 "generate-runtime-verification pass: set verboseLevel to 0 or 1");
80 getOperation()->walk([&](RuntimeVerifiableOpInterface verifiableOp) {
81 ops.push_back(verifiableOp);
90 AsmState state(getOperation(), flags);
93 DefaultErrMsgGenerator defaultErrMsgGenerator(verboseLevel.getValue(), state);
96 for (RuntimeVerifiableOpInterface verifiableOp : ops) {
97 builder.setInsertionPoint(verifiableOp);
98 verifiableOp.generateRuntimeVerification(builder, verifiableOp.getLoc(),
99 defaultErrMsgGenerator);
104 return std::make_unique<GenerateRuntimeVerificationPass>();
static MLIRContext * getContext(OpFoldResult val)
This class provides management for the lifetime of the state used when printing the IR.
void print(raw_ostream &os) const
Print the location.
This class helps build Operations.
Set of flags used to control the behavior of the various IR print methods (e.g.
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.
Operation is the basic unit of execution within MLIR.
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.