aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-09-03 01:39:20 +0000
committerDevang Patel <dpatel@apple.com>2009-09-03 01:39:20 +0000
commit5f4ac848d94b0a92e19ac7f2b3d0284d7d323173 (patch)
treeaf81190be5b56edee3349ab035ca80c06e75b145 /include/llvm
parentc0ff8c85dcc0bb3c58c15890b180dedaa726cb76 (diff)
downloadexternal_llvm-5f4ac848d94b0a92e19ac7f2b3d0284d7d323173.zip
external_llvm-5f4ac848d94b0a92e19ac7f2b3d0284d7d323173.tar.gz
external_llvm-5f4ac848d94b0a92e19ac7f2b3d0284d7d323173.tar.bz2
Now Bitcode reader bug is fixed. Reapply 80839.
Use CallbackVH, instead of WeakVH, to hold MDNode elements. Use FoldingSetNode to unique MDNodes in a context. Use CallbackVH hooks to update context's MDNodeSet appropriately. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80868 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r--include/llvm/Constants.h4
-rw-r--r--include/llvm/Metadata.h36
2 files changed, 31 insertions, 9 deletions
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index fdcc53b..da6fe96 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -38,7 +38,7 @@ class VectorType;
template<class ConstantClass, class TypeClass, class ValType>
struct ConstantCreator;
template<class ConstantClass, class TypeClass>
-struct ConvertConstant;
+struct ConvertConstantType;
//===----------------------------------------------------------------------===//
/// This is the shared class of boolean and integer constants. This class
@@ -559,7 +559,7 @@ public:
class ConstantExpr : public Constant {
friend struct ConstantCreator<ConstantExpr,Type,
std::pair<unsigned, std::vector<Constant*> > >;
- friend struct ConvertConstant<ConstantExpr, Type>;
+ friend struct ConvertConstantType<ConstantExpr, Type>;
protected:
ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h
index b38336b..0844006 100644
--- a/include/llvm/Metadata.h
+++ b/include/llvm/Metadata.h
@@ -19,7 +19,9 @@
#include "llvm/User.h"
#include "llvm/Type.h"
#include "llvm/OperandTraits.h"
+#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ValueHandle.h"
@@ -27,8 +29,6 @@
namespace llvm {
class Constant;
class LLVMContext;
-template<class ConstantClass, class TypeClass, class ValType>
-struct ConstantCreator;
//===----------------------------------------------------------------------===//
// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
@@ -103,14 +103,32 @@ public:
/// MDNode - a tuple of other values.
/// These contain a list of the values that represent the metadata.
/// MDNode is always unnamed.
-class MDNode : public MetadataBase {
+class MDNode : public MetadataBase, public FoldingSetNode {
MDNode(const MDNode &); // DO NOT IMPLEMENT
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
// getNumOperands - Make this only available for private uses.
unsigned getNumOperands() { return User::getNumOperands(); }
- SmallVector<WeakVH, 4> Node;
- friend struct ConstantCreator<MDNode, Type, std::vector<Value*> >;
+ friend class ElementVH;
+ // Use CallbackVH to hold MDNOde elements.
+ 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:
explicit MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals);
public:
@@ -140,8 +158,8 @@ public:
}
// Element access
- typedef SmallVectorImpl<WeakVH>::const_iterator const_elem_iterator;
- typedef SmallVectorImpl<WeakVH>::iterator elem_iterator;
+ typedef SmallVectorImpl<ElementVH>::const_iterator const_elem_iterator;
+ typedef SmallVectorImpl<ElementVH>::iterator elem_iterator;
/// elem_empty - Return true if MDNode is empty.
bool elem_empty() const { return Node.empty(); }
const_elem_iterator elem_begin() const { return Node.begin(); }
@@ -156,6 +174,10 @@ public:
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) {
llvm_unreachable("This should never be called because MDNodes have no ops");
}