/// This should not be stored in a container, because the underlying MDNode may
/// change in certain situations.
class DIDescriptor {
- // Befriends DIRef so DIRef can befriend the protected member
- // function: getFieldAs<DIRef>.
- template <typename T> friend class DIRef;
-
public:
/// \brief Duplicated debug info flags.
///
protected:
const MDNode *DbgNode;
- DIDescriptor getDescriptorField(unsigned Elt) const;
- template <typename DescTy> DescTy getFieldAs(unsigned Elt) const {
- return DescTy(getDescriptorField(Elt));
- }
-
public:
explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {}
DIDescriptor(const DebugNode *N) : DbgNode(N) {}
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();
- }
+ MDNode &operator*() const { return *get(); }
// An explicit operator bool so that we can do testing of DI values
// easily.
void print(raw_ostream &OS) const;
void dump() const;
-
- /// \brief Replace all uses of debug info referenced by this descriptor.
- void replaceAllUsesWith(LLVMContext &VMContext, DIDescriptor D);
- void replaceAllUsesWith(MDNode *D);
};
#define DECLARE_SIMPLIFY_DESCRIPTOR(DESC) \
}
operator MDSubrange *() const { return get(); }
MDSubrange *operator->() const { return get(); }
- MDSubrange &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDSubrange &operator*() const { return *get(); }
int64_t getLo() const { return get()->getLowerBound(); }
int64_t getCount() const { return get()->getCount(); }
}
operator MDEnumerator *() const { return get(); }
MDEnumerator *operator->() const { return get(); }
- MDEnumerator &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDEnumerator &operator*() const { return *get(); }
StringRef getName() const { return get()->getName(); }
int64_t getEnumValue() const { return get()->getValue(); }
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();
- }
+ MDScope &operator*() const { return *get(); }
- /// \brief Get the parent scope.
- ///
- /// Gets the parent scope for this scope node or returns a default
- /// constructed scope.
- DIScopeRef getContext() const;
- /// \brief Get the scope name.
- ///
- /// If the scope node has a name, return that, else return an empty string.
- StringRef getName() const;
- StringRef getFilename() const;
- StringRef getDirectory() const;
+ inline DIScopeRef getContext() const;
+ StringRef getName() const { return get()->getName(); }
+ StringRef getFilename() const { return get()->getFilename(); }
+ StringRef getDirectory() const { return get()->getDirectory(); }
/// \brief Generate a reference to this DIScope.
///
///
/// Abstracts over direct and identifier-based metadata references.
template <typename T> class DIRef {
- template <typename DescTy>
- friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
- friend DIScopeRef DIScope::getContext() const;
- friend DIScopeRef DIScope::getRef() const;
- friend class DIType;
-
/// \brief Val can be either a MDNode or a MDString.
///
/// In the latter, MDString specifies the type identifier.
DIScope DIRef<DIScope>::resolve(const DITypeIdentifierMap &Map) const;
template <> DIType DIRef<DIType>::resolve(const DITypeIdentifierMap &Map) const;
+DIScopeRef DIScope::getContext() const { return get()->getScope(); }
+
/// \brief This is a wrapper for a type.
///
/// FIXME: Types should be factored much better so that CV qualifiers and
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();
- }
+ MDType &operator*() const { return *get(); }
DIScopeRef getContext() const { return get()->getScope(); }
StringRef getName() const { return get()->getName(); }
}
operator MDBasicType *() const { return get(); }
MDBasicType *operator->() const { return get(); }
- MDBasicType &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDBasicType &operator*() const { return *get(); }
unsigned getEncoding() const { return get()->getEncoding(); }
};
}
operator MDDerivedTypeBase *() const { return get(); }
MDDerivedTypeBase *operator->() const { return get(); }
- MDDerivedTypeBase &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDDerivedTypeBase &operator*() const { return *get(); }
DITypeRef getTypeDerivedFrom() const { return get()->getBaseType(); }
/// \brief Return property node, if this ivar is associated with one.
- MDNode *getObjCProperty() const {
- if (auto *N = dyn_cast<MDDerivedType>(get()))
- return dyn_cast_or_null<MDNode>(N->getExtraData());
- return nullptr;
+ MDObjCProperty *getObjCProperty() const {
+ return cast<MDDerivedType>(get())->getObjCProperty();
}
DITypeRef getClassType() const {
- assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
- if (auto *N = dyn_cast<MDDerivedType>(get()))
- return MDTypeRef(N->getExtraData());
- return MDTypeRef();
+ return cast<MDDerivedType>(get())->getClassType();
}
Constant *getConstant() const {
- assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
- if (auto *N = dyn_cast<MDDerivedType>(get()))
- if (auto *C = dyn_cast_or_null<ConstantAsMetadata>(N->getExtraData()))
- return C->getValue();
-
- return nullptr;
+ return cast<MDDerivedType>(get())->getConstant();
}
};
}
operator MDCompositeTypeBase *() const { return get(); }
MDCompositeTypeBase *operator->() const { return get(); }
- MDCompositeTypeBase &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDCompositeTypeBase &operator*() const { return *get(); }
DIArray getElements() const {
assert(!isa<MDSubroutineType>(*this) && "no elements for DISubroutineType");
}
operator MDSubroutineType *() const { return get(); }
MDSubroutineType *operator->() const { return get(); }
- MDSubroutineType &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDSubroutineType &operator*() const { return *get(); }
MDTypeRefArray getTypeArray() const { return get()->getTypeArray(); }
};
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();
- }
+ MDFile &operator*() const { return *get(); }
/// \brief Retrieve the MDNode for the directory/file pair.
MDNode *getFileNode() const { return get(); }
}
operator MDCompileUnit *() const { return get(); }
MDCompileUnit *operator->() const { return get(); }
- MDCompileUnit &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDCompileUnit &operator*() const { return *get(); }
dwarf::SourceLanguage getLanguage() const {
return static_cast<dwarf::SourceLanguage>(get()->getSourceLanguage());
StringRef getFlags() const { return get()->getFlags(); }
unsigned getRunTimeVersion() const { return get()->getRuntimeVersion(); }
- DIArray getEnumTypes() const { return DIArray(get()->getEnumTypes()); }
- DIArray getRetainedTypes() const {
- return DIArray(get()->getRetainedTypes());
- }
- DIArray getSubprograms() const { return DIArray(get()->getSubprograms()); }
- DIArray getGlobalVariables() const {
- return DIArray(get()->getGlobalVariables());
- }
- DIArray getImportedEntities() const {
- return DIArray(get()->getImportedEntities());
- }
+ DIArray getEnumTypes() const { return get()->getEnumTypes(); }
+ DIArray getRetainedTypes() const { return get()->getRetainedTypes(); }
+ DIArray getSubprograms() const { return get()->getSubprograms(); }
+ DIArray getGlobalVariables() const { return get()->getGlobalVariables(); }
+ DIArray getImportedEntities() const { return get()->getImportedEntities(); }
void replaceSubprograms(DIArray Subprograms);
void replaceGlobalVariables(DIArray GlobalVariables);
}
operator MDSubprogram *() const { return get(); }
MDSubprogram *operator->() const { return get(); }
- MDSubprogram &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDSubprogram &operator*() const { return *get(); }
StringRef getName() const { return get()->getName(); }
StringRef getDisplayName() const { return get()->getDisplayName(); }
unsigned getScopeLineNumber() const { return get()->getScopeLine(); }
DIScopeRef getContext() const { return get()->getScope(); }
- DISubroutineType getType() const {
- return DISubroutineType(get()->getType());
- }
+ DISubroutineType getType() const { return get()->getType(); }
DITypeRef getContainingType() const { return get()->getContainingType(); }
/// \brief Check if this provides debugging information for the function F.
- bool describes(const Function *F);
+ bool describes(const Function *F) const { return get()->describes(F); }
- Function *getFunction() const;
+ Function *getFunction() const { return get()->getFunction(); }
- void replaceFunction(Function *F) {
- if (auto *N = get())
- N->replaceFunction(F);
- }
- DIArray getTemplateParams() const {
- return DIArray(get()->getTemplateParams());
- }
+ void replaceFunction(Function *F) { get()->replaceFunction(F); }
+ DIArray getTemplateParams() const { return get()->getTemplateParams(); }
DISubprogram getFunctionDeclaration() const {
- return DISubprogram(get()->getDeclaration());
+ return get()->getDeclaration();
}
DIArray getVariables() const { return DIArray(get()->getVariables()); }
}
operator MDLexicalBlockBase *() const { return get(); }
MDLexicalBlockBase *operator->() const { return get(); }
- MDLexicalBlockBase &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDLexicalBlockBase &operator*() const { return *get(); }
DIScope getContext() const { return DIScope(get()->getScope()); }
unsigned getLineNumber() const {
}
operator MDLexicalBlockFile *() const { return get(); }
MDLexicalBlockFile *operator->() const { return get(); }
- MDLexicalBlockFile &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDLexicalBlockFile &operator*() const { return *get(); }
DIScope getContext() const { return get()->getScope(); }
unsigned getDiscriminator() const { return get()->getDiscriminator(); }
}
operator MDNamespace *() const { return get(); }
MDNamespace *operator->() const { return get(); }
- MDNamespace &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDNamespace &operator*() const { return *get(); }
StringRef getName() const { return get()->getName(); }
unsigned getLineNumber() const { return get()->getLine(); }
}
operator MDTemplateTypeParameter *() const { return get(); }
MDTemplateTypeParameter *operator->() const { return get(); }
- MDTemplateTypeParameter &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDTemplateTypeParameter &operator*() const { return *get(); }
StringRef getName() const { return get()->getName(); }
DITypeRef getType() const { return get()->getType(); }
}
operator MDTemplateValueParameter *() const { return get(); }
MDTemplateValueParameter *operator->() const { return get(); }
- MDTemplateValueParameter &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDTemplateValueParameter &operator*() const { return *get(); }
StringRef getName() const { return get()->getName(); }
DITypeRef getType() const { return get()->getType(); }
}
operator MDGlobalVariable *() const { return get(); }
MDGlobalVariable *operator->() const { return get(); }
- MDGlobalVariable &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDGlobalVariable &operator*() const { return *get(); }
StringRef getName() const { return get()->getName(); }
StringRef getDisplayName() const { return get()->getDisplayName(); }
unsigned isLocalToUnit() const { return get()->isLocalToUnit(); }
unsigned isDefinition() const { return get()->isDefinition(); }
- DIScope getContext() const { return DIScope(get()->getScope()); }
- StringRef getFilename() const { return getFile().getFilename(); }
- StringRef getDirectory() const { return getFile().getDirectory(); }
+ DIScope getContext() const { return get()->getScope(); }
+ StringRef getFilename() const { return get()->getFilename(); }
+ StringRef getDirectory() const { return get()->getDirectory(); }
DITypeRef getType() const { return get()->getType(); }
- GlobalVariable *getGlobal() const;
- Constant *getConstant() const {
- if (auto *N = get())
- if (auto *C = dyn_cast_or_null<ConstantAsMetadata>(N->getVariable()))
- return C->getValue();
- return nullptr;
- }
+ Constant *getConstant() const { return get()->getVariable(); }
DIDerivedType getStaticDataMemberDeclaration() const {
- return DIDerivedType(get()->getStaticDataMemberDeclaration());
+ return get()->getStaticDataMemberDeclaration();
}
};
}
operator MDLocalVariable *() const { return get(); }
MDLocalVariable *operator->() const { return get(); }
- MDLocalVariable &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDLocalVariable &operator*() const { return *get(); }
StringRef getName() const { return get()->getName(); }
unsigned getLineNumber() const { return get()->getLine(); }
unsigned getArgNumber() const { return get()->getArg(); }
- DIScope getContext() const { return DIScope(get()->getScope()); }
- DIFile getFile() const { return DIFile(get()->getFile()); }
+ DIScope getContext() const { return get()->getScope(); }
+ DIFile getFile() const { return get()->getFile(); }
DITypeRef getType() const { return get()->getType(); }
bool isArtificial() const { return get()->isArtificial(); }
bool isObjectPointer() const { return get()->isObjectPointer(); }
/// \brief If this variable is inlined then return inline location.
- MDNode *getInlinedAt() const { return DIDescriptor(get()->getInlinedAt()); }
+ MDNode *getInlinedAt() const { return get()->getInlinedAt(); }
/// \brief Check if this is a "__block" variable (Apple Blocks).
bool isBlockByrefVariable(const DITypeIdentifierMap &Map) const {
return (getType().resolve(Map)).isBlockByrefStruct();
}
- /// \brief Check if this is an inlined function argument.
- bool isInlinedFnArgument(const Function *CurFn);
-
- /// \brief Return the size reported by the variable's type.
- unsigned getSizeInBits(const DITypeIdentifierMap &Map);
-
void printExtendedName(raw_ostream &OS) const;
};
}
operator MDExpression *() const { return get(); }
MDExpression *operator->() const { return get(); }
- MDExpression &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDExpression &operator*() const { return *get(); }
unsigned getNumElements() const { return get()->getNumElements(); }
uint64_t getElement(unsigned I) const { return get()->getElement(I); }
}
operator MDLocation *() const { return get(); }
MDLocation *operator->() const { return get(); }
- MDLocation &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDLocation &operator*() const { return *get(); }
unsigned getLineNumber() const { return get()->getLine(); }
unsigned getColumnNumber() const { return get()->getColumn(); }
DIScope getScope() const { return DIScope(get()->getScope()); }
- DILocation getOrigLocation() const {
- return DILocation(get()->getInlinedAt());
- }
- StringRef getFilename() const { return getScope().getFilename(); }
- StringRef getDirectory() const { return getScope().getDirectory(); }
- bool atSameLineAs(const DILocation &Other) const {
- return (getLineNumber() == Other.getLineNumber() &&
- getFilename() == Other.getFilename());
- }
- /// \brief Get the DWAF discriminator.
- ///
- /// DWARF discriminators are used to distinguish identical file locations for
- /// instructions that are on different basic blocks. If two instructions are
- /// inside the same lexical block and are in different basic blocks, we
- /// create a new lexical block with identical location as the original but
- /// with a different discriminator value
- /// (lib/Transforms/Util/AddDiscriminators.cpp for details).
- unsigned getDiscriminator() const {
- // Since discriminators are associated with lexical blocks, make
- // sure this location is a lexical block before retrieving its
- // value.
- if (auto *F = dyn_cast<MDLexicalBlockFile>(get()->getScope()))
- return F->getDiscriminator();
- return 0;
- }
-
- /// \brief Generate a new discriminator value for this location.
- unsigned computeNewDiscriminator(LLVMContext &Ctx);
-
- /// \brief Return a copy of this location with a different scope.
- DILocation copyWithNewScope(LLVMContext &Ctx, DILexicalBlockFile NewScope);
+ DILocation getOrigLocation() const { return get()->getInlinedAt(); }
+ StringRef getFilename() const { return get()->getFilename(); }
+ StringRef getDirectory() const { return get()->getDirectory(); }
+ unsigned getDiscriminator() const { return get()->getDiscriminator(); }
};
class DIObjCProperty : public DIDescriptor {
}
operator MDObjCProperty *() const { return get(); }
MDObjCProperty *operator->() const { return get(); }
- MDObjCProperty &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDObjCProperty &operator*() const { return *get(); }
StringRef getObjCPropertyName() const { return get()->getName(); }
- DIFile getFile() const { return DIFile(get()->getFile()); }
+ DIFile getFile() const { return get()->getFile(); }
unsigned getLineNumber() const { return get()->getLine(); }
StringRef getObjCPropertyGetterName() const { return get()->getGetterName(); }
StringRef getObjCPropertySetterName() const { return get()->getSetterName(); }
unsigned getAttributes() const { return get()->getAttributes(); }
- bool isReadOnlyObjCProperty() const {
- return (getAttributes() & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
- }
- bool isReadWriteObjCProperty() const {
- return (getAttributes() & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
- }
- bool isAssignObjCProperty() const {
- return (getAttributes() & dwarf::DW_APPLE_PROPERTY_assign) != 0;
- }
- bool isRetainObjCProperty() const {
- return (getAttributes() & dwarf::DW_APPLE_PROPERTY_retain) != 0;
- }
- bool isCopyObjCProperty() const {
- return (getAttributes() & dwarf::DW_APPLE_PROPERTY_copy) != 0;
- }
- bool isNonAtomicObjCProperty() const {
- return (getAttributes() & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
- }
/// \brief Get the type.
///
/// \note Objective-C doesn't have an ODR, so there is no benefit in storing
/// the type as a DITypeRef here.
- DIType getType() const { return DIType(get()->getType()); }
+ DIType getType() const { return get()->getType(); }
};
/// \brief An imported module (C++ using directive or similar).
}
operator MDImportedEntity *() const { return get(); }
MDImportedEntity *operator->() const { return get(); }
- MDImportedEntity &operator*() const {
- assert(get() && "Expected valid pointer");
- return *get();
- }
+ MDImportedEntity &operator*() const { return *get(); }
- DIScope getContext() const { return DIScope(get()->getScope()); }
+ DIScope getContext() const { return get()->getScope(); }
DIDescriptorRef getEntity() const { return get()->getEntity(); }
unsigned getLineNumber() const { return get()->getLine(); }
StringRef getName() const { return get()->getName(); }