- /// getNumElements - Return number of NamedMDNode elements.
- unsigned getNumElements() const {
- return Node.size();
- }
-
- /// addElement - Add metadata element.
- void addElement(MetadataBase *M) {
- resizeOperands(0);
- OperandList[NumOperands++] = M;
- Node.push_back(WeakMetadataVH(M));
- }
-
- typedef SmallVectorImpl<WeakMetadataVH>::const_iterator const_elem_iterator;
- bool elem_empty() const { return Node.empty(); }
- const_elem_iterator elem_begin() const { return Node.begin(); }
- const_elem_iterator elem_end() const { return Node.end(); }
- elem_iterator elem_begin() { return Node.begin(); }
- elem_iterator elem_end() { return Node.end(); }
-
- /// isNullValue - Return true if this is the value that would be returned by
- /// getNullValue. This always returns false because getNullValue will never
- /// produce metadata.
- virtual bool isNullValue() const {
- return false;
- }
-
- virtual void replaceUsesOfWithOnConstant(Value *, Value *, Use *) {
- llvm_unreachable(
- "This should never be called because NamedMDNodes have no ops");
- }
-
- /// Methods for support type inquiry through isa, cast, and dyn_cast:
- static inline bool classof(const NamedMDNode *) { return true; }
- static bool classof(const Value *V) {
- return V->getValueID() == NamedMDNodeVal;
- }
-};
-
-//===----------------------------------------------------------------------===//
-/// MetadataContext -
-/// MetadataContext handles uniquing and assignment of IDs for custom metadata
-/// types. Custom metadata handler names do not contain spaces. And the name
-/// must start with an alphabet. The regular expression used to check name
-/// is [a-zA-Z$._][a-zA-Z$._0-9]*
-class MetadataContext {
-public:
- typedef std::pair<unsigned, WeakVH> MDPairTy;
- typedef SmallVector<MDPairTy, 2> MDMapTy;
- typedef DenseMap<const Instruction *, MDMapTy> MDStoreTy;
- friend class BitcodeReader;
-private:
-
- /// MetadataStore - Collection of metadata used in this context.
- MDStoreTy MetadataStore;
-
- /// MDHandlerNames - Map to hold metadata handler names.
- StringMap<unsigned> MDHandlerNames;
-
-public:
- /// RegisterMDKind - Register a new metadata kind and return its ID.
- /// A metadata kind can be registered only once.
- unsigned RegisterMDKind(const char *Name);
-
- /// getMDKind - Return metadata kind. If the requested metadata kind
- /// is not registered then return 0.
- unsigned getMDKind(const char *Name);
-
- /// validName - Return true if Name is a valid custom metadata handler name.
- bool validName(const char *Name);