diff options
author | Adrian Prantl <aprantl@apple.com> | 2015-07-06 16:22:12 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2015-07-06 16:22:12 +0000 |
commit | 0e224a646c549e934dacf09e75000c2132ddb8a0 (patch) | |
tree | 33de2b96d3c69ec04b584fb011e5a7a9b3e2e0bb /llvm/lib/IR/DIBuilder.cpp | |
parent | 4afc1f422565b5afa7f02ea890e773baa3c2ff62 (diff) | |
download | llvm-0e224a646c549e934dacf09e75000c2132ddb8a0.zip llvm-0e224a646c549e934dacf09e75000c2132ddb8a0.tar.gz llvm-0e224a646c549e934dacf09e75000c2132ddb8a0.tar.bz2 |
Use an early exit in DIBuilder::finalize() to improve readability.
llvm-svn: 241465
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r-- | llvm/lib/IR/DIBuilder.cpp | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index 6a3ff0e..1aa7685 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -73,37 +73,41 @@ void DIBuilder::trackIfUnresolved(MDNode *N) { } void DIBuilder::finalize() { - if (CUNode) { - CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes)); - - SmallVector<Metadata *, 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<Metadata *, 16> RetainSet; - for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++) - if (RetainSet.insert(AllRetainTypes[I]).second) - RetainValues.push_back(AllRetainTypes[I]); - CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues)); - - DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms); - CUNode->replaceSubprograms(SPs.get()); - for (auto *SP : SPs) { - if (MDTuple *Temp = SP->getVariables().get()) { - const auto &PV = PreservedVariables.lookup(SP); - SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end()); - DINodeArray AV = getOrCreateArray(Variables); - TempMDTuple(Temp)->replaceAllUsesWith(AV.get()); - } + if (!CUNode) { + assert(!AllowUnresolvedNodes && + "creating type nodes without a CU is not supported"); + return; + } + + CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes)); + + SmallVector<Metadata *, 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<Metadata *, 16> RetainSet; + for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++) + if (RetainSet.insert(AllRetainTypes[I]).second) + RetainValues.push_back(AllRetainTypes[I]); + CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues)); + + DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms); + CUNode->replaceSubprograms(SPs.get()); + for (auto *SP : SPs) { + if (MDTuple *Temp = SP->getVariables().get()) { + const auto &PV = PreservedVariables.lookup(SP); + SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end()); + DINodeArray AV = getOrCreateArray(Variables); + TempMDTuple(Temp)->replaceAllUsesWith(AV.get()); } + } - CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs)); + CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs)); - CUNode->replaceImportedEntities(MDTuple::get( - VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(), - AllImportedModules.end()))); - } + CUNode->replaceImportedEntities(MDTuple::get( + VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(), + AllImportedModules.end()))); // Now that all temp nodes have been replaced or deleted, resolve remaining // cycles. |