Skip to content

Commit 92ae283

Browse files
committed
[CIR][NFC] Move LoweringPrepare into CIRGen
Move LP into CIRGen and give it a handle on the CIRGenBuilderTy. Pull Request: #1223
1 parent f1a29c6 commit 92ae283

28 files changed

+72
-50
lines changed

clang/include/clang/CIR/CIRGenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class CIRGenerator : public clang::ASTConsumer {
9898
std::unique_ptr<mlir::MLIRContext> takeContext() {
9999
return std::move(mlirContext);
100100
};
101+
clang::CIRGen::CIRGenModule &getCGM() { return *CGM; }
101102

102103
bool verifyModule();
103104

clang/include/clang/CIR/CIRToCIRPasses.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
namespace clang {
2020
class ASTContext;
21-
}
21+
namespace CIRGen {
22+
class CIRGenModule;
23+
} // namespace CIRGen
24+
} // namespace clang
2225

2326
namespace mlir {
2427
class MLIRContext;
@@ -30,12 +33,12 @@ namespace cir {
3033
// Run set of cleanup/prepare/etc passes CIR <-> CIR.
3134
mlir::LogicalResult runCIRToCIRPasses(
3235
mlir::ModuleOp theModule, mlir::MLIRContext *mlirCtx,
33-
clang::ASTContext &astCtx, bool enableVerifier, bool enableLifetime,
34-
llvm::StringRef lifetimeOpts, bool enableIdiomRecognizer,
35-
llvm::StringRef idiomRecognizerOpts, bool enableLibOpt,
36-
llvm::StringRef libOptOpts, std::string &passOptParsingFailure,
37-
bool enableCIRSimplify, bool flattenCIR, bool emitMLIR,
38-
bool enableCallConvLowering, bool enableMem2reg);
36+
clang::CIRGen::CIRGenModule &cgm, clang::ASTContext &astCtx,
37+
bool enableVerifier, bool enableLifetime, llvm::StringRef lifetimeOpts,
38+
bool enableIdiomRecognizer, llvm::StringRef idiomRecognizerOpts,
39+
bool enableLibOpt, llvm::StringRef libOptOpts,
40+
std::string &passOptParsingFailure, bool enableCIRSimplify, bool flattenCIR,
41+
bool emitMLIR, bool enableCallConvLowering, bool enableMem2reg);
3942

4043
} // namespace cir
4144

clang/include/clang/CIR/Dialect/Passes.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717

