Skip to content

Commit

Permalink
Apply CC lowering only when --emit-cir-flat and by default when lower…
Browse files Browse the repository at this point in the history
…ing through MLIR
  • Loading branch information
sitio-couto committed Sep 23, 2024
1 parent 7736e57 commit ded4eb9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::unique_ptr<Pass> createGotoSolverPass();
/// Create a pass to lower ABI-independent function definitions/calls.
std::unique_ptr<Pass> createCallConvLoweringPass();

void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm, bool useCCLowering);

//===----------------------------------------------------------------------===//
// Registration
Expand Down
11 changes: 4 additions & 7 deletions clang/lib/CIR/CodeGen/CIRPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,8 @@ mlir::LogicalResult runCIRToCIRPasses(

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

// FIXME(cir): This pass should run by default, but it is lacking support for
// several code bits. Once it's more mature, we should fix this.
if (enableCallConvLowering)
pm.addPass(mlir::createCallConvLoweringPass());

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

if (enableMem2Reg)
pm.addPass(mlir::createMem2Reg());
Expand All @@ -97,7 +92,9 @@ mlir::LogicalResult runCIRToCIRPasses(

namespace mlir {

void populateCIRPreLoweringPasses(OpPassManager &pm) {
void populateCIRPreLoweringPasses(OpPassManager &pm, bool useCCLowering) {
if (useCCLowering)
pm.addPass(createCallConvLoweringPass());
pm.addPass(createFlattenCFGPass());
pm.addPass(createGotoSolverPass());
}
Expand Down
7 changes: 5 additions & 2 deletions clang/lib/CIR/FrontendAction/CIRGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ class CIRGenConsumer : public clang::ASTConsumer {
if (feOptions.ClangIRLibOpt)
libOptOpts = sanitizePassOptions(feOptions.ClangIRLibOptOpts);

bool enableCCLowering = feOptions.ClangIRCallConvLowering &&
action == CIRGenAction::OutputType::EmitCIRFlat;

// Setup and run CIR pipeline.
std::string passOptParsingFailure;
if (runCIRToCIRPasses(
Expand All @@ -205,8 +208,8 @@ class CIRGenConsumer : public clang::ASTConsumer {
feOptions.ClangIRLibOpt, libOptOpts, passOptParsingFailure,
codeGenOptions.OptimizationLevel > 0,
action == CIRGenAction::OutputType::EmitCIRFlat,
action == CIRGenAction::OutputType::EmitMLIR,
feOptions.ClangIRCallConvLowering, feOptions.ClangIREnableMem2Reg)
action == CIRGenAction::OutputType::EmitMLIR, enableCCLowering,
feOptions.ClangIREnableMem2Reg)
.failed()) {
if (!passOptParsingFailure.empty())
diagnosticsEngine.Report(diag::err_drv_cir_pass_opt_parsing)
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4395,7 +4395,7 @@ std::unique_ptr<mlir::Pass> createConvertCIRToLLVMPass() {
}

void populateCIRToLLVMPasses(mlir::OpPassManager &pm) {
populateCIRPreLoweringPasses(pm);
populateCIRPreLoweringPasses(pm, true);
pm.addPass(createConvertCIRToLLVMPass());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -std=c++20 -triple aarch64-unknown-linux-gnu -fclangir -fclangir-call-conv-lowering -emit-cir -mmlir --mlir-print-ir-after=cir-call-conv-lowering %s -o %t.cir
// RUN: %clang_cc1 -std=c++20 -triple aarch64-unknown-linux-gnu -fclangir -fclangir-call-conv-lowering -emit-cir-flat -mmlir --mlir-print-ir-after=cir-call-conv-lowering %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

// CHECK: @_Z4Voidv()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -fclangir-call-conv-lowering -emit-cir -mmlir --mlir-print-ir-after=cir-call-conv-lowering %s -o %t.cir
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -fclangir-call-conv-lowering -emit-cir-flat -mmlir --mlir-print-ir-after=cir-call-conv-lowering %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

// Test call conv lowering for trivial cases. //
Expand Down

0 comments on commit ded4eb9

Please sign in to comment.