[llvm] r190330 - Debug Info: move DIScope::getContext to DwarfDebug.

David Blaikie dblaikie at gmail.com
Mon Sep 9 13:16:21 PDT 2013


On Mon, Sep 9, 2013 at 12:23 PM, Manman Ren <manman.ren at gmail.com> wrote:

> Author: mren
> Date: Mon Sep  9 14:23:58 2013
> New Revision: 190330
>
> URL: http://llvm.org/viewvc/llvm-project?rev=190330&view=rev
> Log:
> Debug Info: move DIScope::getContext to DwarfDebug.
>

This seems a little unfortunate. Though admittedly it's not actually a
feature of all DIScopes to have, themselves, a context.

What would happen if DIScope::getContext returned a DIScopeRef instead of a
DIScope? It shouldn't need the map then, right? Seems like it would be a
smaller change.


>
> DIScope::getContext is a wrapper function that calls the specific
> getContext
> method on each subclass. When we switch DIType::getContext to return
> DIScopeRef
> instead of DIScope, DIScope::getContext can no longer return a DIScope
> without
> a type identifier map.
>
> DIScope::getContext is only used by DwarfDebug, so we move it to DwarfDebug
> to have easy access to the type identifier map.
>
> 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/DebugInfo.cpp
>
> Modified: llvm/trunk/include/llvm/DebugInfo.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo.h?rev=190330&r1=190329&r2=190330&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/DebugInfo.h (original)
> +++ llvm/trunk/include/llvm/DebugInfo.h Mon Sep  9 14:23:58 2013
> @@ -200,9 +200,6 @@ namespace llvm {
>    public:
>      explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
>
> -    /// Gets the parent scope for this scope node or returns a
> -    /// default constructed scope.
> -    DIScope getContext() const;
>      StringRef getFilename() const;
>      StringRef getDirectory() const;
>
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=190330&r1=190329&r2=190330&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Mon Sep  9
> 14:23:58 2013
> @@ -913,19 +913,19 @@ void CompileUnit::constructTypeDIE(DIE &
>
>  /// Return true if the type is appropriately scoped to be contained inside
>  /// its own type unit.
> -static bool isTypeUnitScoped(DIType Ty) {
> +static bool isTypeUnitScoped(DIType Ty, const DwarfDebug *DD) {
>    DIScope Parent = Ty.getContext();
>    while (Parent) {
>      // Don't generate a hash for anything scoped inside a function.
>      if (Parent.isSubprogram())
>        return false;
> -    Parent = Parent.getContext();
> +    Parent = DD->getScopeContext(Parent);
>    }
>    return true;
>  }
>
>  /// Return true if the type should be split out into a type unit.
> -static bool shouldCreateTypeUnit(DICompositeType CTy) {
> +static bool shouldCreateTypeUnit(DICompositeType CTy, const DwarfDebug
> *DD) {
>    uint16_t Tag = CTy.getTag();
>
>    switch (Tag) {
> @@ -936,7 +936,7 @@ static bool shouldCreateTypeUnit(DICompo
>      // If this is a class, structure, union, or enumeration type
>      // that is not a declaration, is a type definition, and not scoped
>      // inside a function then separate this out as a type unit.
> -    if (CTy.isForwardDecl() || !isTypeUnitScoped(CTy))
> +    if (CTy.isForwardDecl() || !isTypeUnitScoped(CTy, DD))
>        return 0;
>      return 1;
>    default:
> @@ -1138,7 +1138,7 @@ void CompileUnit::constructTypeDIE(DIE &
>    }
>    // If this is a type applicable to a type unit it then add it to the
>    // list of types we'll compute a hash for later.
> -  if (shouldCreateTypeUnit(CTy))
> +  if (shouldCreateTypeUnit(CTy, DD))
>      DD->addTypeUnitType(&Buffer);
>  }
>
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=190330&r1=190329&r2=190330&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Mon Sep  9 14:23:58
> 2013
> @@ -2650,3 +2650,26 @@ void DwarfDebug::emitDebugStrDWO() {
>  DIScope DwarfDebug::resolve(DIScopeRef SRef) const {
>    return SRef.resolve(TypeIdentifierMap);
>  }
> +
> +// If the current node has a parent scope then return that,
> +// else return an empty scope.
> +DIScope DwarfDebug::getScopeContext(DIScope S) const {
> +
> +  if (S.isType())
> +    return DIType(S).getContext();
> +
> +  if (S.isSubprogram())
> +    return DISubprogram(S).getContext();
> +
> +  if (S.isLexicalBlock())
> +    return DILexicalBlock(S).getContext();
> +
> +  if (S.isLexicalBlockFile())
> +    return DILexicalBlockFile(S).getContext();
> +
> +  if (S.isNameSpace())
> +    return DINameSpace(S).getContext();
> +
> +  assert((S.isFile() || S.isCompileUnit()) && "Unhandled type of scope.");
> +  return DIScope();
> +}
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=190330&r1=190329&r2=190330&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Mon Sep  9 14:23:58 2013
> @@ -690,6 +690,9 @@ public:
>    /// or another context nested inside a subprogram.
>    bool isSubprogramContext(const MDNode *Context);
>
> +  /// Gets the parent scope for this scope node or returns a
> +  /// default constructed scope.
> +  DIScope getScopeContext(DIScope S) const;
>  };
>  } // End of namespace llvm
>
>
> Modified: llvm/trunk/lib/IR/DebugInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=190330&r1=190329&r2=190330&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/IR/DebugInfo.cpp (original)
> +++ llvm/trunk/lib/IR/DebugInfo.cpp Mon Sep  9 14:23:58 2013
> @@ -779,29 +779,6 @@ Value *DITemplateValueParameter::getValu
>    return getField(DbgNode, 4);
>  }
>
> -// If the current node has a parent scope then return that,
> -// else return an empty scope.
> -DIScope DIScope::getContext() const {
> -
> -  if (isType())
> -    return DIType(DbgNode).getContext();
> -
> -  if (isSubprogram())
> -    return DISubprogram(DbgNode).getContext();
> -
> -  if (isLexicalBlock())
> -    return DILexicalBlock(DbgNode).getContext();
> -
> -  if (isLexicalBlockFile())
> -    return DILexicalBlockFile(DbgNode).getContext();
> -
> -  if (isNameSpace())
> -    return DINameSpace(DbgNode).getContext();
> -
> -  assert((isFile() || isCompileUnit()) && "Unhandled type of scope.");
> -  return DIScope();
> -}
> -
>  StringRef DIScope::getFilename() const {
>    if (!DbgNode)
>      return StringRef();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130909/e2380586/attachment.html>


More information about the llvm-commits mailing list