Skip to content

Commit eb1bb4e

Browse files
author
Devang Patel
committed
Until now all debug info MDNodes referred to a root MDNode, a compile unit. This simplified handling of these needs in dwarf writer. However, one side effect of this is that during link time optimization all these MDNodes are _not_ uniqued. In other words there will be N number of MDNodes describing "int", "char" and all other types, which would suddenly grow when each object file starts using libraries like STL.
MDNodes graph structure such that compiler unit keeps track of important MDNodes and update dwarf writer to process mdnodes top-down instead of bottom up. llvm-svn: 137778
1 parent 0793eb4 commit eb1bb4e

File tree

9 files changed

+249
-179
lines changed

9 files changed

+249
-179
lines changed

llvm/docs/SourceLevelDebugging.html

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ <h4>
355355
;; (DW_TAG_file_type)
356356
metadata, ;; Source file name
357357
metadata, ;; Source file directory (includes trailing slash)
358-
metadata ;; Reference to compile unit where defined
358+
metadata ;; Unused
359359
}
360360
</pre>
361361
</div>
@@ -365,8 +365,7 @@ <h4>
365365
provide context for source line correspondence. </p>
366366

367367
<p>Each input file is encoded as a separate file descriptor in LLVM debugging
368-
information output. Each file descriptor would be defined using a
369-
compile unit. </p>
368+
information output. </p>
370369

371370
</div>
372371

@@ -485,7 +484,7 @@ <h4>
485484
!4 = metadata !{
486485
i32, ;; Tag = 36 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
487486
;; (DW_TAG_base_type)
488-
metadata, ;; Reference to context (typically a compile unit)
487+
metadata, ;; Reference to context
489488
metadata, ;; Name (may be "" for anonymous types)
490489
metadata, ;; Reference to file where defined (may be NULL)
491490
i32, ;; Line number where defined (may be 0)
@@ -500,7 +499,7 @@ <h4>
500499

501500
<p>These descriptors define primitive types used in the code. Example int, bool
502501
and float. The context provides the scope of the type, which is usually the
503-
top level. Since basic types are not usually user defined the compile unit
502+
top level. Since basic types are not usually user defined the context
504503
and line number can be left as NULL and 0. The size, alignment and offset
505504
are expressed in bits and can be 64 bit values. The alignment is used to
506505
round the offset when embedded in a
@@ -585,7 +584,7 @@ <h4>
585584
the <a href="#format_derived_type">derived type</a>. </p>
586585

587586
<p><a href="#format_derived_type">Derived type</a> location can be determined
588-
from the compile unit and line number. The size, alignment and offset are
587+
from the context and line number. The size, alignment and offset are
589588
expressed in bits and can be 64 bit values. The alignment is used to round
590589
the offset when embedded in a <a href="#format_composite_type">composite
591590
type</a> (example to keep float doubles on 64 bit boundaries.) The offset is
@@ -675,7 +674,7 @@ <h4>
675674
the formal arguments to the subroutine.</p>
676675

677676
<p><a href="#format_composite_type">Composite type</a> location can be
678-
determined from the compile unit and line number. The size, alignment and
677+
determined from the context and line number. The size, alignment and
679678
offset are expressed in bits and can be 64 bit values. The alignment is used
680679
to round the offset when embedded in
681680
a <a href="#format_composite_type">composite type</a> (as an example, to keep
@@ -774,7 +773,7 @@ <h4>
774773
has no source correspondent.</p>
775774

776775
<p>The context is either the subprogram or block where the variable is defined.
777-
Name the source variable name. Compile unit and line indicate where the
776+
Name the source variable name. Context and line indicate where the
778777
variable was defined. Type descriptor defines the declared type of the
779778
variable.</p>
780779

llvm/include/llvm/Analysis/DIBuilder.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,19 @@ namespace llvm {
4848
LLVMContext & VMContext;
4949
MDNode *TheCU;
5050

51+
MDNode *TempEnumTypes;
52+
MDNode *TempRetainTypes;
53+
MDNode *TempSubprograms;
54+
MDNode *TempGVs;
55+
5156
Function *DeclareFn; // llvm.dbg.declare
5257
Function *ValueFn; // llvm.dbg.value
5358

59+
SmallVector<Value *, 4> AllEnumTypes;
60+
SmallVector<Value *, 4> AllRetainTypes;
61+
SmallVector<Value *, 4> AllSubprograms;
62+
SmallVector<Value *, 4> AllGVs;
63+
5464
DIBuilder(const DIBuilder &); // DO NOT IMPLEMENT
5565
void operator=(const DIBuilder &); // DO NOT IMPLEMENT
5666

llvm/include/llvm/Analysis/DebugInfo.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ namespace llvm {
182182
StringRef getFlags() const { return getStringField(8); }
183183
unsigned getRunTimeVersion() const { return getUnsignedField(9); }
184184

185+
DIArray getEnumTypes() const;
186+
DIArray getRetainedTypes() const;
187+
DIArray getSubprograms() const;
188+
DIArray getGlobalVariables() const;
189+
185190
/// Verify - Verify that a compile unit is well formed.
186191
bool Verify() const;
187192

@@ -201,7 +206,10 @@ namespace llvm {
201206
}
202207
StringRef getFilename() const { return getStringField(1); }
203208
StringRef getDirectory() const { return getStringField(2); }
204-
DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
209+
DICompileUnit getCompileUnit() const{
210+
assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
211+
return getFieldAs<DICompileUnit>(3);
212+
}
205213
};
206214

207215
/// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
@@ -237,6 +245,7 @@ namespace llvm {
237245
DIScope getContext() const { return getFieldAs<DIScope>(1); }
238246
StringRef getName() const { return getStringField(2); }
239247
DICompileUnit getCompileUnit() const{
248+
assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
240249
if (getVersion() == llvm::LLVMDebugVersion7)
241250
return getFieldAs<DICompileUnit>(3);
242251

@@ -450,6 +459,7 @@ namespace llvm {
450459
StringRef getDisplayName() const { return getStringField(4); }
451460
StringRef getLinkageName() const { return getStringField(5); }
452461
DICompileUnit getCompileUnit() const{
462+
assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
453463
if (getVersion() == llvm::LLVMDebugVersion7)
454464
return getFieldAs<DICompileUnit>(6);
455465

@@ -560,6 +570,7 @@ namespace llvm {
560570
StringRef getDisplayName() const { return getStringField(4); }
561571
StringRef getLinkageName() const { return getStringField(5); }
562572
DICompileUnit getCompileUnit() const{
573+
assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
563574
if (getVersion() == llvm::LLVMDebugVersion7)
564575
return getFieldAs<DICompileUnit>(6);
565576

@@ -595,6 +606,7 @@ namespace llvm {
595606
DIScope getContext() const { return getFieldAs<DIScope>(1); }
596607
StringRef getName() const { return getStringField(2); }
597608
DICompileUnit getCompileUnit() const{
609+
assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
598610
if (getVersion() == llvm::LLVMDebugVersion7)
599611
return getFieldAs<DICompileUnit>(3);
600612

@@ -687,6 +699,7 @@ namespace llvm {
687699
return getFieldAs<DIFile>(3).getFilename();
688700
}
689701
DICompileUnit getCompileUnit() const{
702+
assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
690703
if (getVersion() == llvm::LLVMDebugVersion7)
691704
return getFieldAs<DICompileUnit>(3);
692705

0 commit comments

Comments
 (0)