//===----------------------------------------------------------------------===//
#include "BugDriver.h"
-#include "SystemUtils.h"
#include "ListReducer.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/Linker.h"
#include "Support/CommandLine.h"
-#include "Support/Statistic.h"
+#include "Support/Debug.h"
#include "Support/StringExtras.h"
+#include "Support/FileUtilities.h"
#include <algorithm>
#include <set>
}
}
+ if (verifyModule(*SafeModule) || verifyModule(*TestModule)) {
+ std::cerr << "Bugpoint has a bug, an corrupted a module!!\n";
+ abort();
+ }
+
DEBUG(std::cerr << "Safe module:\n";
typedef Module::iterator MI;
typedef Module::giterator MGI;
// Write out the bytecode to be sent to CBE
std::string SafeModuleBC = getUniqueFilename("bugpoint.safe.bc");
- if (verifyModule(*SafeModule)) {
- std::cerr << "Bytecode file corrupted!\n";
- exit(1);
- }
+
if (BD.writeProgramToFile(SafeModuleBC, SafeModule)) {
std::cerr << "Error writing bytecode to `" << SafeModuleBC << "'\nExiting.";
exit(1);
}
- // Make a shared library
- std::string SharedObject;
- BD.compileSharedObject(SafeModuleBC, SharedObject);
-
// Remove all functions from the Test module EXCEPT for the ones specified in
// Funcs. We know which ones these are because they are non-external in
// ToOptimize, but external in ToNotOptimize.
std::cerr << "Bytecode file corrupted!\n";
exit(1);
}
+
+ // Clean up the modules, removing extra cruft that we don't need anymore...
+ SafeModule = BD.performFinalCleanups(SafeModule);
+ TestModule = BD.performFinalCleanups(TestModule);
+
if (BD.writeProgramToFile(TestModuleBC, TestModule)) {
std::cerr << "Error writing bytecode to `" << SafeModuleBC << "'\nExiting.";
exit(1);
}
+ // Make a shared library
+ std::string SharedObject = compileSharedObject(SafeModuleBC);
+
delete SafeModule;
delete TestModule;
// Run the code generator on the `Test' code, loading the shared library.
// The function returns whether or not the new output differs from reference.
- int Result = BD.diffProgram(TestModuleBC, SharedObject, false);
+ int Result = BD.diffProgram(TestModuleBC, SharedObject, false);
+
+ if (Result)
+ std::cerr << ": still failing!\n";
+ else
+ std::cerr << ": didn't fail.\n";
+
if (KeepFiles) {
- std::cout << "You can reproduce the problem with the command line: \n"
- << (BD.isExecutingJIT() ? "lli" : "llc")
- << " -load " << SharedObject << " " << TestModuleBC;
+ std::cout << "You can reproduce the problem with the command line: \n";
+ if (BD.isExecutingJIT()) {
+ std::cout << " lli -load " << SharedObject << " " << TestModuleBC;
+ } else {
+ std::cout << " llc " << TestModuleBC << " -o " << TestModuleBC << ".s\n";
+ std::cout << " gcc " << SharedObject << " " << TestModuleBC
+ << ".s -o " << TestModuleBC << ".exe\n";
+ std::cout << " " << TestModuleBC << ".exe";
+ }
for (unsigned i=0, e = InputArgv.size(); i != e; ++i)
std::cout << " " << InputArgv[i];
std::cout << "\n";
- std::cout << "The shared object " << SharedObject << " was created from "
- << SafeModuleBC << ", using `dis -c'.\n";
+ std::cout << "The shared object was created with:\n llvm-dis -c "
+ << SafeModuleBC << " -o temporary.c\n"
+ << " gcc -xc temporary.c -O2 -o " << SharedObject
+#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
+ << " -G" // Compile a shared library, `-G' for Sparc
+#else
+ << " -shared" // `-shared' for Linux/X86, maybe others
+#endif
+ << "\n";
} else {
removeFile(TestModuleBC);
removeFile(SafeModuleBC);
Function *oldMain = Program->getNamedFunction("main");
assert(oldMain && "`main' function not found in program!");
// Rename it
- oldMain->setName("old_main");
+ oldMain->setName("llvm_old_main");
// Create a NEW `main' function with same type
Function *newMain = new Function(oldMain->getFunctionType(),
GlobalValue::ExternalLinkage,
// Call the old main function and return its result
BasicBlock *BB = new BasicBlock("entry", newMain);
std::vector<Value*> args;
- for (Function::aiterator I=newMain->abegin(), E=newMain->aend(); I!=E; ++I)
+ for (Function::aiterator I = newMain->abegin(), E = newMain->aend(),
+ OI = oldMain->abegin(); I != E; ++I, ++OI) {
+ I->setName(OI->getName()); // Copy argument names from oldMain
args.push_back(I);
+ }
CallInst *call = new CallInst(oldMain, args);
BB->getInstList().push_back(call);
// Do the reduction...
if (!ReduceMisCodegenFunctions(*this).reduceList(MisCodegenFunctions)) {
- std::cerr << "*** Execution matches reference output! No problem "
- << "detected...\nbugpoint can't help you with your problem!\n";
+ std::cerr << "*** Execution matches reference output! "
+ << "bugpoint can't help you with your problem!\n";
return false;
}