template<class ConstantClass, class TypeClass, class ValType>
struct ConstantCreator;
template<class ConstantClass, class TypeClass>
-struct ConvertConstantType;
+struct ConvertType;
//===----------------------------------------------------------------------===//
/// This is the shared class of boolean and integer constants. This class
class ConstantExpr : public Constant {
friend struct ConstantCreator<ConstantExpr,Type,
std::pair<unsigned, std::vector<Constant*> > >;
- friend struct ConvertConstantType<ConstantExpr, Type>;
+ friend struct ConvertType<ConstantExpr, Type>;
protected:
ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
#define LLVM_CONSTANTSCONTEXT_H
#include "llvm/Instructions.h"
+#include "llvm/Metadata.h"
#include "llvm/Operator.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
};
template<class ConstantClass, class TypeClass>
-struct ConvertConstantType {
+struct ConvertType {
static void convert(ConstantClass *OldC, const TypeClass *NewTy) {
llvm_unreachable("This type cannot be converted!");
}
};
template<>
-struct ConvertConstantType<ConstantExpr, Type> {
+struct ConvertType<ConstantExpr, Type> {
static void convert(ConstantExpr *OldC, const Type *NewTy) {
Constant *New;
switch (OldC->getOpcode()) {
};
template<>
-struct ConvertConstantType<ConstantVector, VectorType> {
+struct ConstantCreator<MDNode, Type, std::vector<Value*> > {
+ static MDNode *create(const Type* Ty, const std::vector<Value*> &V) {
+ return new MDNode(V.data(), V.size());
+ }
+};
+
+template<>
+struct ConvertType<ConstantVector, VectorType> {
static void convert(ConstantVector *OldC, const VectorType *NewTy) {
// Make everyone now use a constant of the new type...
std::vector<Constant*> C;
};
template<>
-struct ConvertConstantType<ConstantAggregateZero, Type> {
+struct ConvertType<ConstantAggregateZero, Type> {
static void convert(ConstantAggregateZero *OldC, const Type *NewTy) {
// Make everyone now use a constant of the new type...
Constant *New = ConstantAggregateZero::get(NewTy);
};
template<>
-struct ConvertConstantType<ConstantArray, ArrayType> {
+struct ConvertType<ConstantArray, ArrayType> {
static void convert(ConstantArray *OldC, const ArrayType *NewTy) {
// Make everyone now use a constant of the new type...
std::vector<Constant*> C;
};
template<>
-struct ConvertConstantType<ConstantStruct, StructType> {
+struct ConvertType<ConstantStruct, StructType> {
static void convert(ConstantStruct *OldC, const StructType *NewTy) {
// Make everyone now use a constant of the new type...
std::vector<Constant*> C;
};
template<>
-struct ConvertConstantType<ConstantPointerNull, PointerType> {
+struct ConvertType<ConstantPointerNull, PointerType> {
static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) {
// Make everyone now use a constant of the new type...
Constant *New = ConstantPointerNull::get(NewTy);
};
template<>
-struct ConvertConstantType<UndefValue, Type> {
+struct ConvertType<UndefValue, Type> {
static void convert(UndefValue *OldC, const Type *NewTy) {
// Make everyone now use a constant of the new type.
Constant *New = UndefValue::get(NewTy);
class ValueMap : public AbstractTypeUser {
public:
typedef std::pair<const Type*, ValType> MapKey;
- typedef std::map<MapKey, Constant *> MapTy;
- typedef std::map<Constant*, typename MapTy::iterator> InverseMapTy;
+ typedef std::map<MapKey, Value *> MapTy;
+ typedef std::map<Value*, typename MapTy::iterator> InverseMapTy;
typedef std::map<const Type*, typename MapTy::iterator> AbstractTypeMapTy;
private:
/// Map - This is the main map from the element descriptor to the Constants.
// leaving will remove() itself, causing the AbstractTypeMapEntry to be
// eliminated eventually.
do {
- ConvertConstantType<ConstantClass,
- TypeClass>::convert(
+ ConvertType<ConstantClass, TypeClass>::convert(
static_cast<ConstantClass *>(I->second->second),
cast<TypeClass>(NewTy));
MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
LLVMContextImpl *pImpl = Context.pImpl;
- FoldingSetNodeID ID;
- for (unsigned i = 0; i != NumVals; ++i)
- ID.AddPointer(Vals[i]);
-
- pImpl->ConstantsLock.reader_acquire();
- void *InsertPoint;
- MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
- pImpl->ConstantsLock.reader_release();
+ std::vector<Value*> V;
+ V.reserve(NumVals);
+ for (unsigned i = 0; i < NumVals; ++i)
+ V.push_back(Vals[i]);
- if (!N) {
- sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
- N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
- if (!N) {
- // InsertPoint will have been set by the FindNodeOrInsertPos call.
- N = new MDNode(Vals, NumVals);
- pImpl->MDNodeSet.InsertNode(N, InsertPoint);
- }
- }
-
- return N;
+ return pImpl->MDNodeSet.getOrCreate(Type::MetadataTy, V);
}
/// dropAllReferences - Remove all uses and clear node vector.