summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-06-16 20:48:27 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-06-16 20:48:27 +0000
commita4d71f09ffdaee54e0728dac39f86113148197a3 (patch)
tree0cb83f7d10a1f7f044dd147bb07c05b030abfc1f /tools
parentab24b4cf70b9476b81808917c9f960c52b8980bf (diff)
downloadllvm-a4d71f09ffdaee54e0728dac39f86113148197a3.tar.gz
llvm-a4d71f09ffdaee54e0728dac39f86113148197a3.tar.bz2
llvm-a4d71f09ffdaee54e0728dac39f86113148197a3.tar.xz
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
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm2cpp/CppWriter.cpp19
1 files changed, 10 insertions, 9 deletions
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<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 @@ void CppWriter::printFunctionUses(const Function* F) {
// 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 @@ 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<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 @@ void CppWriter::printFunctionUses(const Function* F) {
// 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 @@ 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<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);