summaryrefslogtreecommitdiff
path: root/tools/bugpoint/CodeGeneratorBug.cpp
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2003-07-24 21:59:10 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2003-07-24 21:59:10 +0000
commita259c9be2acc9528ec7feb3cfd51dcde36d87bb3 (patch)
tree33c64624d3bad1ab79d47720ca9e7d66f3f91332 /tools/bugpoint/CodeGeneratorBug.cpp
parent4166445b7cde22f81cd1a18b6f33fe94b94bdbb6 (diff)
downloadllvm-a259c9be2acc9528ec7feb3cfd51dcde36d87bb3.tar.gz
llvm-a259c9be2acc9528ec7feb3cfd51dcde36d87bb3.tar.bz2
llvm-a259c9be2acc9528ec7feb3cfd51dcde36d87bb3.tar.xz
Made a bunch of cleanups, as per Chris' recommendations:
* Removed unused global and member variables * Fixed comments (CodeGeneratorBug.cpp) * Check for possibly failing GCC::create() and CBE::create() * Remove generated files after diffing the output (e.g., shared object) * Instead of using std::for_each, use explicit loops as std::for_each may duplicate the functor, and ours carries state * Changed member var from cl::opt<std::string> to just std::string * Fixed doxygen comments * Fixed string comparisons to use [ str.empty() ] instead of [ str == "" ] * Cache instances of CBE and GCC in BugDriver across compilations and executions while testing tools. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7302 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/bugpoint/CodeGeneratorBug.cpp')
-rw-r--r--tools/bugpoint/CodeGeneratorBug.cpp30
1 files changed, 13 insertions, 17 deletions
diff --git a/tools/bugpoint/CodeGeneratorBug.cpp b/tools/bugpoint/CodeGeneratorBug.cpp
index 772b4fdf75..93ee24ea08 100644
--- a/tools/bugpoint/CodeGeneratorBug.cpp
+++ b/tools/bugpoint/CodeGeneratorBug.cpp
@@ -17,9 +17,6 @@
#include <algorithm>
#include <set>
-// Passed as a command-line argument to Bugpoint
-extern cl::opt<std::string> Output;
-
class ReduceMisCodegenFunctions : public ListReducer<Function*> {
BugDriver &BD;
public:
@@ -59,8 +56,7 @@ bool ReduceMisCodegenFunctions::TestFuncs(const std::vector<Function*> &Funcs)
for (Module::giterator I=TestModule->gbegin(),E = TestModule->gend();I!=E;++I)
I->setInitializer(0); // Delete the initializer to make it external
- // Remove the Test functions from the Safe module, and
- // all of the global variables.
+ // Remove the Test functions from the Safe module
for (unsigned i = 0, e = Funcs.size(); i != e; ++i) {
Function *TNOF = SafeModule->getFunction(Funcs[i]->getName(),
Funcs[i]->getFunctionType());
@@ -100,25 +96,25 @@ bool ReduceMisCodegenFunctions::TestFuncs(const std::vector<Function*> &Funcs)
// Run the code generator on the `Test' code, loading the shared library.
// The function returns whether or not the new output differs from reference.
- return BD.diffProgram(TestModuleBC, SharedObject, false);
+ int Result = BD.diffProgram(TestModuleBC, SharedObject, false);
+ removeFile(SharedObject);
+ return Result;
}
namespace {
- struct Disambiguator /*: public unary_function<GlobalValue&, void>*/ {
+ struct Disambiguator {
std::set<std::string> SymbolNames;
- std::set<Value*> Symbols;
uint64_t uniqueCounter;
bool externalOnly;
-
+ public:
Disambiguator() : uniqueCounter(0), externalOnly(true) {}
void setExternalOnly(bool value) { externalOnly = value; }
- void operator() (GlobalValue &V) {
+ void add(GlobalValue &V) {
if (externalOnly && !V.isExternal()) return;
if (SymbolNames.count(V.getName()) == 0) {
DEBUG(std::cerr << "Disambiguator: adding " << V.getName()
<< ", no conflicts.\n");
- Symbols.insert(&V);
SymbolNames.insert(V.getName());
} else {
// Mangle name before adding
@@ -133,7 +129,6 @@ namespace {
<< ", adding: " << newName << "\n");
V.setName(newName);
SymbolNames.insert(newName);
- Symbols.insert(&V);
}
}
};
@@ -142,14 +137,15 @@ namespace {
void ReduceMisCodegenFunctions::DisambiguateGlobalSymbols(Module *M) {
// First, try not to cause collisions by minimizing chances of renaming an
// already-external symbol, so take in external globals and functions as-is.
- Disambiguator D = std::for_each(M->gbegin(), M->gend(), Disambiguator());
- std::for_each(M->begin(), M->end(), D);
+ Disambiguator D;
+ for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) D.add(*I);
+ for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) D.add(*I);
// Now just rename functions and globals as necessary, keeping what's already
// in the set unique.
D.setExternalOnly(false);
- std::for_each(M->gbegin(), M->gend(), D);
- std::for_each(M->begin(), M->end(), D);
+ for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) D.add(*I);
+ for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) D.add(*I);
}
@@ -169,7 +165,7 @@ bool BugDriver::debugCodeGenerator() {
std::cout << "\n";
// Output a bunch of bytecode files for the user...
- ReduceMisCodegenFunctions(*this).TestFuncs(MisCodegenFunctions);
+ // ReduceMisCodegenFunctions(*this).TestFuncs(MisCodegenFunctions);
return false;
}