blob: 5a3056ad8fefb75217cffa466f51f5f7a60d98e4 [file] [log] [blame]
Owen Anderson20b34ac2009-07-16 18:04:31 +00001//===----------------- LLVMContextImpl.h - Implementation ------*- C++ -*--===//
Owen Anderson8e66e0b2009-06-30 00:48:55 +00002//
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 Anderson36f62e52009-06-30 17:06:46 +00009//
10// This file declares LLVMContextImpl, the opaque implementation
11// of LLVMContext.
12//
13//===----------------------------------------------------------------------===//
Owen Anderson8e66e0b2009-06-30 00:48:55 +000014
15#ifndef LLVM_LLVMCONTEXT_IMPL_H
16#define LLVM_LLVMCONTEXT_IMPL_H
17
Owen Andersonafd0c4c2009-08-04 22:41:48 +000018#include "ConstantsContext.h"
Owen Anderson2ad52172009-07-21 02:47:59 +000019#include "llvm/LLVMContext.h"
Owen Andersonedb4a702009-07-24 23:12:02 +000020#include "llvm/Constants.h"
Owen Anderson2ad52172009-07-21 02:47:59 +000021#include "llvm/DerivedTypes.h"
Owen Anderson20b34ac2009-07-16 18:04:31 +000022#include "llvm/System/RWMutex.h"
Owen Andersonc277dc42009-07-16 19:05:41 +000023#include "llvm/ADT/APFloat.h"
Owen Anderson20b34ac2009-07-16 18:04:31 +000024#include "llvm/ADT/APInt.h"
25#include "llvm/ADT/DenseMap.h"
Owen Anderson4118dde2009-07-16 23:44:30 +000026#include "llvm/ADT/FoldingSet.h"
Owen Anderson69ab4162009-07-16 22:11:26 +000027#include "llvm/ADT/StringMap.h"
Owen Anderson909f6002009-07-23 23:25:33 +000028#include <vector>
Owen Anderson39ede7b2009-07-21 20:13:12 +000029
Owen Anderson20b34ac2009-07-16 18:04:31 +000030namespace llvm {
Owen Andersonedb4a702009-07-24 23:12:02 +000031
Owen Anderson20b34ac2009-07-16 18:04:31 +000032class ConstantInt;
Owen Andersonc277dc42009-07-16 19:05:41 +000033class ConstantFP;
Owen Anderson69ab4162009-07-16 22:11:26 +000034class MDString;
Owen Anderson4118dde2009-07-16 23:44:30 +000035class MDNode;
Owen Andersonafd0c4c2009-08-04 22:41:48 +000036struct LLVMContext;
Owen Anderson20b34ac2009-07-16 18:04:31 +000037class Type;
Owen Anderson4118dde2009-07-16 23:44:30 +000038class Value;
Owen Anderson20b34ac2009-07-16 18:04:31 +000039
40struct DenseMapAPIntKeyInfo {
41 struct KeyTy {
42 APInt val;
43 const Type* type;
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;
48 }
49 bool operator!=(const KeyTy& that) const {
50 return !this->operator==(that);
51 }
52 };
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();
58 }
59 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
60 return LHS == RHS;
61 }
62 static bool isPod() { return false; }
63};
64
Owen Andersonc277dc42009-07-16 19:05:41 +000065struct DenseMapAPFloatKeyInfo {
66 struct KeyTy {
67 APFloat val;
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);
72 }
73 bool operator!=(const KeyTy& that) const {
74 return !this->operator==(that);
75 }
76 };
77 static inline KeyTy getEmptyKey() {
78 return KeyTy(APFloat(APFloat::Bogus,1));
79 }
80 static inline KeyTy getTombstoneKey() {
81 return KeyTy(APFloat(APFloat::Bogus,2));
82 }
83 static unsigned getHashValue(const KeyTy &Key) {
84 return Key.val.getHashValue();
85 }
86 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
87 return LHS == RHS;
88 }
89 static bool isPod() { return false; }
90};
91
Owen Anderson1584a292009-08-04 20:25:11 +000092struct LLVMContextImpl {
Owen Anderson20b34ac2009-07-16 18:04:31 +000093 sys::SmartRWMutex<true> ConstantsLock;
94
95 typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
Owen Andersonafd0c4c2009-08-04 22:41:48 +000096 DenseMapAPIntKeyInfo> IntMapTy;
Owen Anderson20b34ac2009-07-16 18:04:31 +000097 IntMapTy IntConstants;
98
Owen Andersonc277dc42009-07-16 19:05:41 +000099 typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*,
Owen Andersonafd0c4c2009-08-04 22:41:48 +0000100 DenseMapAPFloatKeyInfo> FPMapTy;
Owen Andersonc277dc42009-07-16 19:05:41 +0000101 FPMapTy FPConstants;
102
Owen Anderson69ab4162009-07-16 22:11:26 +0000103 StringMap<MDString*> MDStringCache;
104
Owen Anderson4118dde2009-07-16 23:44:30 +0000105 FoldingSet<MDNode> MDNodeSet;
106
Owen Andersonedb4a702009-07-24 23:12:02 +0000107 ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
Owen Anderson3d344922009-07-21 20:55:28 +0000108
109 typedef ValueMap<std::vector<Constant*>, ArrayType,
110 ConstantArray, true /*largekey*/> ArrayConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +0000111 ArrayConstantsTy ArrayConstants;
Owen Anderson39ede7b2009-07-21 20:13:12 +0000112
Owen Anderson909f6002009-07-23 23:25:33 +0000113 typedef ValueMap<std::vector<Constant*>, StructType,
114 ConstantStruct, true /*largekey*/> StructConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +0000115 StructConstantsTy StructConstants;
Owen Anderson909f6002009-07-23 23:25:33 +0000116
Owen Anderson0348a132009-07-24 00:36:24 +0000117 typedef ValueMap<std::vector<Constant*>, VectorType,
118 ConstantVector> VectorConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +0000119 VectorConstantsTy VectorConstants;
Owen Anderson0348a132009-07-24 00:36:24 +0000120
Owen Andersonc8c30262009-07-31 22:45:43 +0000121 ValueMap<char, PointerType, ConstantPointerNull> NullPtrConstants;
122
123 ValueMap<char, Type, UndefValue> UndefValueConstants;
124
Owen Anderson1584a292009-08-04 20:25:11 +0000125 ValueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants;
126
Owen Anderson2ad52172009-07-21 02:47:59 +0000127 ConstantInt *TheTrueVal;
128 ConstantInt *TheFalseVal;
129
Owen Andersonafd0c4c2009-08-04 22:41:48 +0000130 LLVMContextImpl() : TheTrueVal(0), TheFalseVal(0) { }
Owen Anderson8e66e0b2009-06-30 00:48:55 +0000131};
132
133}
134
Owen Anderson36f62e52009-06-30 17:06:46 +0000135#endif