Skip to content

Commit 326c2a9

Browse files
committed
Add verifier check for extract function
1 parent 3350716 commit 326c2a9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mlir/lib/Query/Query.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "QueryParser.h"
1111
#include "mlir/Dialect/Func/IR/FuncOps.h"
1212
#include "mlir/IR/IRMapping.h"
13+
#include "mlir/IR/Verifier.h"
1314
#include "mlir/Query/Matcher/MatchFinder.h"
1415
#include "mlir/Query/QuerySession.h"
1516
#include "llvm/ADT/SetVector.h"
@@ -68,6 +69,7 @@ static Operation *extractFunction(std::vector<Operation *> &ops,
6869
// Clone operations and build function body
6970
std::vector<Operation *> clonedOps;
7071
std::vector<Value> clonedVals;
72+
// TODO: Handle extraction of operations containing block arguments.
7173
for (Operation *slicedOp : slice) {
7274
Operation *clonedOp =
7375
clonedOps.emplace_back(builder.clone(*slicedOp, mapper));
@@ -129,6 +131,8 @@ LogicalResult MatchQuery::run(llvm::raw_ostream &os, QuerySession &qs) const {
129131
finder.flattenMatchedOps(matches);
130132
Operation *function =
131133
extractFunction(flattenedMatches, rootOp->getContext(), functionName);
134+
if (failed(verify(function)))
135+
return mlir::failure();
132136
os << "\n" << *function << "\n\n";
133137
function->erase();
134138
return mlir::success();

0 commit comments

Comments
 (0)