Skip to content

Commit 028114d

Browse files
authored
Add support for splitting if's with barriers in parallel ops without interchanging them (#240)
1 parent 05598d0 commit 028114d

File tree

3 files changed

+948
-46
lines changed

3 files changed

+948
-46
lines changed

include/polygeist/Passes/Utils.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55
#include "mlir/IR/BlockAndValueMapping.h"
66
#include "mlir/IR/IntegerSet.h"
77

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+
827
static inline mlir::scf::IfOp
928
cloneWithoutResults(mlir::scf::IfOp op, mlir::OpBuilder &rewriter,
1029
mlir::BlockAndValueMapping mapping = {},
@@ -49,6 +68,14 @@ cloneWithoutResults(mlir::AffineForOp op, mlir::PatternRewriter &rewriter,
4968
op.getStep());
5069
}
5170

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+
5279
static inline mlir::Block *getThenBlock(mlir::scf::IfOp op) {
5380
return op.thenBlock();
5481
}
@@ -59,7 +86,10 @@ static inline mlir::Block *getElseBlock(mlir::scf::IfOp op) {
5986
return op.elseBlock();
6087
}
6188
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;
6393
}
6494

6595
static inline mlir::Region &getThenRegion(mlir::scf::IfOp op) {

0 commit comments

Comments
 (0)