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 "ConstantsContext.h"
19 #include "llvm/LLVMContext.h"
20 #include "llvm/Constants.h"
21 #include "llvm/DerivedTypes.h"
22 #include "llvm/System/RWMutex.h"
23 #include "llvm/ADT/APFloat.h"
24 #include "llvm/ADT/APInt.h"
25 #include "llvm/ADT/DenseMap.h"
26 #include "llvm/ADT/FoldingSet.h"
27 #include "llvm/ADT/StringMap.h"
40 struct DenseMapAPIntKeyInfo {
44 KeyTy(const APInt& V, const Type* Ty) : val(V), type(Ty) {}
45 KeyTy(const KeyTy& that) : val(that.val), type(that.type) {}
46 bool operator==(const KeyTy& that) const {
47 return type == that.type && this->val == that.val;
49 bool operator!=(const KeyTy& that) const {
50 return !this->operator==(that);
53 static inline KeyTy getEmptyKey() { return KeyTy(APInt(1,0), 0); }
54 static inline KeyTy getTombstoneKey() { return KeyTy(APInt(1,1), 0); }
55 static unsigned getHashValue(const KeyTy &Key) {
56 return DenseMapInfo<void*>::getHashValue(Key.type) ^
57 Key.val.getHashValue();
59 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
62 static bool isPod() { return false; }
65 struct DenseMapAPFloatKeyInfo {
68 KeyTy(const APFloat& V) : val(V){}
69 KeyTy(const KeyTy& that) : val(that.val) {}
70 bool operator==(const KeyTy& that) const {
71 return this->val.bitwiseIsEqual(that.val);
73 bool operator!=(const KeyTy& that) const {
74 return !this->operator==(that);
77 static inline KeyTy getEmptyKey() {
78 return KeyTy(APFloat(APFloat::Bogus,1));
80 static inline KeyTy getTombstoneKey() {
81 return KeyTy(APFloat(APFloat::Bogus,2));
83 static unsigned getHashValue(const KeyTy &Key) {
84 return Key.val.getHashValue();
86 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
89 static bool isPod() { return false; }
92 struct LLVMContextImpl {
93 sys::SmartRWMutex<true> ConstantsLock;
95 typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
96 DenseMapAPIntKeyInfo> IntMapTy;
97 IntMapTy IntConstants;
99 typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*,
100 DenseMapAPFloatKeyInfo> FPMapTy;
103 StringMap<MDString*> MDStringCache;
105 FoldingSet<MDNode> MDNodeSet;
107 ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
109 typedef ValueMap<std::vector<Constant*>, ArrayType,
110 ConstantArray, true /*largekey*/> ArrayConstantsTy;
111 ArrayConstantsTy ArrayConstants;
113 typedef ValueMap<std::vector<Constant*>, StructType,
114 ConstantStruct, true /*largekey*/> StructConstantsTy;
115 StructConstantsTy StructConstants;
117 typedef ValueMap<std::vector<Constant*>, VectorType,
118 ConstantVector> VectorConstantsTy;
119 VectorConstantsTy VectorConstants;
121 ValueMap<char, PointerType, ConstantPointerNull> NullPtrConstants;
123 ValueMap<char, Type, UndefValue> UndefValueConstants;
125 ValueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants;
127 ConstantInt *TheTrueVal;
128 ConstantInt *TheFalseVal;
130 LLVMContextImpl() : TheTrueVal(0), TheFalseVal(0) { }