Miscompilation.cpp revision fa1af1344910ee975f50ffdddf605c26f80ef016
14a10645c70199c8d8567fbc46312158c419720abChris Lattner//===- Miscompilation.cpp - Debug program miscompilations -----------------===// 27c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// 37c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// The LLVM Compiler Infrastructure 47c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// 57c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// This file was developed by the LLVM research group and is distributed under 67c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// the University of Illinois Open Source License. See LICENSE.TXT for details. 77c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// 87c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell//===----------------------------------------------------------------------===// 94a10645c70199c8d8567fbc46312158c419720abChris Lattner// 10a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner// This file implements optimizer and code generation miscompilation debugging 11a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner// support. 124a10645c70199c8d8567fbc46312158c419720abChris Lattner// 134a10645c70199c8d8567fbc46312158c419720abChris Lattner//===----------------------------------------------------------------------===// 144a10645c70199c8d8567fbc46312158c419720abChris Lattner 154a10645c70199c8d8567fbc46312158c419720abChris Lattner#include "BugDriver.h" 16126840f49e8d49156a342e836d4b2adca46dc3baChris Lattner#include "ListReducer.h" 17a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner#include "llvm/Constants.h" 18a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner#include "llvm/DerivedTypes.h" 19a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner#include "llvm/Instructions.h" 20605b9e2c5bd1b0c151a0b15d01e6df3aba93d52fReid Spencer#include "llvm/Linker.h" 214a10645c70199c8d8567fbc46312158c419720abChris Lattner#include "llvm/Module.h" 22e49603d79d220a795bd50684c8b1f503ee40f97fMisha Brukman#include "llvm/Pass.h" 23a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner#include "llvm/Analysis/Verifier.h" 24a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner#include "llvm/Support/Mangler.h" 25640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner#include "llvm/Transforms/Utils/Cloning.h" 26551ccae044b0ff658fe629dd67edd5ffe75d10e8Reid Spencer#include "llvm/Support/CommandLine.h" 27551ccae044b0ff658fe629dd67edd5ffe75d10e8Reid Spencer#include "llvm/Support/FileUtilities.h" 28fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattnerusing namespace llvm; 294a10645c70199c8d8567fbc46312158c419720abChris Lattner 30a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattnernamespace llvm { 31a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner extern cl::list<std::string> InputArgv; 32a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner} 33a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 34efdc0b505712d1ca4460def27e51c430f033d58dChris Lattnernamespace { 35fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner class ReduceMiscompilingPasses : public ListReducer<const PassInfo*> { 36fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner BugDriver &BD; 37fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner public: 38fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner ReduceMiscompilingPasses(BugDriver &bd) : BD(bd) {} 39fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner 40fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner virtual TestResult doTest(std::vector<const PassInfo*> &Prefix, 41fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner std::vector<const PassInfo*> &Suffix); 42fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner }; 43fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner} 44640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 458c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// TestResult - After passes have been split into a test group and a control 468c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// group, see if they still break the program. 478c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// 48640f22e66d90439857a97a83896ee68c4f7128c9Chris LattnerReduceMiscompilingPasses::TestResult 4939aebca3a2d1dd389a6d9cdfb51a53f625e244f0Chris LattnerReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix, 5006943add8b2b764e131979cca064eda9f28826c9Chris Lattner std::vector<const PassInfo*> &Suffix) { 5106943add8b2b764e131979cca064eda9f28826c9Chris Lattner // First, run the program with just the Suffix passes. If it is still broken 52640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // with JUST the kept passes, discard the prefix passes. 5306943add8b2b764e131979cca064eda9f28826c9Chris Lattner std::cout << "Checking to see if '" << getPassesString(Suffix) 54640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner << "' compile correctly: "; 55640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 56640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner std::string BytecodeResult; 5706943add8b2b764e131979cca064eda9f28826c9Chris Lattner if (BD.runPasses(Suffix, BytecodeResult, false/*delete*/, true/*quiet*/)) { 589f71e799c3e6e4cc0c71de82bda81f8753e82942Chris Lattner std::cerr << " Error running this sequence of passes" 59640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner << " on the input program!\n"; 605ef681c19de9c675a265211f8fb0ae49cc3a3a66Chris Lattner BD.setPassesToRun(Suffix); 615ef681c19de9c675a265211f8fb0ae49cc3a3a66Chris Lattner BD.EmitProgressBytecode("pass-error", false); 62025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner exit(BD.debugOptimizerCrash()); 63640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner } 64640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 65640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // Check to see if the finished program matches the reference output... 665073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman if (BD.diffProgram(BytecodeResult, "", true /*delete bytecode*/)) { 67123f8fec94d1f22d876382897231868c62f8eabbMisha Brukman std::cout << " nope.\n"; 68123f8fec94d1f22d876382897231868c62f8eabbMisha Brukman return KeepSuffix; // Miscompilation detected! 69640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner } 70123f8fec94d1f22d876382897231868c62f8eabbMisha Brukman std::cout << " yup.\n"; // No miscompilation! 71640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 72640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner if (Prefix.empty()) return NoFailure; 73640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 7406943add8b2b764e131979cca064eda9f28826c9Chris Lattner // Next, see if the program is broken if we run the "prefix" passes first, 75bc0e998c497446f5448425b3cbd7f8f19a458764Misha Brukman // then separately run the "kept" passes. 76640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner std::cout << "Checking to see if '" << getPassesString(Prefix) 77640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner << "' compile correctly: "; 78640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 79640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // If it is not broken with the kept passes, it's possible that the prefix 80640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // passes must be run before the kept passes to break it. If the program 81640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // WORKS after the prefix passes, but then fails if running the prefix AND 82640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // kept passes, we can update our bytecode file to include the result of the 83640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // prefix passes, then discard the prefix passes. 84640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // 85640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner if (BD.runPasses(Prefix, BytecodeResult, false/*delete*/, true/*quiet*/)) { 869f71e799c3e6e4cc0c71de82bda81f8753e82942Chris Lattner std::cerr << " Error running this sequence of passes" 87640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner << " on the input program!\n"; 889c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner BD.setPassesToRun(Prefix); 899c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner BD.EmitProgressBytecode("pass-error", false); 90025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner exit(BD.debugOptimizerCrash()); 91640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner } 92640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 93640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // If the prefix maintains the predicate by itself, only keep the prefix! 945073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman if (BD.diffProgram(BytecodeResult)) { 95123f8fec94d1f22d876382897231868c62f8eabbMisha Brukman std::cout << " nope.\n"; 96640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner removeFile(BytecodeResult); 97640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner return KeepPrefix; 98640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner } 99123f8fec94d1f22d876382897231868c62f8eabbMisha Brukman std::cout << " yup.\n"; // No miscompilation! 100640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 101640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // Ok, so now we know that the prefix passes work, try running the suffix 102640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // passes on the result of the prefix passes. 103640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // 104efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *PrefixOutput = ParseInputFile(BytecodeResult); 105640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner if (PrefixOutput == 0) { 106640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner std::cerr << BD.getToolName() << ": Error reading bytecode file '" 107640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner << BytecodeResult << "'!\n"; 108640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner exit(1); 109640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner } 110640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner removeFile(BytecodeResult); // No longer need the file on disk 111f4789e6d04c1fddb40092a1193c4a5eb67387accChris Lattner 112f4789e6d04c1fddb40092a1193c4a5eb67387accChris Lattner // Don't check if there are no passes in the suffix. 113f4789e6d04c1fddb40092a1193c4a5eb67387accChris Lattner if (Suffix.empty()) 114f4789e6d04c1fddb40092a1193c4a5eb67387accChris Lattner return NoFailure; 115f4789e6d04c1fddb40092a1193c4a5eb67387accChris Lattner 11606943add8b2b764e131979cca064eda9f28826c9Chris Lattner std::cout << "Checking to see if '" << getPassesString(Suffix) 117640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner << "' passes compile correctly after the '" 118640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner << getPassesString(Prefix) << "' passes: "; 119640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 120efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *OriginalInput = BD.swapProgramIn(PrefixOutput); 12106943add8b2b764e131979cca064eda9f28826c9Chris Lattner if (BD.runPasses(Suffix, BytecodeResult, false/*delete*/, true/*quiet*/)) { 1229f71e799c3e6e4cc0c71de82bda81f8753e82942Chris Lattner std::cerr << " Error running this sequence of passes" 123640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner << " on the input program!\n"; 1245ef681c19de9c675a265211f8fb0ae49cc3a3a66Chris Lattner BD.setPassesToRun(Suffix); 1259c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner BD.EmitProgressBytecode("pass-error", false); 126025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner exit(BD.debugOptimizerCrash()); 127640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner } 128640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 129640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // Run the result... 1305073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman if (BD.diffProgram(BytecodeResult, "", true/*delete bytecode*/)) { 131123f8fec94d1f22d876382897231868c62f8eabbMisha Brukman std::cout << " nope.\n"; 132640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner delete OriginalInput; // We pruned down the original input... 13306943add8b2b764e131979cca064eda9f28826c9Chris Lattner return KeepSuffix; 134640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner } 135640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 136640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // Otherwise, we must not be running the bad pass anymore. 137123f8fec94d1f22d876382897231868c62f8eabbMisha Brukman std::cout << " yup.\n"; // No miscompilation! 138efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner delete BD.swapProgramIn(OriginalInput); // Restore orig program & free test 139640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner return NoFailure; 140640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner} 141640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 142efdc0b505712d1ca4460def27e51c430f033d58dChris Lattnernamespace { 143fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner class ReduceMiscompilingFunctions : public ListReducer<Function*> { 144fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner BugDriver &BD; 145b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner bool (*TestFn)(BugDriver &, Module *, Module *); 146fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner public: 147b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner ReduceMiscompilingFunctions(BugDriver &bd, 148b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner bool (*F)(BugDriver &, Module *, Module *)) 149b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner : BD(bd), TestFn(F) {} 150fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner 151fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner virtual TestResult doTest(std::vector<Function*> &Prefix, 152fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner std::vector<Function*> &Suffix) { 153be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner if (!Suffix.empty() && TestFuncs(Suffix)) 154fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner return KeepSuffix; 155be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner if (!Prefix.empty() && TestFuncs(Prefix)) 156fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner return KeepPrefix; 157fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner return NoFailure; 158fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner } 159fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner 160be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner bool TestFuncs(const std::vector<Function*> &Prefix); 161fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner }; 162fa76183e8e28985dfd17b1d6291c939dab4cbe1dChris Lattner} 163640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 164efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// TestMergedProgram - Given two modules, link them together and run the 165efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// program, checking to see if the program matches the diff. If the diff 166a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner/// matches, return false, otherwise return true. If the DeleteInputs argument 167a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner/// is set to true then this function deletes both input modules before it 168a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner/// returns. 1698c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// 170a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattnerstatic bool TestMergedProgram(BugDriver &BD, Module *M1, Module *M2, 171a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner bool DeleteInputs) { 172efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner // Link the two portions of the program back to together. 173efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner std::string ErrorMsg; 17490c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner if (!DeleteInputs) { 17590c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner M1 = CloneModule(M1); 17690c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner M2 = CloneModule(M2); 17790c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner } 178efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner if (LinkModules(M1, M2, &ErrorMsg)) { 179efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner std::cerr << BD.getToolName() << ": Error linking modules together:" 180eed80e23751ecc50c1fa5604f67be4b826d5b417Misha Brukman << ErrorMsg << '\n'; 181efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner exit(1); 182efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner } 18390c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner delete M2; // We are done with this module. 184efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 185efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *OldProgram = BD.swapProgramIn(M1); 186efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 187efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner // Execute the program. If it does not match the expected output, we must 188efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner // return true. 189efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner bool Broken = BD.diffProgram(); 190efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 191efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner // Delete the linked module & restore the original 192a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner BD.swapProgramIn(OldProgram); 1935313f23b8c3d22a2028beb731c60fc1a25beb149Chris Lattner delete M1; 194efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner return Broken; 195efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner} 196efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 1978c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// TestFuncs - split functions in a Module into two groups: those that are 1988c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// under consideration for miscompilation vs. those that are not, and test 1998c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// accordingly. Each group of functions becomes a separate Module. 2008c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// 201be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattnerbool ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function*>&Funcs){ 202640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // Test to see if the function is misoptimized if we ONLY run it on the 203640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // functions listed in Funcs. 204be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner std::cout << "Checking to see if the program is misoptimized when " 205be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner << (Funcs.size()==1 ? "this function is" : "these functions are") 206be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner << " run through the pass" 207a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner << (BD.getPassesToRun().size() == 1 ? "" : "es") << ":"; 208efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner PrintFunctionList(Funcs); 209eed80e23751ecc50c1fa5604f67be4b826d5b417Misha Brukman std::cout << '\n'; 210640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 211be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner // Split the module into the two halves of the program we want. 212efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *ToNotOptimize = CloneModule(BD.getProgram()); 213efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, Funcs); 214640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 215b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner // Run the predicate, not that the predicate will delete both input modules. 216b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner return TestFn(BD, ToOptimize, ToNotOptimize); 217640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner} 218640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 2198c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// DisambiguateGlobalSymbols - Mangle symbols to guarantee uniqueness by 2208c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// modifying predominantly internal symbols rather than external ones. 2218c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// 22236ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattnerstatic void DisambiguateGlobalSymbols(Module *M) { 22336ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner // Try not to cause collisions by minimizing chances of renaming an 22436ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner // already-external symbol, so take in external globals and functions as-is. 22536ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner // The code should work correctly without disambiguation (assuming the same 22636ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner // mangler is used by the two code generators), but having symbols with the 22736ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner // same name causes warnings to be emitted by the code generator. 22836ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner Mangler Mang(*M); 22936ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) 23036ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner I->setName(Mang.getValueName(I)); 23136ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) 23236ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner I->setName(Mang.getValueName(I)); 23336ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner} 23436ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner 235a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner/// ExtractLoops - Given a reduced list of functions that still exposed the bug, 236a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner/// check to see if we can extract the loops in the region without obscuring the 237a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner/// bug. If so, it reduces the amount of code identified. 2388c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// 239b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattnerstatic bool ExtractLoops(BugDriver &BD, 240b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner bool (*TestFn)(BugDriver &, Module *, Module *), 241a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner std::vector<Function*> &MiscompiledFunctions) { 242a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner bool MadeChange = false; 243a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner while (1) { 244a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner Module *ToNotOptimize = CloneModule(BD.getProgram()); 245a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, 246a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner MiscompiledFunctions); 247a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner Module *ToOptimizeLoopExtracted = BD.ExtractLoop(ToOptimize); 248a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner if (!ToOptimizeLoopExtracted) { 249a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // If the loop extractor crashed or if there were no extractible loops, 250a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // then this chapter of our odyssey is over with. 251a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner delete ToNotOptimize; 252a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner delete ToOptimize; 253a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner return MadeChange; 254a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner } 255a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner 256a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner std::cerr << "Extracted a loop from the breaking portion of the program.\n"; 257a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner delete ToOptimize; 258a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner 259a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // Bugpoint is intentionally not very trusting of LLVM transformations. In 260a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // particular, we're not going to assume that the loop extractor works, so 261a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // we're going to test the newly loop extracted program to make sure nothing 262a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // has broken. If something broke, then we'll inform the user and stop 263a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // extraction. 264a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner AbstractInterpreter *AI = BD.switchToCBE(); 265a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner if (TestMergedProgram(BD, ToOptimizeLoopExtracted, ToNotOptimize, false)) { 266a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner BD.switchToInterpreter(AI); 267a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 268a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // Merged program doesn't work anymore! 269a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner std::cerr << " *** ERROR: Loop extraction broke the program. :(" 270a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner << " Please report a bug!\n"; 271a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner std::cerr << " Continuing on with un-loop-extracted version.\n"; 272a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner delete ToNotOptimize; 273a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner delete ToOptimizeLoopExtracted; 274a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner return MadeChange; 275a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner } 276a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner BD.switchToInterpreter(AI); 277a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner 278b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner std::cout << " Testing after loop extraction:\n"; 279b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner // Clone modules, the tester function will free them. 280b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner Module *TOLEBackup = CloneModule(ToOptimizeLoopExtracted); 281b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner Module *TNOBackup = CloneModule(ToNotOptimize); 282b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner if (!TestFn(BD, ToOptimizeLoopExtracted, ToNotOptimize)) { 283b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner std::cout << "*** Loop extraction masked the problem. Undoing.\n"; 284a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // If the program is not still broken, then loop extraction did something 285a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // that masked the error. Stop loop extraction now. 286b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner delete TOLEBackup; 287b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner delete TNOBackup; 288a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner return MadeChange; 289a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner } 290b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner ToOptimizeLoopExtracted = TOLEBackup; 291b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner ToNotOptimize = TNOBackup; 292b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner 293b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner std::cout << "*** Loop extraction successful!\n"; 294a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner 29590c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner std::vector<std::pair<std::string, const FunctionType*> > MisCompFunctions; 29690c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner for (Module::iterator I = ToOptimizeLoopExtracted->begin(), 29790c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner E = ToOptimizeLoopExtracted->end(); I != E; ++I) 298fa1af1344910ee975f50ffdddf605c26f80ef016Chris Lattner if (!I->isExternal()) 299fa1af1344910ee975f50ffdddf605c26f80ef016Chris Lattner MisCompFunctions.push_back(std::make_pair(I->getName(), 300fa1af1344910ee975f50ffdddf605c26f80ef016Chris Lattner I->getFunctionType())); 30190c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner 302a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // Okay, great! Now we know that we extracted a loop and that loop 303a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // extraction both didn't break the program, and didn't mask the problem. 304a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // Replace the current program with the loop extracted version, and try to 305a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // extract another loop. 306a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner std::string ErrorMsg; 307a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner if (LinkModules(ToNotOptimize, ToOptimizeLoopExtracted, &ErrorMsg)) { 308a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner std::cerr << BD.getToolName() << ": Error linking modules together:" 309eed80e23751ecc50c1fa5604f67be4b826d5b417Misha Brukman << ErrorMsg << '\n'; 310a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner exit(1); 311a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner } 31290c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner delete ToOptimizeLoopExtracted; 313d3a533d94dae1e57194001af08763eb3ba199c8fChris Lattner 314d3a533d94dae1e57194001af08763eb3ba199c8fChris Lattner // All of the Function*'s in the MiscompiledFunctions list are in the old 3155313f23b8c3d22a2028beb731c60fc1a25beb149Chris Lattner // module. Update this list to include all of the functions in the 3165313f23b8c3d22a2028beb731c60fc1a25beb149Chris Lattner // optimized and loop extracted module. 3175313f23b8c3d22a2028beb731c60fc1a25beb149Chris Lattner MiscompiledFunctions.clear(); 31890c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) { 31990c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner Function *NewF = ToNotOptimize->getFunction(MisCompFunctions[i].first, 32090c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner MisCompFunctions[i].second); 32190c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner assert(NewF && "Function not found??"); 32290c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner MiscompiledFunctions.push_back(NewF); 323d3a533d94dae1e57194001af08763eb3ba199c8fChris Lattner } 324d3a533d94dae1e57194001af08763eb3ba199c8fChris Lattner 325a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner BD.setNewProgram(ToNotOptimize); 326a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner MadeChange = true; 327a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner } 328a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner} 329a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner 3305e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattnernamespace { 3315e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner class ReduceMiscompiledBlocks : public ListReducer<BasicBlock*> { 3325e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner BugDriver &BD; 3335e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner bool (*TestFn)(BugDriver &, Module *, Module *); 3345e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner std::vector<Function*> FunctionsBeingTested; 3355e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner public: 3365e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner ReduceMiscompiledBlocks(BugDriver &bd, 3375e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner bool (*F)(BugDriver &, Module *, Module *), 3385e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner const std::vector<Function*> &Fns) 3395e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner : BD(bd), TestFn(F), FunctionsBeingTested(Fns) {} 3405e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 3415e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner virtual TestResult doTest(std::vector<BasicBlock*> &Prefix, 3425e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner std::vector<BasicBlock*> &Suffix) { 3435e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner if (!Suffix.empty() && TestFuncs(Suffix)) 3445e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner return KeepSuffix; 3455e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner if (TestFuncs(Prefix)) 3465e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner return KeepPrefix; 3475e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner return NoFailure; 3485e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner } 3495e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 3505e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner bool TestFuncs(const std::vector<BasicBlock*> &Prefix); 3515e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner }; 3525e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner} 3535e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 3545e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner/// TestFuncs - Extract all blocks for the miscompiled functions except for the 3555e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner/// specified blocks. If the problem still exists, return true. 3565e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner/// 3575e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattnerbool ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock*> &BBs) { 3585e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // Test to see if the function is misoptimized if we ONLY run it on the 3595e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // functions listed in Funcs. 36068bee938e539d884ee89ce4dfebbad777896960eChris Lattner std::cout << "Checking to see if the program is misoptimized when all "; 36168bee938e539d884ee89ce4dfebbad777896960eChris Lattner if (!BBs.empty()) { 36268bee938e539d884ee89ce4dfebbad777896960eChris Lattner std::cout << "but these " << BBs.size() << " blocks are extracted: "; 36368bee938e539d884ee89ce4dfebbad777896960eChris Lattner for (unsigned i = 0, e = BBs.size() < 10 ? BBs.size() : 10; i != e; ++i) 36468bee938e539d884ee89ce4dfebbad777896960eChris Lattner std::cout << BBs[i]->getName() << " "; 36568bee938e539d884ee89ce4dfebbad777896960eChris Lattner if (BBs.size() > 10) std::cout << "..."; 36668bee938e539d884ee89ce4dfebbad777896960eChris Lattner } else { 36768bee938e539d884ee89ce4dfebbad777896960eChris Lattner std::cout << "blocks are extracted."; 36868bee938e539d884ee89ce4dfebbad777896960eChris Lattner } 369eed80e23751ecc50c1fa5604f67be4b826d5b417Misha Brukman std::cout << '\n'; 3705e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 3715e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // Split the module into the two halves of the program we want. 3725e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner Module *ToNotOptimize = CloneModule(BD.getProgram()); 3735e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, 3745e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner FunctionsBeingTested); 3755e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 3765e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // Try the extraction. If it doesn't work, then the block extractor crashed 3775e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // or something, in which case bugpoint can't chase down this possibility. 3785e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner if (Module *New = BD.ExtractMappedBlocksFromModule(BBs, ToOptimize)) { 3795e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner delete ToOptimize; 3805e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // Run the predicate, not that the predicate will delete both input modules. 3815e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner return TestFn(BD, New, ToNotOptimize); 3825e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner } 3835e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner delete ToOptimize; 3845e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner delete ToNotOptimize; 3855e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner return false; 3865e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner} 3875e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 3885e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 3895e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner/// ExtractBlocks - Given a reduced list of functions that still expose the bug, 3905e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner/// extract as many basic blocks from the region as possible without obscuring 3915e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner/// the bug. 3925e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner/// 3935e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattnerstatic bool ExtractBlocks(BugDriver &BD, 3945e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner bool (*TestFn)(BugDriver &, Module *, Module *), 3955e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner std::vector<Function*> &MiscompiledFunctions) { 3965e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner std::vector<BasicBlock*> Blocks; 3975e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner for (unsigned i = 0, e = MiscompiledFunctions.size(); i != e; ++i) 3985e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner for (Function::iterator I = MiscompiledFunctions[i]->begin(), 3995e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner E = MiscompiledFunctions[i]->end(); I != E; ++I) 4005e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner Blocks.push_back(I); 4015e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 4025e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // Use the list reducer to identify blocks that can be extracted without 4035e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // obscuring the bug. The Blocks list will end up containing blocks that must 4045e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // be retained from the original program. 4055e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner unsigned OldSize = Blocks.size(); 40668bee938e539d884ee89ce4dfebbad777896960eChris Lattner 40768bee938e539d884ee89ce4dfebbad777896960eChris Lattner // Check to see if all blocks are extractible first. 40868bee938e539d884ee89ce4dfebbad777896960eChris Lattner if (ReduceMiscompiledBlocks(BD, TestFn, 40968bee938e539d884ee89ce4dfebbad777896960eChris Lattner MiscompiledFunctions).TestFuncs(std::vector<BasicBlock*>())) { 41068bee938e539d884ee89ce4dfebbad777896960eChris Lattner Blocks.clear(); 41168bee938e539d884ee89ce4dfebbad777896960eChris Lattner } else { 41268bee938e539d884ee89ce4dfebbad777896960eChris Lattner ReduceMiscompiledBlocks(BD, TestFn,MiscompiledFunctions).reduceList(Blocks); 41368bee938e539d884ee89ce4dfebbad777896960eChris Lattner if (Blocks.size() == OldSize) 41468bee938e539d884ee89ce4dfebbad777896960eChris Lattner return false; 41568bee938e539d884ee89ce4dfebbad777896960eChris Lattner } 4165e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 4172290e754061f1393bb96b1808ac33dc03399c939Chris Lattner Module *ProgClone = CloneModule(BD.getProgram()); 4182290e754061f1393bb96b1808ac33dc03399c939Chris Lattner Module *ToExtract = SplitFunctionsOutOfModule(ProgClone, 4192290e754061f1393bb96b1808ac33dc03399c939Chris Lattner MiscompiledFunctions); 4202290e754061f1393bb96b1808ac33dc03399c939Chris Lattner Module *Extracted = BD.ExtractMappedBlocksFromModule(Blocks, ToExtract); 4212290e754061f1393bb96b1808ac33dc03399c939Chris Lattner if (Extracted == 0) { 4222290e754061f1393bb96b1808ac33dc03399c939Chris Lattner // Wierd, extraction should have worked. 4232290e754061f1393bb96b1808ac33dc03399c939Chris Lattner std::cerr << "Nondeterministic problem extracting blocks??\n"; 4242290e754061f1393bb96b1808ac33dc03399c939Chris Lattner delete ProgClone; 4252290e754061f1393bb96b1808ac33dc03399c939Chris Lattner delete ToExtract; 4262290e754061f1393bb96b1808ac33dc03399c939Chris Lattner return false; 4272290e754061f1393bb96b1808ac33dc03399c939Chris Lattner } 4285e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 4292290e754061f1393bb96b1808ac33dc03399c939Chris Lattner // Otherwise, block extraction succeeded. Link the two program fragments back 4302290e754061f1393bb96b1808ac33dc03399c939Chris Lattner // together. 4312290e754061f1393bb96b1808ac33dc03399c939Chris Lattner delete ToExtract; 4325e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 43390c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner std::vector<std::pair<std::string, const FunctionType*> > MisCompFunctions; 43490c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner for (Module::iterator I = Extracted->begin(), E = Extracted->end(); 43590c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner I != E; ++I) 436fa1af1344910ee975f50ffdddf605c26f80ef016Chris Lattner if (!I->isExternal()) 437fa1af1344910ee975f50ffdddf605c26f80ef016Chris Lattner MisCompFunctions.push_back(std::make_pair(I->getName(), 438fa1af1344910ee975f50ffdddf605c26f80ef016Chris Lattner I->getFunctionType())); 43990c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner 4402290e754061f1393bb96b1808ac33dc03399c939Chris Lattner std::string ErrorMsg; 4412290e754061f1393bb96b1808ac33dc03399c939Chris Lattner if (LinkModules(ProgClone, Extracted, &ErrorMsg)) { 4422290e754061f1393bb96b1808ac33dc03399c939Chris Lattner std::cerr << BD.getToolName() << ": Error linking modules together:" 443eed80e23751ecc50c1fa5604f67be4b826d5b417Misha Brukman << ErrorMsg << '\n'; 4442290e754061f1393bb96b1808ac33dc03399c939Chris Lattner exit(1); 4452290e754061f1393bb96b1808ac33dc03399c939Chris Lattner } 44690c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner delete Extracted; 4475e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 4482290e754061f1393bb96b1808ac33dc03399c939Chris Lattner // Set the new program and delete the old one. 4492290e754061f1393bb96b1808ac33dc03399c939Chris Lattner BD.setNewProgram(ProgClone); 4505e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 4512290e754061f1393bb96b1808ac33dc03399c939Chris Lattner // Update the list of miscompiled functions. 4522290e754061f1393bb96b1808ac33dc03399c939Chris Lattner MiscompiledFunctions.clear(); 4535e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 45490c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) { 45590c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner Function *NewF = ProgClone->getFunction(MisCompFunctions[i].first, 45690c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner MisCompFunctions[i].second); 45790c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner assert(NewF && "Function not found??"); 45890c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner MiscompiledFunctions.push_back(NewF); 45990c18c5c69d9c451e5fdca1e4b4b95e8ed13291aChris Lattner } 4602290e754061f1393bb96b1808ac33dc03399c939Chris Lattner 4612290e754061f1393bb96b1808ac33dc03399c939Chris Lattner return true; 4625e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner} 4635e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 4645e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 465b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner/// DebugAMiscompilation - This is a generic driver to narrow down 466b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner/// miscompilations, either in an optimization or a code generator. 4678c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// 468b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattnerstatic std::vector<Function*> 469b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris LattnerDebugAMiscompilation(BugDriver &BD, 470b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner bool (*TestFn)(BugDriver &, Module *, Module *)) { 471640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // Okay, now that we have reduced the list of passes which are causing the 472640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // failure, see if we can pin down which functions are being 473640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // miscompiled... first build a list of all of the non-external functions in 474640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // the program. 475640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner std::vector<Function*> MiscompiledFunctions; 476b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner Module *Prog = BD.getProgram(); 477b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner for (Module::iterator I = Prog->begin(), E = Prog->end(); I != E; ++I) 478640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner if (!I->isExternal()) 479640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner MiscompiledFunctions.push_back(I); 4804a10645c70199c8d8567fbc46312158c419720abChris Lattner 481640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // Do the reduction... 482b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions); 483640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 484de9750def7c5ca6cb789f3bba7c913e237cdf849Chris Lattner std::cout << "\n*** The following function" 485de9750def7c5ca6cb789f3bba7c913e237cdf849Chris Lattner << (MiscompiledFunctions.size() == 1 ? " is" : "s are") 486de9750def7c5ca6cb789f3bba7c913e237cdf849Chris Lattner << " being miscompiled: "; 487640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner PrintFunctionList(MiscompiledFunctions); 488eed80e23751ecc50c1fa5604f67be4b826d5b417Misha Brukman std::cout << '\n'; 4894a10645c70199c8d8567fbc46312158c419720abChris Lattner 490a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // See if we can rip any loops out of the miscompiled functions and still 491a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // trigger the problem. 492b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner if (ExtractLoops(BD, TestFn, MiscompiledFunctions)) { 493a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // Okay, we extracted some loops and the problem still appears. See if we 494a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // can eliminate some of the created functions from being candidates. 495a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner 49636ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner // Loop extraction can introduce functions with the same name (foo_code). 49736ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner // Make sure to disambiguate the symbols so that when the program is split 4985e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // apart that we can link it back together again. 4995e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner DisambiguateGlobalSymbols(BD.getProgram()); 5005e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 5015e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // Do the reduction... 5025e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions); 5035e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 5045e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner std::cout << "\n*** The following function" 5055e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner << (MiscompiledFunctions.size() == 1 ? " is" : "s are") 5065e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner << " being miscompiled: "; 5075e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner PrintFunctionList(MiscompiledFunctions); 508eed80e23751ecc50c1fa5604f67be4b826d5b417Misha Brukman std::cout << '\n'; 5095e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner } 5105e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 5115e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner if (ExtractBlocks(BD, TestFn, MiscompiledFunctions)) { 5125e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // Okay, we extracted some blocks and the problem still appears. See if we 5135e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // can eliminate some of the created functions from being candidates. 5145e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 5155e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // Block extraction can introduce functions with the same name (foo_code). 5165e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner // Make sure to disambiguate the symbols so that when the program is split 51736ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner // apart that we can link it back together again. 51836ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner DisambiguateGlobalSymbols(BD.getProgram()); 51936ee07ff9d26a2c6ebf9faf9ba90923644db29c5Chris Lattner 520a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner // Do the reduction... 521b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions); 522a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner 523a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner std::cout << "\n*** The following function" 524a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner << (MiscompiledFunctions.size() == 1 ? " is" : "s are") 525a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner << " being miscompiled: "; 526a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner PrintFunctionList(MiscompiledFunctions); 527eed80e23751ecc50c1fa5604f67be4b826d5b417Misha Brukman std::cout << '\n'; 528a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner } 529a1cf1c8c87f10f12343ff6ae75f332390e7205abChris Lattner 530b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner return MiscompiledFunctions; 531b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner} 532b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner 533a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner/// TestOptimizer - This is the predicate function used to check to see if the 534a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner/// "Test" portion of the program is misoptimized. If so, return true. In any 535a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner/// case, both module arguments are deleted. 5368c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// 537b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattnerstatic bool TestOptimizer(BugDriver &BD, Module *Test, Module *Safe) { 538b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner // Run the optimization passes on ToOptimize, producing a transformed version 539b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner // of the functions being tested. 540b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner std::cout << " Optimizing functions being tested: "; 541b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner Module *Optimized = BD.runPassesOn(Test, BD.getPassesToRun(), 542b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner /*AutoDebugCrashes*/true); 543b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner std::cout << "done.\n"; 544b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner delete Test; 545b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner 546b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner std::cout << " Checking to see if the merged program executes correctly: "; 5472423db0e8577e769ac5ad4e567808e43daf37945Chris Lattner bool Broken = TestMergedProgram(BD, Optimized, Safe, true); 548b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner std::cout << (Broken ? " nope.\n" : " yup.\n"); 549b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner return Broken; 550b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner} 551b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner 552b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner 553b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner/// debugMiscompilation - This method is used when the passes selected are not 554b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner/// crashing, but the generated output is semantically different from the 555b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner/// input. 556b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner/// 557b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattnerbool BugDriver::debugMiscompilation() { 558b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner // Make sure something was miscompiled... 559b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) { 560b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner std::cerr << "*** Optimized program matches reference output! No problem " 561b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner << "detected...\nbugpoint can't help you with your problem!\n"; 562b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner return false; 563b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner } 564b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner 565b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner std::cout << "\n*** Found miscompiling pass" 566b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner << (getPassesToRun().size() == 1 ? "" : "es") << ": " 567eed80e23751ecc50c1fa5604f67be4b826d5b417Misha Brukman << getPassesString(getPassesToRun()) << '\n'; 568b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner EmitProgressBytecode("passinput"); 569b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner 570b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner std::vector<Function*> MiscompiledFunctions = 571b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner DebugAMiscompilation(*this, TestOptimizer); 572b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner 573640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner // Output a bunch of bytecode files for the user... 574be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner std::cout << "Outputting reduced bytecode files which expose the problem:\n"; 575efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *ToNotOptimize = CloneModule(getProgram()); 576efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, 577efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner MiscompiledFunctions); 578be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner 579be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner std::cout << " Non-optimized portion: "; 580b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner ToNotOptimize = swapProgramIn(ToNotOptimize); 581be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner EmitProgressBytecode("tonotoptimize", true); 582be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner setNewProgram(ToNotOptimize); // Delete hacked module. 583be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner 584be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner std::cout << " Portion that is input to optimizer: "; 585b15825b0a29e527b361b63a6e41aff5fdb8fdd5aChris Lattner ToOptimize = swapProgramIn(ToOptimize); 586be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner EmitProgressBytecode("tooptimize"); 587be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner setNewProgram(ToOptimize); // Delete hacked module. 5884a10645c70199c8d8567fbc46312158c419720abChris Lattner 5894a10645c70199c8d8567fbc46312158c419720abChris Lattner return false; 5904a10645c70199c8d8567fbc46312158c419720abChris Lattner} 591d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 592a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner/// CleanupAndPrepareModules - Get the specified modules ready for code 593a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner/// generator testing. 5948c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// 595a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattnerstatic void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, 596a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Module *Safe) { 597a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Clean up the modules, removing extra cruft that we don't need anymore... 598a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Test = BD.performFinalCleanups(Test); 599a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 600a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // If we are executing the JIT, we have several nasty issues to take care of. 601a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (!BD.isExecutingJIT()) return; 602a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 603a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // First, if the main function is in the Safe module, we must add a stub to 604a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // the Test module to call into it. Thus, we create a new function `main' 605a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // which just calls the old one. 606a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (Function *oldMain = Safe->getNamedFunction("main")) 607a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (!oldMain->isExternal()) { 608a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Rename it 609a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner oldMain->setName("llvm_bugpoint_old_main"); 610a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Create a NEW `main' function with same type in the test module. 611a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Function *newMain = new Function(oldMain->getFunctionType(), 612a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner GlobalValue::ExternalLinkage, 613a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner "main", Test); 614a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Create an `oldmain' prototype in the test module, which will 615a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // corresponds to the real main function in the same module. 616a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Function *oldMainProto = new Function(oldMain->getFunctionType(), 617a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner GlobalValue::ExternalLinkage, 618a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner oldMain->getName(), Test); 619a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Set up and remember the argument list for the main function. 620a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::vector<Value*> args; 621a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner for (Function::aiterator I = newMain->abegin(), E = newMain->aend(), 622a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner OI = oldMain->abegin(); I != E; ++I, ++OI) { 623a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner I->setName(OI->getName()); // Copy argument names from oldMain 624a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner args.push_back(I); 625a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 626a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 627a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Call the old main function and return its result 628a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner BasicBlock *BB = new BasicBlock("entry", newMain); 629fa1af1344910ee975f50ffdddf605c26f80ef016Chris Lattner CallInst *call = new CallInst(oldMainProto, args, "", BB); 630a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 631a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // If the type of old function wasn't void, return value of call 632fa1af1344910ee975f50ffdddf605c26f80ef016Chris Lattner new ReturnInst(call, BB); 633a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 634a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 635a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // The second nasty issue we must deal with in the JIT is that the Safe 636a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // module cannot directly reference any functions defined in the test 637a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // module. Instead, we use a JIT API call to dynamically resolve the 638a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // symbol. 639a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 640a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Add the resolver to the Safe module. 641a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Prototype: void *getPointerToNamedFunction(const char* Name) 642a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Function *resolverFunc = 643a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Safe->getOrInsertFunction("getPointerToNamedFunction", 644a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner PointerType::get(Type::SByteTy), 645a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner PointerType::get(Type::SByteTy), 0); 646a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 647a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Use the function we just added to get addresses of functions we need. 648dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) { 649a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (F->isExternal() && !F->use_empty() && &*F != resolverFunc && 650a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner F->getIntrinsicID() == 0 /* ignore intrinsics */) { 651dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman Function *TestFn = Test->getFunction(F->getName(), F->getFunctionType()); 652a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 653a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Don't forward functions which are external in the test module too. 654a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (TestFn && !TestFn->isExternal()) { 655a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // 1. Add a string constant with its name to the global file 656a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Constant *InitArray = ConstantArray::get(F->getName()); 657a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner GlobalVariable *funcName = 658a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner new GlobalVariable(InitArray->getType(), true /*isConstant*/, 659a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner GlobalValue::InternalLinkage, InitArray, 660a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner F->getName() + "_name", Safe); 661a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 662a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // 2. Use `GetElementPtr *funcName, 0, 0' to convert the string to an 663a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // sbyte* so it matches the signature of the resolver function. 664a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 665a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // GetElementPtr *funcName, ulong 0, ulong 0 666a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::vector<Constant*> GEPargs(2,Constant::getNullValue(Type::IntTy)); 667a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Value *GEP = 668518310cb0d136906ff0a99d7a24cb460794de5bfReid Spencer ConstantExpr::getGetElementPtr(funcName, GEPargs); 669a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::vector<Value*> ResolverArgs; 670a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner ResolverArgs.push_back(GEP); 671a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 672de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman // Rewrite uses of F in global initializers, etc. to uses of a wrapper 673de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman // function that dynamically resolves the calls to F via our JIT API 674de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman if (F->use_begin() != F->use_end()) { 675de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman // Construct a new stub function that will re-route calls to F 676dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman const FunctionType *FuncTy = F->getFunctionType(); 677de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman Function *FuncWrapper = new Function(FuncTy, 678de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman GlobalValue::InternalLinkage, 679dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman F->getName() + "_wrapper", 680dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman F->getParent()); 681dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman BasicBlock *Header = new BasicBlock("header", FuncWrapper); 682dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman 683de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman // Resolve the call to function F via the JIT API: 684de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman // 685de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman // call resolver(GetElementPtr...) 686de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman CallInst *resolve = new CallInst(resolverFunc, ResolverArgs, 687de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman "resolver"); 688de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman Header->getInstList().push_back(resolve); 689de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman // cast the result from the resolver to correctly-typed function 690de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman CastInst *castResolver = 691de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman new CastInst(resolve, PointerType::get(F->getFunctionType()), 692de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman "resolverCast"); 693de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman Header->getInstList().push_back(castResolver); 694de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman 695dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman // Save the argument list 696dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman std::vector<Value*> Args; 697dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman for (Function::aiterator i = FuncWrapper->abegin(), 698dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman e = FuncWrapper->aend(); i != e; ++i) 699dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman Args.push_back(i); 700dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman 701dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman // Pass on the arguments to the real function, return its result 702dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman if (F->getReturnType() == Type::VoidTy) { 703de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman CallInst *Call = new CallInst(castResolver, Args); 704dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman Header->getInstList().push_back(Call); 705dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman ReturnInst *Ret = new ReturnInst(); 706dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman Header->getInstList().push_back(Ret); 707dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman } else { 708de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman CallInst *Call = new CallInst(castResolver, Args, "redir"); 709dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman Header->getInstList().push_back(Call); 710dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman ReturnInst *Ret = new ReturnInst(Call); 711dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman Header->getInstList().push_back(Ret); 712dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman } 713dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman 714de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman // Use the wrapper function instead of the old function 715de4803d0af6824a2d5da41fa09b512084c73ce34Misha Brukman F->replaceAllUsesWith(FuncWrapper); 716dc7fef83dcab053f86119d00478e6b008166fcf5Misha Brukman } 717a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 718a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 719a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 720a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 721a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (verifyModule(*Test) || verifyModule(*Safe)) { 722a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cerr << "Bugpoint has a bug, which corrupted a module!!\n"; 723a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner abort(); 724a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 725a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner} 726a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 727a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 728a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 729a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner/// TestCodeGenerator - This is the predicate function used to check to see if 730a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner/// the "Test" portion of the program is miscompiled by the code generator under 731a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner/// test. If so, return true. In any case, both module arguments are deleted. 7328c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// 733a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattnerstatic bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe) { 734a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner CleanupAndPrepareModules(BD, Test, Safe); 735a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 736a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::string TestModuleBC = getUniqueFilename("bugpoint.test.bc"); 737a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (BD.writeProgramToFile(TestModuleBC, Test)) { 738a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cerr << "Error writing bytecode to `" << TestModuleBC << "'\nExiting."; 739a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner exit(1); 740a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 741a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner delete Test; 742a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 743a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Make the shared library 744a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::string SafeModuleBC = getUniqueFilename("bugpoint.safe.bc"); 745a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 746a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (BD.writeProgramToFile(SafeModuleBC, Safe)) { 747a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cerr << "Error writing bytecode to `" << SafeModuleBC << "'\nExiting."; 748a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner exit(1); 749a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 750a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::string SharedObject = BD.compileSharedObject(SafeModuleBC); 751a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner delete Safe; 752a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 753a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Run the code generator on the `Test' code, loading the shared library. 754a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // The function returns whether or not the new output differs from reference. 755a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner int Result = BD.diffProgram(TestModuleBC, SharedObject, false); 756a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 757a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (Result) 758a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cerr << ": still failing!\n"; 759a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner else 760a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cerr << ": didn't fail.\n"; 761a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner removeFile(TestModuleBC); 762a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner removeFile(SafeModuleBC); 763a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner removeFile(SharedObject); 764a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 765a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner return Result; 766a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner} 767a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 768a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 7698c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// debugCodeGenerator - debug errors in LLC, LLI, or CBE. 7708c194eaa0577a207bb1ea91bf2c2a5e664fce9eeMisha Brukman/// 771a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattnerbool BugDriver::debugCodeGenerator() { 772a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if ((void*)cbe == (void*)Interpreter) { 773a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::string Result = executeProgramWithCBE("bugpoint.cbe.out"); 774a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cout << "\n*** The C backend cannot match the reference diff, but it " 775a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << "is used as the 'known good'\n code generator, so I can't" 776a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << " debug it. Perhaps you have a front-end problem?\n As a" 777a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << " sanity check, I left the result of executing the program " 778a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << "with the C backend\n in this file for you: '" 779a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << Result << "'.\n"; 780a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner return true; 781a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 782a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 783a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner DisambiguateGlobalSymbols(Program); 784a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 785a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::vector<Function*> Funcs = DebugAMiscompilation(*this, TestCodeGenerator); 786a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 787a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Split the module into the two halves of the program we want. 788a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Module *ToNotCodeGen = CloneModule(getProgram()); 789a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs); 790a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 791a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Condition the modules 792a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen); 793a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 794a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::string TestModuleBC = getUniqueFilename("bugpoint.test.bc"); 795a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (writeProgramToFile(TestModuleBC, ToCodeGen)) { 796a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cerr << "Error writing bytecode to `" << TestModuleBC << "'\nExiting."; 797a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner exit(1); 798a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 799a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner delete ToCodeGen; 800a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 801a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner // Make the shared library 802a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::string SafeModuleBC = getUniqueFilename("bugpoint.safe.bc"); 803a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (writeProgramToFile(SafeModuleBC, ToNotCodeGen)) { 804a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cerr << "Error writing bytecode to `" << SafeModuleBC << "'\nExiting."; 805a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner exit(1); 806a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 807a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::string SharedObject = compileSharedObject(SafeModuleBC); 808a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner delete ToNotCodeGen; 809a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 810a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cout << "You can reproduce the problem with the command line: \n"; 811a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner if (isExecutingJIT()) { 812a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cout << " lli -load " << SharedObject << " " << TestModuleBC; 813a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } else { 814a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cout << " llc " << TestModuleBC << " -o " << TestModuleBC << ".s\n"; 815a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cout << " gcc " << SharedObject << " " << TestModuleBC 816a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << ".s -o " << TestModuleBC << ".exe -Wl,-R.\n"; 817a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cout << " " << TestModuleBC << ".exe"; 818a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 819a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner for (unsigned i=0, e = InputArgv.size(); i != e; ++i) 820a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cout << " " << InputArgv[i]; 821eed80e23751ecc50c1fa5604f67be4b826d5b417Misha Brukman std::cout << '\n'; 822a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner std::cout << "The shared object was created with:\n llc -march=c " 823a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << SafeModuleBC << " -o temporary.c\n" 824a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << " gcc -xc temporary.c -O2 -o " << SharedObject 825a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner#if defined(sparc) || defined(__sparc__) || defined(__sparcv9) 826a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << " -G" // Compile a shared library, `-G' for Sparc 827a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner#else 828a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << " -shared" // `-shared' for Linux/X86, maybe others 829a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner#endif 830a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner << " -fno-strict-aliasing\n"; 831a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 832a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner return false; 833a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner} 834