5
5
#include " mlir/IR/BlockAndValueMapping.h"
6
6
#include " mlir/IR/IntegerSet.h"
7
7
8
+ static inline mlir::scf::IfOp
9
+ cloneWithResults (mlir::scf::IfOp op, mlir::OpBuilder &rewriter,
10
+ mlir::BlockAndValueMapping mapping = {}) {
11
+ using namespace mlir ;
12
+ return rewriter.create <scf::IfOp>(op.getLoc (), op.getResultTypes (),
13
+ mapping.lookupOrDefault (op.getCondition ()),
14
+ true );
15
+ }
16
+ static inline mlir::AffineIfOp
17
+ cloneWithResults (mlir::AffineIfOp op, mlir::OpBuilder &rewriter,
18
+ mlir::BlockAndValueMapping mapping = {}) {
19
+ using namespace mlir ;
20
+ SmallVector<mlir::Value> lower;
21
+ for (auto o : op.getOperands ())
22
+ lower.push_back (mapping.lookupOrDefault (o));
23
+ return rewriter.create <AffineIfOp>(op.getLoc (), op.getResultTypes (),
24
+ op.getIntegerSet (), lower, true );
25
+ }
26
+
8
27
static inline mlir::scf::IfOp
9
28
cloneWithoutResults (mlir::scf::IfOp op, mlir::OpBuilder &rewriter,
10
29
mlir::BlockAndValueMapping mapping = {},
@@ -49,6 +68,14 @@ cloneWithoutResults(mlir::AffineForOp op, mlir::PatternRewriter &rewriter,
49
68
op.getStep ());
50
69
}
51
70
71
+ static inline void clearBlock (mlir::Block *block,
72
+ mlir::PatternRewriter &rewriter) {
73
+ for (auto &op : llvm::make_early_inc_range (llvm::reverse (*block))) {
74
+ assert (op.use_empty () && " expected 'op' to have no uses" );
75
+ rewriter.eraseOp (&op);
76
+ }
77
+ }
78
+
52
79
static inline mlir::Block *getThenBlock (mlir::scf::IfOp op) {
53
80
return op.thenBlock ();
54
81
}
@@ -59,7 +86,10 @@ static inline mlir::Block *getElseBlock(mlir::scf::IfOp op) {
59
86
return op.elseBlock ();
60
87
}
61
88
static inline mlir::Block *getElseBlock (mlir::AffineIfOp op) {
62
- return op.getElseBlock ();
89
+ if (op.hasElse ())
90
+ return op.getElseBlock ();
91
+ else
92
+ return nullptr ;
63
93
}
64
94
65
95
static inline mlir::Region &getThenRegion (mlir::scf::IfOp op) {
0 commit comments