From c04f46567c3ebf64257d8f03e29d80a69606a6bc Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 3 Jul 2008 23:13:02 +0000 Subject: [PATCH] Don't return std::vector by value, but pass it in by reference to be filled. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53123 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineModuleInfo.h | 15 +++++++-------- lib/CodeGen/DwarfWriter.cpp | 8 ++++---- lib/CodeGen/MachineModuleInfo.cpp | 22 ++++++++++------------ 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/include/llvm/CodeGen/MachineModuleInfo.h b/include/llvm/CodeGen/MachineModuleInfo.h index 54654fda5bd..a9567d2e255 100644 --- a/include/llvm/CodeGen/MachineModuleInfo.h +++ b/include/llvm/CodeGen/MachineModuleInfo.h @@ -1152,16 +1152,17 @@ public: /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the /// named GlobalVariable. - std::vector - getGlobalVariablesUsing(Module &M, const std::string &RootName); + void getGlobalVariablesUsing(Module &M, const std::string &RootName, + std::vector &Result); /// getAnchoredDescriptors - Return a vector of anchored debug descriptors. /// - template std::vector getAnchoredDescriptors(Module &M) { + template + void getAnchoredDescriptors(Module &M, std::vector &AnchoredDescs) { T Desc; - std::vector Globals = - getGlobalVariablesUsing(M, Desc.getAnchorString()); - std::vector AnchoredDescs; + std::vector Globals; + getGlobalVariablesUsing(M, Desc.getAnchorString(), Globals); + for (unsigned i = 0, N = Globals.size(); i < N; ++i) { GlobalVariable *GV = Globals[i]; @@ -1171,8 +1172,6 @@ public: AnchoredDescs.push_back(cast(DR.Deserialize(GV))); } } - - return AnchoredDescs; } /// RecordRegionStart - Indicate the start of a region. diff --git a/lib/CodeGen/DwarfWriter.cpp b/lib/CodeGen/DwarfWriter.cpp index a284ba19eb6..2d0a1142027 100644 --- a/lib/CodeGen/DwarfWriter.cpp +++ b/lib/CodeGen/DwarfWriter.cpp @@ -2630,8 +2630,8 @@ private: /// ConstructGlobalDIEs - Create DIEs for each of the externally visible /// global variables. void ConstructGlobalDIEs() { - std::vector GlobalVariables = - MMI->getAnchoredDescriptors(*M); + std::vector GlobalVariables; + MMI->getAnchoredDescriptors(*M, GlobalVariables); for (unsigned i = 0, N = GlobalVariables.size(); i < N; ++i) { GlobalVariableDesc *GVD = GlobalVariables[i]; @@ -2642,8 +2642,8 @@ private: /// ConstructSubprogramDIEs - Create DIEs for each of the externally visible /// subprograms. void ConstructSubprogramDIEs() { - std::vector Subprograms = - MMI->getAnchoredDescriptors(*M); + std::vector Subprograms; + MMI->getAnchoredDescriptors(*M, Subprograms); for (unsigned i = 0, N = Subprograms.size(); i < N; ++i) { SubprogramDesc *SPD = Subprograms[i]; diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index b33a2d3e369..3d3a9957bb0 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -52,10 +52,9 @@ getGlobalVariablesUsing(Value *V, std::vector &Result) { /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the /// named GlobalVariable. -static std::vector -getGlobalVariablesUsing(Module &M, const std::string &RootName) { - std::vector Result; // GlobalVariables matching criteria. - +static void +getGlobalVariablesUsing(Module &M, const std::string &RootName, + std::vector &Result) { std::vector FieldTypes; FieldTypes.push_back(Type::Int32Ty); FieldTypes.push_back(Type::Int32Ty); @@ -65,11 +64,8 @@ getGlobalVariablesUsing(Module &M, const std::string &RootName) { StructType::get(FieldTypes)); // If present and linkonce then scan for users. - if (UseRoot && UseRoot->hasLinkOnceLinkage()) { + if (UseRoot && UseRoot->hasLinkOnceLinkage()) getGlobalVariablesUsing(UseRoot, Result); - } - - return Result; } /// isStringValue - Return true if the given value can be coerced to a string. @@ -1593,7 +1589,8 @@ void MachineModuleInfo::AnalyzeModule(Module &M) { /// SetupCompileUnits - Set up the unique vector of compile units. /// void MachineModuleInfo::SetupCompileUnits(Module &M) { - std::vectorCU = getAnchoredDescriptors(M); + std::vector CU; + getAnchoredDescriptors(M, CU); for (unsigned i = 0, N = CU.size(); i < N; i++) { CompileUnits.insert(CU[i]); @@ -1608,10 +1605,11 @@ const UniqueVector MachineModuleInfo::getCompileUnits()const{ /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the /// named GlobalVariable. -std::vector +void MachineModuleInfo::getGlobalVariablesUsing(Module &M, - const std::string &RootName) { - return ::getGlobalVariablesUsing(M, RootName); + const std::string &RootName, + std::vector&Result){ + return ::getGlobalVariablesUsing(M, RootName, Result); } /// RecordSourceLine - Records location information and associates it with a