Use DILexicalBlockFile, rather than DILexicalBlock, to track discriminator changes to ensure discriminator changes don't introduce new DWARF DW_TAG_lexical_blocks.

Somewhat unnoticed in the original implementation of discriminators, but
it could cause instructions to end up in new, small,
DW_TAG_lexical_blocks due to the use of DILexicalBlock to track
discriminator changes.

Instead, use DILexicalBlockFile which we already use to track file
changes without introducing new scopes, so it works well to track
discriminator changes in the same way.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216239 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2014-08-21 22:45:21 +00:00
parent d1a09c47d2
commit c7260209a8
16 changed files with 47 additions and 52 deletions

View File

@ -320,7 +320,6 @@ Block descriptors
metadata, ;; Reference to context descriptor
i32, ;; Line number
i32, ;; Column number
i32, ;; DWARF path discriminator value
i32 ;; Unique ID to identify blocks from a template function
}
@ -334,6 +333,7 @@ lexical blocks at same depth.
i32, ;; Tag = 11 (DW_TAG_lexical_block)
metadata, ;; Source directory (including trailing slash) & file pair
metadata ;; Reference to the scope we're annotating with a file change
i32, ;; DWARF path discriminator value
}
This descriptor provides a wrapper around a lexical scope to handle file
@ -733,8 +733,7 @@ Compiled to LLVM, this function would be represented like this:
!15 = metadata !{i32 786688, metadata !16, metadata !"Z", metadata !5, i32 5,
metadata !11, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [Z] \
[line 5]
!16 = metadata !{i32 786443, metadata !1, metadata !4, i32 4, i32 0, i32 0,
i32 0} \
!16 = metadata !{i32 786443, metadata !1, metadata !4, i32 4, i32 0, i32 0} \
; [ DW_TAG_lexical_block ] [/private/tmp/t.c]
!17 = metadata !{i32 5, i32 0, metadata !16, null}
!18 = metadata !{i32 6, i32 0, metadata !16, null}
@ -786,8 +785,7 @@ scope information for the variable ``Z``.
.. code-block:: llvm
!16 = metadata !{i32 786443, metadata !1, metadata !4, i32 4, i32 0, i32 0,
i32 0}
!16 = metadata !{i32 786443, metadata !1, metadata !4, i32 4, i32 0, i32 0} \
; [ DW_TAG_lexical_block ] [/private/tmp/t.c]
!17 = metadata !{i32 5, i32 0, metadata !16, null}

View File

@ -659,8 +659,9 @@ namespace llvm {
/// lexical block as it crosses a file.
/// @param Scope Lexical block.
/// @param File Source file.
DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
DIFile File);
/// @param Discriminator DWARF path discriminator value.
DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope, DIFile File,
unsigned Discriminator = 0);
/// createLexicalBlock - This creates a descriptor for a lexical block
/// with the specified parent context.
@ -668,10 +669,8 @@ namespace llvm {
/// @param File Source file.
/// @param Line Line number.
/// @param Col Column number.
/// @param Discriminator DWARF path discriminator value.
DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
unsigned Line, unsigned Col,
unsigned Discriminator);
unsigned Line, unsigned Col);
/// \brief Create a descriptor for an imported module.
/// @param Context The scope this module is imported into

View File

