From 8df3e509efb0ba2df55e92290fbe6212f51ddd13 Mon Sep 17 00:00:00 2001 From: Nathan Lanza Date: Tue, 10 Dec 2024 23:24:12 -0500 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.5 --- clang/include/clang/CIR/CIRGenerator.h | 1 + clang/include/clang/CIR/CIRToCIRPasses.h | 17 +++++++++------- clang/include/clang/CIR/Dialect/Passes.h | 10 ++++++++-- clang/include/clang/CIR/Dialect/Passes.td | 4 ++-- .../Transforms/LoweringPrepareCXXABI.h | 0 .../Transforms/LoweringPrepareItaniumCXXABI.h | 0 .../CIR/Dialect/Transforms/PassDetail.h | 0 clang/lib/CIR/CodeGen/CIRPasses.cpp | 15 +++++++------- clang/lib/CIR/CodeGen/CMakeLists.txt | 1 + .../LoweringPrepare.cpp | 13 +++++++++--- .../Dialect/Transforms/CIRCanonicalize.cpp | 2 +- .../CIR/Dialect/Transforms/CIRSimplify.cpp | 2 +- .../lib/CIR/Dialect/Transforms/CMakeLists.txt | 1 - clang/lib/CIR/Dialect/Transforms/DropAST.cpp | 2 +- .../lib/CIR/Dialect/Transforms/FlattenCFG.cpp | 2 +- .../lib/CIR/Dialect/Transforms/GotoSolver.cpp | 4 ++-- .../CIR/Dialect/Transforms/HoistAllocas.cpp | 4 ++-- .../Dialect/Transforms/IdiomRecognizer.cpp | 2 +- clang/lib/CIR/Dialect/Transforms/LibOpt.cpp | 2 +- .../CIR/Dialect/Transforms/LifetimeCheck.cpp | 3 +-- .../lib/CIR/Dialect/Transforms/SCFPrepare.cpp | 2 +- clang/lib/CIR/Dialect/Transforms/StdHelpers.h | 2 +- .../TargetLowering/ItaniumCXXABI.cpp | 2 +- .../Targets/LoweringPrepareAArch64CXXABI.cpp | 2 +- .../Targets/LoweringPrepareItaniumCXXABI.cpp | 2 +- .../Targets/LoweringPrepareX86CXXABI.cpp | 3 ++- clang/lib/CIR/FrontendAction/CIRGenAction.cpp | 20 ++++++++++--------- clang/lib/FrontendTool/CMakeLists.txt | 1 + 28 files changed, 70 insertions(+), 49 deletions(-) rename clang/{lib => include/clang}/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h (100%) rename clang/{lib => include/clang}/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.h (100%) rename clang/{lib => include/clang}/CIR/Dialect/Transforms/PassDetail.h (100%) rename clang/lib/CIR/{Dialect/Transforms => CodeGen}/LoweringPrepare.cpp (99%) diff --git a/clang/include/clang/CIR/CIRGenerator.h b/clang/include/clang/CIR/CIRGenerator.h index cb702aa978fa..2c13a8306dc7 100644 --- a/clang/include/clang/CIR/CIRGenerator.h +++ b/clang/include/clang/CIR/CIRGenerator.h @@ -98,6 +98,7 @@ class CIRGenerator : public clang::ASTConsumer { std::unique_ptr takeContext() { return std::move(mlirContext); }; + clang::CIRGen::CIRGenModule &getCGM() { return *CGM; } bool verifyModule(); diff --git a/clang/include/clang/CIR/CIRToCIRPasses.h b/clang/include/clang/CIR/CIRToCIRPasses.h index 4ad4aeebb22e..02a2795b94eb 100644 --- a/clang/include/clang/CIR/CIRToCIRPasses.h +++ b/clang/include/clang/CIR/CIRToCIRPasses.h @@ -18,7 +18,10 @@ namespace clang { class ASTContext; -} +namespace CIRGen { +class CIRGenModule; +} // namespace CIRGen +} // namespace clang namespace mlir { class MLIRContext; @@ -30,12 +33,12 @@ namespace cir { // Run set of cleanup/prepare/etc passes CIR <-> CIR. mlir::LogicalResult runCIRToCIRPasses( mlir::ModuleOp theModule, mlir::MLIRContext *mlirCtx, - clang::ASTContext &astCtx, bool enableVerifier, bool enableLifetime, - llvm::StringRef lifetimeOpts, bool enableIdiomRecognizer, - llvm::StringRef idiomRecognizerOpts, bool enableLibOpt, - llvm::StringRef libOptOpts, std::string &passOptParsingFailure, - bool enableCIRSimplify, bool flattenCIR, bool emitMLIR, - bool enableCallConvLowering, bool enableMem2reg); + clang::CIRGen::CIRGenModule &cgm, clang::ASTContext &astCtx, + bool enableVerifier, bool enableLifetime, llvm::StringRef lifetimeOpts, + bool enableIdiomRecognizer, llvm::StringRef idiomRecognizerOpts, + bool enableLibOpt, llvm::StringRef libOptOpts, + std::string &passOptParsingFailure, bool enableCIRSimplify, bool flattenCIR, + bool emitMLIR, bool enableCallConvLowering, bool enableMem2reg); } // namespace cir diff --git a/clang/include/clang/CIR/Dialect/Passes.h b/clang/include/clang/CIR/Dialect/Passes.h index d6cd4831a6af..ca1cc40353e6 100644 --- a/clang/include/clang/CIR/Dialect/Passes.h +++ b/clang/include/clang/CIR/Dialect/Passes.h @@ -17,7 +17,11 @@ namespace clang { class ASTContext; -} +namespace CIRGen { +class CIRGenModule; +} // namespace CIRGen +} // namespace clang + namespace mlir { std::unique_ptr createLifetimeCheckPass(); @@ -31,7 +35,9 @@ std::unique_ptr createCIRSimplifyPass(); std::unique_ptr createDropASTPass(); std::unique_ptr createSCFPreparePass(); std::unique_ptr createLoweringPreparePass(); -std::unique_ptr createLoweringPreparePass(clang::ASTContext *astCtx); +std::unique_ptr +createLoweringPreparePass(clang::ASTContext *astCtx, + clang::CIRGen::CIRGenModule &cgm); std::unique_ptr createIdiomRecognizerPass(); std::unique_ptr createIdiomRecognizerPass(clang::ASTContext *astCtx); std::unique_ptr createLibOptPass(); diff --git a/clang/include/clang/CIR/Dialect/Passes.td b/clang/include/clang/CIR/Dialect/Passes.td index 4a8d2bfa9672..1ea41cdd34a2 100644 --- a/clang/include/clang/CIR/Dialect/Passes.td +++ b/clang/include/clang/CIR/Dialect/Passes.td @@ -109,7 +109,7 @@ def SCFPrepare : Pass<"cir-mlir-scf-prepare"> { def HoistAllocas : Pass<"cir-hoist-allocas"> { let summary = "Hoist allocas to the entry of the function"; - let description = [{ + let description = [{ This pass hoist all non-dynamic allocas to the entry of the function. This is helpful for later code generation. }]; @@ -119,7 +119,7 @@ def HoistAllocas : Pass<"cir-hoist-allocas"> { def FlattenCFG : Pass<"cir-flatten-cfg"> { let summary = "Produces flatten cfg"; - let description = [{ + let description = [{ This pass transforms CIR and inline all the nested regions. Thus, the next post condtions are met after the pass applied: - there is not any nested region in a function body diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h b/clang/include/clang/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h similarity index 100% rename from clang/lib/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h rename to clang/include/clang/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.h b/clang/include/clang/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.h similarity index 100% rename from clang/lib/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.h rename to clang/include/clang/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.h diff --git a/clang/lib/CIR/Dialect/Transforms/PassDetail.h b/clang/include/clang/CIR/Dialect/Transforms/PassDetail.h similarity index 100% rename from clang/lib/CIR/Dialect/Transforms/PassDetail.h rename to clang/include/clang/CIR/Dialect/Transforms/PassDetail.h diff --git a/clang/lib/CIR/CodeGen/CIRPasses.cpp b/clang/lib/CIR/CodeGen/CIRPasses.cpp index 04582af2f517..b2f0ac655836 100644 --- a/clang/lib/CIR/CodeGen/CIRPasses.cpp +++ b/clang/lib/CIR/CodeGen/CIRPasses.cpp @@ -13,6 +13,7 @@ #include "clang/AST/ASTContext.h" #include "clang/CIR/Dialect/Passes.h" +#include "CIRGenModule.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" @@ -24,12 +25,12 @@ namespace cir { mlir::LogicalResult runCIRToCIRPasses( mlir::ModuleOp theModule, mlir::MLIRContext *mlirContext, - clang::ASTContext &astContext, bool enableVerifier, bool enableLifetime, - llvm::StringRef lifetimeOpts, bool enableIdiomRecognizer, - llvm::StringRef idiomRecognizerOpts, bool enableLibOpt, - llvm::StringRef libOptOpts, std::string &passOptParsingFailure, - bool enableCIRSimplify, bool flattenCIR, bool emitMLIR, - bool enableCallConvLowering, bool enableMem2Reg) { + clang::CIRGen::CIRGenModule &cgm, clang::ASTContext &astContext, + bool enableVerifier, bool enableLifetime, llvm::StringRef lifetimeOpts, + bool enableIdiomRecognizer, llvm::StringRef idiomRecognizerOpts, + bool enableLibOpt, llvm::StringRef libOptOpts, + std::string &passOptParsingFailure, bool enableCIRSimplify, bool flattenCIR, + bool emitMLIR, bool enableCallConvLowering, bool enableMem2Reg) { llvm::TimeTraceScope scope("CIR To CIR Passes"); @@ -73,7 +74,7 @@ mlir::LogicalResult runCIRToCIRPasses( if (enableCIRSimplify) pm.addPass(mlir::createCIRSimplifyPass()); - pm.addPass(mlir::createLoweringPreparePass(&astContext)); + pm.addPass(mlir::createLoweringPreparePass(&astContext, cgm)); if (flattenCIR || enableMem2Reg) mlir::populateCIRPreLoweringPasses(pm, enableCallConvLowering); diff --git a/clang/lib/CIR/CodeGen/CMakeLists.txt b/clang/lib/CIR/CodeGen/CMakeLists.txt index 02ac813ef732..e7d406c07f19 100644 --- a/clang/lib/CIR/CodeGen/CMakeLists.txt +++ b/clang/lib/CIR/CodeGen/CMakeLists.txt @@ -44,6 +44,7 @@ add_clang_library(clangCIR CIRPasses.cpp CIRRecordLayoutBuilder.cpp ConstantInitBuilder.cpp + LoweringPrepare.cpp TargetInfo.cpp DEPENDS diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/CodeGen/LoweringPrepare.cpp similarity index 99% rename from clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp rename to clang/lib/CIR/CodeGen/LoweringPrepare.cpp index b0709e9638ff..ba788b8de32c 100644 --- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp +++ b/clang/lib/CIR/CodeGen/LoweringPrepare.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "LoweringPrepareCXXABI.h" -#include "PassDetail.h" +#include "CIRGenModule.h" + #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/Region.h" #include "clang/AST/ASTContext.h" @@ -19,6 +19,8 @@ #include "clang/CIR/Dialect/IR/CIRDataLayout.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" #include "clang/CIR/Interfaces/ASTAttrInterfaces.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/SmallVector.h" @@ -121,6 +123,7 @@ struct LoweringPreparePass : public LoweringPrepareBase { clang::ASTContext *astCtx; std::shared_ptr cxxABI; + clang::CIRGen::CIRGenModule *cgm; void setASTContext(clang::ASTContext *c) { astCtx = c; @@ -154,6 +157,8 @@ struct LoweringPreparePass : public LoweringPrepareBase { } } + void setCGM(clang::CIRGen::CIRGenModule &cgm) { this->cgm = &cgm; } + /// Tracks current module. ModuleOp theModule; @@ -1212,8 +1217,10 @@ std::unique_ptr mlir::createLoweringPreparePass() { } std::unique_ptr -mlir::createLoweringPreparePass(clang::ASTContext *astCtx) { +mlir::createLoweringPreparePass(clang::ASTContext *astCtx, + clang::CIRGen::CIRGenModule &cgm) { auto pass = std::make_unique(); pass->setASTContext(astCtx); + pass->setCGM(cgm); return std::move(pass); } diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp index d0cb64748bd4..6888088c3e43 100644 --- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp +++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "PassDetail.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Block.h" #include "mlir/IR/Operation.h" @@ -16,6 +15,7 @@ #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" using namespace mlir; using namespace cir; diff --git a/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp b/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp index d5b2aa6cc3d8..08b02d8bace0 100644 --- a/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp +++ b/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "PassDetail.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Block.h" #include "mlir/IR/Operation.h" @@ -16,6 +15,7 @@ #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" #include "llvm/ADT/SmallVector.h" using namespace mlir; diff --git a/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt b/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt index 76ac0cbf1c8d..a51e9c1a76da 100644 --- a/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt +++ b/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt @@ -2,7 +2,6 @@ add_subdirectory(TargetLowering) add_clang_library(MLIRCIRTransforms LifetimeCheck.cpp - LoweringPrepare.cpp CIRCanonicalize.cpp CIRSimplify.cpp DropAST.cpp diff --git a/clang/lib/CIR/Dialect/Transforms/DropAST.cpp b/clang/lib/CIR/Dialect/Transforms/DropAST.cpp index 716412c0f6d8..ebbf85fa0026 100644 --- a/clang/lib/CIR/Dialect/Transforms/DropAST.cpp +++ b/clang/lib/CIR/Dialect/Transforms/DropAST.cpp @@ -8,10 +8,10 @@ #include "clang/CIR/Dialect/Passes.h" -#include "PassDetail.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "clang/AST/ASTContext.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" #include "llvm/ADT/SetOperations.h" #include "llvm/ADT/SmallSet.h" diff --git a/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp b/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp index 95b5b008df1b..098aa5c10186 100644 --- a/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp +++ b/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp @@ -10,7 +10,6 @@ // function region. // //===----------------------------------------------------------------------===// -#include "PassDetail.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Support/LogicalResult.h" @@ -18,6 +17,7 @@ #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" using namespace mlir; using namespace cir; diff --git a/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp b/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp index c46f89e87d12..1e0125cdc17a 100644 --- a/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp +++ b/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp @@ -1,4 +1,3 @@ -#include "PassDetail.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Support/LogicalResult.h" @@ -6,6 +5,7 @@ #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" #include "llvm/Support/TimeProfiler.h" @@ -54,4 +54,4 @@ void GotoSolverPass::runOnOperation() { std::unique_ptr mlir::createGotoSolverPass() { return std::make_unique(); -} \ No newline at end of file +} diff --git a/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp b/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp index 4b29c7235a02..f1078021169a 100644 --- a/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp +++ b/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "PassDetail.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Support/LogicalResult.h" @@ -14,6 +13,7 @@ #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" #include "llvm/Support/TimeProfiler.h" @@ -72,4 +72,4 @@ void HoistAllocasPass::runOnOperation() { std::unique_ptr mlir::createHoistAllocasPass() { return std::make_unique(); -} \ No newline at end of file +} diff --git a/clang/lib/CIR/Dialect/Transforms/IdiomRecognizer.cpp b/clang/lib/CIR/Dialect/Transforms/IdiomRecognizer.cpp index 39a1ac4ef5ce..4a5d32049373 100644 --- a/clang/lib/CIR/Dialect/Transforms/IdiomRecognizer.cpp +++ b/clang/lib/CIR/Dialect/Transforms/IdiomRecognizer.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "PassDetail.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/Region.h" @@ -16,6 +15,7 @@ #include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" #include "clang/CIR/Interfaces/ASTAttrInterfaces.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" diff --git a/clang/lib/CIR/Dialect/Transforms/LibOpt.cpp b/clang/lib/CIR/Dialect/Transforms/LibOpt.cpp index 30719a3d60f9..2c60381b46b1 100644 --- a/clang/lib/CIR/Dialect/Transforms/LibOpt.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LibOpt.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "PassDetail.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/Region.h" @@ -16,6 +15,7 @@ #include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" #include "clang/CIR/Interfaces/ASTAttrInterfaces.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" diff --git a/clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp b/clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp index 368c36b48946..00be93128d1b 100644 --- a/clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp @@ -6,8 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "PassDetail.h" - #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" #include "clang/AST/DeclCXX.h" @@ -15,6 +13,7 @@ #include "clang/CIR/Dialect/IR/CIRAttrs.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" #include "clang/CIR/Interfaces/CIRLoopOpInterface.h" #include "llvm/ADT/SetOperations.h" diff --git a/clang/lib/CIR/Dialect/Transforms/SCFPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/SCFPrepare.cpp index 5bf6f66e7744..c8f58e168cce 100644 --- a/clang/lib/CIR/Dialect/Transforms/SCFPrepare.cpp +++ b/clang/lib/CIR/Dialect/Transforms/SCFPrepare.cpp @@ -6,12 +6,12 @@ // //===----------------------------------------------------------------------===// -#include "PassDetail.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" using namespace mlir; using namespace cir; diff --git a/clang/lib/CIR/Dialect/Transforms/StdHelpers.h b/clang/lib/CIR/Dialect/Transforms/StdHelpers.h index 245e329fb1bd..cccb093d67d9 100644 --- a/clang/lib/CIR/Dialect/Transforms/StdHelpers.h +++ b/clang/lib/CIR/Dialect/Transforms/StdHelpers.h @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "PassDetail.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/Region.h" #include "clang/AST/ASTContext.h" @@ -14,6 +13,7 @@ #include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/Dialect/Transforms/PassDetail.h" #include "clang/CIR/Interfaces/ASTAttrInterfaces.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ItaniumCXXABI.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ItaniumCXXABI.cpp index 0ba1e51232c2..a781e308f957 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ItaniumCXXABI.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ItaniumCXXABI.cpp @@ -20,10 +20,10 @@ // //===----------------------------------------------------------------------===// -#include "../LoweringPrepareCXXABI.h" #include "CIRCXXABI.h" #include "LowerModule.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" +#include "clang/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h" #include "llvm/Support/ErrorHandling.h" namespace cir { diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareAArch64CXXABI.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareAArch64CXXABI.cpp index ec47a929cb34..5db2746e6896 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareAArch64CXXABI.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareAArch64CXXABI.cpp @@ -14,10 +14,10 @@ // TODO(cir): Refactor this to follow some level of codegen parity. -#include "../LoweringPrepareItaniumCXXABI.h" #include "clang/AST/CharUnits.h" #include "clang/CIR/Dialect/IR/CIRDataLayout.h" #include "clang/CIR/Dialect/IR/CIRTypes.h" +#include "clang/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.h" #include "clang/CIR/MissingFeatures.h" #include diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareItaniumCXXABI.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareItaniumCXXABI.cpp index bba759494e3b..07e3e2e4b4f7 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareItaniumCXXABI.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareItaniumCXXABI.cpp @@ -14,7 +14,7 @@ // TODO(cir): Refactor this to follow some level of codegen parity. -#include "../LoweringPrepareItaniumCXXABI.h" +#include "clang/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/Value.h" #include "mlir/IR/ValueRange.h" diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareX86CXXABI.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareX86CXXABI.cpp index d9b574fac4e7..1538bc4f1527 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareX86CXXABI.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareX86CXXABI.cpp @@ -13,9 +13,10 @@ //===------------------------------------------------------------------===// #include "../LowerModule.h" -#include "../LoweringPrepareItaniumCXXABI.h" #include "ABIInfoImpl.h" #include "X86_64ABIInfo.h" +#include "clang/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h" +#include "clang/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.h" using namespace clang; using namespace cir; diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp index 515e213abbef..ef46505699d6 100644 --- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp +++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp @@ -185,6 +185,7 @@ class CIRGenConsumer : public clang::ASTConsumer { auto mlirMod = gen->getModule(); auto mlirCtx = gen->takeContext(); + auto &cgm = gen->getCGM(); auto setupCIRPipelineAndExecute = [&] { // Sanitize passes options. MLIR uses spaces between pass options @@ -203,15 +204,16 @@ class CIRGenConsumer : public clang::ASTConsumer { // Setup and run CIR pipeline. std::string passOptParsingFailure; - if (runCIRToCIRPasses( - mlirMod, mlirCtx.get(), C, !feOptions.ClangIRDisableCIRVerifier, - feOptions.ClangIRLifetimeCheck, lifetimeOpts, - feOptions.ClangIRIdiomRecognizer, idiomRecognizerOpts, - feOptions.ClangIRLibOpt, libOptOpts, passOptParsingFailure, - codeGenOptions.OptimizationLevel > 0, - action == CIRGenAction::OutputType::EmitCIRFlat, - action == CIRGenAction::OutputType::EmitMLIR, enableCCLowering, - feOptions.ClangIREnableMem2Reg) + if (runCIRToCIRPasses(mlirMod, mlirCtx.get(), cgm, C, + !feOptions.ClangIRDisableCIRVerifier, + feOptions.ClangIRLifetimeCheck, lifetimeOpts, + feOptions.ClangIRIdiomRecognizer, + idiomRecognizerOpts, feOptions.ClangIRLibOpt, + libOptOpts, passOptParsingFailure, + codeGenOptions.OptimizationLevel > 0, + action == CIRGenAction::OutputType::EmitCIRFlat, + action == CIRGenAction::OutputType::EmitMLIR, + enableCCLowering, feOptions.ClangIREnableMem2Reg) .failed()) { if (!passOptParsingFailure.empty()) diagnosticsEngine.Report(diag::err_drv_cir_pass_opt_parsing) diff --git a/clang/lib/FrontendTool/CMakeLists.txt b/clang/lib/FrontendTool/CMakeLists.txt index 6dae1455010c..be31fb9628d2 100644 --- a/clang/lib/FrontendTool/CMakeLists.txt +++ b/clang/lib/FrontendTool/CMakeLists.txt @@ -16,6 +16,7 @@ set(deps) if(CLANG_ENABLE_CIR) list(APPEND link_libs + clangCIR clangCIRFrontendAction MLIRCIRTransforms MLIRIR From 8794dc72048644e0962eca8865575abf49d84f2d Mon Sep 17 00:00:00 2001 From: Nathan Lanza Date: Wed, 11 Dec 2024 22:18:23 -0500 Subject: [PATCH 2/2] switch to builder Created using spr 1.3.5 --- clang/include/clang/CIR/Dialect/Passes.h | 4 ++-- clang/lib/CIR/CodeGen/CIRPasses.cpp | 2 +- clang/lib/CIR/CodeGen/LoweringPrepare.cpp | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/Passes.h b/clang/include/clang/CIR/Dialect/Passes.h index ca1cc40353e6..dc6adda614b9 100644 --- a/clang/include/clang/CIR/Dialect/Passes.h +++ b/clang/include/clang/CIR/Dialect/Passes.h @@ -18,7 +18,7 @@ namespace clang { class ASTContext; namespace CIRGen { -class CIRGenModule; +class CIRGenBuilderTy; } // namespace CIRGen } // namespace clang @@ -37,7 +37,7 @@ std::unique_ptr createSCFPreparePass(); std::unique_ptr createLoweringPreparePass(); std::unique_ptr createLoweringPreparePass(clang::ASTContext *astCtx, - clang::CIRGen::CIRGenModule &cgm); + clang::CIRGen::CIRGenBuilderTy &builder); std::unique_ptr createIdiomRecognizerPass(); std::unique_ptr createIdiomRecognizerPass(clang::ASTContext *astCtx); std::unique_ptr createLibOptPass(); diff --git a/clang/lib/CIR/CodeGen/CIRPasses.cpp b/clang/lib/CIR/CodeGen/CIRPasses.cpp index b2f0ac655836..887696c97fd2 100644 --- a/clang/lib/CIR/CodeGen/CIRPasses.cpp +++ b/clang/lib/CIR/CodeGen/CIRPasses.cpp @@ -74,7 +74,7 @@ mlir::LogicalResult runCIRToCIRPasses( if (enableCIRSimplify) pm.addPass(mlir::createCIRSimplifyPass()); - pm.addPass(mlir::createLoweringPreparePass(&astContext, cgm)); + pm.addPass(mlir::createLoweringPreparePass(&astContext, cgm.getBuilder())); if (flattenCIR || enableMem2Reg) mlir::populateCIRPreLoweringPasses(pm, enableCallConvLowering); diff --git a/clang/lib/CIR/CodeGen/LoweringPrepare.cpp b/clang/lib/CIR/CodeGen/LoweringPrepare.cpp index ba788b8de32c..7d8dad7b82d3 100644 --- a/clang/lib/CIR/CodeGen/LoweringPrepare.cpp +++ b/clang/lib/CIR/CodeGen/LoweringPrepare.cpp @@ -123,7 +123,7 @@ struct LoweringPreparePass : public LoweringPrepareBase { clang::ASTContext *astCtx; std::shared_ptr cxxABI; - clang::CIRGen::CIRGenModule *cgm; + clang::CIRGen::CIRGenBuilderTy *builder; void setASTContext(clang::ASTContext *c) { astCtx = c; @@ -157,7 +157,9 @@ struct LoweringPreparePass : public LoweringPrepareBase { } } - void setCGM(clang::CIRGen::CIRGenModule &cgm) { this->cgm = &cgm; } + void setBuilder(clang::CIRGen::CIRGenBuilderTy &builder) { + this->builder = &builder; + } /// Tracks current module. ModuleOp theModule; @@ -1215,12 +1217,11 @@ void LoweringPreparePass::runOnOperation() { std::unique_ptr mlir::createLoweringPreparePass() { return std::make_unique(); } - std::unique_ptr mlir::createLoweringPreparePass(clang::ASTContext *astCtx, - clang::CIRGen::CIRGenModule &cgm) { + clang::CIRGen::CIRGenBuilderTy &builder) { auto pass = std::make_unique(); + pass->setBuilder(builder); pass->setASTContext(astCtx); - pass->setCGM(cgm); return std::move(pass); }