summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-08-20 22:02:26 +0000
committerDan Gohman <gohman@apple.com>2010-08-20 22:02:26 +0000
commit489b29b0a4ee4526e3d50ad88d3d48745baf5042 (patch)
tree6602f14da364b9d6e0714e7b327adf14d7ffac23
parent95c79302259c03aa99010bbbc7d8ffeae3fa9740 (diff)
downloadllvm-489b29b0a4ee4526e3d50ad88d3d48745baf5042.tar.gz
llvm-489b29b0a4ee4526e3d50ad88d3d48745baf5042.tar.bz2
llvm-489b29b0a4ee4526e3d50ad88d3d48745baf5042.tar.xz
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
-rw-r--r--include/llvm/Analysis/DebugInfo.h11
-rw-r--r--include/llvm/Metadata.h10
-rw-r--r--lib/Analysis/DebugInfo.cpp16
-rw-r--r--lib/AsmParser/LLParser.cpp10
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp6
-rw-r--r--lib/VMCore/Metadata.cpp23
6 files changed, 62 insertions, 14 deletions
diff --git a/include/llvm/Analysis/DebugInfo.h b/include/llvm/Analysis/DebugInfo.h
index 625ca8a844..da226273a0 100644
--- a/include/llvm/Analysis/DebugInfo.h
+++ b/include/llvm/Analysis/DebugInfo.h
@@ -272,6 +272,10 @@ namespace llvm {
StringRef getFilename() const { return getCompileUnit().getFilename();}
StringRef getDirectory() const { return getCompileUnit().getDirectory();}
+ /// replaceAllUsesWith - Replace all uses of debug info referenced by
+ /// this descriptor.
+ void replaceAllUsesWith(DIDescriptor &D);
+
/// print - print type.
void print(raw_ostream &OS) const;
@@ -314,10 +318,6 @@ namespace llvm {
/// dump - print derived type to dbgs() with a newline.
void dump() const;
-
- /// replaceAllUsesWith - Replace all uses of debug info referenced by
- /// this descriptor.
- void replaceAllUsesWith(DIDescriptor &D);
};
/// DICompositeType - This descriptor holds a type that can refer to multiple
@@ -654,6 +654,9 @@ namespace llvm {
unsigned RunTimeLang = 0,
MDNode *ContainingType = 0);
+ /// CreateTemporaryType - Create a temporary forward-declared type.
+ DIType CreateTemporaryType(DIDescriptor Context);
+
/// CreateArtificialType - Create a new DIType with "artificial" flag set.
DIType CreateArtificialType(DIType Ty);
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h
index ef9646e977..f773817e82 100644
--- a/include/llvm/Metadata.h
+++ b/include/llvm/Metadata.h
@@ -128,6 +128,16 @@ public:
static MDNode *getIfExists(LLVMContext &Context, Value *const *Vals,
unsigned NumVals);
+
+ /// getTemporary - Return a temporary MDNode, for use in constructing
+ /// cyclic MDNode structures. A temporary MDNode is not uniqued,
+ /// may be RAUW'd, and must be manually deleted with deleteTemporary.
+ static MDNode *getTemporary(LLVMContext &Context, Value *const *Vals,
+ unsigned NumVals);
+
+ /// deleteTemporary - Deallocate a node created by getTemporary. The
+ /// node must not have any users.
+ static void deleteTemporary(MDNode *N);
/// getOperand - Return specified operand.
Value *getOperand(unsigned i) const;
diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp
index 1b9008cca7..065a00ae60 100644
--- a/lib/Analysis/DebugInfo.cpp
+++ b/lib/Analysis/DebugInfo.cpp
@@ -22,6 +22,7 @@
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/raw_ostream.h"
@@ -260,7 +261,7 @@ unsigned DIArray::getNumElements() const {
/// replaceAllUsesWith - Replace all uses of debug info referenced by
/// this descriptor.
-void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) {
+void DIType::replaceAllUsesWith(DIDescriptor &D) {
if (!DbgNode)
return;
@@ -274,6 +275,7 @@ void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) {
const MDNode *DN = D;
const Value *V = cast_or_null<Value>(DN);
Node->replaceAllUsesWith(const_cast<Value*>(V));
+ MDNode::deleteTemporary(Node);
}
}
@@ -934,6 +936,18 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
}
+/// CreateTemporaryType - Create a temporary forward-declared type.
+DIType DIFactory::CreateTemporaryType(DIDescriptor Context) {
+ // Give the temporary MDNode a tag. It doesn't matter what tag we
+ // use here as long as DIType accepts it.
+ Value *Elts[] = {
+ GetTagConstant(DW_TAG_base_type)
+ };
+ MDNode *Node = MDNode::getTemporary(VMContext, Elts, array_lengthof(Elts));
+ return DIType(Node);
+}
+
+
/// CreateCompositeType - Create a composite type like array, struct, etc.
DICompositeType DIFactory::CreateCompositeTypeEx(unsigned Tag,
DIDescriptor Context,
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index c55a16520f..dc545fff2d 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -517,11 +517,7 @@ bool LLParser::ParseMDNodeID(MDNode *&Result) {
if (Result) return false;
// Otherwise, create MDNode forward reference.
-
- // FIXME: This is not unique enough!
- std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
- Value *V = MDString::get(Context, FwdRefName);
- MDNode *FwdNode = MDNode::get(Context, &V, 1);
+ MDNode *FwdNode = MDNode::getTemporary(Context, 0, 0);
ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
if (NumberedMetadata.size() <= MID)
@@ -585,7 +581,9 @@ bool LLParser::ParseStandaloneMetadata() {
std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> >::iterator
FI = ForwardRefMDNodes.find(MetadataID);
if (FI != ForwardRefMDNodes.end()) {
- FI->second.first->replaceAllUsesWith(Init);
+ MDNode *Temp = FI->second.first;
+ Temp->replaceAllUsesWith(Init);
+ MDNode::deleteTemporary(Temp);
ForwardRefMDNodes.erase(FI);
assert(NumberedMetadata[MetadataID] == Init && "Tracking VH didn't work");
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index 8f999a6875..2010468824 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -333,9 +333,9 @@ void BitcodeReaderMDValueList::AssignValue(Value *V, unsigned Idx) {
}
// If there was a forward reference to this value, replace it.
- Value *PrevVal = OldV;
+ MDNode *PrevVal = cast<MDNode>(OldV);
OldV->replaceAllUsesWith(V);
- delete PrevVal;
+ MDNode::deleteTemporary(PrevVal);
// Deleting PrevVal sets Idx value in MDValuePtrs to null. Set new
// value for Idx.
MDValuePtrs[Idx] = V;
@@ -351,7 +351,7 @@ Value *BitcodeReaderMDValueList::getValueFwdRef(unsigned Idx) {
}
// Create and return a placeholder, which will later be RAUW'd.
- Value *V = new Argument(Type::getMetadataTy(Context));
+ Value *V = MDNode::getTemporary(Context, 0, 0);
MDValuePtrs[Idx] = V;
return V;
}
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp
index 442b5c51b6..236ddaa15b 100644
--- a/lib/VMCore/Metadata.cpp
+++ b/lib/VMCore/Metadata.cpp
@@ -20,6 +20,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/SmallString.h"
#include "SymbolTableListTraitsImpl.h"
+#include "llvm/Support/LeakDetector.h"
#include "llvm/Support/ValueHandle.h"
using namespace llvm;
@@ -244,6 +245,28 @@ MDNode *MDNode::getIfExists(LLVMContext &Context, Value *const *Vals,
return getMDNode(Context, Vals, NumVals, FL_Unknown, false);
}
+MDNode *MDNode::getTemporary(LLVMContext &Context, Value *const *Vals,
+ unsigned NumVals) {
+ MDNode *N = (MDNode *)malloc(sizeof(MDNode)+NumVals*sizeof(MDNodeOperand));
+ N = new (N) MDNode(Context, Vals, NumVals, FL_No);
+ N->setValueSubclassData(N->getSubclassDataFromValue() |
+ NotUniquedBit);
+ LeakDetector::addGarbageObject(N);
+ return N;
+}
+
+void MDNode::deleteTemporary(MDNode *N) {
+ assert(N->use_empty() && "Temporary MDNode has uses!");
+ assert((N->getSubclassDataFromValue() & NotUniquedBit) &&
+ "Temporary MDNode does not have NotUniquedBit set!");
+ assert((N->getSubclassDataFromValue() & DestroyFlag) == 0 &&
+ "Temporary MDNode does has DestroyFlag set!");
+ N->setValueSubclassData(N->getSubclassDataFromValue() |
+ DestroyFlag);
+ LeakDetector::removeGarbageObject(N);
+ delete N;
+}
+
/// getOperand - Return specified operand.
Value *MDNode::getOperand(unsigned i) const {
return *getOperandPtr(const_cast<MDNode*>(this), i);