Jeffrey Yasskin | 4cfb3a7 | 2010-03-21 21:17:34 +0000 | [diff] [blame] | 1 | //===-- LLVMContextImpl.h - The LLVMContextImpl opaque class ----*- C++ -*-===// |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Owen Anderson | 36f62e5 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file declares LLVMContextImpl, the opaque implementation |
| 11 | // of LLVMContext. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 14 | |
| 15 | #ifndef LLVM_LLVMCONTEXT_IMPL_H |
| 16 | #define LLVM_LLVMCONTEXT_IMPL_H |
| 17 | |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 18 | #include "ConstantsContext.h" |
Owen Anderson | 6d549d6 | 2009-08-19 17:07:46 +0000 | [diff] [blame] | 19 | #include "LeaksContext.h" |
Owen Anderson | 542cffc | 2009-08-04 23:33:01 +0000 | [diff] [blame] | 20 | #include "TypesContext.h" |
Owen Anderson | 2ad5217 | 2009-07-21 02:47:59 +0000 | [diff] [blame] | 21 | #include "llvm/LLVMContext.h" |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 22 | #include "llvm/Constants.h" |
Owen Anderson | 2ad5217 | 2009-07-21 02:47:59 +0000 | [diff] [blame] | 23 | #include "llvm/DerivedTypes.h" |
Jeffrey Yasskin | cd3706c | 2010-03-21 22:08:41 +0000 | [diff] [blame^] | 24 | #include "llvm/Metadata.h" |
Owen Anderson | 9801560 | 2009-08-17 17:59:35 +0000 | [diff] [blame] | 25 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | a056697 | 2009-12-29 09:01:33 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ValueHandle.h" |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/APFloat.h" |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/APInt.h" |
| 29 | #include "llvm/ADT/DenseMap.h" |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/FoldingSet.h" |
Jeffrey Yasskin | 28f2448 | 2009-12-17 19:55:06 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/SmallPtrSet.h" |
Owen Anderson | 69ab416 | 2009-07-16 22:11:26 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/StringMap.h" |
Owen Anderson | 909f600 | 2009-07-23 23:25:33 +0000 | [diff] [blame] | 33 | #include <vector> |
Owen Anderson | 39ede7b | 2009-07-21 20:13:12 +0000 | [diff] [blame] | 34 | |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 35 | namespace llvm { |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 36 | |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 37 | class ConstantInt; |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 38 | class ConstantFP; |
Benjamin Kramer | 78c3bcb | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 39 | class LLVMContext; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 40 | class Type; |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 41 | class Value; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 42 | |
| 43 | struct DenseMapAPIntKeyInfo { |
| 44 | struct KeyTy { |
| 45 | APInt val; |
| 46 | const Type* type; |
| 47 | KeyTy(const APInt& V, const Type* Ty) : val(V), type(Ty) {} |
| 48 | KeyTy(const KeyTy& that) : val(that.val), type(that.type) {} |
| 49 | bool operator==(const KeyTy& that) const { |
| 50 | return type == that.type && this->val == that.val; |
| 51 | } |
| 52 | bool operator!=(const KeyTy& that) const { |
| 53 | return !this->operator==(that); |
| 54 | } |
| 55 | }; |
| 56 | static inline KeyTy getEmptyKey() { return KeyTy(APInt(1,0), 0); } |
| 57 | static inline KeyTy getTombstoneKey() { return KeyTy(APInt(1,1), 0); } |
| 58 | static unsigned getHashValue(const KeyTy &Key) { |
| 59 | return DenseMapInfo<void*>::getHashValue(Key.type) ^ |
| 60 | Key.val.getHashValue(); |
| 61 | } |
| 62 | static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { |
| 63 | return LHS == RHS; |
| 64 | } |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 67 | struct DenseMapAPFloatKeyInfo { |
| 68 | struct KeyTy { |
| 69 | APFloat val; |
| 70 | KeyTy(const APFloat& V) : val(V){} |
| 71 | KeyTy(const KeyTy& that) : val(that.val) {} |
| 72 | bool operator==(const KeyTy& that) const { |
| 73 | return this->val.bitwiseIsEqual(that.val); |
| 74 | } |
| 75 | bool operator!=(const KeyTy& that) const { |
| 76 | return !this->operator==(that); |
| 77 | } |
| 78 | }; |
| 79 | static inline KeyTy getEmptyKey() { |
| 80 | return KeyTy(APFloat(APFloat::Bogus,1)); |
| 81 | } |
| 82 | static inline KeyTy getTombstoneKey() { |
| 83 | return KeyTy(APFloat(APFloat::Bogus,2)); |
| 84 | } |
| 85 | static unsigned getHashValue(const KeyTy &Key) { |
| 86 | return Key.val.getHashValue(); |
| 87 | } |
| 88 | static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { |
| 89 | return LHS == RHS; |
| 90 | } |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Benjamin Kramer | 78c3bcb | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 93 | class LLVMContextImpl { |
| 94 | public: |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 95 | typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*, |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 96 | DenseMapAPIntKeyInfo> IntMapTy; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 97 | IntMapTy IntConstants; |
| 98 | |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 99 | typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*, |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 100 | DenseMapAPFloatKeyInfo> FPMapTy; |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 101 | FPMapTy FPConstants; |
| 102 | |
Owen Anderson | 69ab416 | 2009-07-16 22:11:26 +0000 | [diff] [blame] | 103 | StringMap<MDString*> MDStringCache; |
| 104 | |
Devang Patel | f718832 | 2009-09-03 01:39:20 +0000 | [diff] [blame] | 105 | FoldingSet<MDNode> MDNodeSet; |
Jeffrey Yasskin | 2cc2476 | 2010-03-13 01:26:15 +0000 | [diff] [blame] | 106 | // MDNodes may be uniqued or not uniqued. When they're not uniqued, they |
| 107 | // aren't in the MDNodeSet, but they're still shared between objects, so no |
| 108 | // one object can destroy them. This set allows us to at least destroy them |
| 109 | // on Context destruction. |
| 110 | SmallPtrSet<MDNode*, 1> NonUniquedMDNodes; |
Devang Patel | f718832 | 2009-09-03 01:39:20 +0000 | [diff] [blame] | 111 | |
Jeffrey Yasskin | f6ee7be | 2009-10-27 23:45:55 +0000 | [diff] [blame] | 112 | ConstantUniqueMap<char, Type, ConstantAggregateZero> AggZeroConstants; |
Owen Anderson | 13234f8 | 2009-08-10 18:16:08 +0000 | [diff] [blame] | 113 | |
Jeffrey Yasskin | f6ee7be | 2009-10-27 23:45:55 +0000 | [diff] [blame] | 114 | typedef ConstantUniqueMap<std::vector<Constant*>, ArrayType, |
Owen Anderson | 3d34492 | 2009-07-21 20:55:28 +0000 | [diff] [blame] | 115 | ConstantArray, true /*largekey*/> ArrayConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 116 | ArrayConstantsTy ArrayConstants; |
Owen Anderson | 39ede7b | 2009-07-21 20:13:12 +0000 | [diff] [blame] | 117 | |
Jeffrey Yasskin | f6ee7be | 2009-10-27 23:45:55 +0000 | [diff] [blame] | 118 | typedef ConstantUniqueMap<std::vector<Constant*>, StructType, |
| 119 | ConstantStruct, true /*largekey*/> StructConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 120 | StructConstantsTy StructConstants; |
Owen Anderson | 909f600 | 2009-07-23 23:25:33 +0000 | [diff] [blame] | 121 | |
Chris Lattner | 392be58 | 2010-02-12 20:49:41 +0000 | [diff] [blame] | 122 | typedef ConstantUniqueMap<Constant*, UnionType, ConstantUnion> |
| 123 | UnionConstantsTy; |
| 124 | UnionConstantsTy UnionConstants; |
| 125 | |
Jeffrey Yasskin | f6ee7be | 2009-10-27 23:45:55 +0000 | [diff] [blame] | 126 | typedef ConstantUniqueMap<std::vector<Constant*>, VectorType, |
| 127 | ConstantVector> VectorConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 128 | VectorConstantsTy VectorConstants; |
Owen Anderson | 0348a13 | 2009-07-24 00:36:24 +0000 | [diff] [blame] | 129 | |
Jeffrey Yasskin | f6ee7be | 2009-10-27 23:45:55 +0000 | [diff] [blame] | 130 | ConstantUniqueMap<char, PointerType, ConstantPointerNull> NullPtrConstants; |
Owen Anderson | c8c3026 | 2009-07-31 22:45:43 +0000 | [diff] [blame] | 131 | |
Jeffrey Yasskin | f6ee7be | 2009-10-27 23:45:55 +0000 | [diff] [blame] | 132 | ConstantUniqueMap<char, Type, UndefValue> UndefValueConstants; |
Owen Anderson | c8c3026 | 2009-07-31 22:45:43 +0000 | [diff] [blame] | 133 | |
Chris Lattner | 31b132c | 2009-10-28 00:01:44 +0000 | [diff] [blame] | 134 | DenseMap<std::pair<Function*, BasicBlock*> , BlockAddress*> BlockAddresses; |
Jeffrey Yasskin | f6ee7be | 2009-10-27 23:45:55 +0000 | [diff] [blame] | 135 | ConstantUniqueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants; |
Jeffrey Yasskin | ade270e | 2010-03-21 20:37:19 +0000 | [diff] [blame] | 136 | |
| 137 | ConstantUniqueMap<InlineAsmKeyType, PointerType, InlineAsm> InlineAsms; |
Owen Anderson | 1584a29 | 2009-08-04 20:25:11 +0000 | [diff] [blame] | 138 | |
Owen Anderson | 2ad5217 | 2009-07-21 02:47:59 +0000 | [diff] [blame] | 139 | ConstantInt *TheTrueVal; |
| 140 | ConstantInt *TheFalseVal; |
| 141 | |
Owen Anderson | 6d549d6 | 2009-08-19 17:07:46 +0000 | [diff] [blame] | 142 | LeakDetectorImpl<Value> LLVMObjects; |
| 143 | |
Dan Gohman | 97d2cb8 | 2009-08-25 16:00:35 +0000 | [diff] [blame] | 144 | // Basic type instances. |
| 145 | const Type VoidTy; |
| 146 | const Type LabelTy; |
| 147 | const Type FloatTy; |
| 148 | const Type DoubleTy; |
| 149 | const Type MetadataTy; |
| 150 | const Type X86_FP80Ty; |
| 151 | const Type FP128Ty; |
| 152 | const Type PPC_FP128Ty; |
| 153 | const IntegerType Int1Ty; |
| 154 | const IntegerType Int8Ty; |
| 155 | const IntegerType Int16Ty; |
| 156 | const IntegerType Int32Ty; |
| 157 | const IntegerType Int64Ty; |
| 158 | |
Owen Anderson | 9801560 | 2009-08-17 17:59:35 +0000 | [diff] [blame] | 159 | // Concrete/Abstract TypeDescriptions - We lazily calculate type descriptions |
| 160 | // for types as they are needed. Because resolution of types must invalidate |
| 161 | // all of the abstract type descriptions, we keep them in a seperate map to |
| 162 | // make this easy. |
| 163 | TypePrinting ConcreteTypeDescriptions; |
| 164 | TypePrinting AbstractTypeDescriptions; |
| 165 | |
Owen Anderson | 542cffc | 2009-08-04 23:33:01 +0000 | [diff] [blame] | 166 | TypeMap<ArrayValType, ArrayType> ArrayTypes; |
Owen Anderson | d918649 | 2009-08-04 23:47:44 +0000 | [diff] [blame] | 167 | TypeMap<VectorValType, VectorType> VectorTypes; |
Owen Anderson | e565995 | 2009-08-05 00:15:12 +0000 | [diff] [blame] | 168 | TypeMap<PointerValType, PointerType> PointerTypes; |
Owen Anderson | 4b5c761 | 2009-08-05 18:13:27 +0000 | [diff] [blame] | 169 | TypeMap<FunctionValType, FunctionType> FunctionTypes; |
Owen Anderson | 03cb69f | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 170 | TypeMap<StructValType, StructType> StructTypes; |
Chris Lattner | 392be58 | 2010-02-12 20:49:41 +0000 | [diff] [blame] | 171 | TypeMap<UnionValType, UnionType> UnionTypes; |
Owen Anderson | a42ac69 | 2009-08-13 23:27:32 +0000 | [diff] [blame] | 172 | TypeMap<IntegerValType, IntegerType> IntegerTypes; |
Dan Gohman | 97d2cb8 | 2009-08-25 16:00:35 +0000 | [diff] [blame] | 173 | |
Jeffrey Yasskin | 28f2448 | 2009-12-17 19:55:06 +0000 | [diff] [blame] | 174 | // Opaque types are not structurally uniqued, so don't use TypeMap. |
| 175 | typedef SmallPtrSet<const OpaqueType*, 8> OpaqueTypesTy; |
| 176 | OpaqueTypesTy OpaqueTypes; |
Jeffrey Yasskin | c660b23 | 2010-02-11 06:41:30 +0000 | [diff] [blame] | 177 | |
| 178 | /// Used as an abstract type that will never be resolved. |
| 179 | OpaqueType *const AlwaysOpaqueTy; |
| 180 | |
Jeffrey Yasskin | 28f2448 | 2009-12-17 19:55:06 +0000 | [diff] [blame] | 181 | |
Owen Anderson | e8f2185 | 2009-08-18 18:28:58 +0000 | [diff] [blame] | 182 | /// ValueHandles - This map keeps track of all of the value handles that are |
| 183 | /// watching a Value*. The Value::HasValueHandle bit is used to know |
| 184 | // whether or not a value has an entry in this map. |
| 185 | typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy; |
| 186 | ValueHandlesTy ValueHandles; |
| 187 | |
Chris Lattner | a056697 | 2009-12-29 09:01:33 +0000 | [diff] [blame] | 188 | /// CustomMDKindNames - Map to hold the metadata string to ID mapping. |
| 189 | StringMap<unsigned> CustomMDKindNames; |
| 190 | |
| 191 | typedef std::pair<unsigned, TrackingVH<MDNode> > MDPairTy; |
| 192 | typedef SmallVector<MDPairTy, 2> MDMapTy; |
| 193 | |
| 194 | /// MetadataStore - Collection of per-instruction metadata used in this |
| 195 | /// context. |
| 196 | DenseMap<const Instruction *, MDMapTy> MetadataStore; |
| 197 | |
Jeffrey Yasskin | 4cfb3a7 | 2010-03-21 21:17:34 +0000 | [diff] [blame] | 198 | LLVMContextImpl(LLVMContext &C); |
| 199 | ~LLVMContextImpl(); |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | } |
| 203 | |
Owen Anderson | 36f62e5 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 204 | #endif |