Skip to content

Commit cda5421

Browse files
committedNov 19, 2018
[DebugInfo] DISubprogram flags get their own flags word. NFC.
This will hold flags specific to subprograms. In the future we could potentially free up scarce bits in DIFlags by moving subprogram-specific flags from there to the new flags word. This patch does not change IR/bitcode formats, that will be done in a follow-up. Differential Revision: https://reviews.llvm.org/D54597 llvm-svn: 347239
1 parent 1c803f5 commit cda5421

17 files changed

+373
-331
lines changed
 

‎clang/lib/CodeGen/CGDebugInfo.cpp

+30-18
Original file line numberDiff line numberDiff line change
@@ -1494,16 +1494,16 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
14941494

14951495
// Collect virtual method info.
14961496
llvm::DIType *ContainingType = nullptr;
1497-
unsigned Virtuality = 0;
14981497
unsigned VIndex = 0;
14991498
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1499+
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
15001500
int ThisAdjustment = 0;
15011501

15021502
if (Method->isVirtual()) {
15031503
if (Method->isPure())
1504-
Virtuality = llvm::dwarf::DW_VIRTUALITY_pure_virtual;
1504+
SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
15051505
else
1506-
Virtuality = llvm::dwarf::DW_VIRTUALITY_virtual;
1506+
SPFlags |= llvm::DISubprogram::SPFlagVirtual;
15071507

15081508
if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
15091509
// It doesn't make sense to give a virtual destructor a vtable index,
@@ -1555,12 +1555,13 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
15551555
Flags |= llvm::DINode::FlagLValueReference;
15561556
if (Method->getRefQualifier() == RQ_RValue)
15571557
Flags |= llvm::DINode::FlagRValueReference;
1558+
if (CGM.getLangOpts().Optimize)
1559+
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
15581560

15591561
llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
15601562
llvm::DISubprogram *SP = DBuilder.createMethod(
15611563
RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
1562-
MethodTy, /*isLocalToUnit=*/false, /*isDefinition=*/false, Virtuality,
1563-
VIndex, ThisAdjustment, ContainingType, Flags, CGM.getLangOpts().Optimize,
1564+
MethodTy, VIndex, ThisAdjustment, ContainingType, Flags, SPFlags,
15641565
TParamsArray.get());
15651566

15661567
SPCache[Method->getCanonicalDecl()].reset(SP);
@@ -3168,6 +3169,7 @@ llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,
31683169
llvm::DINodeArray TParamsArray;
31693170
StringRef Name, LinkageName;
31703171
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3172+
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
31713173
SourceLocation Loc = GD.getDecl()->getLocation();
31723174
llvm::DIFile *Unit = getOrCreateFile(Loc);
31733175
llvm::DIScope *DContext = Unit;
@@ -3184,21 +3186,23 @@ llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,
31843186
CallingConv CC = FD->getType()->castAs<FunctionType>()->getCallConv();
31853187
QualType FnType = CGM.getContext().getFunctionType(
31863188
FD->getReturnType(), ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
3189+
if (!FD->isExternallyVisible())
3190+
SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
3191+
if (CGM.getLangOpts().Optimize)
3192+
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
3193+
31873194
if (Stub) {
31883195
Flags |= getCallSiteRelatedAttrs();
3196+
SPFlags |= llvm::DISubprogram::SPFlagDefinition;
31893197
return DBuilder.createFunction(
31903198
DContext, Name, LinkageName, Unit, Line,
3191-
getOrCreateFunctionType(GD.getDecl(), FnType, Unit),
3192-
!FD->isExternallyVisible(),
3193-
/* isDefinition = */ true, 0, Flags, CGM.getLangOpts().Optimize,
3199+
getOrCreateFunctionType(GD.getDecl(), FnType, Unit), 0, Flags, SPFlags,
31943200
TParamsArray.get(), getFunctionDeclaration(FD));
31953201
}
31963202

31973203
llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
31983204
DContext, Name, LinkageName, Unit, Line,
3199-
getOrCreateFunctionType(GD.getDecl(), FnType, Unit),
3200-
!FD->isExternallyVisible(),
3201-
/* isDefinition = */ false, 0, Flags, CGM.getLangOpts().Optimize,
3205+
getOrCreateFunctionType(GD.getDecl(), FnType, Unit), 0, Flags, SPFlags,
32023206
TParamsArray.get(), getFunctionDeclaration(FD));
32033207
const FunctionDecl *CanonDecl = FD->getCanonicalDecl();
32043208
FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
@@ -3386,6 +3390,7 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
33863390
bool HasDecl = (D != nullptr);
33873391

33883392
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3393+
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
33893394
llvm::DIFile *Unit = getOrCreateFile(Loc);
33903395
llvm::DIScope *FDContext = Unit;
33913396
llvm::DINodeArray TParamsArray;
@@ -3425,7 +3430,14 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
34253430
if (CurFuncIsThunk)
34263431
Flags |= llvm::DINode::FlagThunk;
34273432

3433+
if (Fn->hasLocalLinkage())
3434+
SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
3435+
if (CGM.getLangOpts().Optimize)
3436+
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
3437+
34283438
llvm::DINode::DIFlags FlagsForDef = Flags | getCallSiteRelatedAttrs();
3439+
llvm::DISubprogram::DISPFlags SPFlagsForDef =
3440+
SPFlags | llvm::DISubprogram::SPFlagDefinition;
34293441

34303442
unsigned LineNo = getLineNumber(Loc);
34313443
unsigned ScopeLine = getLineNumber(ScopeLoc);
@@ -3437,9 +3449,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
34373449
// are emitted as CU level entities by the backend.
34383450
llvm::DISubprogram *SP = DBuilder.createFunction(
34393451
FDContext, Name, LinkageName, Unit, LineNo,
3440-
getOrCreateFunctionType(D, FnType, Unit), Fn->hasLocalLinkage(),
3441-
true /*definition*/, ScopeLine, FlagsForDef, CGM.getLangOpts().Optimize,
3442-
TParamsArray.get(), getFunctionDeclaration(D));
3452+
getOrCreateFunctionType(D, FnType, Unit), ScopeLine, FlagsForDef,
3453+
SPFlagsForDef, TParamsArray.get(), getFunctionDeclaration(D));
34433454
Fn->setSubprogram(SP);
34443455
// We might get here with a VarDecl in the case we're generating
34453456
// code for the initialization of globals. Do not record these decls
@@ -3459,8 +3470,7 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
34593470
cast<llvm::DICompositeType>(It->second);
34603471
llvm::DISubprogram *FD = DBuilder.createFunction(
34613472
InterfaceDecl, Name, LinkageName, Unit, LineNo,
3462-
getOrCreateFunctionType(D, FnType, Unit), Fn->hasLocalLinkage(),
3463-
false /*definition*/, ScopeLine, Flags, CGM.getLangOpts().Optimize,
3473+
getOrCreateFunctionType(D, FnType, Unit), ScopeLine, Flags, SPFlags,
34643474
TParamsArray.get());
34653475
DBuilder.finalizeSubprogram(FD);
34663476
ObjCMethodCache[ID].push_back(FD);
@@ -3509,11 +3519,13 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
35093519
}
35103520
unsigned LineNo = getLineNumber(Loc);
35113521
unsigned ScopeLine = 0;
3522+
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
3523+
if (CGM.getLangOpts().Optimize)
3524+
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
35123525

