From ded4eb94ab56cc62f7dc1c2fce8d64c9b4e717c8 Mon Sep 17 00:00:00 2001 From: Vinicius Couto Espindola Date: Mon, 23 Sep 2024 20:02:43 -0300 Subject: [PATCH] Apply CC lowering only when --emit-cir-flat and by default when lowering through MLIR --- clang/include/clang/CIR/Dialect/Passes.h | 2 +- clang/lib/CIR/CodeGen/CIRPasses.cpp | 11 ++++------- clang/lib/CIR/FrontendAction/CIRGenAction.cpp | 7 +++++-- clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 2 +- .../aarch64/aarch64-call-conv-lowering-pass.cpp | 2 +- .../Target/x86_64/x86_64-call-conv-lowering-pass.cpp | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/Passes.h b/clang/include/clang/CIR/Dialect/Passes.h index 67e9da2246b6..c9b936ca98fb 100644 --- a/clang/include/clang/CIR/Dialect/Passes.h +++ b/clang/include/clang/CIR/Dialect/Passes.h @@ -42,7 +42,7 @@ std::unique_ptr createGotoSolverPass(); /// Create a pass to lower ABI-independent function definitions/calls. std::unique_ptr createCallConvLoweringPass(); -void populateCIRPreLoweringPasses(mlir::OpPassManager &pm); +void populateCIRPreLoweringPasses(mlir::OpPassManager &pm, bool useCCLowering); //===----------------------------------------------------------------------===// // Registration diff --git a/clang/lib/CIR/CodeGen/CIRPasses.cpp b/clang/lib/CIR/CodeGen/CIRPasses.cpp index 4f89daa1cee4..d56a7cc61e52 100644 --- a/clang/lib/CIR/CodeGen/CIRPasses.cpp +++ b/clang/lib/CIR/CodeGen/CIRPasses.cpp @@ -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()); @@ -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()); } diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp index 0b954a6d424b..a432b3899d36 100644 --- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp +++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp @@ -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( @@ -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) diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index b38c4608f875..9a77c81a1a07 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -4395,7 +4395,7 @@ std::unique_ptr createConvertCIRToLLVMPass() { } void populateCIRToLLVMPasses(mlir::OpPassManager &pm) { - populateCIRPreLoweringPasses(pm); + populateCIRPreLoweringPasses(pm, true); pm.addPass(createConvertCIRToLLVMPass()); } diff --git a/clang/test/CIR/Transforms/Target/aarch64/aarch64-call-conv-lowering-pass.cpp b/clang/test/CIR/Transforms/Target/aarch64/aarch64-call-conv-lowering-pass.cpp index 209679ebf383..f3a926aa93a6 100644 --- a/clang/test/CIR/Transforms/Target/aarch64/aarch64-call-conv-lowering-pass.cpp +++ b/clang/test/CIR/Transforms/Target/aarch64/aarch64-call-conv-lowering-pass.cpp @@ -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() diff --git a/clang/test/CIR/Transforms/Target/x86_64/x86_64-call-conv-lowering-pass.cpp b/clang/test/CIR/Transforms/Target/x86_64/x86_64-call-conv-lowering-pass.cpp index 3789550ce33b..a3c2d6960c39 100644 --- a/clang/test/CIR/Transforms/Target/x86_64/x86_64-call-conv-lowering-pass.cpp +++ b/clang/test/CIR/Transforms/Target/x86_64/x86_64-call-conv-lowering-pass.cpp @@ -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. //