mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-22 10:29:35 +00:00
Revert 80839 for now. It causes test failures.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80841 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d9489cbb0c
commit
8fc5576413
@ -38,7 +38,7 @@ class VectorType;
|
|||||||
template<class ConstantClass, class TypeClass, class ValType>
|
template<class ConstantClass, class TypeClass, class ValType>
|
||||||
struct ConstantCreator;
|
struct ConstantCreator;
|
||||||
template<class ConstantClass, class TypeClass>
|
template<class ConstantClass, class TypeClass>
|
||||||
struct ConvertConstantType;
|
struct ConvertConstant;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
/// This is the shared class of boolean and integer constants. This class
|
/// This is the shared class of boolean and integer constants. This class
|
||||||
@ -559,7 +559,7 @@ public:
|
|||||||
class ConstantExpr : public Constant {
|
class ConstantExpr : public Constant {
|
||||||
friend struct ConstantCreator<ConstantExpr,Type,
|
friend struct ConstantCreator<ConstantExpr,Type,
|
||||||
std::pair<unsigned, std::vector<Constant*> > >;
|
std::pair<unsigned, std::vector<Constant*> > >;
|
||||||
friend struct ConvertConstantType<ConstantExpr, Type>;
|
friend struct ConvertConstant<ConstantExpr, Type>;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
|
ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
|
||||||
|
@ -19,9 +19,7 @@
|
|||||||
#include "llvm/User.h"
|
#include "llvm/User.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
#include "llvm/OperandTraits.h"
|
#include "llvm/OperandTraits.h"
|
||||||
#include "llvm/ADT/FoldingSet.h"
|
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/SmallPtrSet.h"
|
|
||||||
#include "llvm/ADT/ilist_node.h"
|
#include "llvm/ADT/ilist_node.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/ValueHandle.h"
|
#include "llvm/Support/ValueHandle.h"
|
||||||
@ -29,6 +27,8 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
class Constant;
|
class Constant;
|
||||||
class LLVMContext;
|
class LLVMContext;
|
||||||
|
template<class ConstantClass, class TypeClass, class ValType>
|
||||||
|
struct ConstantCreator;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
|
// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
|
||||||
@ -103,32 +103,14 @@ public:
|
|||||||
/// MDNode - a tuple of other values.
|
/// MDNode - a tuple of other values.
|
||||||
/// These contain a list of the values that represent the metadata.
|
/// These contain a list of the values that represent the metadata.
|
||||||
/// MDNode is always unnamed.
|
/// MDNode is always unnamed.
|
||||||
class MDNode : public MetadataBase, public FoldingSetNode {
|
class MDNode : public MetadataBase {
|
||||||
MDNode(const MDNode &); // DO NOT IMPLEMENT
|
MDNode(const MDNode &); // DO NOT IMPLEMENT
|
||||||
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
|
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
|
||||||
// getNumOperands - Make this only available for private uses.
|
// getNumOperands - Make this only available for private uses.
|
||||||
unsigned getNumOperands() { return User::getNumOperands(); }
|
unsigned getNumOperands() { return User::getNumOperands(); }
|
||||||
|
|
||||||
friend class ElementVH;
|
SmallVector<WeakVH, 4> Node;
|
||||||
// Use CallbackVH to hold MDNOde elements.
|
friend struct ConstantCreator<MDNode, Type, std::vector<Value*> >;
|
||||||
struct ElementVH : public CallbackVH {
|
|
||||||
MDNode *Parent;
|
|
||||||
ElementVH(Value *V, MDNode *P) : CallbackVH(V), Parent(P) {}
|
|
||||||
~ElementVH() {}
|
|
||||||
|
|
||||||
virtual void deleted() {
|
|
||||||
Parent->replaceElement(this->operator Value*(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void allUsesReplacedWith(Value *NV) {
|
|
||||||
Parent->replaceElement(this->operator Value*(), NV);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Replace each instance of F from the element list of this node with T.
|
|
||||||
void replaceElement(Value *F, Value *T);
|
|
||||||
|
|
||||||
SmallVector<ElementVH, 4> Node;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals);
|
explicit MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals);
|
||||||
public:
|
public:
|
||||||
@ -158,8 +140,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Element access
|
// Element access
|
||||||
typedef SmallVectorImpl<ElementVH>::const_iterator const_elem_iterator;
|
typedef SmallVectorImpl<WeakVH>::const_iterator const_elem_iterator;
|
||||||
typedef SmallVectorImpl<ElementVH>::iterator elem_iterator;
|
typedef SmallVectorImpl<WeakVH>::iterator elem_iterator;
|
||||||
/// elem_empty - Return true if MDNode is empty.
|
/// elem_empty - Return true if MDNode is empty.
|
||||||
bool elem_empty() const { return Node.empty(); }
|
bool elem_empty() const { return Node.empty(); }
|
||||||
const_elem_iterator elem_begin() const { return Node.begin(); }
|
const_elem_iterator elem_begin() const { return Node.begin(); }
|
||||||
@ -174,10 +156,6 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Profile - calculate a unique identifier for this MDNode to collapse
|
|
||||||
/// duplicates
|
|
||||||
void Profile(FoldingSetNodeID &ID) const;
|
|
||||||
|
|
||||||
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) {
|
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) {
|
||||||
llvm_unreachable("This should never be called because MDNodes have no ops");
|
llvm_unreachable("This should never be called because MDNodes have no ops");
|
||||||
}
|
}
|
||||||
|
@ -1880,7 +1880,7 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
pImpl->ArrayConstants.InsertOrGetItem(Lookup, Exists);
|
pImpl->ArrayConstants.InsertOrGetItem(Lookup, Exists);
|
||||||
|
|
||||||
if (Exists) {
|
if (Exists) {
|
||||||
Replacement = I->second;
|
Replacement = cast<Constant>(I->second);
|
||||||
} else {
|
} else {
|
||||||
// Okay, the new shape doesn't exist in the system yet. Instead of
|
// Okay, the new shape doesn't exist in the system yet. Instead of
|
||||||
// creating a new constant array, inserting it, replaceallusesof'ing the
|
// creating a new constant array, inserting it, replaceallusesof'ing the
|
||||||
@ -1967,7 +1967,7 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
pImpl->StructConstants.InsertOrGetItem(Lookup, Exists);
|
pImpl->StructConstants.InsertOrGetItem(Lookup, Exists);
|
||||||
|
|
||||||
if (Exists) {
|
if (Exists) {
|
||||||
Replacement = I->second;
|
Replacement = cast<Constant>(I->second);
|
||||||
} else {
|
} else {
|
||||||
// Okay, the new shape doesn't exist in the system yet. Instead of
|
// Okay, the new shape doesn't exist in the system yet. Instead of
|
||||||
// creating a new constant struct, inserting it, replaceallusesof'ing the
|
// creating a new constant struct, inserting it, replaceallusesof'ing the
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#define LLVM_CONSTANTSCONTEXT_H
|
#define LLVM_CONSTANTSCONTEXT_H
|
||||||
|
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
|
#include "llvm/Metadata.h"
|
||||||
#include "llvm/Operator.h"
|
#include "llvm/Operator.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
@ -340,7 +341,7 @@ struct ConstantCreator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<class ConstantClass, class TypeClass>
|
template<class ConstantClass, class TypeClass>
|
||||||
struct ConvertConstantType {
|
struct ConvertConstant {
|
||||||
static void convert(ConstantClass *OldC, const TypeClass *NewTy) {
|
static void convert(ConstantClass *OldC, const TypeClass *NewTy) {
|
||||||
llvm_unreachable("This type cannot be converted!");
|
llvm_unreachable("This type cannot be converted!");
|
||||||
}
|
}
|
||||||
@ -391,7 +392,7 @@ struct ConstantCreator<ConstantExpr, Type, ExprMapKeyType> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ConvertConstantType<ConstantExpr, Type> {
|
struct ConvertConstant<ConstantExpr, Type> {
|
||||||
static void convert(ConstantExpr *OldC, const Type *NewTy) {
|
static void convert(ConstantExpr *OldC, const Type *NewTy) {
|
||||||
Constant *New;
|
Constant *New;
|
||||||
switch (OldC->getOpcode()) {
|
switch (OldC->getOpcode()) {
|
||||||
@ -444,7 +445,14 @@ struct ConstantCreator<ConstantAggregateZero, Type, ValType> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
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(Ty->getContext(), &V[0], V.size());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct ConvertConstant<ConstantVector, VectorType> {
|
||||||
static void convert(ConstantVector *OldC, const VectorType *NewTy) {
|
static void convert(ConstantVector *OldC, const VectorType *NewTy) {
|
||||||
// Make everyone now use a constant of the new type...
|
// Make everyone now use a constant of the new type...
|
||||||
std::vector<Constant*> C;
|
std::vector<Constant*> C;
|
||||||
@ -458,7 +466,7 @@ struct ConvertConstantType<ConstantVector, VectorType> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ConvertConstantType<ConstantAggregateZero, Type> {
|
struct ConvertConstant<ConstantAggregateZero, Type> {
|
||||||
static void convert(ConstantAggregateZero *OldC, const Type *NewTy) {
|
static void convert(ConstantAggregateZero *OldC, const Type *NewTy) {
|
||||||
// Make everyone now use a constant of the new type...
|
// Make everyone now use a constant of the new type...
|
||||||
Constant *New = ConstantAggregateZero::get(NewTy);
|
Constant *New = ConstantAggregateZero::get(NewTy);
|
||||||
@ -469,7 +477,7 @@ struct ConvertConstantType<ConstantAggregateZero, Type> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ConvertConstantType<ConstantArray, ArrayType> {
|
struct ConvertConstant<ConstantArray, ArrayType> {
|
||||||
static void convert(ConstantArray *OldC, const ArrayType *NewTy) {
|
static void convert(ConstantArray *OldC, const ArrayType *NewTy) {
|
||||||
// Make everyone now use a constant of the new type...
|
// Make everyone now use a constant of the new type...
|
||||||
std::vector<Constant*> C;
|
std::vector<Constant*> C;
|
||||||
@ -483,7 +491,7 @@ struct ConvertConstantType<ConstantArray, ArrayType> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ConvertConstantType<ConstantStruct, StructType> {
|
struct ConvertConstant<ConstantStruct, StructType> {
|
||||||
static void convert(ConstantStruct *OldC, const StructType *NewTy) {
|
static void convert(ConstantStruct *OldC, const StructType *NewTy) {
|
||||||
// Make everyone now use a constant of the new type...
|
// Make everyone now use a constant of the new type...
|
||||||
std::vector<Constant*> C;
|
std::vector<Constant*> C;
|
||||||
@ -506,7 +514,7 @@ struct ConstantCreator<ConstantPointerNull, PointerType, ValType> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ConvertConstantType<ConstantPointerNull, PointerType> {
|
struct ConvertConstant<ConstantPointerNull, PointerType> {
|
||||||
static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) {
|
static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) {
|
||||||
// Make everyone now use a constant of the new type...
|
// Make everyone now use a constant of the new type...
|
||||||
Constant *New = ConstantPointerNull::get(NewTy);
|
Constant *New = ConstantPointerNull::get(NewTy);
|
||||||
@ -525,7 +533,7 @@ struct ConstantCreator<UndefValue, Type, ValType> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ConvertConstantType<UndefValue, Type> {
|
struct ConvertConstant<UndefValue, Type> {
|
||||||
static void convert(UndefValue *OldC, const Type *NewTy) {
|
static void convert(UndefValue *OldC, const Type *NewTy) {
|
||||||
// Make everyone now use a constant of the new type.
|
// Make everyone now use a constant of the new type.
|
||||||
Constant *New = UndefValue::get(NewTy);
|
Constant *New = UndefValue::get(NewTy);
|
||||||
@ -540,8 +548,8 @@ template<class ValType, class TypeClass, class ConstantClass,
|
|||||||
class ValueMap : public AbstractTypeUser {
|
class ValueMap : public AbstractTypeUser {
|
||||||
public:
|
public:
|
||||||
typedef std::pair<const Type*, ValType> MapKey;
|
typedef std::pair<const Type*, ValType> MapKey;
|
||||||
typedef std::map<MapKey, Constant *> MapTy;
|
typedef std::map<MapKey, Value *> MapTy;
|
||||||
typedef std::map<Constant*, typename MapTy::iterator> InverseMapTy;
|
typedef std::map<Value*, typename MapTy::iterator> InverseMapTy;
|
||||||
typedef std::map<const Type*, typename MapTy::iterator> AbstractTypeMapTy;
|
typedef std::map<const Type*, typename MapTy::iterator> AbstractTypeMapTy;
|
||||||
private:
|
private:
|
||||||
/// Map - This is the main map from the element descriptor to the Constants.
|
/// Map - This is the main map from the element descriptor to the Constants.
|
||||||
@ -759,8 +767,7 @@ public:
|
|||||||
// leaving will remove() itself, causing the AbstractTypeMapEntry to be
|
// leaving will remove() itself, causing the AbstractTypeMapEntry to be
|
||||||
// eliminated eventually.
|
// eliminated eventually.
|
||||||
do {
|
do {
|
||||||
ConvertConstantType<ConstantClass,
|
ConvertConstant<ConstantClass, TypeClass>::convert(
|
||||||
TypeClass>::convert(
|
|
||||||
static_cast<ConstantClass *>(I->second->second),
|
static_cast<ConstantClass *>(I->second->second),
|
||||||
cast<TypeClass>(NewTy));
|
cast<TypeClass>(NewTy));
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/LLVMContext.h"
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Metadata.h"
|
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/Instruction.h"
|
#include "llvm/Instruction.h"
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
#include "llvm/Support/ManagedStatic.h"
|
||||||
@ -49,10 +48,10 @@ bool LLVMContext::RemoveDeadMetadata() {
|
|||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
for (FoldingSet<MDNode>::iterator
|
for (SmallPtrSet<const MDNode *, 8>::iterator
|
||||||
I = pImpl->MDNodeSet.begin(),
|
I = pImpl->MDNodes.begin(),
|
||||||
E = pImpl->MDNodeSet.end(); I != E; ++I) {
|
E = pImpl->MDNodes.end(); I != E; ++I) {
|
||||||
const MDNode *N = &(*I);
|
const MDNode *N = cast<MDNode>(*I);
|
||||||
if (N->use_empty())
|
if (N->use_empty())
|
||||||
DeadMDNodes.push_back(N);
|
DeadMDNodes.push_back(N);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#include "LeaksContext.h"
|
#include "LeaksContext.h"
|
||||||
#include "TypesContext.h"
|
#include "TypesContext.h"
|
||||||
#include "llvm/LLVMContext.h"
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Metadata.h"
|
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/System/Mutex.h"
|
#include "llvm/System/Mutex.h"
|
||||||
@ -107,8 +106,6 @@ public:
|
|||||||
|
|
||||||
StringMap<MDString*> MDStringCache;
|
StringMap<MDString*> MDStringCache;
|
||||||
|
|
||||||
FoldingSet<MDNode> MDNodeSet;
|
|
||||||
|
|
||||||
ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
|
ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
|
||||||
|
|
||||||
SmallPtrSet<const MDNode *, 8> MDNodes;
|
SmallPtrSet<const MDNode *, 8> MDNodes;
|
||||||
@ -202,6 +199,7 @@ public:
|
|||||||
ArrayConstants.freeConstants();
|
ArrayConstants.freeConstants();
|
||||||
StructConstants.freeConstants();
|
StructConstants.freeConstants();
|
||||||
VectorConstants.freeConstants();
|
VectorConstants.freeConstants();
|
||||||
|
|
||||||
AggZeroConstants.freeConstants();
|
AggZeroConstants.freeConstants();
|
||||||
NullPtrConstants.freeConstants();
|
NullPtrConstants.freeConstants();
|
||||||
UndefValueConstants.freeConstants();
|
UndefValueConstants.freeConstants();
|
||||||
|
@ -72,37 +72,18 @@ MDNode::MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals)
|
|||||||
// Only record metadata uses.
|
// Only record metadata uses.
|
||||||
if (MetadataBase *MB = dyn_cast_or_null<MetadataBase>(Vals[i]))
|
if (MetadataBase *MB = dyn_cast_or_null<MetadataBase>(Vals[i]))
|
||||||
OperandList[NumOperands++] = MB;
|
OperandList[NumOperands++] = MB;
|
||||||
Node.push_back(ElementVH(Vals[i], this));
|
Node.push_back(WeakVH(Vals[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MDNode::Profile(FoldingSetNodeID &ID) const {
|
|
||||||
for (const_elem_iterator I = elem_begin(), E = elem_end(); I != E; ++I)
|
|
||||||
ID.AddPointer(*I);
|
|
||||||
}
|
|
||||||
|
|
||||||
MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
|
MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
|
||||||
LLVMContextImpl *pImpl = Context.pImpl;
|
std::vector<Value*> V;
|
||||||
FoldingSetNodeID ID;
|
V.reserve(NumVals);
|
||||||
for (unsigned i = 0; i != NumVals; ++i)
|
for (unsigned i = 0; i < NumVals; ++i)
|
||||||
ID.AddPointer(Vals[i]);
|
V.push_back(Vals[i]);
|
||||||
|
|
||||||
pImpl->ConstantsLock.reader_acquire();
|
// FIXME : Avoid creating duplicate node.
|
||||||
void *InsertPoint;
|
return new MDNode(Context, &V[0], V.size());
|
||||||
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
|
|
||||||
pImpl->ConstantsLock.reader_release();
|
|
||||||
|
|
||||||
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(Context, Vals, NumVals);
|
|
||||||
pImpl->MDNodeSet.InsertNode(N, InsertPoint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return N;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// dropAllReferences - Remove all uses and clear node vector.
|
/// dropAllReferences - Remove all uses and clear node vector.
|
||||||
@ -112,73 +93,10 @@ void MDNode::dropAllReferences() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MDNode::~MDNode() {
|
MDNode::~MDNode() {
|
||||||
getType()->getContext().pImpl->MDNodeSet.RemoveNode(this);
|
getType()->getContext().pImpl->MDNodes.erase(this);
|
||||||
dropAllReferences();
|
dropAllReferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace value from this node's element list.
|
|
||||||
void MDNode::replaceElement(Value *From, Value *To) {
|
|
||||||
if (From == To || !getType())
|
|
||||||
return;
|
|
||||||
LLVMContext &Context = getType()->getContext();
|
|
||||||
LLVMContextImpl *pImpl = Context.pImpl;
|
|
||||||
|
|
||||||
// Find value. This is a linear search, do something if it consumes
|
|
||||||
// lot of time. It is possible that to have multiple instances of
|
|
||||||
// From in this MDNode's element list.
|
|
||||||
SmallVector<unsigned, 4> Indexes;
|
|
||||||
unsigned Index = 0;
|
|
||||||
for (SmallVector<ElementVH, 4>::iterator I = Node.begin(),
|
|
||||||
E = Node.end(); I != E; ++I, ++Index) {
|
|
||||||
Value *V = *I;
|
|
||||||
if (V && V == From)
|
|
||||||
Indexes.push_back(Index);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Indexes.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Remove "this" from the context map.
|
|
||||||
{
|
|
||||||
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
|
|
||||||
pImpl->MDNodeSet.RemoveNode(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace From element(s) in place.
|
|
||||||
for (SmallVector<unsigned, 4>::iterator I = Indexes.begin(), E = Indexes.end();
|
|
||||||
I != E; ++I) {
|
|
||||||
unsigned Index = *I;
|
|
||||||
Node[Index] = ElementVH(To, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert updated "this" into the context's folding node set.
|
|
||||||
// If a node with same element list already exist then before inserting
|
|
||||||
// updated "this" into the folding node set, replace all uses of existing
|
|
||||||
// node with updated "this" node.
|
|
||||||
FoldingSetNodeID ID;
|
|
||||||
Profile(ID);
|
|
||||||
pImpl->ConstantsLock.reader_acquire();
|
|
||||||
void *InsertPoint;
|
|
||||||
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
|
|
||||||
pImpl->ConstantsLock.reader_release();
|
|
||||||
|
|
||||||
if (N) {
|
|
||||||
N->replaceAllUsesWith(this);
|
|
||||||
delete N;
|
|
||||||
N = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
|
|
||||||
N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
|
|
||||||
if (!N) {
|
|
||||||
// InsertPoint will have been set by the FindNodeOrInsertPos call.
|
|
||||||
N = this;
|
|
||||||
pImpl->MDNodeSet.InsertNode(N, InsertPoint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//NamedMDNode implementation
|
//NamedMDNode implementation
|
||||||
//
|
//
|
||||||
|
@ -85,7 +85,7 @@ TEST(MDNodeTest, Simple) {
|
|||||||
MDNode *n2 = MDNode::get(Context, &c1, 1);
|
MDNode *n2 = MDNode::get(Context, &c1, 1);
|
||||||
MDNode *n3 = MDNode::get(Context, &V[0], 3);
|
MDNode *n3 = MDNode::get(Context, &V[0], 3);
|
||||||
EXPECT_NE(n1, n2);
|
EXPECT_NE(n1, n2);
|
||||||
EXPECT_EQ(n1, n3);
|
// FIXME: Enable uniqueness test. EXPECT_EQ(n1, n3);
|
||||||
|
|
||||||
EXPECT_EQ(3u, n1->getNumElements());
|
EXPECT_EQ(3u, n1->getNumElements());
|
||||||
EXPECT_EQ(s1, n1->getElement(0));
|
EXPECT_EQ(s1, n1->getElement(0));
|
||||||
|
Loading…
Reference in New Issue
Block a user