diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index b1f052cd3e09..787ccabbdb28 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -75,6 +75,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/TimeProfiler.h" #include #include @@ -462,6 +463,19 @@ void CIRGenModule::setDSOLocal(CIRGlobalValueInterface GV) const { } void CIRGenModule::buildGlobal(GlobalDecl GD) { + llvm::TimeTraceScope scope("build CIR Global", [&]() -> std::string { + auto *ND = dyn_cast(GD.getDecl()); + if (!ND) + // TODO: How to print decls which is not named decl? + return "Unnamed decl"; + + std::string Name; + llvm::raw_string_ostream OS(Name); + ND->getNameForDiagnostic(OS, getASTContext().getPrintingPolicy(), + /*Qualified=*/true); + return Name; + }); + const auto *Global = cast(GD.getDecl()); assert(!Global->hasAttr() && "NYI"); diff --git a/clang/lib/CIR/CodeGen/CIRPasses.cpp b/clang/lib/CIR/CodeGen/CIRPasses.cpp index d56a7cc61e52..4a06689327b5 100644 --- a/clang/lib/CIR/CodeGen/CIRPasses.cpp +++ b/clang/lib/CIR/CodeGen/CIRPasses.cpp @@ -19,6 +19,8 @@ #include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/Passes.h" +#include "llvm/Support/TimeProfiler.h" + namespace cir { mlir::LogicalResult runCIRToCIRPasses( mlir::ModuleOp theModule, mlir::MLIRContext *mlirCtx, @@ -29,6 +31,8 @@ mlir::LogicalResult runCIRToCIRPasses( bool enableCIRSimplify, bool flattenCIR, bool emitMLIR, bool enableCallConvLowering, bool enableMem2Reg) { + llvm::TimeTraceScope scope("CIR To CIR Passes"); + mlir::PassManager pm(mlirCtx); pm.addPass(mlir::createCIRCanonicalizePass()); diff --git a/clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp b/clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp index 94539dc3dc21..8ce5c6aa2a62 100644 --- a/clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp +++ b/clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp @@ -18,6 +18,8 @@ #define GEN_PASS_DEF_CALLCONVLOWERING #include "clang/CIR/Dialect/Passes.h.inc" +#include "llvm/Support/TimeProfiler.h" + namespace mlir { namespace cir { @@ -30,6 +32,8 @@ struct CallConvLoweringPattern : public OpRewritePattern { LogicalResult matchAndRewrite(FuncOp op, PatternRewriter &rewriter) const final { + llvm::TimeTraceScope scope("Call Conv Lowering Pass", op.getSymName().str()); + const auto module = op->getParentOfType(); if (!op.getAst()) diff --git a/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp b/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp index 34eb488b732c..56e2308272ed 100644 --- a/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp +++ b/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp @@ -7,6 +7,8 @@ #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/Passes.h" +#include "llvm/Support/TimeProfiler.h" + using namespace mlir; using namespace mlir::cir; @@ -43,6 +45,7 @@ static void process(mlir::cir::FuncOp func) { } void GotoSolverPass::runOnOperation() { + llvm::TimeTraceScope scope("Goto Solver"); SmallVector ops; getOperation()->walk([&](mlir::cir::FuncOp op) { process(op); }); } diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp index a432b3899d36..da355053b0f1 100644 --- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp +++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp @@ -169,6 +169,8 @@ class CIRGenConsumer : public clang::ASTConsumer { } void HandleTranslationUnit(ASTContext &C) override { + llvm::TimeTraceScope scope("CIR Gen"); + // Note that this method is called after `HandleTopLevelDecl` has already // ran all over the top level decls. Here clang mostly wraps defered and // global codegen, followed by running CIR passes. diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 9a77c81a1a07..14789e5f59ba 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -64,6 +64,7 @@ #include "llvm/IR/DerivedTypes.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/TimeProfiler.h" #include #include #include @@ -4322,6 +4323,8 @@ void ConvertCIRToLLVMPass::buildGlobalAnnotationsVar() { } void ConvertCIRToLLVMPass::runOnOperation() { + llvm::TimeTraceScope scope("Convert CIR to LLVM Pass"); + auto module = getOperation(); mlir::DataLayout dataLayout(module); mlir::LLVMTypeConverter converter(&getContext()); @@ -4404,6 +4407,8 @@ extern void registerCIRDialectTranslation(mlir::MLIRContext &context); std::unique_ptr lowerDirectlyFromCIRToLLVMIR(mlir::ModuleOp theModule, LLVMContext &llvmCtx, bool disableVerifier) { + llvm::TimeTraceScope scope("lower from CIR to LLVM directly"); + mlir::MLIRContext *mlirCtx = theModule.getContext(); mlir::PassManager pm(mlirCtx); populateCIRToLLVMPasses(pm); @@ -4435,6 +4440,8 @@ lowerDirectlyFromCIRToLLVMIR(mlir::ModuleOp theModule, LLVMContext &llvmCtx, mlir::registerOpenMPDialectTranslation(*mlirCtx); registerCIRDialectTranslation(*mlirCtx); + llvm::TimeTraceScope __scope("translateModuleToLLVMIR"); + auto ModuleName = theModule.getName(); auto llvmModule = mlir::translateModuleToLLVMIR( theModule, llvmCtx, ModuleName ? *ModuleName : "CIRToLLVMModule"); diff --git a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp index 92f4108a5d40..e98345d67e56 100644 --- a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp +++ b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp @@ -53,6 +53,7 @@ #include "llvm/ADT/Sequence.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/TypeSwitch.h" +#include "llvm/Support/TimeProfiler.h" using namespace cir; using namespace llvm; @@ -1419,6 +1420,8 @@ std::unique_ptr lowerFromCIRToMLIRToLLVMIR(mlir::ModuleOp theModule, std::unique_ptr mlirCtx, LLVMContext &llvmCtx) { + llvm::TimeTraceScope scope("Lower from CIR to MLIR To LLVM"); + mlir::PassManager pm(mlirCtx.get()); pm.addPass(createConvertCIRToMLIRPass()); @@ -1451,6 +1454,8 @@ std::unique_ptr createConvertCIRToMLIRPass() { mlir::ModuleOp lowerFromCIRToMLIR(mlir::ModuleOp theModule, mlir::MLIRContext *mlirCtx) { + llvm::TimeTraceScope scope("Lower CIR To MLIR"); + mlir::PassManager pm(mlirCtx); pm.addPass(createConvertCIRToMLIRPass());