mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-02 08:46:37 +00:00
74382b7c69
forcing them down into various .cpp files. This change also: 1. Renames TimeValue::toString() and Path::toString() to ::str() for similarity with the STL. 2. Removes all stream insertion support for sys::Path, forcing clients to call .str(). 3. Removes a use of Config/alloca.h from bugpoint, using smallvector instead. 4. Weans llvm-db off <iostream> sys::Path really needs to be gutted, but I don't have the desire to do it at this point. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79869 91177308-0d34-0410-b5e6-96231b3b80d8
113 lines
3.5 KiB
C++
113 lines
3.5 KiB
C++
//===-- FindBugs.cpp - Run Many Different Optimizations -------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines an interface that allows bugpoint to choose different
|
|
// combinations of optimizations to run on the selected input. Bugpoint will
|
|
// run these optimizations and record the success/failure of each. This way
|
|
// we can hopefully spot bugs in the optimizations.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "BugDriver.h"
|
|
#include "ToolRunner.h"
|
|
#include "llvm/Pass.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
#include <algorithm>
|
|
#include <ctime>
|
|
using namespace llvm;
|
|
|
|
/// runManyPasses - Take the specified pass list and create different
|
|
/// combinations of passes to compile the program with. Compile the program with
|
|
/// each set and mark test to see if it compiled correctly. If the passes
|
|
/// compiled correctly output nothing and rearrange the passes into a new order.
|
|
/// If the passes did not compile correctly, output the command required to
|
|
/// recreate the failure. This returns true if a compiler error is found.
|
|
///
|
|
bool BugDriver::runManyPasses(const std::vector<const PassInfo*> &AllPasses) {
|
|
setPassesToRun(AllPasses);
|
|
outs() << "Starting bug finding procedure...\n\n";
|
|
|
|
// Creating a reference output if necessary
|
|
if (initializeExecutionEnvironment()) return false;
|
|
|
|
outs() << "\n";
|
|
if (ReferenceOutputFile.empty()) {
|
|
outs() << "Generating reference output from raw program: \n";
|
|
if (!createReferenceFile(Program))
|
|
return false;
|
|
}
|
|
|
|
srand(time(NULL));
|
|
|
|
unsigned num = 1;
|
|
while(1) {
|
|
//
|
|
// Step 1: Randomize the order of the optimizer passes.
|
|
//
|
|
std::random_shuffle(PassesToRun.begin(), PassesToRun.end());
|
|
|
|
//
|
|
// Step 2: Run optimizer passes on the program and check for success.
|
|
//
|
|
outs() << "Running selected passes on program to test for crash: ";
|
|
for(int i = 0, e = PassesToRun.size(); i != e; i++) {
|
|
outs() << "-" << PassesToRun[i]->getPassArgument( )<< " ";
|
|
}
|
|
|
|
std::string Filename;
|
|
if(runPasses(PassesToRun, Filename, false)) {
|
|
outs() << "\n";
|
|
outs() << "Optimizer passes caused failure!\n\n";
|
|
debugOptimizerCrash();
|
|
return true;
|
|
} else {
|
|
outs() << "Combination " << num << " optimized successfully!\n";
|
|
}
|
|
|
|
//
|
|
// Step 3: Compile the optimized code.
|
|
//
|
|
outs() << "Running the code generator to test for a crash: ";
|
|
try {
|
|
compileProgram(Program);
|
|
outs() << '\n';
|
|
} catch (ToolExecutionError &TEE) {
|
|
outs() << "\n*** compileProgram threw an exception: ";
|
|
outs() << TEE.what();
|
|
return debugCodeGeneratorCrash();
|
|
}
|
|
|
|
//
|
|
// Step 4: Run the program and compare its output to the reference
|
|
// output (created above).
|
|
//
|
|
outs() << "*** Checking if passes caused miscompliation:\n";
|
|
try {
|
|
if (diffProgram(Filename, "", false)) {
|
|
outs() << "\n*** diffProgram returned true!\n";
|
|
debugMiscompilation();
|
|
return true;
|
|
} else {
|
|
outs() << "\n*** diff'd output matches!\n";
|
|
}
|
|
} catch (ToolExecutionError &TEE) {
|
|
errs() << TEE.what();
|
|
debugCodeGeneratorCrash();
|
|
return true;
|
|
}
|
|
|
|
sys::Path(Filename).eraseFromDisk();
|
|
|
|
outs() << "\n\n";
|
|
num++;
|
|
} //end while
|
|
|
|
// Unreachable.
|
|
}
|