2002-12-24 07:50:16 +08:00
|
|
|
//===- Miscompilation.cpp - Debug program miscompilations -----------------===//
|
2003-10-21 01:47:21 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-24 07:50:16 +08:00
|
|
|
//
|
|
|
|
// This file implements program miscompilation debugging support.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "BugDriver.h"
|
2003-04-25 04:16:29 +08:00
|
|
|
#include "ListReducer.h"
|
2002-12-24 07:50:16 +08:00
|
|
|
#include "llvm/Module.h"
|
2003-08-08 05:19:30 +08:00
|
|
|
#include "llvm/Pass.h"
|
2003-04-25 01:02:17 +08:00
|
|
|
#include "llvm/Transforms/Utils/Cloning.h"
|
|
|
|
#include "llvm/Transforms/Utils/Linker.h"
|
2003-08-08 05:42:28 +08:00
|
|
|
#include "Support/FileUtilities.h"
|
2004-01-14 11:38:37 +08:00
|
|
|
using namespace llvm;
|
2002-12-24 07:50:16 +08:00
|
|
|
|
2004-03-15 04:50:42 +08:00
|
|
|
namespace {
|
2004-01-14 11:38:37 +08:00
|
|
|
class ReduceMiscompilingPasses : public ListReducer<const PassInfo*> {
|
|
|
|
BugDriver &BD;
|
|
|
|
public:
|
|
|
|
ReduceMiscompilingPasses(BugDriver &bd) : BD(bd) {}
|
|
|
|
|
|
|
|
virtual TestResult doTest(std::vector<const PassInfo*> &Prefix,
|
|
|
|
std::vector<const PassInfo*> &Suffix);
|
|
|
|
};
|
|
|
|
}
|
2003-04-25 01:02:17 +08:00
|
|
|
|
|
|
|
ReduceMiscompilingPasses::TestResult
|
2003-04-25 06:24:22 +08:00
|
|
|
ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
|
2003-04-25 11:16:05 +08:00
|
|
|
std::vector<const PassInfo*> &Suffix) {
|
|
|
|
// First, run the program with just the Suffix passes. If it is still broken
|
2003-04-25 01:02:17 +08:00
|
|
|
// with JUST the kept passes, discard the prefix passes.
|
2003-04-25 11:16:05 +08:00
|
|
|
std::cout << "Checking to see if '" << getPassesString(Suffix)
|
2003-04-25 01:02:17 +08:00
|
|
|
<< "' compile correctly: ";
|
|
|
|
|
|
|
|
std::string BytecodeResult;
|
2003-04-25 11:16:05 +08:00
|
|
|
if (BD.runPasses(Suffix, BytecodeResult, false/*delete*/, true/*quiet*/)) {
|
2003-10-18 08:05:05 +08:00
|
|
|
std::cerr << " Error running this sequence of passes"
|
2003-04-25 01:02:17 +08:00
|
|
|
<< " on the input program!\n";
|
2003-10-18 07:07:47 +08:00
|
|
|
BD.setPassesToRun(Suffix);
|
|
|
|
BD.EmitProgressBytecode("pass-error", false);
|
2004-02-19 05:02:04 +08:00
|
|
|
exit(BD.debugOptimizerCrash());
|
2003-04-25 01:02:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if the finished program matches the reference output...
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-25 02:17:43 +08:00
|
|
|
if (BD.diffProgram(BytecodeResult, "", true /*delete bytecode*/)) {
|
2003-04-25 01:02:17 +08:00
|
|
|
std::cout << "nope.\n";
|
|
|
|
return KeepSuffix; // Miscompilation detected!
|
|
|
|
}
|
|
|
|
std::cout << "yup.\n"; // No miscompilation!
|
|
|
|
|
|
|
|
if (Prefix.empty()) return NoFailure;
|
|
|
|
|
2003-04-25 11:16:05 +08:00
|
|
|
// Next, see if the program is broken if we run the "prefix" passes first,
|
2003-07-15 01:20:40 +08:00
|
|
|
// then separately run the "kept" passes.
|
2003-04-25 01:02:17 +08:00
|
|
|
std::cout << "Checking to see if '" << getPassesString(Prefix)
|
|
|
|
<< "' compile correctly: ";
|
|
|
|
|
|
|
|
// If it is not broken with the kept passes, it's possible that the prefix
|
|
|
|
// passes must be run before the kept passes to break it. If the program
|
|
|
|
// WORKS after the prefix passes, but then fails if running the prefix AND
|
|
|
|
// kept passes, we can update our bytecode file to include the result of the
|
|
|
|
// prefix passes, then discard the prefix passes.
|
|
|
|
//
|
|
|
|
if (BD.runPasses(Prefix, BytecodeResult, false/*delete*/, true/*quiet*/)) {
|
2003-10-18 08:05:05 +08:00
|
|
|
std::cerr << " Error running this sequence of passes"
|
2003-04-25 01:02:17 +08:00
|
|
|
<< " on the input program!\n";
|
2003-10-18 07:03:16 +08:00
|
|
|
BD.setPassesToRun(Prefix);
|
|
|
|
BD.EmitProgressBytecode("pass-error", false);
|
2004-02-19 05:02:04 +08:00
|
|
|
exit(BD.debugOptimizerCrash());
|
2003-04-25 01:02:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the prefix maintains the predicate by itself, only keep the prefix!
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-25 02:17:43 +08:00
|
|
|
if (BD.diffProgram(BytecodeResult)) {
|
2003-04-25 01:02:17 +08:00
|
|
|
std::cout << "nope.\n";
|
|
|
|
removeFile(BytecodeResult);
|
|
|
|
return KeepPrefix;
|
|
|
|
}
|
|
|
|
std::cout << "yup.\n"; // No miscompilation!
|
|
|
|
|
|
|
|
// Ok, so now we know that the prefix passes work, try running the suffix
|
|
|
|
// passes on the result of the prefix passes.
|
|
|
|
//
|
2004-03-15 04:50:42 +08:00
|
|
|
Module *PrefixOutput = ParseInputFile(BytecodeResult);
|
2003-04-25 01:02:17 +08:00
|
|
|
if (PrefixOutput == 0) {
|
|
|
|
std::cerr << BD.getToolName() << ": Error reading bytecode file '"
|
|
|
|
<< BytecodeResult << "'!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
removeFile(BytecodeResult); // No longer need the file on disk
|
|
|
|
|
2003-04-25 11:16:05 +08:00
|
|
|
std::cout << "Checking to see if '" << getPassesString(Suffix)
|
2003-04-25 01:02:17 +08:00
|
|
|
<< "' passes compile correctly after the '"
|
|
|
|
<< getPassesString(Prefix) << "' passes: ";
|
|
|
|
|
2004-03-15 04:50:42 +08:00
|
|
|
Module *OriginalInput = BD.swapProgramIn(PrefixOutput);
|
2003-04-25 11:16:05 +08:00
|
|
|
if (BD.runPasses(Suffix, BytecodeResult, false/*delete*/, true/*quiet*/)) {
|
2003-10-18 08:05:05 +08:00
|
|
|
std::cerr << " Error running this sequence of passes"
|
2003-04-25 01:02:17 +08:00
|
|
|
<< " on the input program!\n";
|
2003-10-18 07:07:47 +08:00
|
|
|
BD.setPassesToRun(Suffix);
|
2003-10-18 07:03:16 +08:00
|
|
|
BD.EmitProgressBytecode("pass-error", false);
|
2004-02-19 05:02:04 +08:00
|
|
|
exit(BD.debugOptimizerCrash());
|
2003-04-25 01:02:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the result...
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-25 02:17:43 +08:00
|
|
|
if (BD.diffProgram(BytecodeResult, "", true/*delete bytecode*/)) {
|
2003-04-25 01:02:17 +08:00
|
|
|
std::cout << "nope.\n";
|
|
|
|
delete OriginalInput; // We pruned down the original input...
|
2003-04-25 11:16:05 +08:00
|
|
|
return KeepSuffix;
|
2003-04-25 01:02:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we must not be running the bad pass anymore.
|
|
|
|
std::cout << "yup.\n"; // No miscompilation!
|
2004-03-15 04:50:42 +08:00
|
|
|
delete BD.swapProgramIn(OriginalInput); // Restore orig program & free test
|
2003-04-25 01:02:17 +08:00
|
|
|
return NoFailure;
|
|
|
|
}
|
|
|
|
|
2004-03-15 04:50:42 +08:00
|
|
|
namespace {
|
2004-01-14 11:38:37 +08:00
|
|
|
class ReduceMiscompilingFunctions : public ListReducer<Function*> {
|
|
|
|
BugDriver &BD;
|
|
|
|
public:
|
|
|
|
ReduceMiscompilingFunctions(BugDriver &bd) : BD(bd) {}
|
|
|
|
|
|
|
|
virtual TestResult doTest(std::vector<Function*> &Prefix,
|
|
|
|
std::vector<Function*> &Suffix) {
|
2004-03-15 03:27:19 +08:00
|
|
|
if (!Suffix.empty() && TestFuncs(Suffix))
|
2004-01-14 11:38:37 +08:00
|
|
|
return KeepSuffix;
|
2004-03-15 03:27:19 +08:00
|
|
|
if (!Prefix.empty() && TestFuncs(Prefix))
|
2004-01-14 11:38:37 +08:00
|
|
|
return KeepPrefix;
|
|
|
|
return NoFailure;
|
|
|
|
}
|
|
|
|
|
2004-03-15 03:27:19 +08:00
|
|
|
bool TestFuncs(const std::vector<Function*> &Prefix);
|
2004-01-14 11:38:37 +08:00
|
|
|
};
|
|
|
|
}
|
2003-04-25 01:02:17 +08:00
|
|
|
|
2004-03-15 04:50:42 +08:00
|
|
|
/// TestMergedProgram - Given two modules, link them together and run the
|
|
|
|
/// program, checking to see if the program matches the diff. If the diff
|
2004-03-15 06:08:00 +08:00
|
|
|
/// matches, return false, otherwise return true. If the DeleteInputs argument
|
|
|
|
/// is set to true then this function deletes both input modules before it
|
|
|
|
/// returns.
|
|
|
|
static bool TestMergedProgram(BugDriver &BD, Module *M1, Module *M2,
|
|
|
|
bool DeleteInputs) {
|
2004-03-15 04:50:42 +08:00
|
|
|
// Link the two portions of the program back to together.
|
|
|
|
std::string ErrorMsg;
|
2004-03-15 06:08:00 +08:00
|
|
|
if (!DeleteInputs) M1 = CloneModule(M1);
|
2004-03-15 04:50:42 +08:00
|
|
|
if (LinkModules(M1, M2, &ErrorMsg)) {
|
|
|
|
std::cerr << BD.getToolName() << ": Error linking modules together:"
|
|
|
|
<< ErrorMsg << "\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-03-15 06:08:00 +08:00
|
|
|
if (DeleteInputs) delete M2; // We are done with this module...
|
2004-03-15 04:50:42 +08:00
|
|
|
|
|
|
|
Module *OldProgram = BD.swapProgramIn(M1);
|
|
|
|
|
|
|
|
// Execute the program. If it does not match the expected output, we must
|
|
|
|
// return true.
|
|
|
|
bool Broken = BD.diffProgram();
|
|
|
|
|
|
|
|
// Delete the linked module & restore the original
|
2004-03-15 06:08:00 +08:00
|
|
|
BD.swapProgramIn(OldProgram);
|
|
|
|
if (DeleteInputs) delete M1;
|
2004-03-15 04:50:42 +08:00
|
|
|
return Broken;
|
|
|
|
}
|
|
|
|
|
2004-03-15 03:27:19 +08:00
|
|
|
bool ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function*>&Funcs){
|
2003-04-25 01:02:17 +08:00
|
|
|
// Test to see if the function is misoptimized if we ONLY run it on the
|
|
|
|
// functions listed in Funcs.
|
2004-03-15 03:27:19 +08:00
|
|
|
std::cout << "Checking to see if the program is misoptimized when "
|
|
|
|
<< (Funcs.size()==1 ? "this function is" : "these functions are")
|
|
|
|
<< " run through the pass"
|
2004-03-15 06:08:00 +08:00
|
|
|
<< (BD.getPassesToRun().size() == 1 ? "" : "es") << ":";
|
2004-03-15 04:50:42 +08:00
|
|
|
PrintFunctionList(Funcs);
|
2004-03-15 03:27:19 +08:00
|
|
|
std::cout << "\n";
|
2003-04-25 01:02:17 +08:00
|
|
|
|
2004-03-15 03:27:19 +08:00
|
|
|
// Split the module into the two halves of the program we want.
|
2004-03-15 04:50:42 +08:00
|
|
|
Module *ToNotOptimize = CloneModule(BD.getProgram());
|
|
|
|
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, Funcs);
|
2003-04-25 01:02:17 +08:00
|
|
|
|
2004-03-15 03:27:19 +08:00
|
|
|
// Run the optimization passes on ToOptimize, producing a transformed version
|
|
|
|
// of the functions being tested.
|
|
|
|
std::cout << " Optimizing functions being tested: ";
|
2004-03-15 06:08:00 +08:00
|
|
|
Module *Optimized = BD.runPassesOn(ToOptimize, BD.getPassesToRun(),
|
|
|
|
/*AutoDebugCrashes*/true);
|
2004-03-15 03:27:19 +08:00
|
|
|
std::cout << "done.\n";
|
2004-03-15 06:08:00 +08:00
|
|
|
delete ToOptimize;
|
2003-04-25 01:02:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
std::cout << " Checking to see if the merged program executes correctly: ";
|
2004-03-15 06:08:00 +08:00
|
|
|
bool Broken = TestMergedProgram(BD, Optimized, ToNotOptimize, true);
|
2003-12-07 10:43:09 +08:00
|
|
|
std::cout << (Broken ? " nope.\n" : " yup.\n");
|
2003-04-25 01:02:17 +08:00
|
|
|
return Broken;
|
|
|
|
}
|
|
|
|
|
2004-03-15 06:08:00 +08:00
|
|
|
/// ExtractLoops - Given a reduced list of functions that still exposed the bug,
|
|
|
|
/// check to see if we can extract the loops in the region without obscuring the
|
|
|
|
/// bug. If so, it reduces the amount of code identified.
|
|
|
|
static bool ExtractLoops(BugDriver &BD,
|
|
|
|
std::vector<Function*> &MiscompiledFunctions) {
|
|
|
|
bool MadeChange = false;
|
|
|
|
while (1) {
|
|
|
|
Module *ToNotOptimize = CloneModule(BD.getProgram());
|
|
|
|
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
|
|
|
|
MiscompiledFunctions);
|
|
|
|
Module *ToOptimizeLoopExtracted = BD.ExtractLoop(ToOptimize);
|
|
|
|
if (!ToOptimizeLoopExtracted) {
|
|
|
|
// If the loop extractor crashed or if there were no extractible loops,
|
|
|
|
// then this chapter of our odyssey is over with.
|
|
|
|
delete ToNotOptimize;
|
|
|
|
delete ToOptimize;
|
|
|
|
return MadeChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "Extracted a loop from the breaking portion of the program.\n";
|
|
|
|
delete ToOptimize;
|
|
|
|
|
|
|
|
// Bugpoint is intentionally not very trusting of LLVM transformations. In
|
|
|
|
// particular, we're not going to assume that the loop extractor works, so
|
|
|
|
// we're going to test the newly loop extracted program to make sure nothing
|
|
|
|
// has broken. If something broke, then we'll inform the user and stop
|
|
|
|
// extraction.
|
|
|
|
if (TestMergedProgram(BD, ToOptimizeLoopExtracted, ToNotOptimize, false)) {
|
|
|
|
// Merged program doesn't work anymore!
|
|
|
|
std::cerr << " *** ERROR: Loop extraction broke the program. :("
|
|
|
|
<< " Please report a bug!\n";
|
|
|
|
std::cerr << " Continuing on with un-loop-extracted version.\n";
|
|
|
|
delete ToNotOptimize;
|
|
|
|
delete ToOptimizeLoopExtracted;
|
|
|
|
return MadeChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay, the loop extractor didn't break the program. Run the series of
|
|
|
|
// optimizations on the loop extracted portion and see if THEY still break
|
|
|
|
// the program. If so, it was safe to extract these loops!
|
|
|
|
std::cout << " Running optimizations on loop extracted portion: ";
|
|
|
|
Module *Optimized = BD.runPassesOn(ToOptimizeLoopExtracted,
|
|
|
|
BD.getPassesToRun(),
|
|
|
|
/*AutoDebugCrashes*/true);
|
|
|
|
std::cout << "done.\n";
|
|
|
|
|
|
|
|
std::cout << " Checking to see if the merged program executes correctly: ";
|
2004-03-16 09:51:54 +08:00
|
|
|
bool Broken = TestMergedProgram(BD, Optimized, ToNotOptimize, false);
|
2004-03-15 06:08:00 +08:00
|
|
|
delete Optimized;
|
|
|
|
if (!Broken) {
|
|
|
|
std::cout << "yup: loop extraction masked the problem. Undoing.\n";
|
|
|
|
// If the program is not still broken, then loop extraction did something
|
|
|
|
// that masked the error. Stop loop extraction now.
|
|
|
|
delete ToNotOptimize;
|
|
|
|
delete ToOptimizeLoopExtracted;
|
|
|
|
return MadeChange;
|
|
|
|
}
|
|
|
|
std::cout << "nope: loop extraction successful!\n";
|
|
|
|
|
|
|
|
// Okay, great! Now we know that we extracted a loop and that loop
|
|
|
|
// extraction both didn't break the program, and didn't mask the problem.
|
|
|
|
// Replace the current program with the loop extracted version, and try to
|
|
|
|
// extract another loop.
|
|
|
|
std::string ErrorMsg;
|
|
|
|
if (LinkModules(ToNotOptimize, ToOptimizeLoopExtracted, &ErrorMsg)) {
|
|
|
|
std::cerr << BD.getToolName() << ": Error linking modules together:"
|
|
|
|
<< ErrorMsg << "\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
delete ToOptimizeLoopExtracted;
|
2004-03-18 01:42:09 +08:00
|
|
|
|
|
|
|
// All of the Function*'s in the MiscompiledFunctions list are in the old
|
|
|
|
// module. Make sure to update them to point to the corresponding functions
|
|
|
|
// in the new module.
|
|
|
|
for (unsigned i = 0, e = MiscompiledFunctions.size(); i != e; ++i) {
|
|
|
|
Function *OldF = MiscompiledFunctions[i];
|
|
|
|
Function *NewF =
|
|
|
|
ToNotOptimize->getFunction(OldF->getName(), OldF->getFunctionType());
|
|
|
|
MiscompiledFunctions[i] = NewF;
|
|
|
|
}
|
|
|
|
|
2004-03-15 06:08:00 +08:00
|
|
|
BD.setNewProgram(ToNotOptimize);
|
|
|
|
MadeChange = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-24 07:50:16 +08:00
|
|
|
/// debugMiscompilation - This method is used when the passes selected are not
|
|
|
|
/// crashing, but the generated output is semantically different from the
|
|
|
|
/// input.
|
|
|
|
///
|
|
|
|
bool BugDriver::debugMiscompilation() {
|
|
|
|
// Make sure something was miscompiled...
|
2003-07-31 04:15:56 +08:00
|
|
|
if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) {
|
2002-12-24 07:50:16 +08:00
|
|
|
std::cerr << "*** Optimized program matches reference output! No problem "
|
|
|
|
<< "detected...\nbugpoint can't help you with your problem!\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-04-25 01:02:17 +08:00
|
|
|
std::cout << "\n*** Found miscompiling pass"
|
2004-03-15 04:50:42 +08:00
|
|
|
<< (getPassesToRun().size() == 1 ? "" : "es") << ": "
|
|
|
|
<< getPassesString(getPassesToRun()) << "\n";
|
2003-04-25 01:02:17 +08:00
|
|
|
EmitProgressBytecode("passinput");
|
2002-12-24 07:50:16 +08:00
|
|
|
|
2003-04-25 01:02:17 +08:00
|
|
|
// Okay, now that we have reduced the list of passes which are causing the
|
|
|
|
// failure, see if we can pin down which functions are being
|
|
|
|
// miscompiled... first build a list of all of the non-external functions in
|
|
|
|
// the program.
|
|
|
|
std::vector<Function*> MiscompiledFunctions;
|
|
|
|
for (Module::iterator I = Program->begin(), E = Program->end(); I != E; ++I)
|
|
|
|
if (!I->isExternal())
|
|
|
|
MiscompiledFunctions.push_back(I);
|
2002-12-24 07:50:16 +08:00
|
|
|
|
2003-04-25 01:02:17 +08:00
|
|
|
// Do the reduction...
|
|
|
|
ReduceMiscompilingFunctions(*this).reduceList(MiscompiledFunctions);
|
|
|
|
|
2003-12-07 10:43:09 +08:00
|
|
|
std::cout << "\n*** The following function"
|
|
|
|
<< (MiscompiledFunctions.size() == 1 ? " is" : "s are")
|
|
|
|
<< " being miscompiled: ";
|
2003-04-25 01:02:17 +08:00
|
|
|
PrintFunctionList(MiscompiledFunctions);
|
|
|
|
std::cout << "\n";
|
2002-12-24 07:50:16 +08:00
|
|
|
|
2004-03-15 06:08:00 +08:00
|
|
|
// See if we can rip any loops out of the miscompiled functions and still
|
|
|
|
// trigger the problem.
|
|
|
|
if (ExtractLoops(*this, MiscompiledFunctions)) {
|
|
|
|
// Okay, we extracted some loops and the problem still appears. See if we
|
|
|
|
// can eliminate some of the created functions from being candidates.
|
|
|
|
|
|
|
|
// Do the reduction...
|
|
|
|
ReduceMiscompilingFunctions(*this).reduceList(MiscompiledFunctions);
|
|
|
|
|
|
|
|
std::cout << "\n*** The following function"
|
|
|
|
<< (MiscompiledFunctions.size() == 1 ? " is" : "s are")
|
|
|
|
<< " being miscompiled: ";
|
|
|
|
PrintFunctionList(MiscompiledFunctions);
|
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
|
2003-04-25 01:02:17 +08:00
|
|
|
// Output a bunch of bytecode files for the user...
|
2004-03-15 03:27:19 +08:00
|
|
|
std::cout << "Outputting reduced bytecode files which expose the problem:\n";
|
2004-03-15 04:50:42 +08:00
|
|
|
Module *ToNotOptimize = CloneModule(getProgram());
|
|
|
|
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
|
|
|
|
MiscompiledFunctions);
|
2004-03-15 03:27:19 +08:00
|
|
|
|
|
|
|
std::cout << " Non-optimized portion: ";
|
|
|
|
std::swap(Program, ToNotOptimize);
|
|
|
|
EmitProgressBytecode("tonotoptimize", true);
|
|
|
|
setNewProgram(ToNotOptimize); // Delete hacked module.
|
|
|
|
|
|
|
|
std::cout << " Portion that is input to optimizer: ";
|
|
|
|
std::swap(Program, ToOptimize);
|
|
|
|
EmitProgressBytecode("tooptimize");
|
|
|
|
setNewProgram(ToOptimize); // Delete hacked module.
|
2002-12-24 07:50:16 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2003-11-12 06:41:34 +08:00
|
|
|
|