diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-16 18:04:31 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-16 18:04:31 +0000 |
commit | e1f1f82a2c1506c57f77df09c0a86de6e59ff952 (patch) | |
tree | 1dc61249ea3e7ecc74b897c4c6014f9bbbc341ac /lib/VMCore/LLVMContextImpl.cpp | |
parent | 68c81be2885e98f6894bf458eb3e9a84355bfc16 (diff) | |
download | external_llvm-e1f1f82a2c1506c57f77df09c0a86de6e59ff952.zip external_llvm-e1f1f82a2c1506c57f77df09c0a86de6e59ff952.tar.gz external_llvm-e1f1f82a2c1506c57f77df09c0a86de6e59ff952.tar.bz2 |
Move the ConstantInt uniquing table into LLVMContextImpl. This exposed a number of issues in
our current context-passing stuff, which is also fixed here
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76089 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/LLVMContextImpl.cpp')
-rw-r--r-- | lib/VMCore/LLVMContextImpl.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp new file mode 100644 index 0000000..a92c19f --- /dev/null +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -0,0 +1,48 @@ +//===--------------- LLVMContextImpl.cpp - Implementation ------*- C++ -*--===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements LLVMContextImpl, the opaque implementation +// of LLVMContext. +// +//===----------------------------------------------------------------------===// + +#include "LLVMContextImpl.h" +#include "llvm/Constants.h" +#include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" +using namespace llvm; + +// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap +// as the key, is a DenseMapAPIntKeyInfo::KeyTy which has provided the +// operator== and operator!= to ensure that the DenseMap doesn't attempt to +// compare APInt's of different widths, which would violate an APInt class +// invariant which generates an assertion. +ConstantInt *LLVMContextImpl::getConstantInt(const APInt& V) { + // Get the corresponding integer type for the bit width of the value. + const IntegerType *ITy = Context.getIntegerType(V.getBitWidth()); + // get an existing value or the insertion position + DenseMapAPIntKeyInfo::KeyTy Key(V, ITy); + + ConstantsLock.reader_acquire(); + ConstantInt *&Slot = IntConstants[Key]; + ConstantsLock.reader_release(); + + if (!Slot) { + sys::SmartScopedWriter<true> Writer(ConstantsLock); + ConstantInt *&NewSlot = IntConstants[Key]; + if (!Slot) { + NewSlot = new ConstantInt(ITy, V); + } + + return NewSlot; + } else { + return Slot; + } +} + |