28#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h"
29#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h"
30#include "mlir/Dialect/SCF/IR/SCF.h"
31#include "mlir/Pass/Pass.h"
32#include "mlir/Transforms/DialectConversion.h"
35#define GEN_PASS_DEF_AIESCFTOCONTROLFLOW
36#include "aie/Dialect/AIEX/Transforms/AIEXPasses.h.inc"
45struct AIESCFToControlFlowPass
46 : xilinx::AIEX::impl::AIESCFToControlFlowBase<AIESCFToControlFlowPass> {
48 void runOnOperation()
override {
49 ModuleOp module = getOperation();
51 SmallVector<scf::ForOp> foreverLoops;
52 module.walk([&](scf::ForOp forOp) {
53 if (forOp->getParentOfType<AIE::CoreOp>() &&
54 forOp.getInitArgs().empty() && AIE::isForeverForLoop(forOp))
55 foreverLoops.push_back(forOp);
57 for (scf::ForOp forOp : foreverLoops)
60 ConversionTarget target(getContext());
64 target.markUnknownOpDynamicallyLegal([](Operation *) {
return true; });
65 target.addLegalDialect<cf::ControlFlowDialect>();
68 target.addDynamicallyLegalDialect<scf::SCFDialect>([](Operation *op) {
69 return op->getParentOfType<AIE::RuntimeSequenceOp>() !=
nullptr;
72 RewritePatternSet patterns(&getContext());
73 populateSCFToControlFlowConversionPatterns(patterns);
75 if (failed(applyPartialConversion(module, target, std::move(patterns))))
82std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
84 return std::make_unique<AIESCFToControlFlowPass>();
std::unique_ptr< mlir::OperationPass< mlir::ModuleOp > > createAIESCFToControlFlowPass()
mlir::scf::WhileOp replaceWithForeverLoop(mlir::scf::ForOp forOp)
Replace forOp, which isForeverForLoop accepts, with an scf.while that isForeverLoop accepts and that ...