35133526
DBuilder.retainType(DBuilder.createFunction(
35143527
FDContext, Name, LinkageName, Unit, LineNo,
3515-
getOrCreateFunctionType(D, FnType, Unit), false /*internalLinkage*/,
3516-
false /*definition*/, ScopeLine, Flags, CGM.getLangOpts().Optimize,
3528+
getOrCreateFunctionType(D, FnType, Unit), ScopeLine, Flags, SPFlags,
35173529
TParamsArray.get(), getFunctionDeclaration(D)));
35183530
}
35193531

‎llvm/include/llvm/IR/DIBuilder.h

+22-26
Original file line numberDiff line numberDiff line change
@@ -653,29 +653,28 @@ namespace llvm {
653653
/// \param File File where this variable is defined.
654654
/// \param LineNo Line number.
655655
/// \param Ty Function type.
656-
/// \param isLocalToUnit True if this function is not externally visible.
657-
/// \param isDefinition True if this is a function definition.
658656
/// \param ScopeLine Set to the beginning of the scope this starts
659657
/// \param Flags e.g. is this function prototyped or not.
660658
/// These flags are used to emit dwarf attributes.
661-
/// \param isOptimized True if optimization is ON.
659+
/// \param SPFlags Additional flags specific to subprograms.
662660
/// \param TParams Function template parameters.
663661
/// \param ThrownTypes Exception types this function may throw.
664-
DISubprogram *createFunction(
665-
DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
666-
unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
667-
bool isDefinition, unsigned ScopeLine,
668-
DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false,
669-
DITemplateParameterArray TParams = nullptr,
670-
DISubprogram *Decl = nullptr, DITypeArray ThrownTypes = nullptr);
662+
DISubprogram *
663+
createFunction(DIScope *Scope, StringRef Name, StringRef LinkageName,
664+
DIFile *File, unsigned LineNo, DISubroutineType *Ty,
665+
unsigned ScopeLine, DINode::DIFlags Flags = DINode::FlagZero,
666+
DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagZero,
667+
DITemplateParameterArray TParams = nullptr,
668+
DISubprogram *Decl = nullptr,
669+
DITypeArray ThrownTypes = nullptr);
671670

672671
/// Identical to createFunction,
673672
/// except that the resulting DbgNode is meant to be RAUWed.
674673
DISubprogram *createTempFunctionFwdDecl(
675674
DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
676-
unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
677-
bool isDefinition, unsigned ScopeLine,
678-
DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false,
675+
unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
676+
DINode::DIFlags Flags = DINode::FlagZero,
677+
DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagZero,
679678
DITemplateParameterArray TParams = nullptr,
680679
DISubprogram *Decl = nullptr, DITypeArray ThrownTypes = nullptr);
681680

@@ -687,10 +686,6 @@ namespace llvm {
687686
/// \param File File where this variable is defined.
688687
/// \param LineNo Line number.
689688
/// \param Ty Function type.
690-
/// \param isLocalToUnit True if this function is not externally visible..
691-
/// \param isDefinition True if this is a function definition.
692-
/// \param Virtuality Attributes describing virtualness. e.g. pure
693-
/// virtual function.
694689
/// \param VTableIndex Index no of this method in virtual table, or -1u if
695690
/// unrepresentable.
696691
/// \param ThisAdjustment
@@ -699,17 +694,18 @@ namespace llvm {
699694
/// \param VTableHolder Type that holds vtable.
700695
/// \param Flags e.g. is this function prototyped or not.
701696
/// This flags are used to emit dwarf attributes.
702-
/// \param isOptimized True if optimization is ON.
697+
/// \param SPFlags Additional flags specific to subprograms.
703698
/// \param TParams Function template parameters.
704699
/// \param ThrownTypes Exception types this function may throw.
705-
DISubprogram *createMethod(
706-
DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
707-
unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
708-
bool isDefinition, unsigned Virtuality = 0, unsigned VTableIndex = 0,
709-
int ThisAdjustment = 0, DIType *VTableHolder = nullptr,
710-
DINode::DIFlags Flags = DINode::FlagZero, bool isOptimized = false,
711-
DITemplateParameterArray TParams = nullptr,
712-
DITypeArray ThrownTypes = nullptr);
700+
DISubprogram *
701+
createMethod(DIScope *Scope, StringRef Name, StringRef LinkageName,
702+
DIFile *File, unsigned LineNo, DISubroutineType *Ty,
703+
unsigned VTableIndex = 0, int ThisAdjustment = 0,
704+
DIType *VTableHolder = nullptr,
705+
DINode::DIFlags Flags = DINode::FlagZero,
706+
DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagZero,
707+
DITemplateParameterArray TParams = nullptr,
708+
DITypeArray ThrownTypes = nullptr);
713709

714710
/// This creates new descriptor for a namespace with the specified
715711
/// parent scope.

‎llvm/include/llvm/IR/DebugInfoFlags.def

+32-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
// TODO: Add other DW-based macros.
14+
#if !(defined HANDLE_DI_FLAG || defined HANDLE_DISP_FLAG)
15+
#error "Missing macro definition of HANDLE_DI*"
16+
#endif
17+
1518
#ifndef HANDLE_DI_FLAG
16-
#error "Missing macro definition of HANDLE_DI_FLAG"
19+
#define HANDLE_DI_FLAG(ID, NAME)
1720
#endif
1821

22+
#ifndef HANDLE_DISP_FLAG
23+
#define HANDLE_DISP_FLAG(ID, NAME)
24+
#endif
25+
26+
// General flags kept in DINode.
27+
1928
HANDLE_DI_FLAG(0, Zero) // Use it as zero value.
2029
// For example: void foo(DIFlags Flags = FlagZero).
2130
HANDLE_DI_FLAG(1, Private)
@@ -64,4 +73,25 @@ HANDLE_DI_FLAG((1 << 29), Largest)
6473
#undef DI_FLAG_LARGEST_NEEDED
6574
#endif
6675

76+
// Subprogram-specific flags kept in DISubprogram.
77+
78+
// Use this as a zero/initialization value.
79+
// For example: void foo(DISPFlags Flags = SPFlagZero).
80+
HANDLE_DISP_FLAG(0, Zero)
81+
// Virtuality is a two-bit valued field.
82+
HANDLE_DISP_FLAG(0u, Nonvirtual)
83+
HANDLE_DISP_FLAG(1u, Virtual)
84+
HANDLE_DISP_FLAG(2u, PureVirtual)
85+
HANDLE_DISP_FLAG((1u << 2), LocalToUnit)
86+
HANDLE_DISP_FLAG((1u << 3), Definition)
87+
HANDLE_DISP_FLAG((1u << 4), Optimized)
88+
89+
#ifdef DISP_FLAG_LARGEST_NEEDED
90+
// Intended to be used with ADT/BitmaskEnum.h.
91+
// NOTE: Always must be equal to largest flag, check this when adding new flags.
92+
HANDLE_DISP_FLAG((1 << 4), Largest)
93+
#undef DISP_FLAG_LARGEST_NEEDED
94+
#endif
95+
6796
#undef HANDLE_DI_FLAG
97+
#undef HANDLE_DISP_FLAG

0 commit comments

Comments
 (0)
Please sign in to comment.