[llvm] r204106 - Switch the type field in DIVariable and DIGlobalVariable over to DITypeRefs.

Adrian Prantl aprantl at apple.com
Mon Mar 17 19:34:59 PDT 2014


Author: adrian
Date: Mon Mar 17 21:34:58 2014
New Revision: 204106

URL: http://llvm.org/viewvc/llvm-project?rev=204106&view=rev
Log:
Switch the type field in DIVariable and DIGlobalVariable over to DITypeRefs.
This allows us to catch more opportunities for ODR-based type uniquing
during LTO.
Paired commit with CFE which updates some testcases to verify the new
DIBuilder behavior.

Modified:
    llvm/trunk/docs/SourceLevelDebugging.rst
    llvm/trunk/include/llvm/IR/DIBuilder.h
    llvm/trunk/include/llvm/IR/DebugInfo.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/trunk/lib/IR/DIBuilder.cpp
    llvm/trunk/lib/IR/DebugInfo.cpp
    llvm/trunk/test/Linker/type-unique-odr-a.ll

Modified: llvm/trunk/docs/SourceLevelDebugging.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/SourceLevelDebugging.rst?rev=204106&r1=204105&r2=204106&view=diff
==============================================================================
--- llvm/trunk/docs/SourceLevelDebugging.rst (original)
+++ llvm/trunk/docs/SourceLevelDebugging.rst Mon Mar 17 21:34:58 2014
@@ -567,7 +567,7 @@ Local variables
     metadata, ;; Reference to file where defined
     i32,      ;; 24 bit - Line number where defined
               ;; 8 bit - Argument number. 1 indicates 1st argument.
-    metadata, ;; Type descriptor
+    metadata, ;; Reference to the type descriptor
     i32,      ;; flags
     metadata  ;; (optional) Reference to inline location
   }

Modified: llvm/trunk/include/llvm/IR/DIBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=204106&r1=204105&r2=204106&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DIBuilder.h (original)
+++ llvm/trunk/include/llvm/IR/DIBuilder.h Mon Mar 17 21:34:58 2014
@@ -466,7 +466,7 @@ namespace llvm {
     /// @param Val         llvm::Value of the variable.
     DIGlobalVariable
     createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
-                         DIType Ty, bool isLocalToUnit, llvm::Value *Val);
+                         DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val);
 
     /// \brief Create a new descriptor for the specified global.
     /// @param Name        Name of the variable.
@@ -479,7 +479,7 @@ namespace llvm {
     /// @param Val         llvm::Value of the variable.
     DIGlobalVariable
     createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile File,
-                         unsigned LineNo, DIType Ty, bool isLocalToUnit,
+                         unsigned LineNo, DITypeRef Ty, bool isLocalToUnit,
                          llvm::Value *Val);
 
     /// createStaticVariable - Create a new descriptor for the specified
