X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FIR%2FMetadata.h;h=94b24f4e288e05c059558a55b7bf1ea7c1a046c1;hb=d16725c31fbb40fcbf0cdf68b2b417ba445c5140;hp=a31bdbfac65f19f4370b504ae0e6df93c368959f;hpb=9ca358021c2df17869cb20cae61f321a4b2ccd58;p=oota-llvm.git diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h index a31bdbfac65..94b24f4e288 100644 --- a/include/llvm/IR/Metadata.h +++ b/include/llvm/IR/Metadata.h @@ -27,8 +27,11 @@ #include namespace llvm { + class LLVMContext; class Module; +class ModuleSlotTracker; + template class SymbolTableListTraits; @@ -59,27 +62,28 @@ protected: public: enum MetadataKind { MDTupleKind, - MDLocationKind, - GenericDebugNodeKind, - MDSubrangeKind, - MDEnumeratorKind, - MDBasicTypeKind, - MDDerivedTypeKind, - MDCompositeTypeKind, - MDSubroutineTypeKind, - MDFileKind, - MDCompileUnitKind, - MDSubprogramKind, - MDLexicalBlockKind, - MDLexicalBlockFileKind, - MDNamespaceKind, - MDTemplateTypeParameterKind, - MDTemplateValueParameterKind, - MDGlobalVariableKind, - MDLocalVariableKind, - MDExpressionKind, - MDObjCPropertyKind, - MDImportedEntityKind, + DILocationKind, + GenericDINodeKind, + DISubrangeKind, + DIEnumeratorKind, + DIBasicTypeKind, + DIDerivedTypeKind, + DICompositeTypeKind, + DISubroutineTypeKind, + DIFileKind, + DICompileUnitKind, + DISubprogramKind, + DILexicalBlockKind, + DILexicalBlockFileKind, + DINamespaceKind, + DIModuleKind, + DITemplateTypeParameterKind, + DITemplateValueParameterKind, + DIGlobalVariableKind, + DILocalVariableKind, + DIExpressionKind, + DIObjCPropertyKind, + DIImportedEntityKind, ConstantAsMetadataKind, LocalAsMetadataKind, MDStringKind @@ -89,7 +93,7 @@ protected: Metadata(unsigned ID, StorageType Storage) : SubclassID(ID), Storage(Storage), SubclassData16(0), SubclassData32(0) { } - ~Metadata() {} + ~Metadata() = default; /// \brief Default handling of a changed operand, which asserts. /// @@ -121,7 +125,12 @@ public: /// /// If \c M is provided, metadata nodes will be numbered canonically; /// otherwise, pointer addresses are substituted. - void print(raw_ostream &OS, const Module *M = nullptr) const; + /// @{ + void print(raw_ostream &OS, const Module *M = nullptr, + bool IsForDebug = false) const; + void print(raw_ostream &OS, ModuleSlotTracker &MST, const Module *M = nullptr, + bool IsForDebug = false) const; + /// @} /// \brief Print as operand. /// @@ -129,7 +138,11 @@ public: /// /// If \c M is provided, metadata nodes will be numbered canonically; /// otherwise, pointer addresses are substituted. + /// @{ void printAsOperand(raw_ostream &OS, const Module *M = nullptr) const; + void printAsOperand(raw_ostream &OS, ModuleSlotTracker &MST, + const Module *M = nullptr) const; + /// @} }; #define HANDLE_METADATA(CLASS) class CLASS; @@ -164,7 +177,7 @@ class MetadataAsValue : public Value { Metadata *MD; MetadataAsValue(Type *Ty, Metadata *MD); - ~MetadataAsValue(); + ~MetadataAsValue() override; /// \brief Drop use of metadata (during teardown). void dropUse() { MD = nullptr; } @@ -253,7 +266,7 @@ protected: : Metadata(ID, Uniqued), ReplaceableMetadataImpl(V->getContext()), V(V) { assert(V && "Expected valid value"); } - ~ValueAsMetadata() {} + ~ValueAsMetadata() = default; public: static ValueAsMetadata *get(Value *V); @@ -560,10 +573,12 @@ struct AAMDNodes { template<> struct DenseMapInfo { static inline AAMDNodes getEmptyKey() { - return AAMDNodes(DenseMapInfo::getEmptyKey(), 0, 0); + return AAMDNodes(DenseMapInfo::getEmptyKey(), + nullptr, nullptr); } static inline AAMDNodes getTombstoneKey() { - return AAMDNodes(DenseMapInfo::getTombstoneKey(), 0, 0); + return AAMDNodes(DenseMapInfo::getTombstoneKey(), + nullptr, nullptr); } static unsigned getHashValue(const AAMDNodes &Val) { return DenseMapInfo::getHashValue(Val.TBAA) ^ @@ -754,13 +769,18 @@ protected: MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, ArrayRef Ops1, ArrayRef Ops2 = None); - ~MDNode() {} + ~MDNode() = default; void dropAllReferences(); MDOperand *mutable_begin() { return mutable_end() - NumOperands; } MDOperand *mutable_end() { return reinterpret_cast(this); } + typedef iterator_range mutable_op_range; + mutable_op_range mutable_operands() { + return mutable_op_range(mutable_begin(), mutable_end()); + } + public: static inline MDTuple *get(LLVMContext &Context, ArrayRef MDs); static inline MDTuple *getIfExists(LLVMContext &Context, @@ -864,6 +884,7 @@ protected: void storeDistinctInContext(); template static T *storeImpl(T *N, StorageType Storage, StoreT &Store); + template static T *storeImpl(T *N, StorageType Storage); private: void handleChangedOperand(void *Ref, Metadata *New); @@ -1028,6 +1049,78 @@ void TempMDNodeDeleter::operator()(MDNode *Node) const { MDNode::deleteTemporary(Node); } +/// \brief Typed iterator through MDNode operands. +/// +/// An iterator that transforms an \a MDNode::iterator into an iterator over a +/// particular Metadata subclass. +template +class TypedMDOperandIterator + : std::iterator { + MDNode::op_iterator I = nullptr; + +public: + TypedMDOperandIterator() = default; + explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {} + T *operator*() const { return cast_or_null(*I); } + TypedMDOperandIterator &operator++() { + ++I; + return *this; + } + TypedMDOperandIterator operator++(int) { + TypedMDOperandIterator Temp(*this); + ++I; + return Temp; + } + bool operator==(const TypedMDOperandIterator &X) const { return I == X.I; } + bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; } +}; + +/// \brief Typed, array-like tuple of metadata. +/// +/// This is a wrapper for \a MDTuple that makes it act like an array holding a +/// particular type of metadata. +template class MDTupleTypedArrayWrapper { + const MDTuple *N = nullptr; + +public: + MDTupleTypedArrayWrapper() = default; + MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {} + + template + MDTupleTypedArrayWrapper( + const MDTupleTypedArrayWrapper &Other, + typename std::enable_if::value>::type * = + nullptr) + : N(Other.get()) {} + + template + explicit MDTupleTypedArrayWrapper( + const MDTupleTypedArrayWrapper &Other, + typename std::enable_if::value>::type * = + nullptr) + : N(Other.get()) {} + + explicit operator bool() const { return get(); } + explicit operator MDTuple *() const { return get(); } + + MDTuple *get() const { return const_cast(N); } + MDTuple *operator->() const { return get(); } + MDTuple &operator*() const { return *get(); } + + // FIXME: Fix callers and remove condition on N. + unsigned size() const { return N ? N->getNumOperands() : 0u; } + T *operator[](unsigned I) const { return cast_or_null(N->getOperand(I)); } + + // FIXME: Fix callers and remove condition on N. + typedef TypedMDOperandIterator iterator; + iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); } + iterator end() const { return N ? iterator(N->op_end()) : iterator(); } +}; + +#define HANDLE_METADATA(CLASS) \ + typedef MDTupleTypedArrayWrapper CLASS##Array; +#include "llvm/IR/Metadata.def" + //===----------------------------------------------------------------------===// /// \brief A tuple of MDNodes. /// @@ -1104,7 +1197,7 @@ public: void addOperand(MDNode *M); void setOperand(unsigned I, MDNode *New); StringRef getName() const; - void print(raw_ostream &ROS) const; + void print(raw_ostream &ROS, bool IsForDebug = false) const; void dump() const; // --------------------------------------------------------------------------- @@ -1128,4 +1221,4 @@ public: } // end llvm namespace -#endif +#endif // LLVM_IR_METADATA_H