X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fbugpoint%2FMiscompilation.cpp;h=98e299d76d82ddce5d5677e024ddf90ddf2ab21d;hb=0ad91703274b57f98a08baa545712b64c4b89987;hp=5ec8b1543e36ac8cec8974c3c72990bc58b468ea;hpb=943211187d72eb27d4f54de9ac7e5786e72b38e1;p=oota-llvm.git diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index 5ec8b1543e3..98e299d76d8 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -18,15 +18,19 @@ #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/Linker.h" #include "Support/FileUtilities.h" +using namespace llvm; -class ReduceMiscompilingPasses : public ListReducer { - BugDriver &BD; -public: - ReduceMiscompilingPasses(BugDriver &bd) : BD(bd) {} +namespace llvm { - virtual TestResult doTest(std::vector &Prefix, - std::vector &Suffix); -}; + class ReduceMiscompilingPasses : public ListReducer { + BugDriver &BD; + public: + ReduceMiscompilingPasses(BugDriver &bd) : BD(bd) {} + + virtual TestResult doTest(std::vector &Prefix, + std::vector &Suffix); + }; +} ReduceMiscompilingPasses::TestResult ReduceMiscompilingPasses::doTest(std::vector &Prefix, @@ -42,7 +46,7 @@ ReduceMiscompilingPasses::doTest(std::vector &Prefix, << " on the input program!\n"; BD.setPassesToRun(Suffix); BD.EmitProgressBytecode("pass-error", false); - exit(BD.debugCrash()); + exit(BD.debugOptimizerCrash()); } // Check to see if the finished program matches the reference output... @@ -70,7 +74,7 @@ ReduceMiscompilingPasses::doTest(std::vector &Prefix, << " on the input program!\n"; BD.setPassesToRun(Prefix); BD.EmitProgressBytecode("pass-error", false); - exit(BD.debugCrash()); + exit(BD.debugOptimizerCrash()); } // If the prefix maintains the predicate by itself, only keep the prefix! @@ -103,7 +107,7 @@ ReduceMiscompilingPasses::doTest(std::vector &Prefix, << " on the input program!\n"; BD.setPassesToRun(Suffix); BD.EmitProgressBytecode("pass-error", false); - exit(BD.debugCrash()); + exit(BD.debugOptimizerCrash()); } // Run the result... @@ -120,30 +124,34 @@ ReduceMiscompilingPasses::doTest(std::vector &Prefix, return NoFailure; } -class ReduceMiscompilingFunctions : public ListReducer { - BugDriver &BD; -public: - ReduceMiscompilingFunctions(BugDriver &bd) : BD(bd) {} - - virtual TestResult doTest(std::vector &Prefix, - std::vector &Suffix) { - if (!Suffix.empty() && TestFuncs(Suffix, false)) - return KeepSuffix; - if (!Prefix.empty() && TestFuncs(Prefix, false)) - return KeepPrefix; - return NoFailure; - } - - bool TestFuncs(const std::vector &Prefix, bool EmitBytecode); -}; +namespace llvm { + class ReduceMiscompilingFunctions : public ListReducer { + BugDriver &BD; + public: + ReduceMiscompilingFunctions(BugDriver &bd) : BD(bd) {} + + virtual TestResult doTest(std::vector &Prefix, + std::vector &Suffix) { + if (!Suffix.empty() && TestFuncs(Suffix, false)) + return KeepSuffix; + if (!Prefix.empty() && TestFuncs(Prefix, false)) + return KeepPrefix; + return NoFailure; + } + + bool TestFuncs(const std::vector &Prefix, bool EmitBytecode); + }; +} bool ReduceMiscompilingFunctions::TestFuncs(const std::vector &Funcs, bool EmitBytecode) { // Test to see if the function is misoptimized if we ONLY run it on the // functions listed in Funcs. if (!EmitBytecode) { - std::cout << "Checking to see if the program is misoptimized when these " - << "functions are run\nthrough the passes: "; + std::cout << "Checking to see if the program is misoptimized when " + << (Funcs.size()==1 ? "this function is" : "these functions are") + << " run through the pass" + << (BD.PassesToRun.size() == 1 ? "" : "es") << ": "; BD.PrintFunctionList(Funcs); std::cout << "\n"; } else { @@ -151,7 +159,7 @@ bool ReduceMiscompilingFunctions::TestFuncs(const std::vector &Funcs, } // First step: clone the module for the two halves of the program we want. - Module *ToOptimize = CloneModule(BD.Program); + Module *ToOptimize = CloneModule(BD.getProgram()); // Second step: Make sure functions & globals are all external so that linkage // between the two modules will work. @@ -217,13 +225,13 @@ bool ReduceMiscompilingFunctions::TestFuncs(const std::vector &Funcs, std::cerr << " Error running this sequence of passes" << " on the input program!\n"; BD.EmitProgressBytecode("pass-error", false); - exit(BD.debugCrash()); + exit(BD.debugOptimizerCrash()); } if (!EmitBytecode) std::cout << "done.\n"; - delete BD.Program; // Delete the old "ToOptimize" module + delete BD.getProgram(); // Delete the old "ToOptimize" module BD.Program = BD.ParseInputFile(BytecodeResult); if (EmitBytecode) { @@ -262,10 +270,10 @@ bool ReduceMiscompilingFunctions::TestFuncs(const std::vector &Funcs, // output, then 'Funcs' are being misoptimized! bool Broken = BD.diffProgram(); - delete BD.Program; // Delete the hacked up program + delete BD.Program; // Delete the hacked up program BD.Program = OldProgram; // Restore the original - std::cout << (Broken ? "nope.\n" : "yup.\n"); + std::cout << (Broken ? " nope.\n" : " yup.\n"); return Broken; } @@ -299,7 +307,9 @@ bool BugDriver::debugMiscompilation() { // Do the reduction... ReduceMiscompilingFunctions(*this).reduceList(MiscompiledFunctions); - std::cout << "\n*** The following functions are being miscompiled: "; + std::cout << "\n*** The following function" + << (MiscompiledFunctions.size() == 1 ? " is" : "s are") + << " being miscompiled: "; PrintFunctionList(MiscompiledFunctions); std::cout << "\n"; @@ -308,3 +318,4 @@ bool BugDriver::debugMiscompilation() { return false; } +