Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 1 | //===----------------- LLVMContextImpl.h - Implementation ------*- 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 | 542cffc | 2009-08-04 23:33:01 +0000 | [diff] [blame] | 19 | #include "TypesContext.h" |
Owen Anderson | 2ad5217 | 2009-07-21 02:47:59 +0000 | [diff] [blame] | 20 | #include "llvm/LLVMContext.h" |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 21 | #include "llvm/Constants.h" |
Owen Anderson | 2ad5217 | 2009-07-21 02:47:59 +0000 | [diff] [blame] | 22 | #include "llvm/DerivedTypes.h" |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 23 | #include "llvm/System/RWMutex.h" |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/APFloat.h" |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/APInt.h" |
| 26 | #include "llvm/ADT/DenseMap.h" |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/FoldingSet.h" |
Owen Anderson | 69ab416 | 2009-07-16 22:11:26 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/StringMap.h" |
Owen Anderson | 909f600 | 2009-07-23 23:25:33 +0000 | [diff] [blame] | 29 | #include <vector> |
Owen Anderson | 39ede7b | 2009-07-21 20:13:12 +0000 | [diff] [blame] | 30 | |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 31 | namespace llvm { |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 32 | |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 33 | class ConstantInt; |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 34 | class ConstantFP; |
Owen Anderson | 69ab416 | 2009-07-16 22:11:26 +0000 | [diff] [blame] | 35 | class MDString; |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 36 | class MDNode; |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 37 | struct LLVMContext; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 38 | class Type; |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 39 | class Value; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 40 | |
| 41 | struct DenseMapAPIntKeyInfo { |
| 42 | struct KeyTy { |
| 43 | APInt val; |
| 44 | const Type* type; |
| 45 | KeyTy(const APInt& V, const Type* Ty) : val(V), type(Ty) {} |
| 46 | KeyTy(const KeyTy& that) : val(that.val), type(that.type) {} |
| 47 | bool operator==(const KeyTy& that) const { |
| 48 | return type == that.type && this->val == that.val; |
| 49 | } |
| 50 | bool operator!=(const KeyTy& that) const { |
| 51 | return !this->operator==(that); |
| 52 | } |
| 53 | }; |
| 54 | static inline KeyTy getEmptyKey() { return KeyTy(APInt(1,0), 0); } |
| 55 | static inline KeyTy getTombstoneKey() { return KeyTy(APInt(1,1), 0); } |
| 56 | static unsigned getHashValue(const KeyTy &Key) { |
| 57 | return DenseMapInfo<void*>::getHashValue(Key.type) ^ |
| 58 | Key.val.getHashValue(); |
| 59 | } |
| 60 | static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { |
| 61 | return LHS == RHS; |
| 62 | } |
| 63 | static bool isPod() { return false; } |
| 64 | }; |
| 65 | |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 66 | struct DenseMapAPFloatKeyInfo { |
| 67 | struct KeyTy { |
| 68 | APFloat val; |
| 69 | KeyTy(const APFloat& V) : val(V){} |
| 70 | KeyTy(const KeyTy& that) : val(that.val) {} |
| 71 | bool operator==(const KeyTy& that) const { |
| 72 | return this->val.bitwiseIsEqual(that.val); |
| 73 | } |
| 74 | bool operator!=(const KeyTy& that) const { |
| 75 | return !this->operator==(that); |
| 76 | } |
| 77 | }; |
| 78 | static inline KeyTy getEmptyKey() { |
| 79 | return KeyTy(APFloat(APFloat::Bogus,1)); |
| 80 | } |
| 81 | static inline KeyTy getTombstoneKey() { |
| 82 | return KeyTy(APFloat(APFloat::Bogus,2)); |
| 83 | } |
| 84 | static unsigned getHashValue(const KeyTy &Key) { |
| 85 | return Key.val.getHashValue(); |
| 86 | } |
| 87 | static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { |
| 88 | return LHS == RHS; |
| 89 | } |
| 90 | static bool isPod() { return false; } |
| 91 | }; |
| 92 | |
Owen Anderson | 1584a29 | 2009-08-04 20:25:11 +0000 | [diff] [blame] | 93 | struct LLVMContextImpl { |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 94 | sys::SmartRWMutex<true> ConstantsLock; |
| 95 | |
| 96 | typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*, |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 97 | DenseMapAPIntKeyInfo> IntMapTy; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 98 | IntMapTy IntConstants; |
| 99 | |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 100 | typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*, |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 101 | DenseMapAPFloatKeyInfo> FPMapTy; |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 102 | FPMapTy FPConstants; |
| 103 | |
Owen Anderson | 69ab416 | 2009-07-16 22:11:26 +0000 | [diff] [blame] | 104 | StringMap<MDString*> MDStringCache; |
| 105 | |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 106 | FoldingSet<MDNode> MDNodeSet; |
| 107 | |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 108 | ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants; |
Owen Anderson | 3d34492 | 2009-07-21 20:55:28 +0000 | [diff] [blame] | 109 | |
| 110 | typedef ValueMap<std::vector<Constant*>, ArrayType, |
| 111 | ConstantArray, true /*largekey*/> ArrayConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 112 | ArrayConstantsTy ArrayConstants; |
Owen Anderson | 39ede7b | 2009-07-21 20:13:12 +0000 | [diff] [blame] | 113 | |
Owen Anderson | 909f600 | 2009-07-23 23:25:33 +0000 | [diff] [blame] | 114 | typedef ValueMap<std::vector<Constant*>, StructType, |
| 115 | ConstantStruct, true /*largekey*/> StructConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 116 | StructConstantsTy StructConstants; |
Owen Anderson | 909f600 | 2009-07-23 23:25:33 +0000 | [diff] [blame] | 117 | |
Owen Anderson | 0348a13 | 2009-07-24 00:36:24 +0000 | [diff] [blame] | 118 | typedef ValueMap<std::vector<Constant*>, VectorType, |
| 119 | ConstantVector> VectorConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 120 | VectorConstantsTy VectorConstants; |
Owen Anderson | 0348a13 | 2009-07-24 00:36:24 +0000 | [diff] [blame] | 121 | |
Owen Anderson | c8c3026 | 2009-07-31 22:45:43 +0000 | [diff] [blame] | 122 | ValueMap<char, PointerType, ConstantPointerNull> NullPtrConstants; |
| 123 | |
| 124 | ValueMap<char, Type, UndefValue> UndefValueConstants; |
| 125 | |
Owen Anderson | 1584a29 | 2009-08-04 20:25:11 +0000 | [diff] [blame] | 126 | ValueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants; |
| 127 | |
Owen Anderson | 2ad5217 | 2009-07-21 02:47:59 +0000 | [diff] [blame] | 128 | ConstantInt *TheTrueVal; |
| 129 | ConstantInt *TheFalseVal; |
| 130 | |
Owen Anderson | 542cffc | 2009-08-04 23:33:01 +0000 | [diff] [blame] | 131 | TypeMap<ArrayValType, ArrayType> ArrayTypes; |
Owen Anderson | d918649 | 2009-08-04 23:47:44 +0000 | [diff] [blame] | 132 | TypeMap<VectorValType, VectorType> VectorTypes; |
Owen Anderson | e565995 | 2009-08-05 00:15:12 +0000 | [diff] [blame] | 133 | TypeMap<PointerValType, PointerType> PointerTypes; |
Owen Anderson | 4b5c761 | 2009-08-05 18:13:27 +0000 | [diff] [blame^] | 134 | TypeMap<FunctionValType, FunctionType> FunctionTypes; |
Owen Anderson | 542cffc | 2009-08-04 23:33:01 +0000 | [diff] [blame] | 135 | |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 136 | LLVMContextImpl() : TheTrueVal(0), TheFalseVal(0) { } |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | } |
| 140 | |
Owen Anderson | 36f62e5 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 141 | #endif |