Owen Anderson | 3fb4aab | 2009-08-23 04:24:24 +0000 | [diff] [blame] | 1 | //===-- LLVMContextImpl.h - The LLVMContextImpl opaque class --------------===// |
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" |
Owen Anderson | 286b3af | 2009-08-17 17:34:27 +0000 | [diff] [blame] | 24 | #include "llvm/System/Mutex.h" |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 25 | #include "llvm/System/RWMutex.h" |
Owen Anderson | 9801560 | 2009-08-17 17:59:35 +0000 | [diff] [blame] | 26 | #include "llvm/Assembly/Writer.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" |
Owen Anderson | 69ab416 | 2009-07-16 22:11:26 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/StringMap.h" |
Owen Anderson | 909f600 | 2009-07-23 23:25:33 +0000 | [diff] [blame] | 32 | #include <vector> |
Owen Anderson | 39ede7b | 2009-07-21 20:13:12 +0000 | [diff] [blame] | 33 | |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 34 | namespace llvm { |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 35 | |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 36 | class ConstantInt; |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 37 | class ConstantFP; |
Owen Anderson | 69ab416 | 2009-07-16 22:11:26 +0000 | [diff] [blame] | 38 | class MDString; |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 39 | class MDNode; |
Benjamin Kramer | 78c3bcb | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 40 | class LLVMContext; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 41 | class Type; |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 42 | class Value; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 43 | |
| 44 | struct DenseMapAPIntKeyInfo { |
| 45 | struct KeyTy { |
| 46 | APInt val; |
| 47 | const Type* type; |
| 48 | KeyTy(const APInt& V, const Type* Ty) : val(V), type(Ty) {} |
| 49 | KeyTy(const KeyTy& that) : val(that.val), type(that.type) {} |
| 50 | bool operator==(const KeyTy& that) const { |
| 51 | return type == that.type && this->val == that.val; |
| 52 | } |
| 53 | bool operator!=(const KeyTy& that) const { |
| 54 | return !this->operator==(that); |
| 55 | } |
| 56 | }; |
| 57 | static inline KeyTy getEmptyKey() { return KeyTy(APInt(1,0), 0); } |
| 58 | static inline KeyTy getTombstoneKey() { return KeyTy(APInt(1,1), 0); } |
| 59 | static unsigned getHashValue(const KeyTy &Key) { |
| 60 | return DenseMapInfo<void*>::getHashValue(Key.type) ^ |
| 61 | Key.val.getHashValue(); |
| 62 | } |
| 63 | static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { |
| 64 | return LHS == RHS; |
| 65 | } |
| 66 | static bool isPod() { return false; } |
| 67 | }; |
| 68 | |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 69 | struct DenseMapAPFloatKeyInfo { |
| 70 | struct KeyTy { |
| 71 | APFloat val; |
| 72 | KeyTy(const APFloat& V) : val(V){} |
| 73 | KeyTy(const KeyTy& that) : val(that.val) {} |
| 74 | bool operator==(const KeyTy& that) const { |
| 75 | return this->val.bitwiseIsEqual(that.val); |
| 76 | } |
| 77 | bool operator!=(const KeyTy& that) const { |
| 78 | return !this->operator==(that); |
| 79 | } |
| 80 | }; |
| 81 | static inline KeyTy getEmptyKey() { |
| 82 | return KeyTy(APFloat(APFloat::Bogus,1)); |
| 83 | } |
| 84 | static inline KeyTy getTombstoneKey() { |
| 85 | return KeyTy(APFloat(APFloat::Bogus,2)); |
| 86 | } |
| 87 | static unsigned getHashValue(const KeyTy &Key) { |
| 88 | return Key.val.getHashValue(); |
| 89 | } |
| 90 | static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { |
| 91 | return LHS == RHS; |
| 92 | } |
| 93 | static bool isPod() { return false; } |
| 94 | }; |
| 95 | |
Benjamin Kramer | 78c3bcb | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 96 | class LLVMContextImpl { |
| 97 | public: |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 98 | sys::SmartRWMutex<true> ConstantsLock; |
| 99 | |
| 100 | typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*, |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 101 | DenseMapAPIntKeyInfo> IntMapTy; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 102 | IntMapTy IntConstants; |
| 103 | |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 104 | typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*, |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 105 | DenseMapAPFloatKeyInfo> FPMapTy; |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 106 | FPMapTy FPConstants; |
| 107 | |
Owen Anderson | 69ab416 | 2009-07-16 22:11:26 +0000 | [diff] [blame] | 108 | StringMap<MDString*> MDStringCache; |
| 109 | |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 110 | ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants; |
Owen Anderson | 13234f8 | 2009-08-10 18:16:08 +0000 | [diff] [blame] | 111 | |
Devang Patel | c5aa8c6 | 2009-08-11 06:31:57 +0000 | [diff] [blame] | 112 | typedef ValueMap<std::vector<Value*>, Type, MDNode, true /*largekey*/> |
| 113 | MDNodeMapTy; |
| 114 | |
| 115 | MDNodeMapTy MDNodes; |
Owen Anderson | 3d34492 | 2009-07-21 20:55:28 +0000 | [diff] [blame] | 116 | |
| 117 | typedef ValueMap<std::vector<Constant*>, ArrayType, |
| 118 | ConstantArray, true /*largekey*/> ArrayConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 119 | ArrayConstantsTy ArrayConstants; |
Owen Anderson | 39ede7b | 2009-07-21 20:13:12 +0000 | [diff] [blame] | 120 | |
Owen Anderson | 909f600 | 2009-07-23 23:25:33 +0000 | [diff] [blame] | 121 | typedef ValueMap<std::vector<Constant*>, StructType, |
| 122 | ConstantStruct, true /*largekey*/> StructConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 123 | StructConstantsTy StructConstants; |
Owen Anderson | 909f600 | 2009-07-23 23:25:33 +0000 | [diff] [blame] | 124 | |
Owen Anderson | 0348a13 | 2009-07-24 00:36:24 +0000 | [diff] [blame] | 125 | typedef ValueMap<std::vector<Constant*>, VectorType, |
| 126 | ConstantVector> VectorConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 127 | VectorConstantsTy VectorConstants; |
Owen Anderson | 0348a13 | 2009-07-24 00:36:24 +0000 | [diff] [blame] | 128 | |
Owen Anderson | c8c3026 | 2009-07-31 22:45:43 +0000 | [diff] [blame] | 129 | ValueMap<char, PointerType, ConstantPointerNull> NullPtrConstants; |
| 130 | |
| 131 | ValueMap<char, Type, UndefValue> UndefValueConstants; |
| 132 | |
Owen Anderson | 1584a29 | 2009-08-04 20:25:11 +0000 | [diff] [blame] | 133 | ValueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants; |
| 134 | |
Owen Anderson | 2ad5217 | 2009-07-21 02:47:59 +0000 | [diff] [blame] | 135 | ConstantInt *TheTrueVal; |
| 136 | ConstantInt *TheFalseVal; |
| 137 | |
Owen Anderson | 6d549d6 | 2009-08-19 17:07:46 +0000 | [diff] [blame] | 138 | // Lock used for guarding access to the leak detector |
| 139 | sys::SmartMutex<true> LLVMObjectsLock; |
| 140 | LeakDetectorImpl<Value> LLVMObjects; |
| 141 | |
Owen Anderson | 286b3af | 2009-08-17 17:34:27 +0000 | [diff] [blame] | 142 | // Lock used for guarding access to the type maps. |
| 143 | sys::SmartMutex<true> TypeMapLock; |
| 144 | |
Owen Anderson | 9801560 | 2009-08-17 17:59:35 +0000 | [diff] [blame] | 145 | // Recursive lock used for guarding access to AbstractTypeUsers. |
| 146 | // NOTE: The true template parameter means this will no-op when we're not in |
| 147 | // multithreaded mode. |
| 148 | sys::SmartMutex<true> AbstractTypeUsersLock; |
| 149 | |
Dan Gohman | 97d2cb8 | 2009-08-25 16:00:35 +0000 | [diff] [blame^] | 150 | // Basic type instances. |
| 151 | const Type VoidTy; |
| 152 | const Type LabelTy; |
| 153 | const Type FloatTy; |
| 154 | const Type DoubleTy; |
| 155 | const Type MetadataTy; |
| 156 | const Type X86_FP80Ty; |
| 157 | const Type FP128Ty; |
| 158 | const Type PPC_FP128Ty; |
| 159 | const IntegerType Int1Ty; |
| 160 | const IntegerType Int8Ty; |
| 161 | const IntegerType Int16Ty; |
| 162 | const IntegerType Int32Ty; |
| 163 | const IntegerType Int64Ty; |
| 164 | |
Owen Anderson | 9801560 | 2009-08-17 17:59:35 +0000 | [diff] [blame] | 165 | // Concrete/Abstract TypeDescriptions - We lazily calculate type descriptions |
| 166 | // for types as they are needed. Because resolution of types must invalidate |
| 167 | // all of the abstract type descriptions, we keep them in a seperate map to |
| 168 | // make this easy. |
| 169 | TypePrinting ConcreteTypeDescriptions; |
| 170 | TypePrinting AbstractTypeDescriptions; |
| 171 | |
Owen Anderson | 542cffc | 2009-08-04 23:33:01 +0000 | [diff] [blame] | 172 | TypeMap<ArrayValType, ArrayType> ArrayTypes; |
Owen Anderson | d918649 | 2009-08-04 23:47:44 +0000 | [diff] [blame] | 173 | TypeMap<VectorValType, VectorType> VectorTypes; |
Owen Anderson | e565995 | 2009-08-05 00:15:12 +0000 | [diff] [blame] | 174 | TypeMap<PointerValType, PointerType> PointerTypes; |
Owen Anderson | 4b5c761 | 2009-08-05 18:13:27 +0000 | [diff] [blame] | 175 | TypeMap<FunctionValType, FunctionType> FunctionTypes; |
Owen Anderson | 03cb69f | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 176 | TypeMap<StructValType, StructType> StructTypes; |
Owen Anderson | a42ac69 | 2009-08-13 23:27:32 +0000 | [diff] [blame] | 177 | TypeMap<IntegerValType, IntegerType> IntegerTypes; |
Dan Gohman | 97d2cb8 | 2009-08-25 16:00:35 +0000 | [diff] [blame^] | 178 | |
Owen Anderson | e8f2185 | 2009-08-18 18:28:58 +0000 | [diff] [blame] | 179 | /// ValueHandles - This map keeps track of all of the value handles that are |
| 180 | /// watching a Value*. The Value::HasValueHandle bit is used to know |
| 181 | // whether or not a value has an entry in this map. |
| 182 | typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy; |
| 183 | ValueHandlesTy ValueHandles; |
| 184 | |
Owen Anderson | a42ac69 | 2009-08-13 23:27:32 +0000 | [diff] [blame] | 185 | LLVMContextImpl(LLVMContext &C) : TheTrueVal(0), TheFalseVal(0), |
Dan Gohman | 97d2cb8 | 2009-08-25 16:00:35 +0000 | [diff] [blame^] | 186 | VoidTy(C, Type::VoidTyID), |
| 187 | LabelTy(C, Type::LabelTyID), |
| 188 | FloatTy(C, Type::FloatTyID), |
| 189 | DoubleTy(C, Type::DoubleTyID), |
| 190 | MetadataTy(C, Type::MetadataTyID), |
| 191 | X86_FP80Ty(C, Type::X86_FP80TyID), |
| 192 | FP128Ty(C, Type::FP128TyID), |
| 193 | PPC_FP128Ty(C, Type::PPC_FP128TyID), |
| 194 | Int1Ty(C, 1), |
| 195 | Int8Ty(C, 8), |
| 196 | Int16Ty(C, 16), |
| 197 | Int32Ty(C, 32), |
| 198 | Int64Ty(C, 64) { } |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | } |
| 202 | |
Owen Anderson | 36f62e5 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 203 | #endif |