llvm.org GIT mirror llvm / 489b29b
Introduce a new temporary MDNode concept. Temporary MDNodes are not part of the IR, are not uniqued, and may be safely RAUW'd. This replaces a variety of alternate mechanisms for achieving the same effect. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111681 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 9 years ago
6 changed file(s) with 62 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
271271 StringRef getFilename() const { return getCompileUnit().getFilename();}
272272 StringRef getDirectory() const { return getCompileUnit().getDirectory();}
273273
274 /// replaceAllUsesWith - Replace all uses of debug info referenced by
275 /// this descriptor.
276 void replaceAllUsesWith(DIDescriptor &D);
277
274278 /// print - print type.
275279 void print(raw_ostream &OS) const;
276280
313317
314318 /// dump - print derived type to dbgs() with a newline.
315319 void dump() const;
316
317 /// replaceAllUsesWith - Replace all uses of debug info referenced by
318 /// this descriptor.
319 void replaceAllUsesWith(DIDescriptor &D);
320320 };
321321
322322 /// DICompositeType - This descriptor holds a type that can refer to multiple
652652 DIArray Elements,
653653 unsigned RunTimeLang = 0,
654654 MDNode *ContainingType = 0);
655
656 /// CreateTemporaryType - Create a temporary forward-declared type.
657 DIType CreateTemporaryType(DIDescriptor Context);
655658
656659 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
657660 DIType CreateArtificialType(DIType Ty);
127127
128128 static MDNode *getIfExists(LLVMContext &Context, Value *const *Vals,
129129 unsigned NumVals);
130
131 /// getTemporary - Return a temporary MDNode, for use in constructing
132 /// cyclic MDNode structures. A temporary MDNode is not uniqued,
133 /// may be RAUW'd, and must be manually deleted with deleteTemporary.
134 static MDNode *getTemporary(LLVMContext &Context, Value *const *Vals,
135 unsigned NumVals);
136
137 /// deleteTemporary - Deallocate a node created by getTemporary. The
138 /// node must not have any users.
139 static void deleteTemporary(MDNode *N);
130140
131141 /// getOperand - Return specified operand.
132142 Value *getOperand(unsigned i) const;
2121 #include "llvm/Analysis/ValueTracking.h"
2222 #include "llvm/ADT/SmallPtrSet.h"
2323 #include "llvm/ADT/SmallString.h"
24 #include "llvm/ADT/STLExtras.h"
2425 #include "llvm/Support/Debug.h"
2526 #include "llvm/Support/Dwarf.h"
2627 #include "llvm/Support/raw_ostream.h"
259260
260261 /// replaceAllUsesWith - Replace all uses of debug info referenced by
261262 /// this descriptor.
262 void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) {
263 void DIType::replaceAllUsesWith(DIDescriptor &D) {
263264 if (!DbgNode)
264265 return;
265266
273274 const MDNode *DN = D;
274275 const Value *V = cast_or_null(DN);
275276 Node->replaceAllUsesWith(const_cast(V));
277 MDNode::deleteTemporary(Node);
276278 }
277279 }
278280
933935 }
934936
935937
938 /// CreateTemporaryType - Create a temporary forward-declared type.
939 DIType DIFactory::CreateTemporaryType(DIDescriptor Context) {
940 // Give the temporary MDNode a tag. It doesn't matter what tag we
941 // use here as long as DIType accepts it.
942 Value *Elts[] = {
943 GetTagConstant(DW_TAG_base_type)
944 };
945 MDNode *Node = MDNode::getTemporary(VMContext, Elts, array_lengthof(Elts));
946 return DIType(Node);
947 }
948
949
936950 /// CreateCompositeType - Create a composite type like array, struct, etc.
937951 DICompositeType DIFactory::CreateCompositeTypeEx(unsigned Tag,
938952 DIDescriptor Context,
516516 if (Result) return false;
517517
518518 // Otherwise, create MDNode forward reference.
519
520 // FIXME: This is not unique enough!
521 std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
522 Value *V = MDString::get(Context, FwdRefName);
523 MDNode *FwdNode = MDNode::get(Context, &V, 1);
519 MDNode *FwdNode = MDNode::getTemporary(Context, 0, 0);
524520 ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
525521
526522 if (NumberedMetadata.size() <= MID)
584580 std::map, LocTy> >::iterator
585581 FI = ForwardRefMDNodes.find(MetadataID);
586582 if (FI != ForwardRefMDNodes.end()) {
587 FI->second.first->replaceAllUsesWith(Init);
583 MDNode *Temp = FI->second.first;
584 Temp->replaceAllUsesWith(Init);
585 MDNode::deleteTemporary(Temp);
588586 ForwardRefMDNodes.erase(FI);
589587
590588 assert(NumberedMetadata[MetadataID] == Init && "Tracking VH didn't work");
332332 }
333333
334334 // If there was a forward reference to this value, replace it.
335 Value *PrevVal = OldV;
335 MDNode *PrevVal = cast(OldV);
336336 OldV->replaceAllUsesWith(V);
337 delete PrevVal;
337 MDNode::deleteTemporary(PrevVal);
338338 // Deleting PrevVal sets Idx value in MDValuePtrs to null. Set new
339339 // value for Idx.
340340 MDValuePtrs[Idx] = V;
350350 }
351351
352352 // Create and return a placeholder, which will later be RAUW'd.
353 Value *V = new Argument(Type::getMetadataTy(Context));
353 Value *V = MDNode::getTemporary(Context, 0, 0);
354354 MDValuePtrs[Idx] = V;
355355 return V;
356356 }
1919 #include "llvm/ADT/StringMap.h"
2020 #include "llvm/ADT/SmallString.h"
2121 #include "SymbolTableListTraitsImpl.h"
22 #include "llvm/Support/LeakDetector.h"
2223 #include "llvm/Support/ValueHandle.h"
2324 using namespace llvm;
2425
243244 return getMDNode(Context, Vals, NumVals, FL_Unknown, false);
244245 }
245246
247 MDNode *MDNode::getTemporary(LLVMContext &Context, Value *const *Vals,
248 unsigned NumVals) {
249 MDNode *N = (MDNode *)malloc(sizeof(MDNode)+NumVals*sizeof(MDNodeOperand));
250 N = new (N) MDNode(Context, Vals, NumVals, FL_No);
251 N->setValueSubclassData(N->getSubclassDataFromValue() |
252 NotUniquedBit);
253 LeakDetector::addGarbageObject(N);
254 return N;
255 }
256
257 void MDNode::deleteTemporary(MDNode *N) {
258 assert(N->use_empty() && "Temporary MDNode has uses!");
259 assert((N->getSubclassDataFromValue() & NotUniquedBit) &&
260 "Temporary MDNode does not have NotUniquedBit set!");
261 assert((N->getSubclassDataFromValue() & DestroyFlag) == 0 &&
262 "Temporary MDNode does has DestroyFlag set!");
263 N->setValueSubclassData(N->getSubclassDataFromValue() |
264 DestroyFlag);
265 LeakDetector::removeGarbageObject(N);
266 delete N;
267 }
268
246269 /// getOperand - Return specified operand.
247270 Value *MDNode::getOperand(unsigned i) const {
248271 return *getOperandPtr(const_cast(this), i);