From: Duncan P. N. Exon Smith Date: Wed, 15 Oct 2014 16:11:41 +0000 (+0000) Subject: DI: Use a `DenseMap` instead of named metadata, NFC X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=5c2d60d357b16c7ee1fef47c40b23d198616ca14 DI: Use a `DenseMap` instead of named metadata, NFC Remove a strange round-trip through named metadata to assign preserved local variables to their subprograms. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219798 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/DIBuilder.h b/include/llvm/IR/DIBuilder.h index d12a0c609db..8484d04e914 100644 --- a/include/llvm/IR/DIBuilder.h +++ b/include/llvm/IR/DIBuilder.h @@ -73,6 +73,9 @@ namespace llvm { SmallVector AllGVs; SmallVector, 4> AllImportedModules; + /// Each subprogram's preserved local variables. + DenseMap>> PreservedVariables; + // Private use for multiple types of template parameters. DITemplateValueParameter createTemplateValueParameter(unsigned Tag, DIDescriptor Scope, diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index 510c36cb5cd..fe627d52dff 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -958,14 +958,6 @@ DISubprogram getDISubprogram(const MDNode *Scope); /// getDICompositeType - Find underlying composite type. DICompositeType getDICompositeType(DIType T); -/// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable -/// to hold function specific information. -NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP); - -/// getFnSpecificMDNode - Return a NameMDNode, if available, that is -/// suitable to hold function specific information. -NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP); - /// createInlinedVariable - Create a new inlined variable based on current /// variable. /// @param DV Current Variable. diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index c131b544b5f..3276fe6452a 100644 --- a/lib/IR/DIBuilder.cpp +++ b/lib/IR/DIBuilder.cpp @@ -73,13 +73,10 @@ void DIBuilder::finalize() { DIType(TempSubprograms).replaceAllUsesWith(SPs); for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) { DISubprogram SP(SPs.getElement(i)); - SmallVector Variables; - if (NamedMDNode *NMD = getFnSpecificMDNode(M, SP)) { - for (unsigned ii = 0, ee = NMD->getNumOperands(); ii != ee; ++ii) - Variables.push_back(NMD->getOperand(ii)); - NMD->eraseFromParent(); - } if (MDNode *Temp = SP.getVariablesNodes()) { + SmallVector Variables; + for (Value *V : PreservedVariables.lookup(SP)) + Variables.push_back(V); DIArray AV = getOrCreateArray(Variables); DIType(Temp).replaceAllUsesWith(AV); } @@ -906,8 +903,8 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, // to preserve variable info in such situation then stash it in a // named mdnode. DISubprogram Fn(getDISubprogram(Scope)); - NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn); - FnLocals->addOperand(Node); + assert(Fn && "Missing subprogram for local variable"); + PreservedVariables[Fn].push_back(Node); } DIVariable RetVar(Node); assert(RetVar.isVariable() && diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 4a52a9312fa..d5c2e6751cc 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -936,47 +936,6 @@ unsigned DILocation::computeNewDiscriminator(LLVMContext &Ctx) { return ++Ctx.pImpl->DiscriminatorTable[Key]; } -/// fixupSubprogramName - Replace contains special characters used -/// in a typical Objective-C names with '.' in a given string. -static void fixupSubprogramName(DISubprogram Fn, SmallVectorImpl &Out) { - StringRef FName = - Fn.getFunction() ? Fn.getFunction()->getName() : Fn.getName(); - FName = Function::getRealLinkageName(FName); - - StringRef Prefix("llvm.dbg.lv."); - Out.reserve(FName.size() + Prefix.size()); - Out.append(Prefix.begin(), Prefix.end()); - - bool isObjCLike = false; - for (size_t i = 0, e = FName.size(); i < e; ++i) { - char C = FName[i]; - if (C == '[') - isObjCLike = true; - - if (isObjCLike && (C == '[' || C == ']' || C == ' ' || C == ':' || - C == '+' || C == '(' || C == ')')) - Out.push_back('.'); - else - Out.push_back(C); - } -} - -/// getFnSpecificMDNode - Return a NameMDNode, if available, that is -/// suitable to hold function specific information. -NamedMDNode *llvm::getFnSpecificMDNode(const Module &M, DISubprogram Fn) { - SmallString<32> Name; - fixupSubprogramName(Fn, Name); - return M.getNamedMetadata(Name.str()); -} - -/// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable -/// to hold function specific information. -NamedMDNode *llvm::getOrInsertFnSpecificMDNode(Module &M, DISubprogram Fn) { - SmallString<32> Name; - fixupSubprogramName(Fn, Name); - return M.getOrInsertNamedMetadata(Name.str()); -} - /// createInlinedVariable - Create a new inlined variable based on current /// variable. /// @param DV Current Variable.