[llvm] r191800 - Debug Info: In DIBuilder, the derived-from field of a DW_TAG_pointer_type

Eric Christopher echristo at gmail.com
Fri Oct 4 10:12:56 PDT 2013


Hi Manman,

This patch very much depended upon the 191972 so I needed to revert
this (and the corresponding clang commit) as well for now.

Sorry, and thanks.

-eric


On Tue, Oct 1, 2013 at 4:45 PM, Manman Ren <manman.ren at gmail.com> wrote:
> Author: mren
> Date: Tue Oct  1 18:45:54 2013
> New Revision: 191800
>
> URL: http://llvm.org/viewvc/llvm-project?rev=191800&view=rev
> Log:
> Debug Info: In DIBuilder, the derived-from field of a DW_TAG_pointer_type
> is updated to use DITypeRef.
>
> Move isUnsignedDIType and getOriginalTypeSize from DebugInfo.h to be static
> helper functions in DwarfCompileUnit. We already have a static helper function
> "isTypeSigned" in DwarfCompileUnit, and a pointer to DwarfDebug is added to
> resolve the derived-from field. All three functions need to go across link
> for derived-from fields, so we need to get hold of a type identifier map.
>
> A pointer to DwarfDebug is also added to DbgVariable in order to resolve the
> derived-from field.
>
> Debug info verifier is updated to check a derived-from field is a TypeRef.
> Verifier will not go across link for derived-from fields, in debug info finder,
> we go across the link to add derived-from fields to types.
>
> Function getDICompositeType is only used by dragonegg and since dragonegg does
> not generate identifier for types, we use an empty map to resolve the
> derived-from field.
>
> When printing a derived-from field, we use DITypeRef::getName to either return
> the type identifier or getName of the DIType.
>
> A paired commit at clang is required due to changes to DIBuilder.
>
> Added:
>     llvm/trunk/test/Linker/Inputs/type-unique-simple2-a.ll
>     llvm/trunk/test/Linker/Inputs/type-unique-simple2-b.ll
>     llvm/trunk/test/Linker/type-unique-simple2.ll
> Modified:
>     llvm/trunk/include/llvm/DebugInfo.h
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
>     llvm/trunk/lib/IR/DIBuilder.cpp
>     llvm/trunk/lib/IR/DebugInfo.cpp
>     llvm/trunk/test/Transforms/LICM/debug-value.ll
>
> Modified: llvm/trunk/include/llvm/DebugInfo.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo.h?rev=191800&r1=191799&r2=191800&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/DebugInfo.h (original)
> +++ llvm/trunk/include/llvm/DebugInfo.h Tue Oct  1 18:45:54 2013
> @@ -22,6 +22,7 @@
>  #include "llvm/ADT/SmallPtrSet.h"
>  #include "llvm/ADT/SmallVector.h"
>  #include "llvm/ADT/StringRef.h"
> +#include "llvm/IR/Metadata.h"
>  #include "llvm/Support/Dwarf.h"
>
>  namespace llvm {
> @@ -206,6 +207,8 @@ namespace llvm {
>      /// Gets the parent scope for this scope node or returns a
>      /// default constructed scope.
>      DIScopeRef getContext() const;
> +    /// If the scope node has a name, return that, else return an empty string.
> +    StringRef getName() const;
>      StringRef getFilename() const;
>      StringRef getDirectory() const;
>
> @@ -243,6 +246,16 @@ namespace llvm {
>               "MDNode in DITypeIdentifierMap should be a DIType.");
>        return T(Iter->second);
>      }
> +    StringRef getName() const {
> +      if (!Val)
> +        return StringRef();
> +
> +      if (const MDNode *MD = dyn_cast<MDNode>(Val))
> +        return T(MD).getName();
> +
> +      const MDString *MS = cast<MDString>(Val);
> +      return MS->getString();
> +    }
>      operator Value *() const { return const_cast<Value*>(Val); }
>    };
>
> @@ -321,9 +334,6 @@ namespace llvm {
>        return DbgNode && isType();
>      }
>
> -    /// isUnsignedDIType - Return true if type encoding is unsigned.
> -    bool isUnsignedDIType();
> -
>      /// replaceAllUsesWith - Replace all uses of debug info referenced by
>      /// this descriptor.
>      void replaceAllUsesWith(DIDescriptor &D);
> @@ -351,11 +361,7 @@ namespace llvm {
>    public:
>      explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
>
> -    DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
> -
> -    /// getOriginalTypeSize - If this type is derived from a base type then
> -    /// return base type size.
> -    uint64_t getOriginalTypeSize() const;
> +    DITypeRef getTypeDerivedFrom() const { return getFieldAs<DITypeRef>(9); }
>
>      /// getObjCProperty - Return property node, if this ivar is
>      /// associated with one.
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=191800&r1=191799&r2=191800&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Tue Oct  1 18:45:54 2013
> @@ -534,7 +534,7 @@ void CompileUnit::addBlockByrefAddress(c
>
>    if (Tag == dwarf::DW_TAG_pointer_type) {
>      DIDerivedType DTy = DIDerivedType(Ty);
> -    TmpTy = DTy.getTypeDerivedFrom();
> +    TmpTy = DD->resolve(DTy.getTypeDerivedFrom());
>      isPointer = true;
>    }
>
> @@ -601,9 +601,10 @@ void CompileUnit::addBlockByrefAddress(c
>  }
>
>  /// isTypeSigned - Return true if the type is signed.
> -static bool isTypeSigned(DIType Ty, int *SizeInBits) {
> +static bool isTypeSigned(DwarfDebug *DD, DIType Ty, int *SizeInBits) {
>    if (Ty.isDerivedType())
> -    return isTypeSigned(DIDerivedType(Ty).getTypeDerivedFrom(), SizeInBits);
> +    return isTypeSigned(DD, DD->resolve(DIDerivedType(Ty).getTypeDerivedFrom()),
> +                        SizeInBits);
>    if (Ty.isBasicType())
>      if (DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed
>          || DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed_char) {
> @@ -613,6 +614,51 @@ static bool isTypeSigned(DIType Ty, int
>    return false;
>  }
>
> +/// Return true if type encoding is unsigned.
> +static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) {
> +  DIDerivedType DTy(Ty);
> +  if (DTy.isDerivedType())
> +    return isUnsignedDIType(DD, DD->resolve(DTy.getTypeDerivedFrom()));
> +
> +  DIBasicType BTy(Ty);
> +  if (BTy.isBasicType()) {
> +    unsigned Encoding = BTy.getEncoding();
> +    if (Encoding == dwarf::DW_ATE_unsigned ||
> +        Encoding == dwarf::DW_ATE_unsigned_char ||
> +        Encoding == dwarf::DW_ATE_boolean)
> +      return true;
> +  }
> +  return false;
> +}
> +
> +/// If this type is derived from a base type then return base type size.
> +static uint64_t getOriginalTypeSize(DwarfDebug *DD, DIDerivedType Ty) {
> +  unsigned Tag = Ty.getTag();
> +
> +  if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef &&
> +      Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type &&
> +      Tag != dwarf::DW_TAG_restrict_type)
> +    return Ty.getSizeInBits();
> +
> +  DIType BaseType = DD->resolve(Ty.getTypeDerivedFrom());
> +
> +  // If this type is not derived from any type then take conservative approach.
> +  if (!BaseType.isValid())
> +    return Ty.getSizeInBits();
> +
> +  // If this is a derived type, go ahead and get the base type, unless it's a
> +  // reference then it's just the size of the field. Pointer types have no need
> +  // of this since they're a different type of qualification on the type.
> +  if (BaseType.getTag() == dwarf::DW_TAG_reference_type ||
> +      BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type)
> +    return Ty.getSizeInBits();
> +
> +  if (BaseType.isDerivedType())
> +    return getOriginalTypeSize(DD, DIDerivedType(BaseType));
> +
> +  return BaseType.getSizeInBits();
> +}
> +
>  /// addConstantValue - Add constant value entry in variable DIE.
>  void CompileUnit::addConstantValue(DIE *Die, const MachineOperand &MO,
>                                     DIType Ty) {
> @@ -621,7 +667,7 @@ void CompileUnit::addConstantValue(DIE *
>    // udata/sdata over dataN as suggested by the DWARF spec)
>    assert(MO.isImm() && "Invalid machine operand!");
>    int SizeInBits = -1;
> -  bool SignedConstant = isTypeSigned(Ty, &SizeInBits);
> +  bool SignedConstant = isTypeSigned(DD, Ty, &SizeInBits);
>    uint16_t Form;
>
>    // If we're a signed constant definitely use sdata.
> @@ -938,7 +984,7 @@ void CompileUnit::constructTypeDIE(DIE &
>    Buffer.setTag(Tag);
>
>    // Map to main type, void will not have a type.
> -  DIType FromTy = DTy.getTypeDerivedFrom();
> +  DIType FromTy = DD->resolve(DTy.getTypeDerivedFrom());
>    if (FromTy)
>      addType(&Buffer, FromTy);
>
> @@ -1016,7 +1062,7 @@ void CompileUnit::constructTypeDIE(DIE &
>          Buffer.addChild(ElemDie);
>        }
>      }
> -    DIType DTy = CTy.getTypeDerivedFrom();
> +    DIType DTy = DD->resolve(CTy.getTypeDerivedFrom());
>      if (DTy) {
>        addType(&Buffer, DTy);
>        addUInt(&Buffer, dwarf::DW_AT_enum_class, dwarf::DW_FORM_flag, 1);
> @@ -1082,7 +1128,8 @@ void CompileUnit::constructTypeDIE(DIE &
>          DIDerivedType DDTy(Element);
>          if (DDTy.getTag() == dwarf::DW_TAG_friend) {
>            ElemDie = new DIE(dwarf::DW_TAG_friend);
> -          addType(ElemDie, DDTy.getTypeDerivedFrom(), dwarf::DW_AT_friend);
> +          addType(ElemDie, DD->resolve(DDTy.getTypeDerivedFrom()),
> +                  dwarf::DW_AT_friend);
>          } else if (DDTy.isStaticMember())
>            ElemDie = createStaticMemberDIE(DDTy);
>          else
> @@ -1224,7 +1271,7 @@ CompileUnit::getOrCreateTemplateValuePar
>      addString(ParamDIE, dwarf::DW_AT_name, VP.getName());
>    if (Value *Val = VP.getValue()) {
>      if (ConstantInt *CI = dyn_cast<ConstantInt>(Val))
> -      addConstantValue(ParamDIE, CI, VP.getType().isUnsignedDIType());
> +      addConstantValue(ParamDIE, CI, isUnsignedDIType(DD, VP.getType()));
>      else if (GlobalValue *GV = dyn_cast<GlobalValue>(Val)) {
>        // For declaration non-type template parameters (such as global values and
>        // functions)
> @@ -1511,7 +1558,7 @@ void CompileUnit::createGlobalVariableDI
>      // emitting AT_const_value multiple times, we only add AT_const_value when
>      // it is not a static member.
>      if (!IsStaticMember)
> -      addConstantValue(VariableDIE, CI, GTy.isUnsignedDIType());
> +      addConstantValue(VariableDIE, CI, isUnsignedDIType(DD, GTy));
>    } else if (const ConstantExpr *CE = getMergedGlobalExpr(N->getOperand(11))) {
>      addToAccelTable = true;
>      // GV is a merged global.
> @@ -1572,7 +1619,7 @@ void CompileUnit::constructArrayTypeDIE(
>      addFlag(&Buffer, dwarf::DW_AT_GNU_vector);
>
>    // Emit the element type.
> -  addType(&Buffer, CTy->getTypeDerivedFrom());
> +  addType(&Buffer, DD->resolve(CTy->getTypeDerivedFrom()));
>
>    // Get an anonymous type for index type.
>    // FIXME: This type should be passed down from the front end
> @@ -1679,7 +1726,7 @@ DIE *CompileUnit::constructVariableDIE(D
>        addConstantFPValue(VariableDie, DVInsn->getOperand(0));
>      else if (DVInsn->getOperand(0).isCImm())
>        addConstantValue(VariableDie, DVInsn->getOperand(0).getCImm(),
> -                       DV->getType().isUnsignedDIType());
> +                       isUnsignedDIType(DD, DV->getType()));
>
>      DV->setDIE(VariableDie);
>      return VariableDie;
> @@ -1707,7 +1754,7 @@ DIE *CompileUnit::createMemberDIE(DIDeri
>    if (!Name.empty())
>      addString(MemberDie, dwarf::DW_AT_name, Name);
>
> -  addType(MemberDie, DT.getTypeDerivedFrom());
> +  addType(MemberDie, DD->resolve(DT.getTypeDerivedFrom()));
>
>    addSourceLine(MemberDie, DT);
>
> @@ -1715,11 +1762,12 @@ DIE *CompileUnit::createMemberDIE(DIDeri
>    addUInt(MemLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
>
>    uint64_t Size = DT.getSizeInBits();
> -  uint64_t FieldSize = DT.getOriginalTypeSize();
> +  uint64_t FieldSize = getOriginalTypeSize(DD, DT);
>
>    if (Size != FieldSize) {
>      // Handle bitfield.
> -    addUInt(MemberDie, dwarf::DW_AT_byte_size, 0, DT.getOriginalTypeSize()>>3);
> +    addUInt(MemberDie, dwarf::DW_AT_byte_size, 0,
> +            getOriginalTypeSize(DD, DT)>>3);
>      addUInt(MemberDie, dwarf::DW_AT_bit_size, 0, DT.getSizeInBits());
>
>      uint64_t Offset = DT.getOffsetInBits();
> @@ -1794,7 +1842,7 @@ DIE *CompileUnit::createStaticMemberDIE(
>      return NULL;
>
>    DIE *StaticMemberDIE = new DIE(DT.getTag());
> -  DIType Ty = DT.getTypeDerivedFrom();
> +  DIType Ty = DD->resolve(DT.getTypeDerivedFrom());
>
>    addString(StaticMemberDIE, dwarf::DW_AT_name, DT.getName());
>    addType(StaticMemberDIE, Ty);
> @@ -1815,7 +1863,7 @@ DIE *CompileUnit::createStaticMemberDIE(
>              dwarf::DW_ACCESS_public);
>
>    if (const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT.getConstant()))
> -    addConstantValue(StaticMemberDIE, CI, Ty.isUnsignedDIType());
> +    addConstantValue(StaticMemberDIE, CI, isUnsignedDIType(DD, Ty));
>    if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT.getConstant()))
>      addConstantFPValue(StaticMemberDIE, CFP);
>
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=191800&r1=191799&r2=191800&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Oct  1 18:45:54 2013
> @@ -149,13 +149,13 @@ DIType DbgVariable::getType() const {
>      uint16_t tag = Ty.getTag();
>
>      if (tag == dwarf::DW_TAG_pointer_type)
> -      subType = DIDerivedType(Ty).getTypeDerivedFrom();
> +      subType = DD->resolve(DIDerivedType(Ty).getTypeDerivedFrom());
>
>      DIArray Elements = DICompositeType(subType).getTypeArray();
>      for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
>        DIDerivedType DT = DIDerivedType(Elements.getElement(i));
>        if (getName() == DT.getName())
> -        return (DT.getTypeDerivedFrom());
> +        return (DD->resolve(DT.getTypeDerivedFrom()));
>      }
>    }
>    return Ty;
> @@ -996,7 +996,7 @@ void DwarfDebug::collectDeadVariables()
>          for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) {
>            DIVariable DV(Variables.getElement(vi));
>            if (!DV.isVariable()) continue;
> -          DbgVariable NewVar(DV, NULL);
> +          DbgVariable NewVar(DV, NULL, this);
>            if (DIE *VariableDIE =
>                SPCU->constructVariableDIE(&NewVar, Scope->isAbstractScope()))
>              ScopeDIE->addChild(VariableDIE);
> @@ -1252,7 +1252,7 @@ DbgVariable *DwarfDebug::findAbstractVar
>    if (!Scope)
>      return NULL;
>
> -  AbsDbgVariable = new DbgVariable(Var, NULL);
> +  AbsDbgVariable = new DbgVariable(Var, NULL, this);
>    addScopeVariable(Scope, AbsDbgVariable);
>    AbstractVariables[Var] = AbsDbgVariable;
>    return AbsDbgVariable;
> @@ -1301,7 +1301,7 @@ DwarfDebug::collectVariableInfoFromMMITa
>        continue;
>
>      DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second);
> -    DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable);
> +    DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable, this);
>      RegVar->setFrameIndex(VP.first);
>      if (!addCurrentFnArgument(MF, RegVar, Scope))
>        addScopeVariable(Scope, RegVar);
> @@ -1386,7 +1386,7 @@ DwarfDebug::collectVariableInfo(const Ma
>      Processed.insert(DV);
>      assert(MInsn->isDebugValue() && "History must begin with debug value");
>      DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc());
> -    DbgVariable *RegVar = new DbgVariable(DV, AbsVar);
> +    DbgVariable *RegVar = new DbgVariable(DV, AbsVar, this);
>      if (!addCurrentFnArgument(MF, RegVar, Scope))
>        addScopeVariable(Scope, RegVar);
>      if (AbsVar)
> @@ -1449,7 +1449,7 @@ DwarfDebug::collectVariableInfo(const Ma
>      if (!DV || !DV.isVariable() || !Processed.insert(DV))
>        continue;
>      if (LexicalScope *Scope = LScopes.findLexicalScope(DV.getContext()))
> -      addScopeVariable(Scope, new DbgVariable(DV, NULL));
> +      addScopeVariable(Scope, new DbgVariable(DV, NULL, this));
>    }
>  }
>
> @@ -1845,7 +1845,7 @@ void DwarfDebug::endFunction(const Machi
>          if (AbstractVariables.lookup(CleanDV))
>            continue;
>          if (LexicalScope *Scope = LScopes.findAbstractScope(DV.getContext()))
> -          addScopeVariable(Scope, new DbgVariable(DV, NULL));
> +          addScopeVariable(Scope, new DbgVariable(DV, NULL, this));
>        }
>      }
>      if (ProcessedSPNodes.count(AScope->getScopeNode()) == 0)
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=191800&r1=191799&r2=191800&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Tue Oct  1 18:45:54 2013
> @@ -150,11 +150,12 @@ class DbgVariable {
>    DbgVariable *AbsVar;               // Corresponding Abstract variable, if any.
>    const MachineInstr *MInsn;         // DBG_VALUE instruction of the variable.
>    int FrameIndex;
> +  DwarfDebug *DD;
>  public:
>    // AbsVar may be NULL.
> -  DbgVariable(DIVariable V, DbgVariable *AV)
> +  DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
>      : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
> -      FrameIndex(~0) {}
> +      FrameIndex(~0), DD(DD) {}
>
>    // Accessors.
>    DIVariable getVariable()           const { return Var; }
>
> Modified: llvm/trunk/lib/IR/DIBuilder.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=191800&r1=191799&r2=191800&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/DIBuilder.cpp (original)
> +++ llvm/trunk/lib/IR/DIBuilder.cpp Tue Oct  1 18:45:54 2013
> @@ -303,7 +303,7 @@ DIBuilder::createPointerType(DIType Poin
>      ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
>      ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
>      ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
> -    PointeeTy
> +    PointeeTy.getRef()
>    };
>    return DIDerivedType(MDNode::get(VMContext, Elts));
>  }
>
> Modified: llvm/trunk/lib/IR/DebugInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=191800&r1=191799&r2=191800&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/DebugInfo.cpp (original)
> +++ llvm/trunk/lib/IR/DebugInfo.cpp Tue Oct  1 18:45:54 2013
> @@ -368,23 +368,6 @@ void DIType::replaceAllUsesWith(MDNode *
>    }
>  }
>
> -/// isUnsignedDIType - Return true if type encoding is unsigned.
> -bool DIType::isUnsignedDIType() {
> -  DIDerivedType DTy(DbgNode);
> -  if (DTy.Verify())
> -    return DTy.getTypeDerivedFrom().isUnsignedDIType();
> -
> -  DIBasicType BTy(DbgNode);
> -  if (BTy.Verify()) {
> -    unsigned Encoding = BTy.getEncoding();
> -    if (Encoding == dwarf::DW_ATE_unsigned ||
> -        Encoding == dwarf::DW_ATE_unsigned_char ||
> -        Encoding == dwarf::DW_ATE_boolean)
> -      return true;
> -  }
> -  return false;
> -}
> -
>  /// Verify - Verify that a compile unit is well formed.
>  bool DICompileUnit::Verify() const {
>    if (!isCompileUnit())
> @@ -493,8 +476,8 @@ bool DIBasicType::Verify() const {
>
>  /// Verify - Verify that a derived type descriptor is well formed.
>  bool DIDerivedType::Verify() const {
> -  // Make sure DerivedFrom @ field 9 is MDNode.
> -  if (!fieldIsMDNode(DbgNode, 9))
> +  // Make sure DerivedFrom @ field 9 is TypeRef.
> +  if (!fieldIsTypeRef(DbgNode, 9))
>      return false;
>    if (getTag() == dwarf::DW_TAG_ptr_to_member_type)
>      // Make sure ClassType @ field 10 is a TypeRef.
> @@ -510,8 +493,8 @@ bool DICompositeType::Verify() const {
>    if (!isCompositeType())
>      return false;
>
> -  // Make sure DerivedFrom @ field 9 and ContainingType @ field 12 are MDNodes.
> -  if (!fieldIsMDNode(DbgNode, 9))
> +  // Make sure DerivedFrom @ field 9 and ContainingType @ field 12 are TypeRef.
> +  if (!fieldIsTypeRef(DbgNode, 9))
>      return false;
>    if (!fieldIsTypeRef(DbgNode, 12))
>      return false;
> @@ -520,12 +503,6 @@ bool DICompositeType::Verify() const {
>    if (!fieldIsMDString(DbgNode, 14))
>      return false;
>
> -  // If this is an array type verify that we have a DIType in the derived type
> -  // field as that's the type of our element.
> -  if (getTag() == dwarf::DW_TAG_array_type)
> -    if (!DIType(getTypeDerivedFrom()))
> -      return false;
> -
>    return DbgNode->getNumOperands() == 15;
>  }
>
> @@ -638,35 +615,6 @@ bool DIImportedEntity::Verify() const {
>           (DbgNode->getNumOperands() == 4 || DbgNode->getNumOperands() == 5);
>  }
>
> -/// getOriginalTypeSize - If this type is derived from a base type then
> -/// return base type size.
> -uint64_t DIDerivedType::getOriginalTypeSize() const {
> -  uint16_t Tag = getTag();
> -
> -  if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef &&
> -      Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type &&
> -      Tag != dwarf::DW_TAG_restrict_type)
> -    return getSizeInBits();
> -
> -  DIType BaseType = getTypeDerivedFrom();
> -
> -  // If this type is not derived from any type then take conservative approach.
> -  if (!BaseType.isValid())
> -    return getSizeInBits();
> -
> -  // If this is a derived type, go ahead and get the base type, unless it's a
> -  // reference then it's just the size of the field. Pointer types have no need
> -  // of this since they're a different type of qualification on the type.
> -  if (BaseType.getTag() == dwarf::DW_TAG_reference_type ||
> -      BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type)
> -    return getSizeInBits();
> -
> -  if (BaseType.isDerivedType())
> -    return DIDerivedType(BaseType).getOriginalTypeSize();
> -
> -  return BaseType.getSizeInBits();
> -}
> -
>  /// getObjCProperty - Return property node, if this ivar is associated with one.
>  MDNode *DIDerivedType::getObjCProperty() const {
>    return getNodeField(DbgNode, 10);
> @@ -808,6 +756,19 @@ DIScopeRef DIScope::getContext() const {
>    return DIScopeRef(NULL);
>  }
>
> +// If the scope node has a name, return that, else return an empty string.
> +StringRef DIScope::getName() const {
> +  if (isType())
> +    return DIType(DbgNode).getName();
> +  if (isSubprogram())
> +    return DISubprogram(DbgNode).getName();
> +  if (isNameSpace())
> +    return DINameSpace(DbgNode).getName();
> +  assert((isLexicalBlock() || isLexicalBlockFile() || isFile() ||
> +          isCompileUnit()) && "Unhandled type of scope.");
> +  return StringRef();
> +}
> +
>  StringRef DIScope::getFilename() const {
>    if (!DbgNode)
>      return StringRef();
> @@ -942,8 +903,14 @@ DICompositeType llvm::getDICompositeType
>    if (T.isCompositeType())
>      return DICompositeType(T);
>
> -  if (T.isDerivedType())
> -    return getDICompositeType(DIDerivedType(T).getTypeDerivedFrom());
> +  if (T.isDerivedType()) {
> +    // This function is currently used by dragonegg and dragonegg does
> +    // not generate identifier for types, so using an empty map to resolve
> +    // DerivedFrom should be fine.
> +    DITypeIdentifierMap EmptyMap;
> +    return getDICompositeType(DIDerivedType(T).getTypeDerivedFrom()
> +                                              .resolve(EmptyMap));
> +  }
>
>    return DICompositeType();
>  }
> @@ -1044,7 +1011,7 @@ void DebugInfoFinder::processType(DIType
>    processScope(DT.getContext().resolve(TypeIdentifierMap));
>    if (DT.isCompositeType()) {
>      DICompositeType DCT(DT);
> -    processType(DCT.getTypeDerivedFrom());
> +    processType(DCT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
>      DIArray DA = DCT.getTypeArray();
>      for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
>        DIDescriptor D = DA.getElement(i);
> @@ -1055,7 +1022,7 @@ void DebugInfoFinder::processType(DIType
>      }
>    } else if (DT.isDerivedType()) {
>      DIDerivedType DDT(DT);
> -    processType(DDT.getTypeDerivedFrom());
> +    processType(DDT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
>    }
>  }
>
>
> Added: llvm/trunk/test/Linker/Inputs/type-unique-simple2-a.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/type-unique-simple2-a.ll?rev=191800&view=auto
> ==============================================================================
> --- llvm/trunk/test/Linker/Inputs/type-unique-simple2-a.ll (added)
> +++ llvm/trunk/test/Linker/Inputs/type-unique-simple2-a.ll Tue Oct  1 18:45:54 2013
> @@ -0,0 +1,83 @@
> +; CHECK: 0x[[INT:.*]]: DW_TAG_base_type
> +; CHECK-NEXT: DW_AT_name {{.*}} = "int"
> +; CHECK-NOT: DW_TAG_base_type
> +; CHECK: 0x[[BASE:.*]]: DW_TAG_structure_type
> +; CHECK-NEXT: DW_AT_name {{.*}} = "Base"
> +; CHECK-NOT: DW_TAG_structure_type
> +; CHECK: DW_TAG_formal_parameter
> +; CHECK: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[INT]])
> +; CHECK: DW_TAG_variable
> +; CHECK: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[BASE]])
> +
> +; LINK: DW_TAG_structure_type
> +; LINK-NOT: DW_TAG_structure_type
> +
> +; Content of header files:
> +; struct Base {
> +;   int a;
> +;   Base *b;
> +; };
> +; Content of foo.cpp:
> +;
> +; #include "a.hpp"
> +; void f(int a) {
> +;   Base t;
> +; }
> +; Content of bar.cpp:
> +;
> +; #include "a.hpp"
> +; void f(int);
> +; void g(int a) {
> +;   Base t;
> +; }
> +; int main() {
> +;   f(0);
> +;   g(1);
> +;   return 0;
> +; }
> +; ModuleID = 'foo.cpp'
> +
> +%struct.Base = type { i32, %struct.Base* }
> +
> +; Function Attrs: nounwind ssp uwtable
> +define void @_Z1fi(i32 %a) #0 {
> +entry:
> +  %a.addr = alloca i32, align 4
> +  %t = alloca %struct.Base, align 8
> +  store i32 %a, i32* %a.addr, align 4
> +  call void @llvm.dbg.declare(metadata !{i32* %a.addr}, metadata !17), !dbg !18
> +  call void @llvm.dbg.declare(metadata !{%struct.Base* %t}, metadata !19), !dbg !20
> +  ret void, !dbg !21
> +}
> +
> +; Function Attrs: nounwind readnone
> +declare void @llvm.dbg.declare(metadata, metadata) #1
> +
> +attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
> +attributes #1 = { nounwind readnone }
> +
> +!llvm.dbg.cu = !{!0}
> +!llvm.module.flags = !{!16}
> +
> +!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.4 (http://llvm.org/git/clang.git 8a3f9e46cb988d2c664395b21910091e3730ae82) (http://llvm.org/git/llvm.git 4699e9549358bc77824a59114548eecc3f7c523c)", i1 false, metadata !"", i32 0, metadata !2, metadata !3, metadata !11, metadata !2, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [foo.cpp] [DW_LANG_C_plus_plus]
> +!1 = metadata !{metadata !"foo.cpp", metadata !"."}
> +!2 = metadata !{i32 0}
> +!3 = metadata !{metadata !4}
> +!4 = metadata !{i32 786451, metadata !5, null, metadata !"Base", i32 1, i64 128, i64 64, i32 0, i32 0, null, metadata !6, i32 0, null, null, metadata !"_ZTS4Base"} ; [ DW_TAG_structure_type ] [Base] [line 1, size 128, align 64, offset 0] [def] [from ]
> +!5 = metadata !{metadata !"./a.hpp", metadata !"."}
> +!6 = metadata !{metadata !7, metadata !9}
> +!7 = metadata !{i32 786445, metadata !5, metadata !"_ZTS4Base", metadata !"a", i32 2, i64 32, i64 32, i64 0, i32 0, metadata !8} ; [ DW_TAG_member ] [a] [line 2, size 32, align 32, offset 0] [from int]
> +!8 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
> +!9 = metadata !{i32 786445, metadata !5, metadata !"_ZTS4Base", metadata !"b", i32 3, i64 64, i64 64, i64 64, i32 0, metadata !10} ; [ DW_TAG_member ] [b] [line 3, size 64, align 64, offset 64] [from ]
> +!10 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 0, metadata !"_ZTS4Base"}
> +!11 = metadata !{metadata !12}
> +!12 = metadata !{i32 786478, metadata !1, metadata !13, metadata !"f", metadata !"f", metadata !"_Z1fi", i32 3, metadata !14, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (i32)* @_Z1fi, null, null, metadata !2, i32 3} ; [ DW_TAG_subprogram ] [line 3] [def] [f]
> +!13 = metadata !{i32 786473, metadata !1}         ; [ DW_TAG_file_type ] [foo.cpp]
> +!14 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !15, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
> +!15 = metadata !{null, metadata !8}
> +!16 = metadata !{i32 2, metadata !"Dwarf Version", i32 2}
> +!17 = metadata !{i32 786689, metadata !12, metadata !"a", metadata !13, i32 16777219, metadata !8, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [a] [line 3]
> +!18 = metadata !{i32 3, i32 0, metadata !12, null}
> +!19 = metadata !{i32 786688, metadata !12, metadata !"t", metadata !13, i32 4, metadata !4, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [t] [line 4]
> +!20 = metadata !{i32 4, i32 0, metadata !12, null}
> +!21 = metadata !{i32 5, i32 0, metadata !12, null}
>
> Added: llvm/trunk/test/Linker/Inputs/type-unique-simple2-b.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/type-unique-simple2-b.ll?rev=191800&view=auto
> ==============================================================================
> --- llvm/trunk/test/Linker/Inputs/type-unique-simple2-b.ll (added)
> +++ llvm/trunk/test/Linker/Inputs/type-unique-simple2-b.ll Tue Oct  1 18:45:54 2013
> @@ -0,0 +1,66 @@
> +; ModuleID = 'bar.cpp'
> +
> +%struct.Base = type { i32, %struct.Base* }
> +
> +; Function Attrs: nounwind ssp uwtable
> +define void @_Z1gi(i32 %a) #0 {
> +entry:
> +  %a.addr = alloca i32, align 4
> +  %t = alloca %struct.Base, align 8
> +  store i32 %a, i32* %a.addr, align 4
> +  call void @llvm.dbg.declare(metadata !{i32* %a.addr}, metadata !20), !dbg !21
> +  call void @llvm.dbg.declare(metadata !{%struct.Base* %t}, metadata !22), !dbg !23
> +  ret void, !dbg !24
> +}
> +
> +; Function Attrs: nounwind readnone
> +declare void @llvm.dbg.declare(metadata, metadata) #1
> +
> +; Function Attrs: ssp uwtable
> +define i32 @main() #2 {
> +entry:
> +  %retval = alloca i32, align 4
> +  store i32 0, i32* %retval
> +  call void @_Z1fi(i32 0), !dbg !25
> +  call void @_Z1gi(i32 1), !dbg !26
> +  ret i32 0, !dbg !27
> +}
> +
> +declare void @_Z1fi(i32) #3
> +
> +attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
> +attributes #1 = { nounwind readnone }
> +attributes #2 = { ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
> +attributes #3 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
> +
> +!llvm.dbg.cu = !{!0}
> +!llvm.module.flags = !{!19}
> +
> +!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.4 (http://llvm.org/git/clang.git 8a3f9e46cb988d2c664395b21910091e3730ae82) (http://llvm.org/git/llvm.git 4699e9549358bc77824a59114548eecc3f7c523c)", i1 false, metadata !"", i32 0, metadata !2, metadata !3, metadata !11, metadata !2, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [bar.cpp] [DW_LANG_C_plus_plus]
> +!1 = metadata !{metadata !"bar.cpp", metadata !"."}
> +!2 = metadata !{i32 0}
> +!3 = metadata !{metadata !4}
> +!4 = metadata !{i32 786451, metadata !5, null, metadata !"Base", i32 1, i64 128, i64 64, i32 0, i32 0, null, metadata !6, i32 0, null, null, metadata !"_ZTS4Base"} ; [ DW_TAG_structure_type ] [Base] [line 1, size 128, align 64, offset 0] [def] [from ]
> +!5 = metadata !{metadata !"./a.hpp", metadata !"."}
> +!6 = metadata !{metadata !7, metadata !9}
> +!7 = metadata !{i32 786445, metadata !5, metadata !"_ZTS4Base", metadata !"a", i32 2, i64 32, i64 32, i64 0, i32 0, metadata !8} ; [ DW_TAG_member ] [a] [line 2, size 32, align 32, offset 0] [from int]
> +!8 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
> +!9 = metadata !{i32 786445, metadata !5, metadata !"_ZTS4Base", metadata !"b", i32 3, i64 64, i64 64, i64 64, i32 0, metadata !10} ; [ DW_TAG_member ] [b] [line 3, size 64, align 64, offset 64] [from ]
> +!10 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 0, metadata !"_ZTS4Base"}
> +!11 = metadata !{metadata !12, metadata !16}
> +!12 = metadata !{i32 786478, metadata !1, metadata !13, metadata !"g", metadata !"g", metadata !"_Z1gi", i32 4, metadata !14, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (i32)* @_Z1gi, null, null, metadata !2, i32 4} ; [ DW_TAG_subprogram ] [line 4] [def] [g]
> +!13 = metadata !{i32 786473, metadata !1}         ; [ DW_TAG_file_type ] [bar.cpp]
> +!14 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !15, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
> +!15 = metadata !{null, metadata !8}
> +!16 = metadata !{i32 786478, metadata !1, metadata !13, metadata !"main", metadata !"main", metadata !"", i32 7, metadata !17, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @main, null, null, metadata !2, i32 7} ; [ DW_TAG_subprogram ] [line 7] [def] [main]
> +!17 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !18, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
> +!18 = metadata !{metadata !8}
> +!19 = metadata !{i32 2, metadata !"Dwarf Version", i32 2}
> +!20 = metadata !{i32 786689, metadata !12, metadata !"a", metadata !13, i32 16777220, metadata !8, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [a] [line 4]
> +!21 = metadata !{i32 4, i32 0, metadata !12, null}
> +!22 = metadata !{i32 786688, metadata !12, metadata !"t", metadata !13, i32 5, metadata !4, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [t] [line 5]
> +!23 = metadata !{i32 5, i32 0, metadata !12, null}
> +!24 = metadata !{i32 6, i32 0, metadata !12, null}
> +!25 = metadata !{i32 8, i32 0, metadata !16, null} ; [ DW_TAG_imported_declaration ]
> +!26 = metadata !{i32 9, i32 0, metadata !16, null}
> +!27 = metadata !{i32 10, i32 0, metadata !16, null}
>
> Added: llvm/trunk/test/Linker/type-unique-simple2.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/type-unique-simple2.ll?rev=191800&view=auto
> ==============================================================================
> --- llvm/trunk/test/Linker/type-unique-simple2.ll (added)
> +++ llvm/trunk/test/Linker/type-unique-simple2.ll Tue Oct  1 18:45:54 2013
> @@ -0,0 +1,6 @@
> +; REQUIRES: object-emission
> +
> +; RUN: llvm-link %S/Inputs/type-unique-simple2-a.ll %S/Inputs/type-unique-simple2-b.ll -S -o %t
> +; RUN: cat %t | FileCheck %S/Inputs/type-unique-simple2-a.ll -check-prefix=LINK
> +; RUN: llc -filetype=obj -O0 < %t > %t2
> +; RUN: llvm-dwarfdump -debug-dump=info %t2 | FileCheck %S/Inputs/type-unique-simple2-a.ll
>
> Modified: llvm/trunk/test/Transforms/LICM/debug-value.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LICM/debug-value.ll?rev=191800&r1=191799&r2=191800&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/LICM/debug-value.ll (original)
> +++ llvm/trunk/test/Transforms/LICM/debug-value.ll Tue Oct  1 18:45:54 2013
> @@ -38,7 +38,7 @@ declare void @llvm.dbg.value(metadata, i
>  !0 = metadata !{i32 589870, metadata !25, metadata !1, metadata !"idamax", metadata !"idamax", metadata !"", i32 112, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, null, null, null, null, i32 0} ; [ DW_TAG_subprogram ]
>  !1 = metadata !{i32 589865, metadata !25} ; [ DW_TAG_file_type ]
>  !2 = metadata !{i32 589841, metadata !25, i32 12, metadata !"clang version 2.9 (trunk 127169)", i1 true, metadata !"", i32 0, metadata !8, metadata !8, metadata !8, null, null, metadata !""} ; [ DW_TAG_compile_unit ]
> -!3 = metadata !{i32 589845, metadata !25, metadata !1, metadata !"", i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
> +!3 = metadata !{i32 589845, metadata !25, metadata !1, metadata !"", i32 0, i64 0, i64 0, i32 0, i32 0, null, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
>  !4 = metadata !{metadata !5}
>  !5 = metadata !{i32 589860, null, metadata !2, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
>  !6 = metadata !{i32 589870, metadata !25, metadata !1, metadata !"dscal", metadata !"dscal", metadata !"", i32 206, metadata !7, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, null, null, null, null, i32 0} ; [ DW_TAG_subprogram ]
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list