Skip to content

Commit b384d6d

Browse files
authored
[CodeGen] Don't include CGDebugInfo.h in CodeGenFunction.h (NFC) (llvm#134100)
This is an expensive header, only include it where needed. Move some functions out of line to achieve that. This reduces time to build clang by ~0.5% in terms of instructions retired.
1 parent a19c018 commit b384d6d

19 files changed

+53
-29
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ABIInfo.h"
1515
#include "CGCUDARuntime.h"
1616
#include "CGCXXABI.h"
17+
#include "CGDebugInfo.h"
1718
#include "CGObjCRuntime.h"
1819
#include "CGOpenCLRuntime.h"
1920
#include "CGRecordLayout.h"

clang/lib/CodeGen/CGCall.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "CGBlocks.h"
1818
#include "CGCXXABI.h"
1919
#include "CGCleanup.h"
20+
#include "CGDebugInfo.h"
2021
#include "CGRecordLayout.h"
2122
#include "CodeGenFunction.h"
2223
#include "CodeGenModule.h"

clang/lib/CodeGen/CGCoroutine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "CGCleanup.h"
14+
#include "CGDebugInfo.h"
1415
#include "CodeGenFunction.h"
15-
#include "llvm/ADT/ScopeExit.h"
1616
#include "clang/AST/StmtCXX.h"
1717
#include "clang/AST/StmtVisitor.h"
18+
#include "llvm/ADT/ScopeExit.h"
1819

1920
using namespace clang;
2021
using namespace CodeGen;

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6223,3 +6223,23 @@ CGDebugInfo::createConstantValueExpression(const clang::ValueDecl *VD,
62236223

62246224
return nullptr;
62256225
}
6226+
6227+
CodeGenFunction::LexicalScope::LexicalScope(CodeGenFunction &CGF,
6228+
SourceRange Range)
6229+
: RunCleanupsScope(CGF), Range(Range), ParentScope(CGF.CurLexicalScope) {
6230+
CGF.CurLexicalScope = this;
6231+
if (CGDebugInfo *DI = CGF.getDebugInfo())
6232+
DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin());
6233+
}
6234+
6235+
CodeGenFunction::LexicalScope::~LexicalScope() {
6236+
if (CGDebugInfo *DI = CGF.getDebugInfo())
6237+
DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd());
6238+
6239+
// If we should perform a cleanup, force them now. Note that
6240+
// this ends the cleanup scope before rescoping any labels.
6241+
if (PerformCleanup) {
6242+
ApplyDebugLocation DL(CGF, Range.getEnd());
6243+
ForceCleanup();
6244+
}
6245+
}

clang/lib/CodeGen/CGDeclCXX.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "CGCXXABI.h"
14+
#include "CGDebugInfo.h"
1415
#include "CGHLSLRuntime.h"
1516
#include "CGObjCRuntime.h"
1617
#include "CGOpenMPRuntime.h"

clang/lib/CodeGen/CGException.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "CGCXXABI.h"
1414
#include "CGCleanup.h"
15+
#include "CGDebugInfo.h"
1516
#include "CGObjCRuntime.h"
1617
#include "CodeGenFunction.h"
1718
#include "ConstantEmitter.h"

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "CGCXXABI.h"
14+
#include "CGDebugInfo.h"
1415
#include "CGHLSLRuntime.h"
1516
#include "CGObjCRuntime.h"
1617
#include "CGRecordLayout.h"

clang/lib/CodeGen/CGExprComplex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "CGDebugInfo.h"
1314
#include "CGOpenMPRuntime.h"
1415
#include "CodeGenFunction.h"
1516
#include "CodeGenModule.h"

clang/lib/CodeGen/CGNonTrivialStruct.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "CGDebugInfo.h"
1415
#include "CodeGenFunction.h"
1516
#include "CodeGenModule.h"
1617
#include "clang/AST/NonTrivialTypeVisitor.h"

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ABIInfoImpl.h"
1515
#include "CGCXXABI.h"
1616
#include "CGCleanup.h"
17+
#include "CGDebugInfo.h"
1718
#include "CGRecordLayout.h"
1819
#include "CodeGenFunction.h"
1920
#include "TargetInfo.h"

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "CGOpenMPRuntimeGPU.h"
15+
#include "CGDebugInfo.h"
1516
#include "CodeGenFunction.h"
1617
#include "clang/AST/Attr.h"
1718
#include "clang/AST/DeclOpenMP.h"

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "CGCleanup.h"
14+
#include "CGDebugInfo.h"
1415
#include "CGOpenMPRuntime.h"
1516
#include "CodeGenFunction.h"
1617
#include "CodeGenModule.h"

clang/lib/CodeGen/CGVTables.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "CGCXXABI.h"
14+
#include "CGDebugInfo.h"
1415
#include "CodeGenFunction.h"
1516
#include "CodeGenModule.h"
1617
#include "clang/AST/Attr.h"

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define LLVM_CLANG_LIB_CODEGEN_CODEGENFUNCTION_H
1515

