[llvm] r187212 - Add a way to get the context of any particular scope.

David Blaikie dblaikie at gmail.com
Fri Jul 26 10:33:09 PDT 2013


On Fri, Jul 26, 2013 at 10:02 AM, Eric Christopher <echristo at gmail.com> wrote:
> Author: echristo
> Date: Fri Jul 26 12:02:36 2013
> New Revision: 187212
>
> URL: http://llvm.org/viewvc/llvm-project?rev=187212&view=rev
> Log:
> Add a way to get the context of any particular scope.
>
> Modified:
>     llvm/trunk/include/llvm/DebugInfo.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=187212&r1=187211&r2=187212&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/DebugInfo.h (original)
> +++ llvm/trunk/include/llvm/DebugInfo.h Fri Jul 26 12:02:36 2013
> @@ -187,6 +187,9 @@ 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/IR/DebugInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=187212&r1=187211&r2=187212&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/DebugInfo.cpp (original)
> +++ llvm/trunk/lib/IR/DebugInfo.cpp Fri Jul 26 12:02:36 2013
> @@ -692,6 +692,31 @@ 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 {

As discussed offline, a FIXME or notes about the necessity/problems
with some more general solution to this API might be nice.

> +
> +  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();
> +
> +  if (isFile() || isCompileUnit())

Given that this 'if' and the trailing block are the same, this seems
unnecessary, perhaps just ending with:

assert(isFile() || isCompileUnit());
return DIScope();

(technically different behavior from your original code if there are
other DIScope types or if you call getContext() on a null DIScope (in
which case I assume all the is* functions return false, which would
lead you to the final unconditional return in your version and an
assert failure in mine)

would suit?

> +    return DIScope();
> +
> +  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



More information about the llvm-commits mailing list