From abce593dfdca2aa2b2ace018de64d52457d93647 Mon Sep 17 00:00:00 2001 From: Ronan Keryell Date: Wed, 13 Nov 2024 13:06:16 -0800 Subject: [PATCH] [CIR] Use only cir:: instead of mlir::cir:: to match latest ClangIR Follow up the change made up-stream with https://github.com/llvm/clangir/pull/1084 --- include/aie/CIR/CIRToAIEPasses.td | 4 +- lib/CIR/CIRToAIEPasses.cpp | 89 ++++++++++++------------- tools/aie-lsp-server/aie-lsp-server.cpp | 2 +- tools/aie-opt/aie-opt.cpp | 2 +- 4 files changed, 46 insertions(+), 51 deletions(-) diff --git a/include/aie/CIR/CIRToAIEPasses.td b/include/aie/CIR/CIRToAIEPasses.td index 2be02fd854..08503a441f 100644 --- a/include/aie/CIR/CIRToAIEPasses.td +++ b/include/aie/CIR/CIRToAIEPasses.td @@ -24,7 +24,7 @@ def CIRToAIEPrepare : Pass<"cir-to-aie-prepare", "mlir::ModuleOp"> { let constructor = "xilinx::AIE::CIR::createCIRToAIEPreparePass()"; let dependentDialects = [ - "mlir::cir::CIRDialect", + "cir::CIRDialect", "xilinx::AIE::AIEDialect", ]; } @@ -40,7 +40,7 @@ def CIRToAIE : Pass<"cir-to-aie", "mlir::ModuleOp"> { let constructor = "xilinx::AIE::CIR::createCIRToAIEPass()"; let dependentDialects = [ - "mlir::cir::CIRDialect", + "cir::CIRDialect", "xilinx::AIE::AIEDialect", ]; } diff --git a/lib/CIR/CIRToAIEPasses.cpp b/lib/CIR/CIRToAIEPasses.cpp index ee34fa410c..6c72b0ba44 100644 --- a/lib/CIR/CIRToAIEPasses.cpp +++ b/lib/CIR/CIRToAIEPasses.cpp @@ -155,9 +155,9 @@ class CIRToAIETypesAnalysis { llvm::Regex{"^(aie::buffer)<([^,]+), ([^>]+)>$"}}; for (auto &[type, value] : moduleTypes) { - if (auto maybePointerType = mlir::dyn_cast(type)) - if (auto maybeStructType = mlir::dyn_cast( - maybePointerType.getPointee())) + if (auto maybePointerType = mlir::dyn_cast(type)) + if (auto maybeStructType = + mlir::dyn_cast(maybePointerType.getPointee())) for (auto &tnp : typeNamePatterns) if (llvm::SmallVector matches; tnp.match(maybeStructType.getName(), &matches)) { @@ -258,14 +258,13 @@ namespace { // Return true if the call operation calls a function with any of the given // string annotations bool isCallingFunctionWithAnnotation( - mlir::cir::CallOp op, llvm::ArrayRef anyAnnotations) { - if (auto calledFunc = - mlir::SymbolTable::lookupNearestSymbolFrom( - op, op.getCalleeAttr())) { + cir::CallOp op, llvm::ArrayRef anyAnnotations) { + if (auto calledFunc = mlir::SymbolTable::lookupNearestSymbolFrom( + op, op.getCalleeAttr())) { if (auto annnotations = calledFunc.getAnnotationsAttr()) for (auto a : calledFunc.getAnnotationsAttr()) { for (auto one : anyAnnotations) - if (mlir::cast(a).getName() == one) + if (mlir::cast(a).getName() == one) return true; } } @@ -288,18 +287,17 @@ bool isUnrealizedConversionCastWithAnnotation( mlir::MemRefType bufferMemrefType(mlir::Type buffer) { static mlir::TypeConverter typeConverter = cir::prepareTypeConverter(); LLVM_DEBUG(buffer.dump()); - if (auto p = mlir::dyn_cast(buffer)) { - if (auto bufferType = - mlir::dyn_cast(p.getPointee())) { + if (auto p = mlir::dyn_cast(buffer)) { + if (auto bufferType = mlir::dyn_cast(p.getPointee())) { LLVM_DEBUG(bufferType.dump()); // For now the aie::buffer is implemented as a std::array in the buffer // struct auto members = bufferType.getMembers(); if (auto stdArrayType = - mlir::dyn_cast(members.front())) { + mlir::dyn_cast(members.front())) { LLVM_DEBUG(stdArrayType.dump()); // Access the array inside the std::array struct - if (auto arrayType = mlir::dyn_cast( + if (auto arrayType = mlir::dyn_cast( stdArrayType.getMembers().front())) { LLVM_DEBUG(arrayType.dump()); auto memref = mlir::dyn_cast( @@ -367,9 +365,8 @@ void cloneReferencedSymbolsIntoDevice(xilinx::AIE::DeviceOp device) { // Lower C++ code like \code aie::device into an \code // aie.device(npu1){} operation -struct PrepareDeviceLowering - : public mlir::OpConversionPattern { - using mlir::OpConversionPattern::OpConversionPattern; +struct PrepareDeviceLowering : public mlir::OpConversionPattern { + using mlir::OpConversionPattern::OpConversionPattern; // \todo Find a less ugly way to access the analysis. How is it possible for a // pattern to access some contextual information? @@ -377,7 +374,7 @@ struct PrepareDeviceLowering static inline CIRToAIETypesAnalysis *cat; mlir::LogicalResult - matchAndRewrite(mlir::cir::AllocaOp op, OpAdaptor adaptor, + matchAndRewrite(cir::AllocaOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const final { // The struct has a name like "aie::device" and the "npu1" // is used directly for the MLIR aie.device attribute @@ -415,8 +412,8 @@ struct PrepareDeviceLowering // %2 = builtin.unrealized_conversion_cast %1 : !cir.ptr to !cir.ptr {"aie::tile" = ["1", "4"]} // clang-format on struct PrepareTileBufferLowering - : public mlir::OpConversionPattern { - using mlir::OpConversionPattern::OpConversionPattern; + : public mlir::OpConversionPattern { + using mlir::OpConversionPattern::OpConversionPattern; // \todo Find a less ugly way to access the analysis. How is it possible for a // pattern to access some contextual information? @@ -424,16 +421,16 @@ struct PrepareTileBufferLowering static inline CIRToAIETypesAnalysis *cat; mlir::LogicalResult - matchAndRewrite(mlir::cir::CallOp op, OpAdaptor adaptor, + matchAndRewrite(cir::CallOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const final { if (isCallingFunctionWithAnnotation( op, {"aie.device.tile", "aie.tile.buffer"})) { auto device = op.getOperand(0); auto user = op.getResult().getUsers().begin(); // Track the alloca where the tiled is stored - auto store = mlir::dyn_cast(*user); - auto alloca = mlir::dyn_cast( - store.getOperand(1).getDefiningOp()); + auto store = mlir::dyn_cast(*user); + auto alloca = + mlir::dyn_cast(store.getOperand(1).getDefiningOp()); auto aieLike = cat->getTypeDetail(alloca.getResult().getType()); // Replace the alloca by a conversion to be replaced later in // another pass. @@ -471,30 +468,29 @@ struct PrepareTileBufferLowering capture by the direct def/use forwarding */ -struct PrepareCoreLowering - : public mlir::OpConversionPattern { - using mlir::OpConversionPattern::OpConversionPattern; +struct PrepareCoreLowering : public mlir::OpConversionPattern { + using mlir::OpConversionPattern::OpConversionPattern; mlir::LogicalResult - matchAndRewrite(mlir::cir::CallOp op, OpAdaptor adaptor, + matchAndRewrite(cir::CallOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const final { if (isCallingFunctionWithAnnotation(op, {"aie.tile.program"})) { // Get tile::program() member function if (auto calledFunc = - mlir::SymbolTable::lookupNearestSymbolFrom( + mlir::SymbolTable::lookupNearestSymbolFrom( op, op.getCalleeAttr())) { // The last function instruction is cir.return and the one before // is the call to the lambda // calledFunc.getBlocks().front().back().dump(); - auto lambdaCall = mlir::dyn_cast( + auto lambdaCall = mlir::dyn_cast( *std::next(calledFunc.getBlocks().front().rbegin())); // lambdaCall.dump(); if (auto lambdaFunc = - mlir::SymbolTable::lookupNearestSymbolFrom( + mlir::SymbolTable::lookupNearestSymbolFrom( lambdaCall, lambdaCall.getCalleeAttr())) { // lambdaFunc.dump(); assert(lambdaFunc.getLambda()); - // auto scopeOp = op->getParentOfType(); + // auto scopeOp = op->getParentOfType(); // scopeOp.dump(); // The aie++ tile value rewriter.setInsertionPoint(op); @@ -526,14 +522,13 @@ struct CIRToAIEPrepare : CIRToAIEPrepareBase { mlir::ConversionTarget target{getContext()}; target.addLegalDialect(); target.addLegalOp(); - target.addDynamicallyLegalOp( - [&](mlir::cir::AllocaOp op) { - // If the struct has a name like "aie::device", mark - // the operation illegal so it has to be rewritten - auto aieLike = cat.getOptionalTypeDetail(op.getType()); - return !(aieLike && aieLike->base == "aie::device"); - }); - target.addDynamicallyLegalOp([](mlir::cir::CallOp op) { + target.addDynamicallyLegalOp([&](cir::AllocaOp op) { + // If the struct has a name like "aie::device", mark + // the operation illegal so it has to be rewritten + auto aieLike = cat.getOptionalTypeDetail(op.getType()); + return !(aieLike && aieLike->base == "aie::device"); + }); + target.addDynamicallyLegalOp([](cir::CallOp op) { return !isCallingFunctionWithAnnotation( op, {"aie.device.tile", "aie.tile.buffer"}); }); @@ -628,27 +623,27 @@ struct CIRToAIE : CIRToAIEBase { // Lower aie::tile::program() to aie.core bool tryTileProgramLowering(mlir::Operation *op, mlir::OpBuilder &b) { - if (auto callOp = mlir::dyn_cast(op)) { + if (auto callOp = mlir::dyn_cast(op)) { LLVM_DEBUG( callOp.emitRemark("tryTileProgramLowering: CallOp using a tile")); if (isCallingFunctionWithAnnotation(callOp, {"aie.tile.program"})) { LLVM_DEBUG( callOp.emitRemark("tryTileProgramLowering: CallOp using a tile")); if (auto calledFunc = - mlir::SymbolTable::lookupNearestSymbolFrom( + mlir::SymbolTable::lookupNearestSymbolFrom( callOp, callOp.getCalleeAttr())) { // The last function instruction is cir.return and the one before // is the call to the lambda - if (auto lambdaCall = mlir::dyn_cast( + if (auto lambdaCall = mlir::dyn_cast( *std::next(calledFunc.getBlocks().front().rbegin()))) { LLVM_DEBUG(lambdaCall.emitRemark("lambdaCall")); - if (auto lambdaFunc = mlir::SymbolTable::lookupNearestSymbolFrom< - mlir::cir::FuncOp>(lambdaCall, - lambdaCall.getCalleeAttr())) { + if (auto lambdaFunc = + mlir::SymbolTable::lookupNearestSymbolFrom( + lambdaCall, lambdaCall.getCalleeAttr())) { LLVM_DEBUG(lambdaFunc.emitRemark( "tryTileProgramLowering: Tile core lambda")); assert(lambdaFunc.getLambda()); - auto scopeOp = callOp->getParentOfType(); + auto scopeOp = callOp->getParentOfType(); LLVM_DEBUG(scopeOp.emitRemark("tryTileProgramLowering: Scope")); // \todo outline auto tileDetail = @@ -699,7 +694,7 @@ struct CIRToAIE : CIRToAIEBase { resolveSomeDeviceToTileAfterCloning(clone); LLVM_DEBUG( coreOp.emitRemark("tryTileProgramLowering: Stuffed core"); - coreOp->getParentOfType().emitRemark( + coreOp->getParentOfType().emitRemark( "tryTileProgramLowering: Top function")); } } diff --git a/tools/aie-lsp-server/aie-lsp-server.cpp b/tools/aie-lsp-server/aie-lsp-server.cpp index ea69cef319..a2fd189f14 100644 --- a/tools/aie-lsp-server/aie-lsp-server.cpp +++ b/tools/aie-lsp-server/aie-lsp-server.cpp @@ -20,6 +20,6 @@ int main(int argc, char **argv) { mlir::DialectRegistry registry; mlir::registerAllDialects(registry); xilinx::registerAllDialects(registry); - registry.insert(); + registry.insert(); return mlir::failed(mlir::MlirLspServerMain(argc, argv, registry)); } diff --git a/tools/aie-opt/aie-opt.cpp b/tools/aie-opt/aie-opt.cpp index ce94da217e..35787805a0 100644 --- a/tools/aie-opt/aie-opt.cpp +++ b/tools/aie-opt/aie-opt.cpp @@ -53,7 +53,7 @@ int main(int argc, char **argv) { llvm::cl::AddExtraVersionPrinter(versionPrinter); // ClangIR dialect - registry.insert(); + registry.insert(); // ClangIR-specific passes mlir::registerPass([]() -> std::unique_ptr {