#include "LeaksContext.h"
#include "TypesContext.h"
#include "llvm/LLVMContext.h"
+#include "llvm/Metadata.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
-#include "llvm/System/Mutex.h"
-#include "llvm/System/RWMutex.h"
#include "llvm/Assembly/Writer.h"
+#include "llvm/Support/ValueHandle.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringMap.h"
#include <vector>
static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
return LHS == RHS;
}
- static bool isPod() { return false; }
};
struct DenseMapAPFloatKeyInfo {
static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
return LHS == RHS;
}
- static bool isPod() { return false; }
};
class LLVMContextImpl {
public:
- sys::SmartRWMutex<true> ConstantsLock;
typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
DenseMapAPIntKeyInfo> IntMapTy;
IntMapTy IntConstants;
StringMap<MDString*> MDStringCache;
- ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
-
- SmallPtrSet<const MDNode *, 8> MDNodes;
+ FoldingSet<MDNode> MDNodeSet;
- typedef ValueMap<std::vector<Constant*>, ArrayType,
+ ConstantUniqueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
+
+ typedef ConstantUniqueMap<std::vector<Constant*>, ArrayType,
ConstantArray, true /*largekey*/> ArrayConstantsTy;
ArrayConstantsTy ArrayConstants;
- typedef ValueMap<std::vector<Constant*>, StructType,
- ConstantStruct, true /*largekey*/> StructConstantsTy;
+ typedef ConstantUniqueMap<std::vector<Constant*>, StructType,
+ ConstantStruct, true /*largekey*/> StructConstantsTy;
StructConstantsTy StructConstants;
- typedef ValueMap<std::vector<Constant*>, VectorType,
- ConstantVector> VectorConstantsTy;
+ typedef ConstantUniqueMap<std::vector<Constant*>, VectorType,
+ ConstantVector> VectorConstantsTy;
VectorConstantsTy VectorConstants;
- ValueMap<char, PointerType, ConstantPointerNull> NullPtrConstants;
+ ConstantUniqueMap<char, PointerType, ConstantPointerNull> NullPtrConstants;
- ValueMap<char, Type, UndefValue> UndefValueConstants;
+ ConstantUniqueMap<char, Type, UndefValue> UndefValueConstants;
- ValueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants;
+ DenseMap<std::pair<Function*, BasicBlock*> , BlockAddress*> BlockAddresses;
+ ConstantUniqueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants;
ConstantInt *TheTrueVal;
ConstantInt *TheFalseVal;
- // Lock used for guarding access to the leak detector
- sys::SmartMutex<true> LLVMObjectsLock;
LeakDetectorImpl<Value> LLVMObjects;
- // Lock used for guarding access to the type maps.
- sys::SmartMutex<true> TypeMapLock;
-
- // Recursive lock used for guarding access to AbstractTypeUsers.
- // NOTE: The true template parameter means this will no-op when we're not in
- // multithreaded mode.
- sys::SmartMutex<true> AbstractTypeUsersLock;
-
// Basic type instances.
const Type VoidTy;
const Type LabelTy;
TypeMap<StructValType, StructType> StructTypes;
TypeMap<IntegerValType, IntegerType> IntegerTypes;
+ // Opaque types are not structurally uniqued, so don't use TypeMap.
+ typedef SmallPtrSet<const OpaqueType*, 8> OpaqueTypesTy;
+ OpaqueTypesTy OpaqueTypes;
+
+
/// ValueHandles - This map keeps track of all of the value handles that are
/// watching a Value*. The Value::HasValueHandle bit is used to know
// whether or not a value has an entry in this map.
typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
ValueHandlesTy ValueHandles;
+ /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
+ StringMap<unsigned> CustomMDKindNames;
+
+ typedef std::pair<unsigned, TrackingVH<MDNode> > MDPairTy;
+ typedef SmallVector<MDPairTy, 2> MDMapTy;
+
+ /// MetadataStore - Collection of per-instruction metadata used in this
+ /// context.
+ DenseMap<const Instruction *, MDMapTy> MetadataStore;
+
+
LLVMContextImpl(LLVMContext &C) : TheTrueVal(0), TheFalseVal(0),
VoidTy(C, Type::VoidTyID),
LabelTy(C, Type::LabelTyID),
Int32Ty(C, 32),
Int64Ty(C, 64) { }
- ~LLVMContextImpl()
- {
+ ~LLVMContextImpl() {
ExprConstants.freeConstants();
ArrayConstants.freeConstants();
StructConstants.freeConstants();
VectorConstants.freeConstants();
-
AggZeroConstants.freeConstants();
NullPtrConstants.freeConstants();
UndefValueConstants.freeConstants();
- for (IntMapTy::iterator I=IntConstants.begin(), E=IntConstants.end();
+ for (IntMapTy::iterator I = IntConstants.begin(), E = IntConstants.end();
I != E; ++I) {
if (I->second->use_empty())
delete I->second;
}
- for (FPMapTy::iterator I=FPConstants.begin(), E=FPConstants.end();
+ for (FPMapTy::iterator I = FPConstants.begin(), E = FPConstants.end();
I != E; ++I) {
if (I->second->use_empty())
delete I->second;
}
+ MDNodeSet.clear();
+ for (OpaqueTypesTy::iterator I = OpaqueTypes.begin(), E = OpaqueTypes.end();
+ I != E; ++I) {
+ (*I)->AbstractTypeUsers.clear();
+ delete *I;
+ }
}
};