Skip to content

Commit 4d3a2f5

Browse files
authored
[NFC] Improve time tracing data (#7146)
This is a bunch of small changes to improve the quality of the time traces. This mostly adds new timers breakign down dxcompilerobj and the always inliner code.
1 parent f7f1e3d commit 4d3a2f5

6 files changed

Lines changed: 39 additions & 12 deletions

File tree

lib/DxilContainer/DxilContainerAssembler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "llvm/IR/Module.h"
3838
#include "llvm/IR/Operator.h"
3939
#include "llvm/Support/MD5.h"
40+
#include "llvm/Support/TimeProfiler.h"
4041
#include "llvm/Transforms/Utils/Cloning.h"
4142
#include <algorithm>
4243
#include <assert.h> // Needed for DxilPipelineStateValidation.h
@@ -1895,6 +1896,7 @@ void hlsl::SerializeDxilContainerForModule(
18951896
DxilShaderHash *pShaderHashOut, AbstractMemoryStream *pReflectionStreamOut,
18961897
AbstractMemoryStream *pRootSigStreamOut, void *pPrivateData,
18971898
size_t PrivateDataSize) {
1899+
llvm::TimeTraceScope TimeScope("SerializeDxilContainer", StringRef(""));
18981900
// TODO: add a flag to update the module and remove information that is not
18991901
// part of DXIL proper and is used only to assemble the container.
19001902

lib/Transforms/Utils/CloneFunction.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16-
#include "llvm/Transforms/Utils/Cloning.h"
1716
#include "llvm/ADT/SmallVector.h"
1817
#include "llvm/Analysis/ConstantFolding.h"
1918
#include "llvm/Analysis/InstructionSimplify.h"
@@ -29,7 +28,9 @@
2928
#include "llvm/IR/LLVMContext.h"
3029
#include "llvm/IR/Metadata.h"
3130
#include "llvm/IR/Module.h"
31+
#include "llvm/Support/TimeProfiler.h"
3232
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
33+
#include "llvm/Transforms/Utils/Cloning.h"
3334
#include "llvm/Transforms/Utils/Local.h"
3435
#include "llvm/Transforms/Utils/ValueMapper.h"
3536
#include <map>
@@ -473,6 +474,9 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
473474
const char *NameSuffix,
474475
ClonedCodeInfo *CodeInfo,
475476
CloningDirector *Director) {
477+
TimeTraceScope TimeScope("CloneAndPruneIntoFromInst", [&] {
478+
return (Twine(OldFunc->getName()) + "->" + NewFunc->getName()).str();
479+
});
476480
assert(NameSuffix && "NameSuffix cannot be null!");
477481

478482
ValueMapTypeRemapper *TypeMapper = nullptr;

lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#include "llvm/Transforms/Utils/Cloning.h"
15+
#include "llvm/ADT/SetVector.h"
1616
#include "llvm/ADT/SmallSet.h"
1717
#include "llvm/ADT/SmallVector.h"
18-
#include "llvm/ADT/SetVector.h"
1918
#include "llvm/ADT/StringExtras.h"
2019
#include "llvm/Analysis/AliasAnalysis.h"
2120
#include "llvm/Analysis/AssumptionCache.h"
@@ -24,22 +23,24 @@
2423
#include "llvm/Analysis/InstructionSimplify.h"
2524
#include "llvm/Analysis/ValueTracking.h"
2625
#include "llvm/IR/Attributes.h"
27-
#include "llvm/IR/CallSite.h"
2826
#include "llvm/IR/CFG.h"
27+
#include "llvm/IR/CallSite.h"
2928
#include "llvm/IR/Constants.h"
29+
#include "llvm/IR/DIBuilder.h"
3030
#include "llvm/IR/DataLayout.h"
3131
#include "llvm/IR/DebugInfo.h"
3232
#include "llvm/IR/DerivedTypes.h"
33-
#include "llvm/IR/DIBuilder.h"
3433
#include "llvm/IR/Dominators.h"
3534
#include "llvm/IR/IRBuilder.h"
3635
#include "llvm/IR/Instructions.h"
3736
#include "llvm/IR/IntrinsicInst.h"
3837
#include "llvm/IR/Intrinsics.h"
3938
#include "llvm/IR/MDBuilder.h"
4039
#include "llvm/IR/Module.h"
41-
#include "llvm/Transforms/Utils/Local.h"
4240
#include "llvm/Support/CommandLine.h"
41+
#include "llvm/Support/TimeProfiler.h"
42+
#include "llvm/Transforms/Utils/Cloning.h"
43+
#include "llvm/Transforms/Utils/Local.h"
4344
#include <algorithm>
4445
using namespace llvm;
4546

@@ -291,6 +292,8 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
291292
/// non-aliasing property communicated by the metadata could have
292293
/// call-site-specific control dependencies).
293294
static void CloneAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap) {
295+
TimeTraceScope TimeScope("CloneAliasScopeMetadata",
296+
[&] { return CS.getCalledFunction()->getName(); });
294297
const Function *CalledFunc = CS.getCalledFunction();
295298
SetVector<const MDNode *> MD;
296299

@@ -401,6 +404,8 @@ static void CloneAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap) {
401404
/// non-derived loads, stores and memory intrinsics with the new alias scopes.
402405
static void AddAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap,
403406
const DataLayout &DL, AliasAnalysis *AA) {
407+
TimeTraceScope TimeScope("AddAliasScopeMetadata",
408+
[&] { return CS.getCalledFunction()->getName(); });
404409
if (!EnableNoAliasConversion)
405410
return;
406411

@@ -872,6 +877,7 @@ updateInlinedAtInfo(DebugLoc DL, DILocation *InlinedAtNode, LLVMContext &Ctx,
872877
/// to encode location where these instructions are inlined.
873878
static void fixupLineNumbers(Function *Fn, Function::iterator FI,
874879
Instruction *TheCall) {
880+
TimeTraceScope TimeScope("fixupLineNumbers", [&] { return Fn->getName(); });
875881
DebugLoc TheCallDL = TheCall->getDebugLoc();
876882
#if 0 // HLSL Change
877883
if (!TheCallDL)

tools/clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,6 +3376,12 @@ void CodeGenModule::EmitLinkageSpec(const LinkageSpecDecl *LSD) {
33763376

33773377
/// EmitTopLevelDecl - Emit code for a single top level declaration.
33783378
void CodeGenModule::EmitTopLevelDecl(Decl *D) {
3379+
llvm::TimeTraceScope TimeScope("CGM::EmitTopLevelDecl", [&] {
3380+
if (const auto *ND = dyn_cast<NamedDecl>(D))
3381+
return ND->getName();
3382+
return StringRef("Unnamed decl");
3383+
});
3384+
33793385
// Ignore dependent declarations.
33803386
if (D->getDeclContext() && D->getDeclContext()->isDependentContext())
33813387
return;

tools/clang/lib/Parse/ParseAST.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
100100

101101
void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) {
102102

103-
// HLSL Change - Support hierarchial time tracing.
104-
llvm::TimeTraceScope TimeScope("Frontend", StringRef(""));
105103
// Collect global stats on Decls/Stmts (until we have a module streamer).
106104
if (PrintStats) {
107105
Decl::EnableStatistics();
@@ -137,6 +135,8 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) {
137135
External->StartTranslationUnit(Consumer);
138136

139137
if (!S.getDiagnostics().hasUnrecoverableErrorOccurred()) { // HLSL Change: Skip if fatal error already occurred
138+
// HLSL Change - Support hierarchial time tracing.
139+
llvm::TimeTraceScope TimeScope("Frontend", StringRef(""));
140140
if (P.ParseTopLevelDecl(ADecl)) {
141141
if (!External && !S.getLangOpts().CPlusPlus)
142142
P.Diag(diag::ext_empty_translation_unit);
@@ -151,10 +151,14 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) {
151151
}
152152
} // HLSL Change: Skip if fatal error already occurred
153153

154-
// Process any TopLevelDecls generated by #pragma weak.
155-
for (Decl *D : S.WeakTopLevelDecls())
156-
Consumer->HandleTopLevelDecl(DeclGroupRef(D));
157-
154+
{
155+
// HLSL Change - Support hierarchial time tracing.
156+
llvm::TimeTraceScope TimeScope("Frontend - Consumer", StringRef(""));
157+
// Process any TopLevelDecls generated by #pragma weak.
158+
for (Decl *D : S.WeakTopLevelDecls())
159+
Consumer->HandleTopLevelDecl(DeclGroupRef(D));
160+
}
161+
158162
// HLSL Change Starts
159163
// Provide the opportunity to generate translation-unit level validation
160164
// errors in the front-end, without relying on code generation being

tools/clang/tools/dxcompiler/dxcompilerobj.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ class DxcCompiler : public IDxcCompiler3,
722722
bool validateRootSigContainer = false;
723723

724724
if (isPreprocessing) {
725+
TimeTraceScope TimeScope("PreprocessAction", StringRef(""));
725726
// These settings are back-compatible with fxc.
726727
clang::PreprocessorOutputOptions &PPOutOpts =
727728
compiler.getPreprocessorOutputOpts();
@@ -867,6 +868,7 @@ class DxcCompiler : public IDxcCompiler3,
867868
compiler.getTarget().adjust(compiler.getLangOpts());
868869

869870
if (opts.AstDump) {
871+
TimeTraceScope TimeScope("DumpAST", StringRef(""));
870872
clang::ASTDumpAction dumpAction;
871873
// Consider - ASTDumpFilter, ASTDumpLookups
872874
compiler.getFrontendOpts().ASTDumpDecls = true;
@@ -876,6 +878,7 @@ class DxcCompiler : public IDxcCompiler3,
876878
dumpAction.EndSourceFile();
877879
outStream.flush();
878880
} else if (opts.DumpDependencies) {
881+
TimeTraceScope TimeScope("DumpDependencies", StringRef(""));
879882
auto dependencyCollector = std::make_shared<DependencyCollector>();
880883
compiler.addDependencyCollector(dependencyCollector);
881884
compiler.createPreprocessor(clang::TranslationUnitKind::TU_Complete);
@@ -978,6 +981,7 @@ class DxcCompiler : public IDxcCompiler3,
978981
EmitBCAction action(&llvmContext);
979982
FrontendInputFile file(pUtf8SourceName, IK_HLSL);
980983
bool compileOK;
984+
TimeTraceScope TimeScope("Compile Action", StringRef(""));
981985
if (action.BeginSourceFile(compiler, file)) {
982986
action.Execute();
983987
action.EndSourceFile();
@@ -1032,6 +1036,7 @@ class DxcCompiler : public IDxcCompiler3,
10321036
// Do not create a container when there is only a a high-level
10331037
// representation in the module.
10341038
if (compileOK && !opts.CodeGenHighLevel) {
1039+
TimeTraceScope TimeScope("AssembleAndWriteContainer", StringRef(""));
10351040
HRESULT valHR = S_OK;
10361041
CComPtr<AbstractMemoryStream> pRootSigStream;
10371042
IFT(CreateMemoryStream(DxcGetThreadMallocNoRef(),

0 commit comments

Comments
 (0)