Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iterator>
#include <numeric>
Expand Down Expand Up @@ -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<NamedDecl>(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<ValueDecl>(GD.getDecl());

assert(!Global->hasAttr<IFuncAttr>() && "NYI");
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CIR/CodeGen/CIRPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CIR/Dialect/Transforms/CallConvLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -30,6 +32,8 @@ struct CallConvLoweringPattern : public OpRewritePattern<FuncOp> {

LogicalResult matchAndRewrite(FuncOp op,
PatternRewriter &rewriter) const final {
llvm::TimeTraceScope scope("Call Conv Lowering Pass", op.getSymName().str());

const auto module = op->getParentOfType<mlir::ModuleOp>();

if (!op.getAst())
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -43,6 +45,7 @@ static void process(mlir::cir::FuncOp func) {
}

void GotoSolverPass::runOnOperation() {
llvm::TimeTraceScope scope("Goto Solver");
SmallVector<Operation *, 16> ops;
getOperation()->walk([&](mlir::cir::FuncOp op) { process(op); });
}
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CIR/FrontendAction/CIRGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstdint>
#include <deque>
#include <optional>
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -4404,6 +4407,8 @@ extern void registerCIRDialectTranslation(mlir::MLIRContext &context);
std::unique_ptr<llvm::Module>
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);
Expand Down Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1419,6 +1420,8 @@ std::unique_ptr<llvm::Module>
lowerFromCIRToMLIRToLLVMIR(mlir::ModuleOp theModule,
std::unique_ptr<mlir::MLIRContext> mlirCtx,
LLVMContext &llvmCtx) {
llvm::TimeTraceScope scope("Lower from CIR to MLIR To LLVM");

mlir::PassManager pm(mlirCtx.get());

pm.addPass(createConvertCIRToMLIRPass());
Expand Down Expand Up @@ -1451,6 +1454,8 @@ std::unique_ptr<mlir::Pass> createConvertCIRToMLIRPass() {

mlir::ModuleOp lowerFromCIRToMLIR(mlir::ModuleOp theModule,
mlir::MLIRContext *mlirCtx) {
llvm::TimeTraceScope scope("Lower CIR To MLIR");

mlir::PassManager pm(mlirCtx);

pm.addPass(createConvertCIRToMLIRPass());
Expand Down