[llvm] r189621 - DIBuilder: retain a type when created with a unique identifier.
Manman Ren
manman.ren at gmail.com
Thu Aug 29 16:17:54 PDT 2013
Author: mren
Date: Thu Aug 29 18:17:54 2013
New Revision: 189621
URL: http://llvm.org/viewvc/llvm-project?rev=189621&view=rev
Log:
DIBuilder: retain a type when created with a unique identifier.
createClassType, createStructType, createUnionType, createEnumerationType,
and createForwardDecl will retain a type when created with a unique identifier,
to make sure they are treated as used even when all uses are replaced with
the identifiers.
Use TrackingVH<MDNode> instead of MDNode in AllRetainTypes, since the created
node can later be updated.
The change will be tested when clients of DIBuilder start to pass in non-empty
unique identifier.
Modified:
llvm/trunk/include/llvm/DIBuilder.h
llvm/trunk/lib/IR/DIBuilder.cpp
Modified: llvm/trunk/include/llvm/DIBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DIBuilder.h?rev=189621&r1=189620&r2=189621&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DIBuilder.h (original)
+++ llvm/trunk/include/llvm/DIBuilder.h Thu Aug 29 18:17:54 2013
@@ -18,6 +18,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/ValueHandle.h"
namespace llvm {
class BasicBlock;
@@ -65,7 +66,9 @@ namespace llvm {
Function *ValueFn; // llvm.dbg.value
SmallVector<Value *, 4> AllEnumTypes;
- SmallVector<Value *, 4> AllRetainTypes;
+ /// Use TrackingVH to collect RetainTypes, since they can be updated
+ /// later on.
+ SmallVector<TrackingVH<MDNode>, 4> AllRetainTypes;
SmallVector<Value *, 4> AllSubprograms;
SmallVector<Value *, 4> AllGVs;
SmallVector<Value *, 4> AllImportedModules;
Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=189621&r1=189620&r2=189621&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Thu Aug 29 18:17:54 2013
@@ -40,7 +40,16 @@ void DIBuilder::finalize() {
DIArray Enums = getOrCreateArray(AllEnumTypes);
DIType(TempEnumTypes).replaceAllUsesWith(Enums);
- DIArray RetainTypes = getOrCreateArray(AllRetainTypes);
+ SmallVector<Value *, 16> RetainValues;
+ // Declarations and definitions of the same type may be retained. Some
+ // clients RAUW these pairs, leaving duplicates in the retained types
+ // list. Use a set to remove the duplicates while we transform the
+ // TrackingVHs back into Values.
+ SmallPtrSet<Value *, 16> RetainSet;
+ for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
+ if (RetainSet.insert(AllRetainTypes[I]))
+ RetainValues.push_back(AllRetainTypes[I]);
+ DIArray RetainTypes = getOrCreateArray(RetainValues);
DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
DIArray SPs = getOrCreateArray(AllSubprograms);
@@ -624,6 +633,8 @@ DICompositeType DIBuilder::createClassTy
DICompositeType R(MDNode::get(VMContext, Elts));
assert(R.isCompositeType() &&
"createClassType should return a DICompositeType");
+ if (!UniqueIdentifier.empty())
+ retainType(R);
return R;
}
@@ -659,6 +670,8 @@ DICompositeType DIBuilder::createStructT
DICompositeType R(MDNode::get(VMContext, Elts));
assert(R.isCompositeType() &&
"createStructType should return a DICompositeType");
+ if (!UniqueIdentifier.empty())
+ retainType(R);
return R;
}
@@ -688,7 +701,10 @@ DICompositeType DIBuilder::createUnionTy
NULL,
UniqueIdentifier.empty() ? NULL : MDString::get(VMContext, UniqueIdentifier)
};
- return DICompositeType(MDNode::get(VMContext, Elts));
+ DICompositeType R(MDNode::get(VMContext, Elts));
+ if (!UniqueIdentifier.empty())
+ retainType(R);
+ return R;
}
/// createSubroutineType - Create subroutine type.
@@ -741,6 +757,8 @@ DICompositeType DIBuilder::createEnumera
};
MDNode *Node = MDNode::get(VMContext, Elts);
AllEnumTypes.push_back(Node);
+ if (!UniqueIdentifier.empty())
+ retainType(Node);
return DICompositeType(Node);
}
@@ -844,7 +862,7 @@ DIType DIBuilder::createObjectPointerTyp
/// retainType - Retain DIType in a module even if it is not referenced
/// through debug info anchors.
void DIBuilder::retainType(DIType T) {
- AllRetainTypes.push_back(T);
+ AllRetainTypes.push_back(TrackingVH<MDNode>(T));
}
/// createUnspecifiedParameter - Create unspeicified type descriptor
@@ -887,6 +905,8 @@ DICompositeType DIBuilder::createForward
DICompositeType RetTy(Node);
assert(RetTy.isCompositeType() &&
"createForwardDecl result should be a DIType");
+ if (!UniqueIdentifier.empty())
+ retainType(RetTy);
return RetTy;
}
More information about the llvm-commits
mailing list