Owen Anderson | 001dbfe | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 1 | //===----------------- LLVMContextImpl.h - Implementation ------*- C++ -*--===// |
Owen Anderson | 2bc29dc | 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 | 5217007 | 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 | 2bc29dc | 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 | 001dbfe | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 18 | #include "llvm/System/RWMutex.h" |
Owen Anderson | 914e50c | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/APFloat.h" |
Owen Anderson | 001dbfe | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/APInt.h" |
| 21 | #include "llvm/ADT/DenseMap.h" |
Owen Anderson | aad3fb7 | 2009-07-16 22:11:26 +0000 | [diff] [blame^] | 22 | #include "llvm/ADT/StringMap.h" |
Owen Anderson | 2bc29dc | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 23 | |
Owen Anderson | 001dbfe | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 25 | |
| 26 | class ConstantInt; |
Owen Anderson | 914e50c | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 27 | class ConstantFP; |
Owen Anderson | aad3fb7 | 2009-07-16 22:11:26 +0000 | [diff] [blame^] | 28 | class MDString; |
Owen Anderson | 001dbfe | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 29 | class LLVMContext; |
| 30 | class Type; |
| 31 | |
| 32 | struct DenseMapAPIntKeyInfo { |
| 33 | struct KeyTy { |
| 34 | APInt val; |
| 35 | const Type* type; |
| 36 | KeyTy(const APInt& V, const Type* Ty) : val(V), type(Ty) {} |
| 37 | KeyTy(const KeyTy& that) : val(that.val), type(that.type) {} |
| 38 | bool operator==(const KeyTy& that) const { |
| 39 | return type == that.type && this->val == that.val; |
| 40 | } |
| 41 | bool operator!=(const KeyTy& that) const { |
| 42 | return !this->operator==(that); |
| 43 | } |
| 44 | }; |
| 45 | static inline KeyTy getEmptyKey() { return KeyTy(APInt(1,0), 0); } |
| 46 | static inline KeyTy getTombstoneKey() { return KeyTy(APInt(1,1), 0); } |
| 47 | static unsigned getHashValue(const KeyTy &Key) { |
| 48 | return DenseMapInfo<void*>::getHashValue(Key.type) ^ |
| 49 | Key.val.getHashValue(); |
| 50 | } |
| 51 | static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { |
| 52 | return LHS == RHS; |
| 53 | } |
| 54 | static bool isPod() { return false; } |
| 55 | }; |
| 56 | |
Owen Anderson | 914e50c | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 57 | struct DenseMapAPFloatKeyInfo { |
| 58 | struct KeyTy { |
| 59 | APFloat val; |
| 60 | KeyTy(const APFloat& V) : val(V){} |
| 61 | KeyTy(const KeyTy& that) : val(that.val) {} |
| 62 | bool operator==(const KeyTy& that) const { |
| 63 | return this->val.bitwiseIsEqual(that.val); |
| 64 | } |
| 65 | bool operator!=(const KeyTy& that) const { |
| 66 | return !this->operator==(that); |
| 67 | } |
| 68 | }; |
| 69 | static inline KeyTy getEmptyKey() { |
| 70 | return KeyTy(APFloat(APFloat::Bogus,1)); |
| 71 | } |
| 72 | static inline KeyTy getTombstoneKey() { |
| 73 | return KeyTy(APFloat(APFloat::Bogus,2)); |
| 74 | } |
| 75 | static unsigned getHashValue(const KeyTy &Key) { |
| 76 | return Key.val.getHashValue(); |
| 77 | } |
| 78 | static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { |
| 79 | return LHS == RHS; |
| 80 | } |
| 81 | static bool isPod() { return false; } |
| 82 | }; |
| 83 | |
Owen Anderson | 001dbfe | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 84 | class LLVMContextImpl { |
| 85 | sys::SmartRWMutex<true> ConstantsLock; |
| 86 | |
| 87 | typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*, |
| 88 | DenseMapAPIntKeyInfo> IntMapTy; |
| 89 | IntMapTy IntConstants; |
| 90 | |
Owen Anderson | 914e50c | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 91 | typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*, |
| 92 | DenseMapAPFloatKeyInfo> FPMapTy; |
| 93 | FPMapTy FPConstants; |
| 94 | |
Owen Anderson | aad3fb7 | 2009-07-16 22:11:26 +0000 | [diff] [blame^] | 95 | StringMap<MDString*> MDStringCache; |
| 96 | |
Owen Anderson | 001dbfe | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 97 | LLVMContext &Context; |
| 98 | LLVMContextImpl(); |
| 99 | LLVMContextImpl(const LLVMContextImpl&); |
| 100 | public: |
| 101 | LLVMContextImpl(LLVMContext &C) : Context(C) { } |
| 102 | |
| 103 | /// Return a ConstantInt with the specified value and an implied Type. The |
| 104 | /// type is the integer type that corresponds to the bit width of the value. |
Owen Anderson | 914e50c | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 105 | ConstantInt *getConstantInt(const APInt &V); |
| 106 | |
| 107 | ConstantFP *getConstantFP(const APFloat &V); |
Owen Anderson | aad3fb7 | 2009-07-16 22:11:26 +0000 | [diff] [blame^] | 108 | |
| 109 | MDString *getMDString(const char *StrBegin, const char *StrEnd); |
| 110 | |
| 111 | |
| 112 | void erase(MDString *M); |
Owen Anderson | 2bc29dc | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | } |
| 116 | |
Owen Anderson | 5217007 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 117 | #endif |