@ -560,7 +560,6 @@ public:
DIScope getContext() const { return getFieldAs<DIScope>(2); }
unsigned getLineNumber() const { return getUnsignedField(3); }
unsigned getColumnNumber() const { return getUnsignedField(4); }
unsigned getDiscriminator() const { return getUnsignedField(5); }
bool Verify() const;
};
@ -577,6 +576,7 @@ public:
unsigned getLineNumber() const { return getScope().getLineNumber(); }
unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
unsigned getDiscriminator() const { return getUnsignedField(3); }
bool Verify() const;
};
@ -767,12 +767,12 @@ public:
// Since discriminators are associated with lexical blocks, make
// sure this location is a lexical block before retrieving its
// value.
return getScope().isLexicalBlock()
? getFieldAs<DILexicalBlock>(2).getDiscriminator()
return getScope().isLexicalBlockFile()
? getFieldAs<DILexicalBlockFile>(2).getDiscriminator()
: 0;
}
unsigned computeNewDiscriminator(LLVMContext &Ctx);
DILocation copyWithNewScope(LLVMContext &Ctx, DILexicalBlock NewScope);
DILocation copyWithNewScope(LLVMContext &Ctx, DILexicalBlockFile NewScope);
};
class DIObjCProperty : public DIDescriptor {

View File

@ -1722,8 +1722,8 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
assert(Scope.isScope());
Fn = Scope.getFilename();
Dir = Scope.getDirectory();
if (Scope.isLexicalBlock())
Discriminator = DILexicalBlock(S).getDiscriminator();
if (Scope.isLexicalBlockFile())
Discriminator = DILexicalBlockFile(S).getDiscriminator();
unsigned CUID = Asm->OutStreamer.getContext().getDwarfCompileUnitID();
Src = static_cast<DwarfCompileUnit &>(*InfoHolder.getUnits()[CUID])

View File

@ -1249,11 +1249,13 @@ DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
/// createLexicalBlockFile - This creates a new MDNode that encapsulates
/// an existing scope with a new filename.
DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
DIFile File) {
DIFile File,
unsigned Discriminator) {
Value *Elts[] = {
GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
File.getFileNode(),
Scope
Scope,
ConstantInt::get(Type::getInt32Ty(VMContext), Discriminator),
};
DILexicalBlockFile R(MDNode::get(VMContext, Elts));
assert(
@ -1263,8 +1265,7 @@ DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
}
DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
unsigned Line, unsigned Col,
unsigned Discriminator) {
unsigned Line, unsigned Col) {
// FIXME: This isn't thread safe nor the right way to defeat MDNode uniquing.
// I believe the right way is to have a self-referential element in the node.
// Also: why do we bother with line/column - they're not used and the
@ -1280,7 +1281,6 @@ DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
getNonCompileUnitScope(Scope),
ConstantInt::get(Type::getInt32Ty(VMContext), Line),
ConstantInt::get(Type::getInt32Ty(VMContext), Col),
ConstantInt::get(Type::getInt32Ty(VMContext), Discriminator),
ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
};
DILexicalBlock R(MDNode::get(VMContext, Elts));

View File

