1 //===----------------- LLVMContextImpl.h - Implementation ------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares LLVMContextImpl, the opaque implementation
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LLVMCONTEXT_IMPL_H
16 #define LLVM_LLVMCONTEXT_IMPL_H
18 #include "llvm/System/RWMutex.h"
19 #include "llvm/ADT/APFloat.h"
20 #include "llvm/ADT/APInt.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/StringMap.h"
32 struct DenseMapAPIntKeyInfo {
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;
41 bool operator!=(const KeyTy& that) const {
42 return !this->operator==(that);
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();
51 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
54 static bool isPod() { return false; }
57 struct DenseMapAPFloatKeyInfo {
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);
65 bool operator!=(const KeyTy& that) const {
66 return !this->operator==(that);
69 static inline KeyTy getEmptyKey() {
70 return KeyTy(APFloat(APFloat::Bogus,1));
72 static inline KeyTy getTombstoneKey() {
73 return KeyTy(APFloat(APFloat::Bogus,2));
75 static unsigned getHashValue(const KeyTy &Key) {
76 return Key.val.getHashValue();
78 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
81 static bool isPod() { return false; }
84 class LLVMContextImpl {
85 sys::SmartRWMutex<true> ConstantsLock;
87 typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
88 DenseMapAPIntKeyInfo> IntMapTy;
89 IntMapTy IntConstants;
91 typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*,
92 DenseMapAPFloatKeyInfo> FPMapTy;
95 StringMap<MDString*> MDStringCache;
99 LLVMContextImpl(const LLVMContextImpl&);
101 LLVMContextImpl(LLVMContext &C) : Context(C) { }
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.
105 ConstantInt *getConstantInt(const APInt &V);
107 ConstantFP *getConstantFP(const APFloat &V);
109 MDString *getMDString(const char *StrBegin, const char *StrEnd);
112 void erase(MDString *M);