Remove lowerAffineConstructs and lowerControlFlow in favor of providing patterns.

These methods don't compose well with the rest of conversion framework, and create artificial breaks in conversion. Replace these methods with two(populateAffineToStdConversionPatterns and populateLoopToStdConversionPatterns respectively) that populate a list of patterns to perform the same behavior.

PiperOrigin-RevId: 258219277
This commit is contained in:
River Riddle
2019-07-15 12:52:44 -07:00
committed by Mehdi Amini
parent e7a2ef21f9
commit 2087bf6386
8 changed files with 61 additions and 56 deletions

View File

@@ -43,8 +43,8 @@ using namespace mlir::loop;
namespace {
struct ControlFlowToCFGPass : public ModulePass<ControlFlowToCFGPass> {
void runOnModule() override;
struct ControlFlowToCFGPass : public FunctionPass<ControlFlowToCFGPass> {
void runOnFunction() override;
};
// Create a CFG subgraph for the loop around its body blocks (if the body
@@ -270,22 +270,23 @@ IfLowering::matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
return matchSuccess();
}
LogicalResult mlir::lowerControlFlow(FuncOp func) {
OwningRewritePatternList patterns;
void mlir::populateLoopToStdConversionPatterns(
OwningRewritePatternList &patterns, MLIRContext *ctx) {
RewriteListBuilder<ForLowering, IfLowering, TerminatorLowering>::build(
patterns, func.getContext());
ConversionTarget target(*func.getContext());
patterns, ctx);
}
void ControlFlowToCFGPass::runOnFunction() {
OwningRewritePatternList patterns;
populateLoopToStdConversionPatterns(patterns, &getContext());
ConversionTarget target(getContext());
target.addLegalDialect<StandardOpsDialect>();
return applyConversionPatterns(func, target, std::move(patterns));
if (failed(
applyConversionPatterns(getFunction(), target, std::move(patterns))))
signalPassFailure();
}
void ControlFlowToCFGPass::runOnModule() {
for (auto func : getModule().getOps<FuncOp>())
if (failed(mlir::lowerControlFlow(func)))
return signalPassFailure();
}
ModulePassBase *mlir::createConvertToCFGPass() {
FunctionPassBase *mlir::createConvertToCFGPass() {
return new ControlFlowToCFGPass();
}