@ -326,7 +326,7 @@ bool DIDescriptor::isNameSpace() const {
/// lexical block with an extra file.
bool DIDescriptor::isLexicalBlockFile() const {
return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
(DbgNode->getNumOperands() == 3);
(DbgNode->getNumOperands() == 4);
}
/// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
@ -638,12 +638,12 @@ bool DISubrange::Verify() const {
/// \brief Verify that the lexical block descriptor is well formed.
bool DILexicalBlock::Verify() const {
return isLexicalBlock() && DbgNode->getNumOperands() == 7;
return isLexicalBlock() && DbgNode->getNumOperands() == 6;
}
/// \brief Verify that the file-scoped lexical block descriptor is well formed.
bool DILexicalBlockFile::Verify() const {
return isLexicalBlockFile() && DbgNode->getNumOperands() == 3;
return isLexicalBlockFile() && DbgNode->getNumOperands() == 4;
}
/// \brief Verify that the template type parameter descriptor is well formed.
@ -851,7 +851,7 @@ DIArray DICompileUnit::getImportedEntities() const {
/// copyWithNewScope - Return a copy of this location, replacing the
/// current scope with the given one.
DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
DILexicalBlock NewScope) {
DILexicalBlockFile NewScope) {
SmallVector<Value *, 10> Elts;
assert(Verify());
for (unsigned I = 0; I < DbgNode->getNumOperands(); ++I) {

View File

@ -193,13 +193,11 @@ bool AddDiscriminators::runOnFunction(Function &F) {
// Create a new lexical scope and compute a new discriminator
// number for it.
StringRef Filename = FirstDIL.getFilename();
unsigned LineNumber = FirstDIL.getLineNumber();
unsigned ColumnNumber = FirstDIL.getColumnNumber();
DIScope Scope = FirstDIL.getScope();
DIFile File = Builder.createFile(Filename, Scope.getDirectory());
unsigned Discriminator = FirstDIL.computeNewDiscriminator(Ctx);
DILexicalBlock NewScope = Builder.createLexicalBlock(
Scope, File, LineNumber, ColumnNumber, Discriminator);
DILexicalBlockFile NewScope =
Builder.createLexicalBlockFile(Scope, File, Discriminator);
DILocation NewDIL = FirstDIL.copyWithNewScope(Ctx, NewScope);
DebugLoc newDebugLoc = DebugLoc::getFromDILocation(NewDIL);

View File

@ -248,10 +248,10 @@ attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "
!10 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
!11 = metadata !{metadata !"clang version 3.5 "}
!12 = metadata !{i32 1, i32 0, metadata !13, null}
!13 = metadata !{i32 786443, metadata !14, metadata !4} ; [ DW_TAG_lexical_block ] [D:\/one.c]
!13 = metadata !{i32 786443, metadata !14, metadata !4, i32 0} ; [ DW_TAG_lexical_block ] [D:\/one.c]
!14 = metadata !{metadata !"one.c", metadata !"D:\5C"}
!15 = metadata !{i32 2, i32 0, metadata !16, null}
!16 = metadata !{i32 786443, metadata !17, metadata !4} ; [ DW_TAG_lexical_block ] [D:\/two.c]
!16 = metadata !{i32 786443, metadata !17, metadata !4, i32 0} ; [ DW_TAG_lexical_block ] [D:\/two.c]
!17 = metadata !{metadata !"two.c", metadata !"D:\5C"}
!18 = metadata !{i32 7, i32 0, metadata !13, null}
!19 = metadata !{i32 8, i32 0, metadata !13, null} ; [ DW_TAG_imported_declaration ]

View File

@ -52,11 +52,11 @@ attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointe
!8 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
!9 = metadata !{metadata !"clang version 3.5 "}
!10 = metadata !{i32 2, i32 0, metadata !11, null}
!11 = metadata !{i32 786443, metadata !1, metadata !4, i32 2, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [./discriminator.c]
!11 = metadata !{i32 786443, metadata !1, metadata !4, i32 2, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [./discriminator.c]
!12 = metadata !{i32 3, i32 0, metadata !4, null}
!13 = metadata !{i32 4, i32 0, metadata !4, null}
!14 = metadata !{i32 2, i32 0, metadata !15, null}
!15 = metadata !{i32 786443, metadata !1, metadata !4, i32 2, i32 0, i32 42, i32 1} ; [ DW_TAG_lexical_block ] [./discriminator.c]
!15 = metadata !{i32 786443, metadata !1, metadata !4, i32 42} ; [ DW_TAG_lexical_block ] [./discriminator.c]
; CHECK: Address Line Column File ISA Discriminator Flags
; CHECK: ------------------ ------ ------ ------ --- ------------- -------------

View File

@ -112,7 +112,7 @@ attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "n
!14 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
!15 = metadata !{metadata !"clang version 3.5.0 "}
!16 = metadata !{i32 786688, metadata !17, metadata !"b", metadata !11, i32 3, metadata !18, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [b] [line 3]
!17 = metadata !{i32 786443, metadata !1, metadata !12, i32 3, i32 0, i32 0, i32 1} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/inline-scopes.cpp]
!17 = metadata !{i32 786443, metadata !1, metadata !12, i32 3, i32 0, i32 1} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/inline-scopes.cpp]
!18 = metadata !{i32 786468, null, null, metadata !"bool", i32 0, i64 8, i64 8, i64 0, i32 0, i32 2} ; [ DW_TAG_base_type ] [bool] [line 0, size 8, align 8, offset 0, enc DW_ATE_boolean]
!19 = metadata !{i32 3, i32 0, metadata !17, metadata !20}
!20 = metadata !{i32 8, i32 0, metadata !4, null} ; [ DW_TAG_imported_declaration ]
@ -120,8 +120,8 @@ attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "n
!22 = metadata !{i32 5, i32 0, metadata !12, metadata !20}
!23 = metadata !{i32 6, i32 0, metadata !12, metadata !20}
!24 = metadata !{i32 786688, metadata !25, metadata !"b", metadata !6, i32 2, metadata !18, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [b] [line 2]
!25 = metadata !{i32 786443, metadata !5, metadata !26, i32 2, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/y.cc]
!26 = metadata !{i32 786443, metadata !5, metadata !10} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/y.cc]
!25 = metadata !{i32 786443, metadata !5, metadata !26, i32 2, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/y.cc]
!26 = metadata !{i32 786443, metadata !5, metadata !10, i32 0} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/y.cc]
!27 = metadata !{i32 2, i32 0, metadata !25, metadata !28}
!28 = metadata !{i32 9, i32 0, metadata !4, null}
!29 = metadata !{i32 3, i32 0, metadata !25, metadata !28}

View File

@ -51,9 +51,9 @@ attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointe
!8 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
!9 = metadata !{metadata !"clang version 3.5 "}
!10 = metadata !{i32 3, i32 0, metadata !11, null}
!11 = metadata !{i32 786443, metadata !1, metadata !4, i32 3, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [basic.c]
!11 = metadata !{i32 786443, metadata !1, metadata !4, i32 3, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [basic.c]
!12 = metadata !{i32 4, i32 0, metadata !4, null}
; CHECK: !12 = metadata !{i32 3, i32 0, metadata !13, null}
; CHECK: !13 = metadata !{i32 786443, metadata !1, metadata !11, i32 3, i32 0, i32 1, i32 0} ; [ DW_TAG_lexical_block ] [./basic.c]
; CHECK: !13 = metadata !{i32 786443, metadata !1, metadata !11, i32 1} ; [ DW_TAG_lexical_block ] [./basic.c]
; CHECK: !14 = metadata !{i32 4, i32 0, metadata !4, null}

View File

@ -68,7 +68,7 @@ attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointe
!12 = metadata !{i32 3, i32 0, metadata !13, null}
!13 = metadata !{i32 786443, metadata !1, metadata !11, i32 3, i32 0, i32 1} ; [ DW_TAG_lexical_block ] [first-only.c]
; CHECK: !13 = metadata !{i32 786443, metadata !1, metadata !14, i32 3, i32 0, i32 1, i32 0} ; [ DW_TAG_lexical_block ] [./first-only.c]
; CHECK: !13 = metadata !{i32 786443, metadata !1, metadata !14, i32 1} ; [ DW_TAG_lexical_block ] [./first-only.c]
!14 = metadata !{i32 4, i32 0, metadata !13, null}
; CHECK: !14 = metadata !{i32 786443, metadata !1, metadata !11, i32 3, i32 0, i32 1}

View File

@ -66,6 +66,6 @@ attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointe
!12 = metadata !{i32 4, i32 0, metadata !4, null}
; CHECK: !12 = metadata !{i32 3, i32 0, metadata !13, null}
; CHECK: !13 = metadata !{i32 786443, metadata !1, metadata !11, i32 3, i32 0, i32 1, i32 0} ; [ DW_TAG_lexical_block ] [./multiple.c]
; CHECK: !13 = metadata !{i32 786443, metadata !1, metadata !11, i32 1} ; [ DW_TAG_lexical_block ] [./multiple.c]
; CHECK: !14 = metadata !{i32 3, i32 0, metadata !15, null}
; CHECK: !15 = metadata !{i32 786443, metadata !1, metadata !11, i32 3, i32 0, i32 2, i32 1} ; [ DW_TAG_lexical_block ] [./multiple.c]
; CHECK: !15 = metadata !{i32 786443, metadata !1, metadata !11, i32 2} ; [ DW_TAG_lexical_block ] [./multiple.c]

View File

@ -66,6 +66,6 @@ attributes #1 = { nounwind readnone }
!14 = metadata !{i32 1, i32 0, metadata !4, null}
!15 = metadata !{i32 2, i32 0, metadata !16, null}
; CHECK: !15 = metadata !{i32 2, i32 0, metadata !16, null}
!16 = metadata !{i32 786443, metadata !1, metadata !4, i32 2, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [./no-discriminators]
; CHECK: !16 = metadata !{i32 786443, metadata !1, metadata !4, i32 2, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [./no-discriminators]
!16 = metadata !{i32 786443, metadata !1, metadata !4, i32 2, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [./no-discriminators]
; CHECK: !16 = metadata !{i32 786443, metadata !1, metadata !4, i32 2, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [./no-discriminators]
!17 = metadata !{i32 3, i32 0, metadata !4, null}

View File

@ -103,14 +103,14 @@ declare i32 @printf(i8*, ...) #2
!12 = metadata !{i32 8, i32 0, metadata !7, null} ; [ DW_TAG_imported_declaration ]
!13 = metadata !{i32 9, i32 0, metadata !7, null}
!14 = metadata !{i32 9, i32 0, metadata !15, null}
!15 = metadata !{i32 786443, metadata !1, metadata !7, i32 9, i32 0, i32 1, i32 1} ; [ DW_TAG_lexical_block ] [./calls.cc]
!15 = metadata !{i32 786443, metadata !1, metadata !7, i32 1} ; [ DW_TAG_lexical_block ] [./calls.cc]
!16 = metadata !{i32 10, i32 0, metadata !17, null}
!17 = metadata !{i32 786443, metadata !1, metadata !7, i32 10, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [./calls.cc]
!17 = metadata !{i32 786443, metadata !1, metadata !7, i32 10, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [./calls.cc]
!18 = metadata !{i32 10, i32 0, metadata !19, null}
!19 = metadata !{i32 786443, metadata !1, metadata !17, i32 10, i32 0, i32 1, i32 2} ; [ DW_TAG_lexical_block ] [./calls.cc]
!19 = metadata !{i32 786443, metadata !1, metadata !17, i32 1} ; [ DW_TAG_lexical_block ] [./calls.cc]
!20 = metadata !{i32 10, i32 0, metadata !21, null}
!21 = metadata !{i32 786443, metadata !1, metadata !17, i32 10, i32 0, i32 2, i32 3} ; [ DW_TAG_lexical_block ] [./calls.cc]
!21 = metadata !{i32 786443, metadata !1, metadata !17, i32 2} ; [ DW_TAG_lexical_block ] [./calls.cc]
!22 = metadata !{i32 10, i32 0, metadata !23, null}
!23 = metadata !{i32 786443, metadata !1, metadata !17, i32 10, i32 0, i32 3, i32 4} ; [ DW_TAG_lexical_block ] [./calls.cc]
!23 = metadata !{i32 786443, metadata !1, metadata !17, i32 3} ; [ DW_TAG_lexical_block ] [./calls.cc]
!24 = metadata !{i32 11, i32 0, metadata !7, null}
!25 = metadata !{i32 12, i32 0, metadata !7, null}

View File

@ -79,12 +79,12 @@ while.end: ; preds = %while.cond
!10 = metadata !{i32 2, i32 0, metadata !4, null}
!11 = metadata !{i32 3, i32 0, metadata !4, null}
!12 = metadata !{i32 3, i32 0, metadata !13, null}
!13 = metadata !{i32 786443, metadata !1, metadata !4, i32 3, i32 0, i32 1, i32 2} ; [ DW_TAG_lexical_block ] [discriminator.c]
!13 = metadata !{i32 786443, metadata !1, metadata !4, i32 1} ; [ DW_TAG_lexical_block ] [discriminator.c]
!14 = metadata !{i32 4, i32 0, metadata !15, null}
!15 = metadata !{i32 786443, metadata !1, metadata !16, i32 4, i32 0, i32 0, i32 1} ; [ DW_TAG_lexical_block ] [discriminator.c]
!16 = metadata !{i32 786443, metadata !1, metadata !4, i32 3, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [discriminator.c]
!15 = metadata !{i32 786443, metadata !1, metadata !16, i32 4, i32 0, i32 1} ; [ DW_TAG_lexical_block ] [discriminator.c]
!16 = metadata !{i32 786443, metadata !1, metadata !4, i32 3, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [discriminator.c]
!17 = metadata !{i32 4, i32 0, metadata !18, null}
!18 = metadata !{i32 786443, metadata !1, metadata !15, i32 4, i32 0, i32 1, i32 3} ; [ DW_TAG_lexical_block ] [discriminator.c]
!18 = metadata !{i32 786443, metadata !1, metadata !15, i32 1} ; [ DW_TAG_lexical_block ] [discriminator.c]
!19 = metadata !{i32 5, i32 0, metadata !16, null}
!20 = metadata !{i32 6, i32 0, metadata !16, null}
!21 = metadata !{i32 7, i32 0, metadata !4, null}