mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-10-31 08:16:47 +00:00 
			
		
		
		
	Reapply r97788 to free MDNodes when the LLVMContext is destroyed. It
bootstraps llvm-gcc this time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97918 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		| @@ -108,9 +108,6 @@ class MDNode : public Value, public FoldingSetNode { | |||||||
|   /// node with T. |   /// node with T. | ||||||
|   void replaceOperand(MDNodeOperand *Op, Value *NewVal); |   void replaceOperand(MDNodeOperand *Op, Value *NewVal); | ||||||
|   ~MDNode(); |   ~MDNode(); | ||||||
|   /// replaceAllOperandsWithNull - This is used while destroying llvm context to  |  | ||||||
|   /// gracefully delete all nodes. This method replaces all operands with null. |  | ||||||
|   void replaceAllOperandsWithNull(); |  | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
|   explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals, |   explicit MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals, | ||||||
| @@ -166,9 +163,7 @@ private: | |||||||
|   bool isNotUniqued() const {  |   bool isNotUniqued() const {  | ||||||
|     return (getSubclassDataFromValue() & NotUniquedBit) != 0; |     return (getSubclassDataFromValue() & NotUniquedBit) != 0; | ||||||
|   } |   } | ||||||
|   void setIsNotUniqued() { |   void setIsNotUniqued(); | ||||||
|     setValueSubclassData(getSubclassDataFromValue() | NotUniquedBit); |  | ||||||
|   } |  | ||||||
|    |    | ||||||
|   // Shadow Value::setValueSubclassData with a private forwarding method so that |   // Shadow Value::setValueSubclassData with a private forwarding method so that | ||||||
|   // any future subclasses cannot accidentally use it. |   // any future subclasses cannot accidentally use it. | ||||||
|   | |||||||
| @@ -105,6 +105,11 @@ public: | |||||||
|   StringMap<MDString*> MDStringCache; |   StringMap<MDString*> MDStringCache; | ||||||
|    |    | ||||||
|   FoldingSet<MDNode> MDNodeSet; |   FoldingSet<MDNode> MDNodeSet; | ||||||
|  |   // MDNodes may be uniqued or not uniqued.  When they're not uniqued, they | ||||||
|  |   // aren't in the MDNodeSet, but they're still shared between objects, so no | ||||||
|  |   // one object can destroy them.  This set allows us to at least destroy them | ||||||
|  |   // on Context destruction. | ||||||
|  |   SmallPtrSet<MDNode*, 1> NonUniquedMDNodes; | ||||||
|    |    | ||||||
|   ConstantUniqueMap<char, Type, ConstantAggregateZero> AggZeroConstants; |   ConstantUniqueMap<char, Type, ConstantAggregateZero> AggZeroConstants; | ||||||
|  |  | ||||||
| @@ -235,17 +240,21 @@ public: | |||||||
|       (*I)->AbstractTypeUsers.clear(); |       (*I)->AbstractTypeUsers.clear(); | ||||||
|       delete *I; |       delete *I; | ||||||
|     } |     } | ||||||
|     // Destroy MDNode operands first. |     // Destroy MDNodes.  ~MDNode can move and remove nodes between the MDNodeSet | ||||||
|  |     // and the NonUniquedMDNodes sets, so copy the values out first. | ||||||
|  |     SmallVector<MDNode*, 8> MDNodes; | ||||||
|  |     MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size()); | ||||||
|     for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end(); |     for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end(); | ||||||
|          I != E;) { |          I != E; ++I) { | ||||||
|       MDNode *N = &(*I); |       MDNodes.push_back(&*I); | ||||||
|       ++I; |  | ||||||
|       N->replaceAllOperandsWithNull(); |  | ||||||
|     } |     } | ||||||
|     while (!MDNodeSet.empty()) { |     MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end()); | ||||||
|       MDNode *N = &(*MDNodeSet.begin()); |     for (SmallVector<MDNode*, 8>::iterator I = MDNodes.begin(), | ||||||
|       N->destroy(); |            E = MDNodes.end(); I != E; ++I) { | ||||||
|  |       (*I)->destroy(); | ||||||
|     } |     } | ||||||
|  |     assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() && | ||||||
|  |            "Destroying all MDNodes didn't empty the Context's sets."); | ||||||
|     // Destroy MDStrings. |     // Destroy MDStrings. | ||||||
|     for (StringMap<MDString*>::iterator I = MDStringCache.begin(), |     for (StringMap<MDString*>::iterator I = MDStringCache.begin(), | ||||||
|            E = MDStringCache.end(); I != E; ++I) { |            E = MDStringCache.end(); I != E; ++I) { | ||||||
|   | |||||||
| @@ -110,8 +110,10 @@ MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals, | |||||||
| MDNode::~MDNode() { | MDNode::~MDNode() { | ||||||
|   assert((getSubclassDataFromValue() & DestroyFlag) != 0 && |   assert((getSubclassDataFromValue() & DestroyFlag) != 0 && | ||||||
|          "Not being destroyed through destroy()?"); |          "Not being destroyed through destroy()?"); | ||||||
|   if (!isNotUniqued()) { |   LLVMContextImpl *pImpl = getType()->getContext().pImpl; | ||||||
|     LLVMContextImpl *pImpl = getType()->getContext().pImpl; |   if (isNotUniqued()) { | ||||||
|  |     pImpl->NonUniquedMDNodes.erase(this); | ||||||
|  |   } else { | ||||||
|     pImpl->MDNodeSet.RemoveNode(this); |     pImpl->MDNodeSet.RemoveNode(this); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -257,12 +259,10 @@ void MDNode::Profile(FoldingSetNodeID &ID) const { | |||||||
|     ID.AddPointer(getOperand(i)); |     ID.AddPointer(getOperand(i)); | ||||||
| } | } | ||||||
|  |  | ||||||
| // replaceAllOperandsWithNull - This is used while destroying llvm context to  | void MDNode::setIsNotUniqued() { | ||||||
| // gracefully delete all nodes. This method replaces all operands with null. |   setValueSubclassData(getSubclassDataFromValue() | NotUniquedBit); | ||||||
| void MDNode::replaceAllOperandsWithNull() { |   LLVMContextImpl *pImpl = getType()->getContext().pImpl; | ||||||
|   for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands; |   pImpl->NonUniquedMDNodes.insert(this); | ||||||
|        Op != E; ++Op) |  | ||||||
|     replaceOperand(Op, 0); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // Replace value from this node's operand list. | // Replace value from this node's operand list. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user