@@ -497,7 +497,7 @@ namespace llvm {
     DIGlobalVariable
     createStaticVariable(DIDescriptor Context, StringRef Name,
                          StringRef LinkageName, DIFile File, unsigned LineNo,
-                         DIType Ty, bool isLocalToUnit, llvm::Value *Val,
+                         DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val,
                          MDNode *Decl = NULL);
 
 
@@ -518,7 +518,7 @@ namespace llvm {
     DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
                                    StringRef Name,
                                    DIFile File, unsigned LineNo,
-                                   DIType Ty, bool AlwaysPreserve = false,
+                                   DITypeRef Ty, bool AlwaysPreserve = false,
                                    unsigned Flags = 0,
                                    unsigned ArgNo = 0);
 
@@ -537,7 +537,7 @@ namespace llvm {
     ///                    number. 1 indicates 1st argument.
     DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
                                      StringRef Name, DIFile F, unsigned LineNo,
-                                     DIType Ty, ArrayRef<Value *> Addr,
+                                     DITypeRef Ty, ArrayRef<Value *> Addr,
                                      unsigned ArgNo = 0);
 
     /// createFunction - Create a new descriptor for the specified subprogram.

Modified: llvm/trunk/include/llvm/IR/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=204106&r1=204105&r2=204106&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfo.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfo.h Mon Mar 17 21:34:58 2014
@@ -224,6 +224,7 @@ template <typename T> class DIRef {
   friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
   friend DIScopeRef DIScope::getContext() const;
   friend DIScopeRef DIScope::getRef() const;
+  friend class DIType;
 
   /// Val can be either a MDNode or a MDString, in the latter,
   /// MDString specifies the type identifier.
@@ -284,6 +285,11 @@ protected:
 
 public:
   explicit DIType(const MDNode *N = 0) : DIScope(N) {}
+  operator DITypeRef () const {
+    assert(isType() &&
+           "constructing DITypeRef from an MDNode that is not a type");
+    return DITypeRef(&*getRef());
+  }
 
   /// Verify - Verify that a type descriptor is well formed.
   bool Verify() const;
@@ -616,7 +622,7 @@ public:
   }
 
   unsigned getLineNumber() const { return getUnsignedField(7); }
-  DIType getType() const { return getFieldAs<DIType>(8); }
+  DITypeRef getType() const { return getFieldAs<DITypeRef>(8); }
   unsigned isLocalToUnit() const { return getUnsignedField(9); }
   unsigned isDefinition() const { return getUnsignedField(10); }
 
@@ -648,7 +654,7 @@ public:
     unsigned L = getUnsignedField(4);
     return L >> 24;
   }
-  DIType getType() const { return getFieldAs<DIType>(5); }
+  DITypeRef getType() const { return getFieldAs<DITypeRef>(5); }
 
   /// isArtificial - Return true if this variable is marked as "artificial".
   bool isArtificial() const {
@@ -681,7 +687,9 @@ public:
 
   /// isBlockByrefVariable - Return true if the variable was declared as
   /// a "__block" variable (Apple Blocks).
-  bool isBlockByrefVariable() const { return getType().isBlockByrefStruct(); }
+  bool isBlockByrefVariable(const DITypeIdentifierMap &Map) const {
+    return (getType().resolve(Map)).isBlockByrefStruct();
+  }
 
   /// isInlinedFnArgument - Return true if this variable provides debugging
   /// information for an inlined function arguments.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=204106&r1=204105&r2=204106&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Mon Mar 17 21:34:58 2014
@@ -115,11 +115,17 @@ template <typename T> T DbgVariable::res
   return DD->resolve(Ref);
 }
 
