Skip to content

Commit

Permalink
Revert "[CIR][NFC] Move LoweringPrepare into CIRGen (#1092)"
Browse files Browse the repository at this point in the history
This reverts commit 4463352.
  • Loading branch information
bcardosolopes committed Nov 9, 2024
1 parent f220fa7 commit 94289aa
Show file tree
Hide file tree
Showing 26 changed files with 48 additions and 69 deletions.
1 change: 0 additions & 1 deletion clang/include/clang/CIR/CIRGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class CIRGenerator : public clang::ASTConsumer {
std::unique_ptr<mlir::MLIRContext> takeContext() {
return std::move(mlirCtx);
};
clang::CIRGen::CIRGenModule &getCGM() { return *CGM; }

bool verifyModule();

Expand Down
17 changes: 7 additions & 10 deletions clang/include/clang/CIR/CIRToCIRPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

namespace clang {
class ASTContext;
namespace CIRGen {
class CIRGenModule;
} // namespace CIRGen
} // namespace clang
}

namespace mlir {
class MLIRContext;
Expand All @@ -33,12 +30,12 @@ namespace cir {
// Run set of cleanup/prepare/etc passes CIR <-> CIR.
mlir::LogicalResult runCIRToCIRPasses(
mlir::ModuleOp theModule, mlir::MLIRContext *mlirCtx,
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);
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

Expand Down
10 changes: 2 additions & 8 deletions clang/include/clang/CIR/Dialect/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@

namespace clang {
class ASTContext;
namespace CIRGen {
class CIRGenModule;
} // namespace CIRGen
} // namespace clang

}
namespace mlir {

std::unique_ptr<Pass> createLifetimeCheckPass();
Expand All @@ -35,9 +31,7 @@ std::unique_ptr<Pass> createCIRSimplifyPass();
std::unique_ptr<Pass> createDropASTPass();
std::unique_ptr<Pass> createSCFPreparePass();
std::unique_ptr<Pass> createLoweringPreparePass();
std::unique_ptr<Pass>
createLoweringPreparePass(clang::ASTContext *astCtx,
clang::CIRGen::CIRGenModule &cgm);
std::unique_ptr<Pass> createLoweringPreparePass(clang::ASTContext *astCtx);
std::unique_ptr<Pass> createIdiomRecognizerPass();
std::unique_ptr<Pass> createIdiomRecognizerPass(clang::ASTContext *astCtx);
std::unique_ptr<Pass> createLibOptPass();
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/CIR/Dialect/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}];
Expand All @@ -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
Expand Down
15 changes: 7 additions & 8 deletions clang/lib/CIR/CodeGen/CIRPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#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"
Expand All @@ -25,12 +24,12 @@
namespace cir {
mlir::LogicalResult runCIRToCIRPasses(
mlir::ModuleOp theModule, mlir::MLIRContext *mlirCtx,
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) {
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) {

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

Expand Down Expand Up @@ -74,7 +73,7 @@ mlir::LogicalResult runCIRToCIRPasses(
if (enableCIRSimplify)
pm.addPass(mlir::createCIRSimplifyPass());

pm.addPass(mlir::createLoweringPreparePass(&astCtx, cgm));
pm.addPass(mlir::createLoweringPreparePass(&astCtx));

if (flattenCIR || enableMem2Reg)
mlir::populateCIRPreLoweringPasses(pm, enableCallConvLowering);
Expand Down
1 change: 0 additions & 1 deletion clang/lib/CIR/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ add_clang_library(clangCIR
CIRPasses.cpp
CIRRecordLayoutBuilder.cpp
ConstantInitBuilder.cpp
LoweringPrepare.cpp
TargetInfo.cpp

DEPENDS
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "PassDetail.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/Block.h"
#include "mlir/IR/Operation.h"
Expand All @@ -15,7 +16,6 @@
#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;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "PassDetail.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/Block.h"
#include "mlir/IR/Operation.h"
Expand All @@ -15,7 +16,6 @@
#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;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_subdirectory(TargetLowering)

add_clang_library(MLIRCIRTransforms
LifetimeCheck.cpp
LoweringPrepare.cpp
CIRCanonicalize.cpp
CIRSimplify.cpp
DropAST.cpp
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/DropAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
// function region.
//
//===----------------------------------------------------------------------===//
#include "PassDetail.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Transforms/DialectConversion.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;
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "PassDetail.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Transforms/DialectConversion.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"

#include "llvm/Support/TimeProfiler.h"

Expand Down Expand Up @@ -54,4 +54,4 @@ void GotoSolverPass::runOnOperation() {

std::unique_ptr<Pass> mlir::createGotoSolverPass() {
return std::make_unique<GotoSolverPass>();
}
}
4 changes: 2 additions & 2 deletions clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "PassDetail.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Transforms/DialectConversion.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"

#include "llvm/Support/TimeProfiler.h"

Expand Down Expand Up @@ -62,4 +62,4 @@ void HoistAllocasPass::runOnOperation() {

std::unique_ptr<Pass> mlir::createHoistAllocasPass() {
return std::make_unique<HoistAllocasPass>();
}
}
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/IdiomRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "PassDetail.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Region.h"
Expand All @@ -15,7 +16,6 @@
#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"
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/LibOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "PassDetail.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Region.h"
Expand All @@ -15,7 +16,6 @@
#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"
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
//
//===----------------------------------------------------------------------===//

#include "PassDetail.h"

#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclTemplate.h"
#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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include "CIRGenModule.h"

#include "LoweringPrepareCXXABI.h"
#include "PassDetail.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Region.h"
#include "clang/AST/ASTContext.h"
Expand All @@ -19,8 +19,6 @@
#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"
Expand Down Expand Up @@ -123,7 +121,6 @@ struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {

clang::ASTContext *astCtx;
std::shared_ptr<cir::LoweringPrepareCXXABI> cxxABI;
clang::CIRGen::CIRGenModule *cgm;

void setASTContext(clang::ASTContext *c) {
astCtx = c;
Expand All @@ -150,8 +147,6 @@ struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
}
}

void setCGM(clang::CIRGen::CIRGenModule &cgm) { this->cgm = &cgm; }

/// Tracks current module.
ModuleOp theModule;

Expand Down Expand Up @@ -1210,10 +1205,8 @@ std::unique_ptr<Pass> mlir::createLoweringPreparePass() {
}

std::unique_ptr<Pass>
mlir::createLoweringPreparePass(clang::ASTContext *astCtx,
clang::CIRGen::CIRGenModule &cgm) {
mlir::createLoweringPreparePass(clang::ASTContext *astCtx) {
auto pass = std::make_unique<LoweringPreparePass>();
pass->setASTContext(astCtx);
pass->setCGM(cgm);
return std::move(pass);
}
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/SCFPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/StdHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "PassDetail.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Region.h"
#include "clang/AST/ASTContext.h"
#include "clang/Basic/Module.h"
#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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <assert.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// TODO(cir): Refactor this to follow some level of codegen parity.

#include "clang/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.h"
#include "../LoweringPrepareItaniumCXXABI.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Value.h"
#include "mlir/IR/ValueRange.h"
Expand Down
Loading

0 comments on commit 94289aa

Please sign in to comment.