summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Metadata.h4
-rw-r--r--llvm/lib/VMCore/LLVMContextImpl.h12
-rw-r--r--llvm/lib/VMCore/Metadata.cpp7
3 files changed, 22 insertions, 1 deletions
diff --git a/llvm/include/llvm/Metadata.h b/llvm/include/llvm/Metadata.h
index 4e459bf7bf5..0369f5e80ca 100644
--- a/llvm/include/llvm/Metadata.h
+++ b/llvm/include/llvm/Metadata.h
@@ -75,6 +75,7 @@ class MDNode : public Value, public FoldingSetNode {
MDNode(const MDNode &); // DO NOT IMPLEMENT
void operator=(const MDNode &); // DO NOT IMPLEMENT
friend class MDNodeOperand;
+ friend class LLVMContextImpl;
/// NumOperands - This many 'MDNodeOperand' items are co-allocated onto the
/// end of this MDNode.
@@ -106,6 +107,9 @@ class MDNode : public Value, public FoldingSetNode {
// Replace each instance of F from the operand list of this node with T.
void replaceOperand(MDNodeOperand *Op, Value *NewVal);
~MDNode();
+ // replaceAllOperandsWithNull - This is used while destroying llvm context to
+ // gracefully delete all nodes. This method replaces all operands with null.
+ void replaceAllOperandsWithNull();
protected:
explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
diff --git a/llvm/lib/VMCore/LLVMContextImpl.h b/llvm/lib/VMCore/LLVMContextImpl.h
index 62491d838fb..85bbe4ac9b0 100644
--- a/llvm/lib/VMCore/LLVMContextImpl.h
+++ b/llvm/lib/VMCore/LLVMContextImpl.h
@@ -229,13 +229,23 @@ public:
if (I->second->use_empty())
delete I->second;
}
- MDNodeSet.clear();
AlwaysOpaqueTy->dropRef();
for (OpaqueTypesTy::iterator I = OpaqueTypes.begin(), E = OpaqueTypes.end();
I != E; ++I) {
(*I)->AbstractTypeUsers.clear();
delete *I;
}
+ // Destroy MDNode operands first.
+ for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
+ I != E;) {
+ MDNode *N = &(*I);
+ ++I;
+ N->replaceAllOperandsWithNull();
+ }
+ while (!MDNodeSet.empty()) {
+ MDNode *N = &(*MDNodeSet.begin());
+ N->destroy();
+ }
}
};
diff --git a/llvm/lib/VMCore/Metadata.cpp b/llvm/lib/VMCore/Metadata.cpp
index 07a5f3c5398..a08c45480b6 100644
--- a/llvm/lib/VMCore/Metadata.cpp
+++ b/llvm/lib/VMCore/Metadata.cpp
@@ -257,6 +257,13 @@ void MDNode::Profile(FoldingSetNodeID &ID) const {
ID.AddPointer(getOperand(i));
}
+// replaceAllOperandsWithNull - This is used while destroying llvm context to
+// gracefully delete all nodes. This method replaces all operands with null.
+void MDNode::replaceAllOperandsWithNull() {
+ for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands;
+ Op != E; ++Op)
+ replaceOperand(Op, 0);
+}
// Replace value from this node's operand list.
void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
OpenPOWER on IntegriCloud