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/APInt.h"
20 #include "llvm/ADT/DenseMap.h"
28 struct DenseMapAPIntKeyInfo {
32 KeyTy(const APInt& V, const Type* Ty) : val(V), type(Ty) {}
33 KeyTy(const KeyTy& that) : val(that.val), type(that.type) {}
34 bool operator==(const KeyTy& that) const {
35 return type == that.type && this->val == that.val;
37 bool operator!=(const KeyTy& that) const {
38 return !this->operator==(that);
41 static inline KeyTy getEmptyKey() { return KeyTy(APInt(1,0), 0); }
42 static inline KeyTy getTombstoneKey() { return KeyTy(APInt(1,1), 0); }
43 static unsigned getHashValue(const KeyTy &Key) {
44 return DenseMapInfo<void*>::getHashValue(Key.type) ^
45 Key.val.getHashValue();
47 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
50 static bool isPod() { return false; }
53 class LLVMContextImpl {
54 sys::SmartRWMutex<true> ConstantsLock;
56 typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
57 DenseMapAPIntKeyInfo> IntMapTy;
58 IntMapTy IntConstants;
62 LLVMContextImpl(const LLVMContextImpl&);
64 LLVMContextImpl(LLVMContext &C) : Context(C) { }
66 /// Return a ConstantInt with the specified value and an implied Type. The
67 /// type is the integer type that corresponds to the bit width of the value.
68 ConstantInt* getConstantInt(const APInt &V);