1616
#include "CGBuilder.h"
17-
#include "CGDebugInfo.h"
1817
#include "CGLoopInfo.h"
1918
#include "CGValue.h"
2019
#include "CodeGenModule.h"
@@ -48,6 +47,7 @@
4847

4948
namespace llvm {
5049
class BasicBlock;
50+
class ConvergenceControlInst;
5151
class LLVMContext;
5252
class MDNode;
5353
class SwitchInst;
@@ -1105,13 +1105,7 @@ class CodeGenFunction : public CodeGenTypeCache {
11051105

11061106
public:
11071107
/// Enter a new cleanup scope.
1108-
explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range)
1109-
: RunCleanupsScope(CGF), Range(Range),
1110-
ParentScope(CGF.CurLexicalScope) {
1111-
CGF.CurLexicalScope = this;
1112-
if (CGDebugInfo *DI = CGF.getDebugInfo())
1113-
DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin());
1114-
}
1108+
explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range);
11151109

11161110
void addLabel(const LabelDecl *label) {
11171111
assert(PerformCleanup && "adding label to dead scope?");
@@ -1120,17 +1114,7 @@ class CodeGenFunction : public CodeGenTypeCache {
11201114

11211115
/// Exit this cleanup scope, emitting any accumulated
11221116
/// cleanups.
1123-
~LexicalScope() {
1124-
if (CGDebugInfo *DI = CGF.getDebugInfo())
1125-
DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd());
1126-
1127-
// If we should perform a cleanup, force them now. Note that
1128-
// this ends the cleanup scope before rescoping any labels.
1129-
if (PerformCleanup) {
1130-
ApplyDebugLocation DL(CGF, Range.getEnd());
1131-
ForceCleanup();
1132-
}
1133-
}
1117+
~LexicalScope();
11341118

11351119
/// Force the emission of cleanups now, instead of waiting
11361120
/// until this object is destroyed.
@@ -1691,15 +1675,7 @@ class CodeGenFunction : public CodeGenTypeCache {
16911675

16921676
/// Increment the profiler's counter for the given statement by \p StepV.
16931677
/// If \p StepV is null, the default increment is 1.
1694-
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) {
1695-
if (CGM.getCodeGenOpts().hasProfileClangInstr() &&
1696-
!CurFn->hasFnAttribute(llvm::Attribute::NoProfile) &&
1697-
!CurFn->hasFnAttribute(llvm::Attribute::SkipProfile)) {
1698-
auto AL = ApplyDebugLocation::CreateArtificial(*this);
1699-
PGO.emitCounterSetOrIncrement(Builder, S, StepV);
1700-
}
1701-
PGO.setCurrentStmt(S);
1702-
}
1678+
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr);
17031679

17041680
bool isMCDCCoverageEnabled() const {
17051681
return (CGM.getCodeGenOpts().hasProfileClangInstr() &&

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "CodeGenPGO.h"
14+
#include "CGDebugInfo.h"
1415
#include "CodeGenFunction.h"
1516
#include "CoverageMappingGen.h"
1617
#include "clang/AST/RecursiveASTVisitor.h"
@@ -1512,3 +1513,14 @@ CodeGenFunction::createProfileWeightsForLoop(const Stmt *Cond,
15121513
return createProfileWeights(LoopCount,
15131514
std::max(*CondCount, LoopCount) - LoopCount);
15141515
}
1516+
1517+
void CodeGenFunction::incrementProfileCounter(const Stmt *S,
1518+
llvm::Value *StepV) {
1519+
if (CGM.getCodeGenOpts().hasProfileClangInstr() &&
1520+
!CurFn->hasFnAttribute(llvm::Attribute::NoProfile) &&
1521+
!CurFn->hasFnAttribute(llvm::Attribute::SkipProfile)) {
1522+
auto AL = ApplyDebugLocation::CreateArtificial(*this);
1523+
PGO.emitCounterSetOrIncrement(Builder, S, StepV);
1524+
}
1525+
PGO.setCurrentStmt(S);
1526+
}

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "CodeGenTypes.h"
1414
#include "CGCXXABI.h"
1515
#include "CGCall.h"
16+
#include "CGDebugInfo.h"
1617
#include "CGHLSLRuntime.h"
1718
#include "CGOpenCLRuntime.h"
1819
#include "CGRecordLayout.h"

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "CGCXXABI.h"
2121
#include "CGCleanup.h"
22+
#include "CGDebugInfo.h"
2223
#include "CGRecordLayout.h"
2324
#include "CGVTables.h"
2425
#include "CodeGenFunction.h"

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "ABIInfo.h"
1717
#include "CGCXXABI.h"
1818
#include "CGCleanup.h"
19+
#include "CGDebugInfo.h"
1920
#include "CGVTables.h"
2021
#include "CodeGenModule.h"
2122
#include "CodeGenTypes.h"

clang/lib/CodeGen/TargetBuiltins/ARM.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "ABIInfo.h"
1414
#include "CGBuiltin.h"
15+
#include "CGDebugInfo.h"
1516
#include "TargetInfo.h"
1617
#include "clang/Basic/TargetBuiltins.h"
1718
#include "llvm/IR/InlineAsm.h"

0 commit comments

Comments
 (0)