| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 1 | //===- MetadataImpl.h - Helpers for implementing metadata -----------------===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
|  | 10 | // This file has private helpers for implementing metadata types. | 
|  | 11 | // | 
|  | 12 | //===----------------------------------------------------------------------===// | 
|  | 13 |  | 
|  | 14 | #ifndef LLVM_IR_METADATAIMPL_H | 
|  | 15 | #define LLVM_IR_METADATAIMPL_H | 
|  | 16 |  | 
|  | 17 | #include "llvm/ADT/DenseSet.h" | 
| Galina Kistanova | d9b46a1 | 2015-02-04 00:20:52 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Metadata.h" | 
| Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 19 |  | 
|  | 20 | namespace llvm { | 
|  | 21 |  | 
|  | 22 | template <class T, class InfoT> | 
|  | 23 | static T *getUniqued(DenseSet<T *, InfoT> &Store, | 
|  | 24 | const typename InfoT::KeyTy &Key) { | 
|  | 25 | auto I = Store.find_as(Key); | 
|  | 26 | return I == Store.end() ? nullptr : *I; | 
|  | 27 | } | 
|  | 28 |  | 
|  | 29 | template <class T, class StoreT> | 
|  | 30 | T *MDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) { | 
|  | 31 | switch (Storage) { | 
|  | 32 | case Uniqued: | 
|  | 33 | Store.insert(N); | 
|  | 34 | break; | 
|  | 35 | case Distinct: | 
|  | 36 | N->storeDistinctInContext(); | 
|  | 37 | break; | 
|  | 38 | case Temporary: | 
|  | 39 | break; | 
|  | 40 | } | 
|  | 41 | return N; | 
|  | 42 | } | 
|  | 43 |  | 
|  | 44 | } // end namespace llvm | 
|  | 45 |  | 
|  | 46 | #endif |