[llvm] r233030 - DebugInfo: Overload get() in DIDescriptor subclasses

David Blaikie dblaikie at gmail.com
Mon Mar 23 15:00:19 PDT 2015


On Mon, Mar 23, 2015 at 2:54 PM, Duncan P. N. Exon Smith <
dexonsmith at apple.com> wrote:

> Author: dexonsmith
> Date: Mon Mar 23 16:54:07 2015
> New Revision: 233030
>
> URL: http://llvm.org/viewvc/llvm-project?rev=233030&view=rev
> Log:
> DebugInfo: Overload get() in DIDescriptor subclasses
>
> Continue to simplify the `DIDescriptor` subclasses, so that they behave
> more like raw pointers.  Remove `getRaw()`, replace it with an
> overloaded `get()`, and overload the arrow and cast operators.  Two
> testcases started to crash on the arrow operators with this change
> because of `scope:` references that weren't real scopes.  I fixed them.
> Soon I'll add verifier checks for them too.
>
> This also adds explicit dereference operators.  Previously, the builtin
> dereference against `operator MDNode *()` would have worked, but now the
> builtins are ambiguous.
>
> Modified:
>     llvm/trunk/include/llvm/IR/DebugInfo.h
>     llvm/trunk/lib/IR/DebugInfo.cpp
>     llvm/trunk/test/CodeGen/X86/2012-11-30-misched-dbg.ll
>     llvm/trunk/test/Transforms/Inline/debug-invoke.ll
>
> Modified: llvm/trunk/include/llvm/IR/DebugInfo.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=233030&r1=233029&r2=233030&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/DebugInfo.h (original)
> +++ llvm/trunk/include/llvm/IR/DebugInfo.h Mon Mar 23 16:54:07 2015
> @@ -174,6 +174,10 @@ public:
>    MDNode *get() const { return const_cast<MDNode *>(DbgNode); }
>    operator MDNode *() const { return get(); }
>    MDNode *operator->() const { return get(); }
> +  MDNode &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
>
>    // An explicit operator bool so that we can do testing of DI values
>    // easily.
> @@ -268,34 +272,39 @@ public:
>
>  #define RETURN_FROM_RAW(VALID, UNUSED)
>      \
>    do {
>      \
> -    assert(this->DbgNode && "Expected non-null in accessor");
>       \
> -    auto *N = getRaw();
>       \
> -    assert(N && "Expected correct subclass in accessor");
>       \
> +    auto *N = get();
>      \
> +    assert(N && "Expected non-null in accessor");
>       \
>      return VALID;
>       \
>    } while (false)
>  #define RETURN_DESCRIPTOR_FROM_RAW(DESC, VALID)
>       \
>    do {
>      \
> -    assert(this->DbgNode && "Expected non-null in accessor");
>       \
> -    auto *N = getRaw();
>       \
> -    assert(N && "Expected correct subclass in accessor");
>       \
> +    auto *N = get();
>      \
> +    assert(N && "Expected non-null in accessor");
>       \
>      return DESC(dyn_cast_or_null<MDNode>(VALID));
>       \
>    } while (false)
>  #define RETURN_REF_FROM_RAW(REF, VALID)
>       \
>    do {
>      \
> -    assert(this->DbgNode && "Expected non-null in accessor");
>       \
> -    auto *N = getRaw();
>       \
> -    assert(N && "Expected correct subclass in accessor");
>       \
> +    auto *N = get();
>      \
> +    assert(N && "Expected non-null in accessor");
>       \
>      return REF::get(VALID);
>       \
>    } while (false)
>
>  /// \brief This is used to represent ranges, for array bounds.
>  class DISubrange : public DIDescriptor {
> -  MDSubrange *getRaw() const { return
> dyn_cast_or_null<MDSubrange>(get()); }
> -
>  public:
>    explicit DISubrange(const MDNode *N = nullptr) : DIDescriptor(N) {}
>    DISubrange(const MDSubrange *N) : DIDescriptor(N) {}
>
> +  MDSubrange *get() const {
> +    return cast_or_null<MDSubrange>(DIDescriptor::get());
> +  }
> +  operator MDSubrange *() const { return get(); }
> +  MDSubrange *operator->() const { return get(); }
> +  MDSubrange &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    int64_t getLo() const { RETURN_FROM_RAW(N->getLo(), 0); }
>    int64_t getCount() const { RETURN_FROM_RAW(N->getCount(), 0); }
>    bool Verify() const;
> @@ -318,12 +327,20 @@ typedef DITypedArray<DIDescriptor> DIArr
>  /// FIXME: it seems strange that this doesn't have either a reference to
> the
>  /// type/precision or a file/line pair for location info.
>  class DIEnumerator : public DIDescriptor {
> -  MDEnumerator *getRaw() const { return
> dyn_cast_or_null<MDEnumerator>(get()); }
> -
>  public:
>    explicit DIEnumerator(const MDNode *N = nullptr) : DIDescriptor(N) {}
>    DIEnumerator(const MDEnumerator *N) : DIDescriptor(N) {}
>
> +  MDEnumerator *get() const {
> +    return cast_or_null<MDEnumerator>(DIDescriptor::get());
> +  }
> +  operator MDEnumerator *() const { return get(); }
> +  MDEnumerator *operator->() const { return get(); }
> +  MDEnumerator &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
>    int64_t getEnumValue() const { RETURN_FROM_RAW(N->getValue(), 0); }
>    bool Verify() const;
> @@ -344,13 +361,18 @@ typedef DITypedArray<DITypeRef> DITypeAr
>  /// DIScopes that are scopes in the strict lexical scope sense
>  /// (DICompileUnit, DISubprogram, etc.), but not for, e.g., a DIType.
>  class DIScope : public DIDescriptor {
> -protected:
> -  MDScope *getRaw() const { return dyn_cast_or_null<MDScope>(get()); }
> -
>  public:
>    explicit DIScope(const MDNode *N = nullptr) : DIDescriptor(N) {}
>    DIScope(const MDScope *N) : DIDescriptor(N) {}
>
> +  MDScope *get() const { return
> cast_or_null<MDScope>(DIDescriptor::get()); }
> +  operator MDScope *() const { return get(); }
> +  MDScope *operator->() const { return get(); }
> +  MDScope &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    /// \brief Get the parent scope.
>    ///
>    /// Gets the parent scope for this scope node or returns a default
> @@ -443,12 +465,18 @@ template <> DIRef<DIType>::DIRef(const M
>  /// FIXME: Types should be factored much better so that CV qualifiers and
>  /// others do not require a huge and empty descriptor full of zeros.
>  class DIType : public DIScope {
> -  MDType *getRaw() const { return dyn_cast_or_null<MDType>(get()); }
> -
>  public:
>    explicit DIType(const MDNode *N = nullptr) : DIScope(N) {}
>    DIType(const MDType *N) : DIScope(N) {}
>
> +  MDType *get() const { return cast_or_null<MDType>(DIDescriptor::get());
> }
> +  operator MDType *() const { return get(); }
> +  MDType *operator->() const { return get(); }
> +  MDType &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    operator DITypeRef() const {
>      assert(isType() &&
>             "constructing DITypeRef from an MDNode that is not a type");
> @@ -503,12 +531,20 @@ public:
>
>  /// \brief A basic type, like 'int' or 'float'.
>  class DIBasicType : public DIType {
> -  MDBasicType *getRaw() const { return
> dyn_cast_or_null<MDBasicType>(get()); }
> -
>  public:
>    explicit DIBasicType(const MDNode *N = nullptr) : DIType(N) {}
>    DIBasicType(const MDBasicType *N) : DIType(N) {}
>
> +  MDBasicType *get() const {
> +    return cast_or_null<MDBasicType>(DIDescriptor::get());
> +  }
> +  operator MDBasicType *() const { return get(); }
> +  MDBasicType *operator->() const { return get(); }
> +  MDBasicType &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    unsigned getEncoding() const { RETURN_FROM_RAW(N->getEncoding(), 0); }
>
>    bool Verify() const;
> @@ -519,35 +555,41 @@ public:
>  /// Like a const qualified type, a typedef, a pointer or reference, et
> cetera.
>  /// Or, a data member of a class/struct/union.
>  class DIDerivedType : public DIType {
> -  MDDerivedTypeBase *getRaw() const {
> -    return dyn_cast_or_null<MDDerivedTypeBase>(get());
> -  }
> -
>  public:
>    explicit DIDerivedType(const MDNode *N = nullptr) : DIType(N) {}
>    DIDerivedType(const MDDerivedTypeBase *N) : DIType(N) {}
>
> +  MDDerivedTypeBase *get() const {
> +    return cast_or_null<MDDerivedTypeBase>(DIDescriptor::get());
> +  }
> +  operator MDDerivedTypeBase *() const { return get(); }
> +  MDDerivedTypeBase *operator->() const { return get(); }
> +  MDDerivedTypeBase &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    DITypeRef getTypeDerivedFrom() const {
>      RETURN_REF_FROM_RAW(DITypeRef, N->getBaseType());
>    }
>
>    /// \brief Return property node, if this ivar is associated with one.
>    MDNode *getObjCProperty() const {
> -    if (auto *N = dyn_cast_or_null<MDDerivedType>(get()))
> +    if (auto *N = dyn_cast<MDDerivedType>(get()))
>        return dyn_cast_or_null<MDNode>(N->getExtraData());
>      return nullptr;
>    }
>
>    DITypeRef getClassType() const {
>      assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
> -    if (auto *N = dyn_cast_or_null<MDDerivedType>(get()))
> +    if (auto *N = dyn_cast<MDDerivedType>(get()))
>        return DITypeRef::get(N->getExtraData());
>      return DITypeRef::get(nullptr);
>    }
>
>    Constant *getConstant() const {
>      assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
> -    if (auto *N = dyn_cast_or_null<MDDerivedType>(get()))
> +    if (auto *N = dyn_cast<MDDerivedType>(get()))
>        if (auto *C =
> dyn_cast_or_null<ConstantAsMetadata>(N->getExtraData()))
>          return C->getValue();
>
> @@ -572,14 +614,20 @@ class DICompositeType : public DIDerived
>    /// \brief Set the array of member DITypes.
>    void setArraysHelper(MDNode *Elements, MDNode *TParams);
>
> -  MDCompositeTypeBase *getRaw() const {
> -    return dyn_cast_or_null<MDCompositeTypeBase>(get());
> -  }
> -
>  public:
>    explicit DICompositeType(const MDNode *N = nullptr) : DIDerivedType(N)
> {}
>    DICompositeType(const MDCompositeTypeBase *N) : DIDerivedType(N) {}
>
> +  MDCompositeTypeBase *get() const {
> +    return cast_or_null<MDCompositeTypeBase>(DIDescriptor::get());
> +  }
> +  operator MDCompositeTypeBase *() const { return get(); }
> +  MDCompositeTypeBase *operator->() const { return get(); }
> +  MDCompositeTypeBase &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    DIArray getElements() const {
>      assert(!isSubroutineType() && "no elements for DISubroutineType");
>      RETURN_DESCRIPTOR_FROM_RAW(DIArray, N->getElements());
> @@ -617,14 +665,20 @@ public:
>  };
>
>  class DISubroutineType : public DICompositeType {
> -  MDSubroutineType *getRaw() const {
> -    return dyn_cast_or_null<MDSubroutineType>(get());
> -  }
> -
>  public:
>    explicit DISubroutineType(const MDNode *N = nullptr) :
> DICompositeType(N) {}
>    DISubroutineType(const MDSubroutineType *N) : DICompositeType(N) {}
>
> +  MDSubroutineType *get() const {
> +    return cast_or_null<MDSubroutineType>(DIDescriptor::get());
> +  }
> +  operator MDSubroutineType *() const { return get(); }
> +  MDSubroutineType *operator->() const { return get(); }
> +  MDSubroutineType &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    DITypedArray<DITypeRef> getTypeArray() const {
>      RETURN_DESCRIPTOR_FROM_RAW(DITypedArray<DITypeRef>,
> N->getTypeArray());
>    }
> @@ -632,12 +686,18 @@ public:
>
>  /// \brief This is a wrapper for a file.
>  class DIFile : public DIScope {
> -  MDFile *getRaw() const { return dyn_cast_or_null<MDFile>(get()); }
> -
>  public:
>    explicit DIFile(const MDNode *N = nullptr) : DIScope(N) {}
>    DIFile(const MDFile *N) : DIScope(N) {}
>
> +  MDFile *get() const { return cast_or_null<MDFile>(DIDescriptor::get());
> }
> +  operator MDFile *() const { return get(); }
> +  MDFile *operator->() const { return get(); }
> +  MDFile &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    /// \brief Retrieve the MDNode for the directory/file pair.
>    MDNode *getFileNode() const { return get(); }
>    bool Verify() const;
> @@ -645,14 +705,20 @@ public:
>
>  /// \brief A wrapper for a compile unit.
>  class DICompileUnit : public DIScope {
> -  MDCompileUnit *getRaw() const {
> -    return dyn_cast_or_null<MDCompileUnit>(get());
> -  }
> -
>  public:
>    explicit DICompileUnit(const MDNode *N = nullptr) : DIScope(N) {}
>    DICompileUnit(const MDCompileUnit *N) : DIScope(N) {}
>
> +  MDCompileUnit *get() const {
> +    return cast_or_null<MDCompileUnit>(DIDescriptor::get());
> +  }
> +  operator MDCompileUnit *() const { return get(); }
> +  MDCompileUnit *operator->() const { return get(); }
> +  MDCompileUnit &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    dwarf::SourceLanguage getLanguage() const {
>
>  RETURN_FROM_RAW(static_cast<dwarf::SourceLanguage>(N->getSourceLanguage()),
>                      static_cast<dwarf::SourceLanguage>(0));
> @@ -693,12 +759,20 @@ public:
>
>  /// \brief This is a wrapper for a subprogram (e.g. a function).
>  class DISubprogram : public DIScope {
> -  MDSubprogram *getRaw() const { return
> dyn_cast_or_null<MDSubprogram>(get()); }
> -
>  public:
>    explicit DISubprogram(const MDNode *N = nullptr) : DIScope(N) {}
>    DISubprogram(const MDSubprogram *N) : DIScope(N) {}
>
> +  MDSubprogram *get() const {
> +    return cast_or_null<MDSubprogram>(DIDescriptor::get());
> +  }
> +  operator MDSubprogram *() const { return get(); }
> +  MDSubprogram *operator->() const { return get(); }
> +  MDSubprogram &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
>    StringRef getDisplayName() const { RETURN_FROM_RAW(N->getDisplayName(),
> ""); }
>    StringRef getLinkageName() const { RETURN_FROM_RAW(N->getLinkageName(),
> ""); }
> @@ -737,7 +811,7 @@ public:
>    Function *getFunction() const;
>
>    void replaceFunction(Function *F) {
> -    if (auto *N = getRaw())
> +    if (auto *N = get())
>

Can we just write that as "auto *N = *this" (not sure if that's better -
but I'm wondering how much we need the 'get()' function?)?


>        N->replaceFunction(F);
>    }
>    DIArray getTemplateParams() const {
> @@ -788,24 +862,30 @@ public:
>
>  /// \brief This is a wrapper for a lexical block.
>  class DILexicalBlock : public DIScope {
> -  MDLexicalBlockBase *getRaw() const {
> -    return dyn_cast_or_null<MDLexicalBlockBase>(get());
> -  }
> -
>  public:
>    explicit DILexicalBlock(const MDNode *N = nullptr) : DIScope(N) {}
>    DILexicalBlock(const MDLexicalBlock *N) : DIScope(N) {}
>
> +  MDLexicalBlockBase *get() const {
> +    return cast_or_null<MDLexicalBlockBase>(DIDescriptor::get());
> +  }
> +  operator MDLexicalBlockBase *() const { return get(); }
> +  MDLexicalBlockBase *operator->() const { return get(); }
> +  MDLexicalBlockBase &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    DIScope getContext() const {
>      RETURN_DESCRIPTOR_FROM_RAW(DIScope, N->getScope());
>    }
>    unsigned getLineNumber() const {
> -    if (auto *N = dyn_cast_or_null<MDLexicalBlock>(get()))
> +    if (auto *N = dyn_cast<MDLexicalBlock>(get()))
>        return N->getLine();
>      return 0;
>    }
>    unsigned getColumnNumber() const {
> -    if (auto *N = dyn_cast_or_null<MDLexicalBlock>(get()))
> +    if (auto *N = dyn_cast<MDLexicalBlock>(get()))
>        return N->getColumn();
>      return 0;
>    }
> @@ -814,14 +894,20 @@ public:
>
>  /// \brief This is a wrapper for a lexical block with a filename change.
>  class DILexicalBlockFile : public DIScope {
> -  MDLexicalBlockFile *getRaw() const {
> -    return dyn_cast_or_null<MDLexicalBlockFile>(get());
> -  }
> -
>  public:
>    explicit DILexicalBlockFile(const MDNode *N = nullptr) : DIScope(N) {}
>    DILexicalBlockFile(const MDLexicalBlockFile *N) : DIScope(N) {}
>
> +  MDLexicalBlockFile *get() const {
> +    return cast_or_null<MDLexicalBlockFile>(DIDescriptor::get());
> +  }
> +  operator MDLexicalBlockFile *() const { return get(); }
> +  MDLexicalBlockFile *operator->() const { return get(); }
> +  MDLexicalBlockFile &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    DIScope getContext() const {
>      // FIXME: This logic is horrible.  getScope() returns a
> DILexicalBlock, but
>      // then we check if it's a subprogram?  WHAT?!?
> @@ -842,12 +928,20 @@ public:
>
>  /// \brief A wrapper for a C++ style name space.
>  class DINameSpace : public DIScope {
> -  MDNamespace *getRaw() const { return
> dyn_cast_or_null<MDNamespace>(get()); }
> -
>  public:
>    explicit DINameSpace(const MDNode *N = nullptr) : DIScope(N) {}
>    DINameSpace(const MDNamespace *N) : DIScope(N) {}
>
> +  MDNamespace *get() const {
> +    return cast_or_null<MDNamespace>(DIDescriptor::get());
> +  }
> +  operator MDNamespace *() const { return get(); }
> +  MDNamespace *operator->() const { return get(); }
> +  MDNamespace &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
>    unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
>    DIScope getContext() const {
> @@ -858,15 +952,21 @@ public:
>
>  /// \brief This is a wrapper for template type parameter.
>  class DITemplateTypeParameter : public DIDescriptor {
> -  MDTemplateTypeParameter *getRaw() const {
> -    return dyn_cast_or_null<MDTemplateTypeParameter>(get());
> -  }
> -
>  public:
>    explicit DITemplateTypeParameter(const MDNode *N = nullptr)
>        : DIDescriptor(N) {}
>    DITemplateTypeParameter(const MDTemplateTypeParameter *N) :
> DIDescriptor(N) {}
>
> +  MDTemplateTypeParameter *get() const {
> +    return cast_or_null<MDTemplateTypeParameter>(DIDescriptor::get());
> +  }
> +  operator MDTemplateTypeParameter *() const { return get(); }
> +  MDTemplateTypeParameter *operator->() const { return get(); }
> +  MDTemplateTypeParameter &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
>
>    DITypeRef getType() const { RETURN_REF_FROM_RAW(DITypeRef,
> N->getType()); }
> @@ -875,16 +975,22 @@ public:
>
>  /// \brief This is a wrapper for template value parameter.
>  class DITemplateValueParameter : public DIDescriptor {
> -  MDTemplateValueParameter *getRaw() const {
> -    return dyn_cast_or_null<MDTemplateValueParameter>(get());
> -  }
> -
>  public:
>    explicit DITemplateValueParameter(const MDNode *N = nullptr)
>        : DIDescriptor(N) {}
>    DITemplateValueParameter(const MDTemplateValueParameter *N)
>        : DIDescriptor(N) {}
>
> +  MDTemplateValueParameter *get() const {
> +    return cast_or_null<MDTemplateValueParameter>(DIDescriptor::get());
> +  }
> +  operator MDTemplateValueParameter *() const { return get(); }
> +  MDTemplateValueParameter *operator->() const { return get(); }
> +  MDTemplateValueParameter &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
>    DITypeRef getType() const { RETURN_REF_FROM_RAW(DITypeRef,
> N->getType()); }
>    Metadata *getValue() const { RETURN_FROM_RAW(N->getValue(), nullptr); }
> @@ -893,16 +999,22 @@ public:
>
>  /// \brief This is a wrapper for a global variable.
>  class DIGlobalVariable : public DIDescriptor {
> -  MDGlobalVariable *getRaw() const {
> -    return dyn_cast_or_null<MDGlobalVariable>(get());
> -  }
> -
>    DIFile getFile() const { RETURN_DESCRIPTOR_FROM_RAW(DIFile,
> N->getFile()); }
>
>  public:
>    explicit DIGlobalVariable(const MDNode *N = nullptr) : DIDescriptor(N)
> {}
>    DIGlobalVariable(const MDGlobalVariable *N) : DIDescriptor(N) {}
>
> +  MDGlobalVariable *get() const {
> +    return cast_or_null<MDGlobalVariable>(DIDescriptor::get());
> +  }
> +  operator MDGlobalVariable *() const { return get(); }
> +  MDGlobalVariable *operator->() const { return get(); }
> +  MDGlobalVariable &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
>    StringRef getDisplayName() const { RETURN_FROM_RAW(N->getDisplayName(),
> ""); }
>    StringRef getLinkageName() const { RETURN_FROM_RAW(N->getLinkageName(),
> ""); }
> @@ -919,7 +1031,7 @@ public:
>
>    GlobalVariable *getGlobal() const;
>    Constant *getConstant() const {
> -    if (auto *N = getRaw())
> +    if (auto *N = get())
>        if (auto *C =
> dyn_cast_or_null<ConstantAsMetadata>(N->getVariable()))
>          return C->getValue();
>      return nullptr;
> @@ -934,16 +1046,22 @@ public:
>
>  /// \brief This is a wrapper for a variable (e.g. parameter, local,
> global etc).
>  class DIVariable : public DIDescriptor {
> -  MDLocalVariable *getRaw() const {
> -    return dyn_cast_or_null<MDLocalVariable>(get());
> -  }
> -
>    unsigned getFlags() const { RETURN_FROM_RAW(N->getFlags(), 0); }
>
>  public:
>    explicit DIVariable(const MDNode *N = nullptr) : DIDescriptor(N) {}
>    DIVariable(const MDLocalVariable *N) : DIDescriptor(N) {}
>
> +  MDLocalVariable *get() const {
> +    return cast_or_null<MDLocalVariable>(DIDescriptor::get());
> +  }
> +  operator MDLocalVariable *() const { return get(); }
> +  MDLocalVariable *operator->() const { return get(); }
> +  MDLocalVariable &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
>    unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
>    unsigned getArgNumber() const { RETURN_FROM_RAW(N->getArg(), 0); }
> @@ -1001,6 +1119,10 @@ public:
>    }
>    operator MDExpression *() const { return get(); }
>    MDExpression *operator->() const { return get(); }
> +  MDExpression &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
>
>    // Don't call this.  Call isValid() directly.
>    bool Verify() const = delete;
> @@ -1083,11 +1205,19 @@ public:
>  ///
>  /// This object is not associated with any DWARF tag.
>  class DILocation : public DIDescriptor {
> -  MDLocation *getRaw() const { return
> dyn_cast_or_null<MDLocation>(get()); }
> -
>  public:
>    explicit DILocation(const MDNode *N) : DIDescriptor(N) {}
>
> +  MDLocation *get() const {
> +    return cast_or_null<MDLocation>(DIDescriptor::get());
> +  }
> +  operator MDLocation *() const { return get(); }
> +  MDLocation *operator->() const { return get(); }
> +  MDLocation &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
>    unsigned getColumnNumber() const { RETURN_FROM_RAW(N->getColumn(), 0); }
>    DIScope getScope() const {
> @@ -1130,14 +1260,20 @@ public:
>  };
>
>  class DIObjCProperty : public DIDescriptor {
> -  MDObjCProperty *getRaw() const {
> -    return dyn_cast_or_null<MDObjCProperty>(get());
> -  }
> -
>  public:
>    explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) {}
>    DIObjCProperty(const MDObjCProperty *N) : DIDescriptor(N) {}
>
> +  MDObjCProperty *get() const {
> +    return cast_or_null<MDObjCProperty>(DIDescriptor::get());
> +  }
> +  operator MDObjCProperty *() const { return get(); }
> +  MDObjCProperty *operator->() const { return get(); }
> +  MDObjCProperty &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    StringRef getObjCPropertyName() const { RETURN_FROM_RAW(N->getName(),
> ""); }
>    DIFile getFile() const { RETURN_DESCRIPTOR_FROM_RAW(DIFile,
> N->getFile()); }
>    unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
> @@ -1179,15 +1315,21 @@ public:
>
>  /// \brief An imported module (C++ using directive or similar).
>  class DIImportedEntity : public DIDescriptor {
> -  MDImportedEntity *getRaw() const {
> -    return dyn_cast_or_null<MDImportedEntity>(get());
> -  }
> -
>  public:
>    DIImportedEntity() = default;
>    explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) {}
>    DIImportedEntity(const MDImportedEntity *N) : DIDescriptor(N) {}
>
> +  MDImportedEntity *get() const {
> +    return cast_or_null<MDImportedEntity>(DIDescriptor::get());
> +  }
> +  operator MDImportedEntity *() const { return get(); }
> +  MDImportedEntity *operator->() const { return get(); }
> +  MDImportedEntity &operator*() const {
> +    assert(get() && "Expected valid pointer");
> +    return *get();
> +  }
> +
>    DIScope getContext() const {
>      RETURN_DESCRIPTOR_FROM_RAW(DIScope, N->getScope());
>    }
>
> Modified: llvm/trunk/lib/IR/DebugInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=233030&r1=233029&r2=233030&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/IR/DebugInfo.cpp (original)
> +++ llvm/trunk/lib/IR/DebugInfo.cpp Mon Mar 23 16:54:07 2015
> @@ -260,7 +260,7 @@ static bool isDescriptorRef(const Metada
>  #endif
>
>  bool DIType::Verify() const {
> -  auto *N = getRaw();
> +  auto *N = dyn_cast_or_null<MDType>(DbgNode);
>    if (!N)
>      return false;
>    if (!isScopeRef(N->getScope()))
> @@ -294,10 +294,12 @@ bool DIType::Verify() const {
>    return false;
>  }
>
> -bool DIBasicType::Verify() const { return getRaw(); }
> +bool DIBasicType::Verify() const {
> +  return dyn_cast_or_null<MDBasicType>(DbgNode);
> +}
>
>  bool DIDerivedType::Verify() const {
> -  auto *N = getRaw();
> +  auto *N = dyn_cast_or_null<MDDerivedTypeBase>(DbgNode);
>    if (!N)
>      return false;
>    if (getTag() == dwarf::DW_TAG_ptr_to_member_type) {
> @@ -311,13 +313,13 @@ bool DIDerivedType::Verify() const {
>  }
>
>  bool DICompositeType::Verify() const {
> -  auto *N = getRaw();
> +  auto *N = dyn_cast_or_null<MDCompositeTypeBase>(DbgNode);
>    return N && isTypeRef(N->getBaseType()) &&
> isTypeRef(N->getVTableHolder()) &&
>           !(isLValueReference() && isRValueReference());
>  }
>
>  bool DISubprogram::Verify() const {
> -  auto *N = getRaw();
> +  auto *N = dyn_cast_or_null<MDSubprogram>(DbgNode);
>    if (!N)
>      return false;
>
> @@ -370,7 +372,7 @@ bool DISubprogram::Verify() const {
>  }
>
>  bool DIGlobalVariable::Verify() const {
> -  auto *N = getRaw();
> +  auto *N = dyn_cast_or_null<MDGlobalVariable>(DbgNode);
>
>    if (!N)
>      return false;
> @@ -390,7 +392,7 @@ bool DIGlobalVariable::Verify() const {
>  }
>
>  bool DIVariable::Verify() const {
> -  auto *N = getRaw();
> +  auto *N = dyn_cast_or_null<MDLocalVariable>(DbgNode);
>
>    if (!N)
>      return false;
> @@ -402,19 +404,37 @@ bool DIVariable::Verify() const {
>    return isTypeRef(N->getType());
>  }
>
> -bool DILocation::Verify() const { return getRaw(); }
> -bool DINameSpace::Verify() const { return getRaw(); }
> -bool DIFile::Verify() const { return getRaw(); }
> -bool DIEnumerator::Verify() const { return getRaw(); }
> -bool DISubrange::Verify() const { return getRaw(); }
> -bool DILexicalBlock::Verify() const { return getRaw(); }
> -bool DILexicalBlockFile::Verify() const { return getRaw(); }
> -bool DITemplateTypeParameter::Verify() const { return getRaw(); }
> -bool DITemplateValueParameter::Verify() const { return getRaw(); }
> -bool DIImportedEntity::Verify() const { return getRaw(); }
> +bool DILocation::Verify() const {
> +  return dyn_cast_or_null<MDLocation>(DbgNode);
> +}
> +bool DINameSpace::Verify() const {
> +  return dyn_cast_or_null<MDNamespace>(DbgNode);
> +}
> +bool DIFile::Verify() const { return dyn_cast_or_null<MDFile>(DbgNode); }
> +bool DIEnumerator::Verify() const {
> +  return dyn_cast_or_null<MDEnumerator>(DbgNode);
> +}
> +bool DISubrange::Verify() const {
> +  return dyn_cast_or_null<MDSubrange>(DbgNode);
> +}
> +bool DILexicalBlock::Verify() const {
> +  return dyn_cast_or_null<MDLexicalBlock>(DbgNode);
> +}
> +bool DILexicalBlockFile::Verify() const {
> +  return dyn_cast_or_null<MDLexicalBlockFile>(DbgNode);
> +}
> +bool DITemplateTypeParameter::Verify() const {
> +  return dyn_cast_or_null<MDTemplateTypeParameter>(DbgNode);
> +}
> +bool DITemplateValueParameter::Verify() const {
> +  return dyn_cast_or_null<MDTemplateValueParameter>(DbgNode);
> +}
> +bool DIImportedEntity::Verify() const {
> +  return dyn_cast_or_null<MDImportedEntity>(DbgNode);
> +}
>
>  void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) {
> -  TypedTrackingMDRef<MDCompositeTypeBase> N(getRaw());
> +  TypedTrackingMDRef<MDCompositeTypeBase> N(get());
>    if (Elements)
>      N->replaceElements(cast<MDTuple>(Elements));
>    if (TParams)
> @@ -432,7 +452,7 @@ DIScopeRef DIScope::getRef() const {
>  }
>
>  void DICompositeType::setContainingType(DICompositeType ContainingType) {
> -  TypedTrackingMDRef<MDCompositeTypeBase> N(getRaw());
> +  TypedTrackingMDRef<MDCompositeTypeBase> N(get());
>    N->replaceVTableHolder(ContainingType.getRef());
>    DbgNode = N;
>  }
> @@ -447,7 +467,7 @@ bool DIVariable::isInlinedFnArgument(con
>  }
>
>  Function *DISubprogram::getFunction() const {
> -  if (auto *N = getRaw())
> +  if (auto *N = get())
>      if (auto *C = dyn_cast_or_null<ConstantAsMetadata>(N->getFunction()))
>        return dyn_cast<Function>(C->getValue());
>    return nullptr;
> @@ -504,26 +524,25 @@ StringRef DIScope::getName() const {
>  }
>
>  StringRef DIScope::getFilename() const {
> -  if (auto *N = getRaw())
> +  if (auto *N = get())
>      return ::getStringField(dyn_cast_or_null<MDNode>(N->getFile()), 0);
>    return "";
>  }
>
>  StringRef DIScope::getDirectory() const {
> -  if (auto *N = getRaw())
> +  if (auto *N = get())
>      return ::getStringField(dyn_cast_or_null<MDNode>(N->getFile()), 1);
>    return "";
>  }
>
>  void DICompileUnit::replaceSubprograms(DIArray Subprograms) {
>    assert(Verify() && "Expected compile unit");
> -  getRaw()->replaceSubprograms(cast_or_null<MDTuple>(Subprograms.get()));
> +  get()->replaceSubprograms(cast_or_null<MDTuple>(Subprograms.get()));
>  }
>
>  void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) {
>    assert(Verify() && "Expected compile unit");
> -  getRaw()->replaceGlobalVariables(
> -      cast_or_null<MDTuple>(GlobalVariables.get()));
> +
> get()->replaceGlobalVariables(cast_or_null<MDTuple>(GlobalVariables.get()));
>  }
>
>  DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
>
> Modified: llvm/trunk/test/CodeGen/X86/2012-11-30-misched-dbg.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2012-11-30-misched-dbg.ll?rev=233030&r1=233029&r2=233030&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/2012-11-30-misched-dbg.ll (original)
> +++ llvm/trunk/test/CodeGen/X86/2012-11-30-misched-dbg.ll Mon Mar 23
> 16:54:07 2015
> @@ -77,7 +77,7 @@ declare i32 @__sprintf_chk(i8*, i32, i64
>  !10 = distinct !MDLexicalBlock(line: 434, column: 0, file: !14, scope:
> !11)
>  !11 = distinct !MDLexicalBlock(line: 250, column: 0, file: !14, scope:
> !12)
>  !12 = distinct !MDLexicalBlock(line: 249, column: 0, file: !14, scope:
> !13)
> -!13 = distinct !MDLexicalBlock(line: 221, column: 0, file: !14, scope: !2)
> +!13 = distinct !MDLexicalBlock(line: 221, column: 0, file: !14, scope:
> !21)
>  !14 = !MDFile(filename:
> "MultiSource/Benchmarks/MiBench/consumer-typeset/z19.c", directory:
> "MultiSource/Benchmarks/MiBench/consumer-typeset")
>  !15 = !MDCompositeType(tag: DW_TAG_array_type, size: 160, align: 8,
> baseType: !16, elements: !17)
>  !16 = !MDBasicType(tag: DW_TAG_base_type, name: "char", size: 8, align:
> 8, encoding: DW_ATE_signed_char)
>
> Modified: llvm/trunk/test/Transforms/Inline/debug-invoke.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/debug-invoke.ll?rev=233030&r1=233029&r2=233030&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/Inline/debug-invoke.ll (original)
> +++ llvm/trunk/test/Transforms/Inline/debug-invoke.ll Mon Mar 23 16:54:07
> 2015
> @@ -4,9 +4,9 @@
>
>  ; CHECK: invoke void @test()
>  ; CHECK-NEXT: to label {{.*}} unwind label {{.*}}, !dbg [[INL_LOC:!.*]]
> -; CHECK: [[EMPTY:.*]] = !{}
> -; CHECK: [[INL_LOC]] = !MDLocation(line: 1, scope: [[EMPTY]], inlinedAt:
> [[INL_AT:.*]])
> -; CHECK: [[INL_AT]] = distinct !MDLocation(line: 2, scope: [[EMPTY]])
> +; CHECK: [[SP:.*]] = !MDSubprogram(
> +; CHECK: [[INL_LOC]] = !MDLocation(line: 1, scope: [[SP]], inlinedAt:
> [[INL_AT:.*]])
> +; CHECK: [[INL_AT]] = distinct !MDLocation(line: 2, scope: [[SP]])
>
>  declare void @test()
>  declare i32 @__gxx_personality_v0(...)
> @@ -32,6 +32,6 @@ lpad:
>
>  !llvm.module.flags = !{!1}
>  !1 = !{i32 2, !"Debug Info Version", i32 3}
> -!2 = !{}
> +!2 = !MDSubprogram()
>  !3 = !MDLocation(line: 1, scope: !2)
>  !4 = !MDLocation(line: 2, scope: !2)
>
>
> _______________________________________________
> 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/20150323/7445cf32/attachment.html>


More information about the llvm-commits mailing list