blob: fbf29fdfc49cece9b348490bc31024563a1403d6 [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 Anderson20b34ac2009-07-16 18:04:31 +000018#include "llvm/System/RWMutex.h"
19#include "llvm/ADT/APInt.h"
20#include "llvm/ADT/DenseMap.h"
Owen Anderson8e66e0b2009-06-30 00:48:55 +000021
Owen Anderson20b34ac2009-07-16 18:04:31 +000022namespace llvm {
23
24class ConstantInt;
25class LLVMContext;
26class Type;
27
28struct DenseMapAPIntKeyInfo {
29 struct KeyTy {
30 APInt val;
31 const Type* type;
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;
36 }
37 bool operator!=(const KeyTy& that) const {
38 return !this->operator==(that);
39 }
40 };
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();
46 }
47 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
48 return LHS == RHS;
49 }
50 static bool isPod() { return false; }
51};
52
53class LLVMContextImpl {
54 sys::SmartRWMutex<true> ConstantsLock;
55
56 typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
57 DenseMapAPIntKeyInfo> IntMapTy;
58 IntMapTy IntConstants;
59
60 LLVMContext &Context;
61 LLVMContextImpl();
62 LLVMContextImpl(const LLVMContextImpl&);
63public:
64 LLVMContextImpl(LLVMContext &C) : Context(C) { }
65
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);
Owen Anderson8e66e0b2009-06-30 00:48:55 +000069};
70
71}
72
Owen Anderson36f62e52009-06-30 17:06:46 +000073#endif