DIBuilder: Now that DICompileUnit is distinct, stop using temporary nodes

for the arrays.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241308 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Adrian Prantl 2015-07-02 22:32:52 +00:00
parent 516286ff69
commit c3d9cd3f73
3 changed files with 44 additions and 47 deletions

View File

@ -36,14 +36,9 @@ namespace llvm {
Module &M; Module &M;
LLVMContext &VMContext; LLVMContext &VMContext;
TempMDTuple TempEnumTypes; DICompileUnit *CUNode; ///< The one compile unit created by this DIBuiler.
TempMDTuple TempRetainTypes; Function *DeclareFn; ///< llvm.dbg.declare
TempMDTuple TempSubprograms; Function *ValueFn; ///< llvm.dbg.value
TempMDTuple TempGVs;
TempMDTuple TempImportedModules;
Function *DeclareFn; // llvm.dbg.declare
Function *ValueFn; // llvm.dbg.value
SmallVector<Metadata *, 4> AllEnumTypes; SmallVector<Metadata *, 4> AllEnumTypes;
/// Track the RetainTypes, since they can be updated later on. /// Track the RetainTypes, since they can be updated later on.

View File

@ -1085,12 +1085,21 @@ public:
/// deleted on a uniquing collision. In practice, uniquing collisions on \a /// deleted on a uniquing collision. In practice, uniquing collisions on \a
/// DICompileUnit should be fairly rare. /// DICompileUnit should be fairly rare.
/// @{ /// @{
void replaceEnumTypes(DISubprogramArray N) {
replaceOperandWith(4, N.get());
}
void replaceRetainedTypes(DISubprogramArray N) {
replaceOperandWith(5, N.get());
}
void replaceSubprograms(DISubprogramArray N) { void replaceSubprograms(DISubprogramArray N) {
replaceOperandWith(6, N.get()); replaceOperandWith(6, N.get());
} }
void replaceGlobalVariables(DIGlobalVariableArray N) { void replaceGlobalVariables(DIGlobalVariableArray N) {
replaceOperandWith(7, N.get()); replaceOperandWith(7, N.get());
} }
void replaceImportedEntities(DIGlobalVariableArray N) {
replaceOperandWith(8, N.get());
}
/// @} /// @}
static bool classof(const Metadata *MD) { static bool classof(const Metadata *MD) {

View File

@ -58,8 +58,7 @@ public:
} }
DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes) DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes)
: M(m), VMContext(M.getContext()), TempEnumTypes(nullptr), : M(m), VMContext(M.getContext()), CUNode(nullptr),
TempRetainTypes(nullptr), TempSubprograms(nullptr), TempGVs(nullptr),
DeclareFn(nullptr), ValueFn(nullptr), DeclareFn(nullptr), ValueFn(nullptr),
AllowUnresolvedNodes(AllowUnresolvedNodes) {} AllowUnresolvedNodes(AllowUnresolvedNodes) {}
@ -74,36 +73,38 @@ void DIBuilder::trackIfUnresolved(MDNode *N) {
} }
void DIBuilder::finalize() { void DIBuilder::finalize() {
TempEnumTypes->replaceAllUsesWith(MDTuple::get(VMContext, AllEnumTypes)); if (CUNode) {
CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
SmallVector<Metadata *, 16> RetainValues; SmallVector<Metadata *, 16> RetainValues;
// Declarations and definitions of the same type may be retained. Some // Declarations and definitions of the same type may be retained. Some
// clients RAUW these pairs, leaving duplicates in the retained types // clients RAUW these pairs, leaving duplicates in the retained types
// list. Use a set to remove the duplicates while we transform the // list. Use a set to remove the duplicates while we transform the
// TrackingVHs back into Values. // TrackingVHs back into Values.
SmallPtrSet<Metadata *, 16> RetainSet; SmallPtrSet<Metadata *, 16> RetainSet;
for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++) for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
if (RetainSet.insert(AllRetainTypes[I]).second) if (RetainSet.insert(AllRetainTypes[I]).second)
RetainValues.push_back(AllRetainTypes[I]); RetainValues.push_back(AllRetainTypes[I]);
TempRetainTypes->replaceAllUsesWith(MDTuple::get(VMContext, RetainValues)); CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms); DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
TempSubprograms->replaceAllUsesWith(SPs.get()); CUNode->replaceSubprograms(SPs.get());
for (auto *SP : SPs) { for (auto *SP : SPs) {
if (MDTuple *Temp = SP->getVariables().get()) { if (MDTuple *Temp = SP->getVariables().get()) {
const auto &PV = PreservedVariables.lookup(SP); const auto &PV = PreservedVariables.lookup(SP);
SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end()); SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end());
DINodeArray AV = getOrCreateArray(Variables); DINodeArray AV = getOrCreateArray(Variables);
TempMDTuple(Temp)->replaceAllUsesWith(AV.get()); TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
}
} }
CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
CUNode->replaceImportedEntities(MDTuple::get(
VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
AllImportedModules.end())));
} }
TempGVs->replaceAllUsesWith(MDTuple::get(VMContext, AllGVs));
TempImportedModules->replaceAllUsesWith(MDTuple::get(
VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
AllImportedModules.end())));
// Now that all temp nodes have been replaced or deleted, resolve remaining // Now that all temp nodes have been replaced or deleted, resolve remaining
// cycles. // cycles.
for (const auto &N : UnresolvedNodes) for (const auto &N : UnresolvedNodes)
@ -133,19 +134,11 @@ DICompileUnit *DIBuilder::createCompileUnit(
assert(!Filename.empty() && assert(!Filename.empty() &&
"Unable to create compile unit without filename"); "Unable to create compile unit without filename");
// TODO: Once we make DICompileUnit distinct, stop using temporaries here assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
// (just start with operands assigned to nullptr). CUNode = DICompileUnit::getDistinct(
TempEnumTypes = MDTuple::getTemporary(VMContext, None);
TempRetainTypes = MDTuple::getTemporary(VMContext, None);
TempSubprograms = MDTuple::getTemporary(VMContext, None);
TempGVs = MDTuple::getTemporary(VMContext, None);
TempImportedModules = MDTuple::getTemporary(VMContext, None);
DICompileUnit *CUNode = DICompileUnit::getDistinct(
VMContext, Lang, DIFile::get(VMContext, Filename, Directory), Producer, VMContext, Lang, DIFile::get(VMContext, Filename, Directory), Producer,
isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes.get(), isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr,
TempRetainTypes.get(), TempSubprograms.get(), TempGVs.get(), nullptr, nullptr, nullptr, nullptr, DWOId);
TempImportedModules.get(), DWOId);
// Create a named metadata so that it is easier to find cu in a module. // Create a named metadata so that it is easier to find cu in a module.
// Note that we only generate this when the caller wants to actually // Note that we only generate this when the caller wants to actually