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"
30 struct DenseMapAPIntKeyInfo {
34 KeyTy(const APInt& V, const Type* Ty) : val(V), type(Ty) {}
35 KeyTy(const KeyTy& that) : val(that.val), type(that.type) {}
36 bool operator==(const KeyTy& that) const {
37 return type == that.type && this->val == that.val;
39 bool operator!=(const KeyTy& that) const {
40 return !this->operator==(that);
43 static inline KeyTy getEmptyKey() { return KeyTy(APInt(1,0), 0); }
44 static inline KeyTy getTombstoneKey() { return KeyTy(APInt(1,1), 0); }
45 static unsigned getHashValue(const KeyTy &Key) {
46 return DenseMapInfo<void*>::getHashValue(Key.type) ^
47 Key.val.getHashValue();
49 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
52 static bool isPod() { return false; }
55 struct DenseMapAPFloatKeyInfo {
58 KeyTy(const APFloat& V) : val(V){}
59 KeyTy(const KeyTy& that) : val(that.val) {}
60 bool operator==(const KeyTy& that) const {
61 return this->val.bitwiseIsEqual(that.val);
63 bool operator!=(const KeyTy& that) const {
64 return !this->operator==(that);
67 static inline KeyTy getEmptyKey() {
68 return KeyTy(APFloat(APFloat::Bogus,1));
70 static inline KeyTy getTombstoneKey() {
71 return KeyTy(APFloat(APFloat::Bogus,2));
73 static unsigned getHashValue(const KeyTy &Key) {
74 return Key.val.getHashValue();
76 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
79 static bool isPod() { return false; }
82 class LLVMContextImpl {
83 sys::SmartRWMutex<true> ConstantsLock;
85 typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
86 DenseMapAPIntKeyInfo> IntMapTy;
87 IntMapTy IntConstants;
89 typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*,
90 DenseMapAPFloatKeyInfo> FPMapTy;
95 LLVMContextImpl(const LLVMContextImpl&);
97 LLVMContextImpl(LLVMContext &C) : Context(C) { }
99 /// Return a ConstantInt with the specified value and an implied Type. The
100 /// type is the integer type that corresponds to the bit width of the value.
101 ConstantInt *getConstantInt(const APInt &V);
103 ConstantFP *getConstantFP(const APFloat &V);