[llvm-commits] CVS: llvm/tools/llvm2cpp/CppWriter.cpp
Reid Spencer
reid at x10sys.com
Sat Jun 16 13:48:49 PDT 2007
Changes in directory llvm/tools/llvm2cpp:
CppWriter.cpp updated: 1.51 -> 1.52
---
Log message:
Fix PR1517: http://llvm.org/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.
---
Diffs of the changes: (+10 -9)
CppWriter.cpp | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
Index: llvm/tools/llvm2cpp/CppWriter.cpp
diff -u llvm/tools/llvm2cpp/CppWriter.cpp:1.51 llvm/tools/llvm2cpp/CppWriter.cpp:1.52
--- llvm/tools/llvm2cpp/CppWriter.cpp:1.51 Sat Jun 16 15:33:24 2007
+++ llvm/tools/llvm2cpp/CppWriter.cpp Sat Jun 16 15:48:27 2007
@@ -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 @@
// 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<GlobalValue*> gvs;
- std::vector<Constant*> consts;
+ SmallPtrSet<GlobalValue*,64> gvs;
+ SmallPtrSet<Constant*,64> 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 @@
// If the operand references a GVal or Constant, make a note of it
if (GlobalValue* GV = dyn_cast<GlobalValue>(operand)) {
- gvs.push_back(GV);
+ gvs.insert(GV);
if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
if (GVar->hasInitializer())
- consts.push_back(GVar->getInitializer());
+ consts.insert(GVar->getInitializer());
} else if (Constant* C = dyn_cast<Constant>(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<GlobalValue*>::iterator I = gvs.begin(), E = gvs.end();
+ for (SmallPtrSet<GlobalValue*,64>::iterator I = gvs.begin(), E = gvs.end();
I != E; ++I) {
if (Function* Fun = dyn_cast<Function>(*I)) {
if (!is_inline || Fun != F)
@@ -1460,7 +1461,7 @@
// Print the global variable declarations for any variables encountered
nl(Out) << "// Global Variable Declarations"; nl(Out);
- for (std::vector<GlobalValue*>::iterator I = gvs.begin(), E = gvs.end();
+ for (SmallPtrSet<GlobalValue*,64>::iterator I = gvs.begin(), E = gvs.end();
I != E; ++I) {
if (GlobalVariable* F = dyn_cast<GlobalVariable>(*I))
printVariableHead(F);
@@ -1468,7 +1469,7 @@
// Print the constants found
nl(Out) << "// Constant Definitions"; nl(Out);
- for (std::vector<Constant*>::iterator I = consts.begin(), E = consts.end();
+ for (SmallPtrSet<Constant*,64>::iterator I = consts.begin(), E = consts.end();
I != E; ++I) {
printConstant(*I);
}
@@ -1477,7 +1478,7 @@
// been emitted. These definitions just couple the gvars with their constant
// initializers.
nl(Out) << "// Global Variable Definitions"; nl(Out);
- for (std::vector<GlobalValue*>::iterator I = gvs.begin(), E = gvs.end();
+ for (SmallPtrSet<GlobalValue*,64>::iterator I = gvs.begin(), E = gvs.end();
I != E; ++I) {
if (GlobalVariable* GV = dyn_cast<GlobalVariable>(*I))
printVariableBody(GV);
More information about the llvm-commits
mailing list