1818
namespace clang {
1919
class ASTContext;
20-
}
20+
namespace CIRGen {
21+
class CIRGenBuilderTy;
22+
} // namespace CIRGen
23+
} // namespace clang
24+
2125
namespace mlir {
2226

2327
std::unique_ptr<Pass> createLifetimeCheckPass();
@@ -31,7 +35,9 @@ std::unique_ptr<Pass> createCIRSimplifyPass();
3135
std::unique_ptr<Pass> createDropASTPass();
3236
std::unique_ptr<Pass> createSCFPreparePass();
3337
std::unique_ptr<Pass> createLoweringPreparePass();
34-
std::unique_ptr<Pass> createLoweringPreparePass(clang::ASTContext *astCtx);
38+
std::unique_ptr<Pass>
39+
createLoweringPreparePass(clang::ASTContext *astCtx,
40+
clang::CIRGen::CIRGenBuilderTy &builder);
3541
std::unique_ptr<Pass> createIdiomRecognizerPass();
3642
std::unique_ptr<Pass> createIdiomRecognizerPass(clang::ASTContext *astCtx);
3743
std::unique_ptr<Pass> createLibOptPass();

clang/include/clang/CIR/Dialect/Passes.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def SCFPrepare : Pass<"cir-mlir-scf-prepare"> {
109109

110110
def HoistAllocas : Pass<"cir-hoist-allocas"> {
111111
let summary = "Hoist allocas to the entry of the function";
112-
let description = [{
112+
let description = [{
113113
This pass hoist all non-dynamic allocas to the entry of the function.
114114
This is helpful for later code generation.
115115
}];
@@ -119,7 +119,7 @@ def HoistAllocas : Pass<"cir-hoist-allocas"> {
119119

120120
def FlattenCFG : Pass<"cir-flatten-cfg"> {
121121
let summary = "Produces flatten cfg";
122-
let description = [{
122+
let description = [{
123123
This pass transforms CIR and inline all the nested regions. Thus,
124124
the next post condtions are met after the pass applied:
125125
- there is not any nested region in a function body

clang/lib/CIR/CodeGen/CIRPasses.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "clang/AST/ASTContext.h"
1414
#include "clang/CIR/Dialect/Passes.h"
1515

16+
#include "CIRGenModule.h"
1617
#include "mlir/IR/BuiltinOps.h"
1718
#include "mlir/Pass/Pass.h"
1819
#include "mlir/Pass/PassManager.h"
@@ -24,12 +25,12 @@
2425
namespace cir {
2526
mlir::LogicalResult runCIRToCIRPasses(
2627
mlir::ModuleOp theModule, mlir::MLIRContext *mlirContext,
27-
clang::ASTContext &astContext, bool enableVerifier, bool enableLifetime,
28-
llvm::StringRef lifetimeOpts, bool enableIdiomRecognizer,
29-
llvm::StringRef idiomRecognizerOpts, bool enableLibOpt,
30-
llvm::StringRef libOptOpts, std::string &passOptParsingFailure,
31-
bool enableCIRSimplify, bool flattenCIR, bool emitMLIR,
32-
bool enableCallConvLowering, bool enableMem2Reg) {
28+
clang::CIRGen::CIRGenModule &cgm, clang::ASTContext &astContext,
29+
bool enableVerifier, bool enableLifetime, llvm::StringRef lifetimeOpts,
30+
bool enableIdiomRecognizer, llvm::StringRef idiomRecognizerOpts,
31+
bool enableLibOpt, llvm::StringRef libOptOpts,
32+
std::string &passOptParsingFailure, bool enableCIRSimplify, bool flattenCIR,
33+
bool emitMLIR, bool enableCallConvLowering, bool enableMem2Reg) {
3334

3435
llvm::TimeTraceScope scope("CIR To CIR Passes");
3536

@@ -73,7 +74,7 @@ mlir::LogicalResult runCIRToCIRPasses(
7374
if (enableCIRSimplify)
7475
pm.addPass(mlir::createCIRSimplifyPass());
7576

76-
pm.addPass(mlir::createLoweringPreparePass(&astContext));
77+
pm.addPass(mlir::createLoweringPreparePass(&astContext, cgm.getBuilder()));
7778

7879
if (flattenCIR || enableMem2Reg)
7980
mlir::populateCIRPreLoweringPasses(pm, enableCallConvLowering);

clang/lib/CIR/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ add_clang_library(clangCIR
4444
CIRPasses.cpp
4545
CIRRecordLayoutBuilder.cpp
4646
ConstantInitBuilder.cpp
47+
LoweringPrepare.cpp
4748
TargetInfo.cpp
4849

4950
DEPENDS

clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp renamed to clang/lib/CIR/CodeGen/LoweringPrepare.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "LoweringPrepareCXXABI.h"
10-
#include "PassDetail.h"
9+
#include "CIRGenModule.h"
10+
1111
#include "mlir/IR/BuiltinAttributes.h"
1212
#include "mlir/IR/Region.h"
1313
#include "clang/AST/ASTContext.h"
@@ -19,6 +19,8 @@
1919
#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
2020
#include "clang/CIR/Dialect/IR/CIRDialect.h"
2121
#include "clang/CIR/Dialect/Passes.h"
22+
#include "clang/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h"
23+
#include "clang/CIR/Dialect/Transforms/PassDetail.h"
2224
#include "clang/CIR/Interfaces/ASTAttrInterfaces.h"
2325
#include "llvm/ADT/APFloat.h"
2426
#include "llvm/ADT/SmallVector.h"
@@ -121,6 +123,7 @@ struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
121123

122124
clang::ASTContext *astCtx;
123125
std::shared_ptr<cir::LoweringPrepareCXXABI> cxxABI;
126+
clang::CIRGen::CIRGenBuilderTy *builder;
124127

125128
void setASTContext(clang::ASTContext *c) {
126129
astCtx = c;
@@ -154,6 +157,10 @@ struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
154157
}
155158
}
156159

160+
void setBuilder(clang::CIRGen::CIRGenBuilderTy &builder) {
161+
this->builder = &builder;
162+
}
163+
157164
/// Tracks current module.
158165
ModuleOp theModule;
159166

@@ -1210,10 +1217,11 @@ void LoweringPreparePass::runOnOperation() {
12101217
std::unique_ptr<Pass> mlir::createLoweringPreparePass() {
12111218
return std::make_unique<LoweringPreparePass>();
12121219
}
1213-
12141220
std::unique_ptr<Pass>
1215-
mlir::createLoweringPreparePass(clang::ASTContext *astCtx) {
1221+
mlir::createLoweringPreparePass(clang::ASTContext *astCtx,
1222+
clang::CIRGen::CIRGenBuilderTy &builder) {
12161223
auto pass = std::make_unique<LoweringPreparePass>();
1224+
pass->setBuilder(builder);
12171225
pass->setASTContext(astCtx);
12181226
return std::move(pass);
12191227
}

0 commit comments

Comments
 (0)