From a4d71f09ffdaee54e0728dac39f86113148197a3 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sat, 16 Jun 2007 20:48:27 +0000 Subject: Fix PR1517: Use SmallPtrSet instead of std::vector to eliminate duplicate uses in a function generated with -gen-function. This prevents the output from having multiple duplicate declarations of constants and gvals. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37616 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm2cpp/CppWriter.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'tools/llvm2cpp/CppWriter.cpp') diff --git a/tools/llvm2cpp/CppWriter.cpp b/tools/llvm2cpp/CppWriter.cpp index a5aa7d46e3..8e30c7990d 100644 --- a/tools/llvm2cpp/CppWriter.cpp +++ b/tools/llvm2cpp/CppWriter.cpp @@ -23,6 +23,7 @@ #include "llvm/TypeSymbolTable.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/CFG.h" #include "llvm/Support/ManagedStatic.h" @@ -1423,8 +1424,8 @@ void CppWriter::printFunctionUses(const Function* F) { // Print type definitions for every type referenced by an instruction and // make a note of any global values or constants that are referenced - std::vector gvs; - std::vector consts; + SmallPtrSet gvs; + SmallPtrSet consts; for (Function::const_iterator BB = F->begin(), BE = F->end(); BB != BE; ++BB){ for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) { @@ -1438,19 +1439,19 @@ void CppWriter::printFunctionUses(const Function* F) { // If the operand references a GVal or Constant, make a note of it if (GlobalValue* GV = dyn_cast(operand)) { - gvs.push_back(GV); + gvs.insert(GV); if (GlobalVariable *GVar = dyn_cast(GV)) if (GVar->hasInitializer()) - consts.push_back(GVar->getInitializer()); + consts.insert(GVar->getInitializer()); } else if (Constant* C = dyn_cast(operand)) - consts.push_back(C); + consts.insert(C); } } } // Print the function declarations for any functions encountered nl(Out) << "// Function Declarations"; nl(Out); - for (std::vector::iterator I = gvs.begin(), E = gvs.end(); + for (SmallPtrSet::iterator I = gvs.begin(), E = gvs.end(); I != E; ++I) { if (Function* Fun = dyn_cast(*I)) { if (!is_inline || Fun != F) @@ -1460,7 +1461,7 @@ void CppWriter::printFunctionUses(const Function* F) { // Print the global variable declarations for any variables encountered nl(Out) << "// Global Variable Declarations"; nl(Out); - for (std::vector::iterator I = gvs.begin(), E = gvs.end(); + for (SmallPtrSet::iterator I = gvs.begin(), E = gvs.end(); I != E; ++I) { if (GlobalVariable* F = dyn_cast(*I)) printVariableHead(F); @@ -1468,7 +1469,7 @@ void CppWriter::printFunctionUses(const Function* F) { // Print the constants found nl(Out) << "// Constant Definitions"; nl(Out); - for (std::vector::iterator I = consts.begin(), E = consts.end(); + for (SmallPtrSet::iterator I = consts.begin(), E = consts.end(); I != E; ++I) { printConstant(*I); } @@ -1477,7 +1478,7 @@ void CppWriter::printFunctionUses(const Function* F) { // been emitted. These definitions just couple the gvars with their constant // initializers. nl(Out) << "// Global Variable Definitions"; nl(Out); - for (std::vector::iterator I = gvs.begin(), E = gvs.end(); + for (SmallPtrSet::iterator I = gvs.begin(), E = gvs.end(); I != E; ++I) { if (GlobalVariable* GV = dyn_cast(*I)) printVariableBody(GV); -- cgit v1.2.3-18-g5258