+bool DbgVariable::isBlockByrefVariable() const {
+  assert(Var.isVariable() && "Invalid complex DbgVariable!");
+  return Var.isBlockByrefVariable(DD->getTypeIdentifierMap());
+}
+
+
 DIType DbgVariable::getType() const {
-  DIType Ty = Var.getType();
+  DIType Ty = Var.getType().resolve(DD->getTypeIdentifierMap());
   // FIXME: isBlockByrefVariable should be reformulated in terms of complex
   // addresses instead.
-  if (Var.isBlockByrefVariable()) {
+  if (Var.isBlockByrefVariable(DD->getTypeIdentifierMap())) {
     /* Byref variables, in Blocks, are declared by the programmer as
        "SomeType VarName;", but the compiler creates a
        __Block_byref_x_VarName struct, and gives the variable VarName
@@ -2301,7 +2307,7 @@ void DwarfDebug::emitDebugLocEntry(ByteS
                                    const DebugLocEntry &Entry) {
   DIVariable DV(Entry.getVariable());
   if (Entry.isInt()) {
-    DIBasicType BTy(DV.getType());
+    DIBasicType BTy(resolve(DV.getType()));
     if (BTy.Verify() && (BTy.getEncoding() == dwarf::DW_ATE_signed ||
                          BTy.getEncoding() == dwarf::DW_ATE_signed_char)) {
       Streamer.EmitInt8(dwarf::DW_OP_consts, "DW_OP_consts");

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=204106&r1=204105&r2=204106&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Mon Mar 17 21:34:58 2014
@@ -199,10 +199,7 @@ public:
     assert(Var.isVariable() && "Invalid complex DbgVariable!");
     return Var.hasComplexAddress();
   }
-  bool isBlockByrefVariable() const {
-    assert(Var.isVariable() && "Invalid complex DbgVariable!");
-    return Var.isBlockByrefVariable();
-  }
+  bool isBlockByrefVariable() const;
   unsigned getNumAddrElements() const {
     assert(Var.isVariable() && "Invalid complex DbgVariable!");
     return Var.getNumAddrElements();
@@ -777,6 +774,11 @@ public:
     return Ref.resolve(TypeIdentifierMap);
   }
 
+  /// \brief Return the TypeIdentifierMap.
+  const DITypeIdentifierMap& getTypeIdentifierMap() const {
+    return TypeIdentifierMap;
+  }
+
   /// Find the DwarfCompileUnit for the given CU Die.
   DwarfCompileUnit *lookupUnit(const DIE *CU) const {
     return CUDieMap.lookup(CU);

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=204106&r1=204105&r2=204106&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Mon Mar 17 21:34:58 2014
@@ -1604,7 +1604,7 @@ void DwarfCompileUnit::createGlobalVaria
   assert(GV.isGlobalVariable());
 
   DIScope GVContext = GV.getContext();
-  DIType GTy = GV.getType();
+  DIType GTy = DD->resolve(GV.getType());
 
   // If this is a static data member definition, some attributes belong
   // to the declaration DIE.

Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=204106&r1=204105&r2=204106&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Mon Mar 17 21:34:58 2014
@@ -927,7 +927,7 @@ DISubrange DIBuilder::getOrCreateSubrang
 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name,
                                                  StringRef LinkageName,
                                                  DIFile F, unsigned LineNumber,
-                                                 DIType Ty, bool isLocalToUnit,
+                                                 DITypeRef Ty, bool isLocalToUnit,
                                                  Value *Val) {
   Value *Elts[] = {
     GetTagConstant(VMContext, dwarf::DW_TAG_variable),
@@ -951,7 +951,8 @@ DIGlobalVariable DIBuilder::createGlobal
 
 /// \brief Create a new descriptor for the specified global.
 DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F,
-                                                 unsigned LineNumber, DIType Ty,
+                                                 unsigned LineNumber,
+                                                 DITypeRef Ty,
                                                  bool isLocalToUnit,
                                                  Value *Val) {
   return createGlobalVariable(Name, Name, F, LineNumber, Ty, isLocalToUnit,
@@ -964,7 +965,8 @@ DIGlobalVariable DIBuilder::createStatic
                                                  StringRef Name,
                                                  StringRef LinkageName,
                                                  DIFile F, unsigned LineNumber,
-                                                 DIType Ty, bool isLocalToUnit,
+                                                 DITypeRef Ty,
+                                                 bool isLocalToUnit,
                                                  Value *Val, MDNode *Decl) {
   Value *Elts[] = {
     GetTagConstant(VMContext, dwarf::DW_TAG_variable),
@@ -989,14 +991,12 @@ DIGlobalVariable DIBuilder::createStatic
 /// createVariable - Create a new descriptor for the specified variable.
 DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
                                           StringRef Name, DIFile File,
-                                          unsigned LineNo, DIType Ty,
+                                          unsigned LineNo, DITypeRef Ty,
                                           bool AlwaysPreserve, unsigned Flags,
                                           unsigned ArgNo) {
   DIDescriptor Context(getNonCompileUnitScope(Scope));
   assert((!Context || Context.isScope()) &&
          "createLocalVariable should be called with a valid Context");
-  assert(Ty.isType() &&
-         "createLocalVariable should be called with a valid type");
   Value *Elts[] = {
     GetTagConstant(VMContext, Tag),
     getNonCompileUnitScope(Scope),
@@ -1027,7 +1027,8 @@ DIVariable DIBuilder::createLocalVariabl
 DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope,
                                             StringRef Name, DIFile F,
                                             unsigned LineNo,
-                                            DIType Ty, ArrayRef<Value *> Addr,
+                                            DITypeRef Ty,
+                                            ArrayRef<Value *> Addr,
                                             unsigned ArgNo) {
   SmallVector<Value *, 15> Elts;
   Elts.push_back(GetTagConstant(VMContext, Tag));

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=204106&r1=204105&r2=204106&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Mon Mar 17 21:34:58 2014
@@ -541,10 +541,11 @@ bool DIGlobalVariable::Verify() const {
 
   if (getDisplayName().empty())
     return false;
-  // Make sure context @ field 2 and type @ field 8 are MDNodes.
+  // Make sure context @ field 2 is an MDNode.
   if (!fieldIsMDNode(DbgNode, 2))
     return false;
-  if (!fieldIsMDNode(DbgNode, 8))
+  // Make sure that type @ field 8 is a DITypeRef.
+  if (!fieldIsTypeRef(DbgNode, 8))
     return false;
   // Make sure StaticDataMemberDeclaration @ field 12 is MDNode.
   if (!fieldIsMDNode(DbgNode, 12))
@@ -558,10 +559,11 @@ bool DIVariable::Verify() const {
   if (!isVariable())
     return false;
 
-  // Make sure context @ field 1 and type @ field 5 are MDNodes.
+  // Make sure context @ field 1 is an MDNode.
   if (!fieldIsMDNode(DbgNode, 1))
     return false;
-  if (!fieldIsMDNode(DbgNode, 5))
+  // Make sure that type @ field 5 is a DITypeRef.
+  if (!fieldIsTypeRef(DbgNode, 5))
     return false;
   return DbgNode->getNumOperands() >= 8;
 }
@@ -999,7 +1001,7 @@ void DebugInfoFinder::processModule(cons
         DIGlobalVariable DIG(GVs.getElement(i));
         if (addGlobalVariable(DIG)) {
           processScope(DIG.getContext());
-          processType(DIG.getType());
+          processType(DIG.getType().resolve(TypeIdentifierMap));
         }
       }
       DIArray SPs = CU.getSubprograms();
@@ -1133,7 +1135,7 @@ void DebugInfoFinder::processDeclare(con
   if (!NodesSeen.insert(DV))
     return;
   processScope(DIVariable(N).getContext());
-  processType(DIVariable(N).getType());
+  processType(DIVariable(N).getType().resolve(TypeIdentifierMap));
 }
 
 void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
@@ -1149,7 +1151,7 @@ void DebugInfoFinder::processValue(const
   if (!NodesSeen.insert(DV))
     return;
   processScope(DIVariable(N).getContext());
-  processType(DIVariable(N).getType());
+  processType(DIVariable(N).getType().resolve(TypeIdentifierMap));
 }
 
 /// addType - Add type into Tys.

Modified: llvm/trunk/test/Linker/type-unique-odr-a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/type-unique-odr-a.ll?rev=204106&r1=204105&r2=204106&view=diff
==============================================================================
--- llvm/trunk/test/Linker/type-unique-odr-a.ll (original)
+++ llvm/trunk/test/Linker/type-unique-odr-a.ll Mon Mar 17 21:34:58 2014
@@ -93,6 +93,6 @@ attributes #1 = { nounwind readnone }
 !21 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
 !22 = metadata !{metadata !"clang version 3.5.0 "}
 !23 = metadata !{i32 11, i32 0, metadata !15, null}
-!24 = metadata !{i32 786688, metadata !19, metadata !"a", metadata !16, i32 8, metadata !4, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [a] [line 8]
+!24 = metadata !{i32 786688, metadata !19, metadata !"a", metadata !16, i32 8, metadata !"_ZTS1A", i32 0, i32 0} ; [ DW_TAG_auto_variable ] [a] [line 8]
 !25 = metadata !{i32 8, i32 0, metadata !19, null} ; [ DW_TAG_imported_declaration ]
 !26 = metadata !{i32 9, i32 0, metadata !19, null}





More information about the llvm-commits mailing list