1//===- RuntimeOpVerification.cpp - Op Verification ------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "mlir/Transforms/Passes.h"
10
11#include "mlir/IR/Builders.h"
12#include "mlir/IR/Operation.h"
13#include "mlir/Interfaces/RuntimeVerifiableOpInterface.h"
14
15namespace mlir {
16#define GEN_PASS_DEF_GENERATERUNTIMEVERIFICATION
17#include "mlir/Transforms/Passes.h.inc"
18} // namespace mlir
19
20using namespace mlir;
21
22namespace {
23struct GenerateRuntimeVerificationPass
24 : public impl::GenerateRuntimeVerificationBase<
25 GenerateRuntimeVerificationPass> {
26 void runOnOperation() override;
27};
28} // namespace
29
30void GenerateRuntimeVerificationPass::runOnOperation() {
31 // The implementation of the RuntimeVerifiableOpInterface may create ops that
32 // can be verified. We don't want to generate verification for IR that
33 // performs verification, so gather all runtime-verifiable ops first.
34 SmallVector<RuntimeVerifiableOpInterface> ops;
35 getOperation()->walk([&](RuntimeVerifiableOpInterface verifiableOp) {
36 ops.push_back(verifiableOp);
37 });
38
39 OpBuilder builder(getOperation()->getContext());
40 for (RuntimeVerifiableOpInterface verifiableOp : ops) {
41 builder.setInsertionPoint(verifiableOp);
42 verifiableOp.generateRuntimeVerification(builder, verifiableOp.getLoc());
43 };
44}
45
46std::unique_ptr<Pass> mlir::createGenerateRuntimeVerificationPass() {
47 return std::make_unique<GenerateRuntimeVerificationPass>();
48}
49

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of mlir/lib/Transforms/GenerateRuntimeVerification.cpp