@@ -987,6 +987,34 @@ struct CIRToAIEDecaptureKernel
987
987
}
988
988
};
989
989
990
+ struct CIRKeepAIEDevice : CIRKeepAIEDeviceBase<CIRKeepAIEDevice> {
991
+ void runOnOperation () override {
992
+ auto module = getOperation ();
993
+ mlir::OpBuilder b{module};
994
+ llvm::SmallVector<mlir::Operation *> opToDelete;
995
+ xilinx::AIE::DeviceOp d;
996
+ // Use pre-order walk for early exit to pick the first aie.device for now
997
+ module->walk <mlir::WalkOrder::PreOrder>([&](mlir::Operation *op) {
998
+ if (!mlir::isa<xilinx::AIE::DeviceOp>(op))
999
+ return mlir::WalkResult::advance ();
1000
+ d = mlir::cast<xilinx::AIE::DeviceOp>(op);
1001
+ return mlir::WalkResult::interrupt ();
1002
+ });
1003
+ // Extract the aie.device from its function up to the top first
1004
+ // operation of the module
1005
+ if (d)
1006
+ d->moveBefore (&module.front ());
1007
+ // Erase all the top-module operations but the aie.device
1008
+ for (auto &op : module) {
1009
+ if (auto dev = mlir::dyn_cast<xilinx::AIE::DeviceOp>(op))
1010
+ if (dev == d)
1011
+ continue ;
1012
+ opToDelete.push_back (&op);
1013
+ }
1014
+ eraseOpsAndUsers (opToDelete);
1015
+ }
1016
+ };
1017
+
990
1018
} // namespace
991
1019
992
1020
std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
@@ -1008,4 +1036,8 @@ createCIRToAIEDecaptureKernelPass() {
1008
1036
return std::make_unique<CIRToAIEDecaptureKernel>();
1009
1037
}
1010
1038
1039
+ std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>> createCIRKeepAIEDevice () {
1040
+ return std::make_unique<CIRKeepAIEDevice>();
1041
+ }
1042
+
1011
1043
} // namespace xilinx::AIE::CIR
0 commit comments