Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 1 | //===- BugDriver.cpp - Top-Level BugPoint class implementation ------------===// |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 7c0e022 | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 21c62da | 2007-12-29 20:44:31 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 7c0e022 | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 9 | // |
| 10 | // This class contains all of the shared state and information that is used by |
| 11 | // the BugPoint tool to track down errors in optimizations. This class is the |
| 12 | // main driver class that invokes all sub-functionality. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "BugDriver.h" |
Chris Lattner | f1b20d8 | 2006-06-06 22:30:59 +0000 | [diff] [blame] | 17 | #include "ToolRunner.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Module.h" |
Duncan P. N. Exon Smith | 7a1a3e9 | 2015-03-26 05:03:10 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | 7fc162f | 2013-03-26 02:25:37 +0000 | [diff] [blame] | 20 | #include "llvm/IRReader/IRReader.h" |
Chandler Carruth | 8a67f12 | 2014-03-06 03:42:23 +0000 | [diff] [blame] | 21 | #include "llvm/Linker/Linker.h" |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 22 | #include "llvm/Pass.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 23 | #include "llvm/Support/CommandLine.h" |
| 24 | #include "llvm/Support/FileUtilities.h" |
Chandler Carruth | f010c46 | 2012-12-04 10:44:52 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Host.h" |
Chris Lattner | 92bcb42 | 2009-07-02 22:46:18 +0000 | [diff] [blame] | 26 | #include "llvm/Support/SourceMgr.h" |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 27 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 28 | #include <memory> |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
Daniel Dunbar | ca74096 | 2009-08-18 03:35:57 +0000 | [diff] [blame] | 31 | namespace llvm { |
Justin Bogner | 388e8b9 | 2016-09-02 01:21:37 +0000 | [diff] [blame] | 32 | Triple TargetTriple; |
Daniel Dunbar | ca74096 | 2009-08-18 03:35:57 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Rafael Espindola | 324f141 | 2017-11-16 17:35:50 +0000 | [diff] [blame] | 35 | DiscardTemp::~DiscardTemp() { |
Rafael Espindola | c138228 | 2017-11-16 21:40:10 +0000 | [diff] [blame] | 36 | if (SaveTemps) { |
| 37 | if (Error E = File.keep()) |
| 38 | errs() << "Failed to keep temp file " << toString(std::move(E)) << '\n'; |
| 39 | return; |
| 40 | } |
Rafael Espindola | 324f141 | 2017-11-16 17:35:50 +0000 | [diff] [blame] | 41 | if (Error E = File.discard()) |
| 42 | errs() << "Failed to delete temp file " << toString(std::move(E)) << '\n'; |
| 43 | } |
| 44 | |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 45 | // Anonymous namespace to define command line options for debugging. |
| 46 | // |
| 47 | namespace { |
Justin Bogner | 388e8b9 | 2016-09-02 01:21:37 +0000 | [diff] [blame] | 48 | // Output - The user can specify a file containing the expected output of the |
| 49 | // program. If this filename is set, it is used as the reference diff source, |
| 50 | // otherwise the raw input run through an interpreter is used as the reference |
| 51 | // source. |
| 52 | // |
| 53 | cl::opt<std::string> OutputFile("output", |
| 54 | cl::desc("Specify a reference program output " |
| 55 | "(for miscompilation detection)")); |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Rafael Espindola | cdac12c | 2018-02-14 21:44:34 +0000 | [diff] [blame] | 58 | /// If we reduce or update the program somehow, call this method to update |
| 59 | /// bugdriver with it. This deletes the old module and sets the specified one |
| 60 | /// as the current program. |
| 61 | void BugDriver::setNewProgram(std::unique_ptr<Module> M) { |
| 62 | Program = std::move(M); |
Chris Lattner | 06905db | 2004-02-18 21:24:48 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Chris Lattner | 640f22e | 2003-04-24 17:02:17 +0000 | [diff] [blame] | 65 | /// getPassesString - Turn a list of passes into a string which indicates the |
| 66 | /// command line options that must be passed to add the passes. |
| 67 | /// |
Rafael Espindola | 8261dfe | 2010-08-08 03:55:08 +0000 | [diff] [blame] | 68 | std::string llvm::getPassesString(const std::vector<std::string> &Passes) { |
Chris Lattner | 640f22e | 2003-04-24 17:02:17 +0000 | [diff] [blame] | 69 | std::string Result; |
| 70 | for (unsigned i = 0, e = Passes.size(); i != e; ++i) { |
Justin Bogner | 388e8b9 | 2016-09-02 01:21:37 +0000 | [diff] [blame] | 71 | if (i) |
| 72 | Result += " "; |
Chris Lattner | 640f22e | 2003-04-24 17:02:17 +0000 | [diff] [blame] | 73 | Result += "-"; |
Rafael Espindola | 8261dfe | 2010-08-08 03:55:08 +0000 | [diff] [blame] | 74 | Result += Passes[i]; |
Chris Lattner | 640f22e | 2003-04-24 17:02:17 +0000 | [diff] [blame] | 75 | } |
| 76 | return Result; |
| 77 | } |
| 78 | |
Justin Bogner | 388e8b9 | 2016-09-02 01:21:37 +0000 | [diff] [blame] | 79 | BugDriver::BugDriver(const char *toolname, bool find_bugs, unsigned timeout, |
| 80 | unsigned memlimit, bool use_valgrind, LLVMContext &ctxt) |
| 81 | : Context(ctxt), ToolName(toolname), ReferenceOutputFile(OutputFile), |
| 82 | Program(nullptr), Interpreter(nullptr), SafeInterpreter(nullptr), |
| 83 | cc(nullptr), run_find_bugs(find_bugs), Timeout(timeout), |
| 84 | MemoryLimit(memlimit), UseValgrind(use_valgrind) {} |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 85 | |
Jeffrey Yasskin | c1dc067 | 2010-03-22 05:23:37 +0000 | [diff] [blame] | 86 | BugDriver::~BugDriver() { |
David Blaikie | 5ed33e0 | 2014-04-25 20:15:16 +0000 | [diff] [blame] | 87 | if (Interpreter != SafeInterpreter) |
| 88 | delete Interpreter; |
| 89 | delete SafeInterpreter; |
Davide Italiano | f7b2acb | 2015-10-14 20:29:54 +0000 | [diff] [blame] | 90 | delete cc; |
Jeffrey Yasskin | c1dc067 | 2010-03-22 05:23:37 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Rafael Espindola | 1bfd87a | 2014-08-26 17:19:03 +0000 | [diff] [blame] | 93 | std::unique_ptr<Module> llvm::parseInputFile(StringRef Filename, |
| 94 | LLVMContext &Ctxt) { |
Chris Lattner | 92bcb42 | 2009-07-02 22:46:18 +0000 | [diff] [blame] | 95 | SMDiagnostic Err; |
Rafael Espindola | 81e4992 | 2014-08-26 17:29:46 +0000 | [diff] [blame] | 96 | std::unique_ptr<Module> Result = parseIRFile(Filename, Err, Ctxt); |
Duncan P. N. Exon Smith | 6a62f78 | 2015-03-26 05:03:06 +0000 | [diff] [blame] | 97 | if (!Result) { |
Chris Lattner | d8b7aa2 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 98 | Err.print("bugpoint", errs()); |
Duncan P. N. Exon Smith | 6a62f78 | 2015-03-26 05:03:06 +0000 | [diff] [blame] | 99 | return Result; |
| 100 | } |
Dan Gohman | dad45ea | 2009-09-03 16:32:58 +0000 | [diff] [blame] | 101 | |
Duncan P. N. Exon Smith | 7a1a3e9 | 2015-03-26 05:03:10 +0000 | [diff] [blame] | 102 | if (verifyModule(*Result, &errs())) { |
Duncan P. N. Exon Smith | 4e5fdbf | 2015-03-31 03:07:23 +0000 | [diff] [blame] | 103 | errs() << "bugpoint: " << Filename << ": error: input module is broken!\n"; |
Duncan P. N. Exon Smith | 7a1a3e9 | 2015-03-26 05:03:10 +0000 | [diff] [blame] | 104 | return std::unique_ptr<Module>(); |
| 105 | } |
| 106 | |
Daniel Dunbar | ca74096 | 2009-08-18 03:35:57 +0000 | [diff] [blame] | 107 | // If we don't have an override triple, use the first one to configure |
| 108 | // bugpoint, or use the host triple if none provided. |
Duncan P. N. Exon Smith | 6a62f78 | 2015-03-26 05:03:06 +0000 | [diff] [blame] | 109 | if (TargetTriple.getTriple().empty()) { |
| 110 | Triple TheTriple(Result->getTargetTriple()); |
Daniel Dunbar | ca74096 | 2009-08-18 03:35:57 +0000 | [diff] [blame] | 111 | |
Duncan P. N. Exon Smith | 6a62f78 | 2015-03-26 05:03:06 +0000 | [diff] [blame] | 112 | if (TheTriple.getTriple().empty()) |
| 113 | TheTriple.setTriple(sys::getDefaultTargetTriple()); |
Michael J. Spencer | 56584fc | 2011-03-31 13:06:39 +0000 | [diff] [blame] | 114 | |
Duncan P. N. Exon Smith | 6a62f78 | 2015-03-26 05:03:06 +0000 | [diff] [blame] | 115 | TargetTriple.setTriple(TheTriple.getTriple()); |
Daniel Dunbar | ca74096 | 2009-08-18 03:35:57 +0000 | [diff] [blame] | 116 | } |
Duncan P. N. Exon Smith | 6a62f78 | 2015-03-26 05:03:06 +0000 | [diff] [blame] | 117 | |
| 118 | Result->setTargetTriple(TargetTriple.getTriple()); // override the triple |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 119 | return Result; |
| 120 | } |
| 121 | |
Rafael Espindola | cdac12c | 2018-02-14 21:44:34 +0000 | [diff] [blame] | 122 | std::unique_ptr<Module> BugDriver::swapProgramIn(std::unique_ptr<Module> M) { |
| 123 | std::unique_ptr<Module> OldProgram = std::move(Program); |
| 124 | Program = std::move(M); |
| 125 | return OldProgram; |
| 126 | } |
| 127 | |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 128 | // This method takes the specified list of LLVM input files, attempts to load |
Gabor Greif | 8ff70c2 | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 129 | // them, either as assembly or bitcode, then link them together. It returns |
| 130 | // true on failure (if, for example, an input bitcode file could not be |
Brian Gaeke | dae7f92 | 2003-05-23 05:34:32 +0000 | [diff] [blame] | 131 | // parsed), and false on success. |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 132 | // |
| 133 | bool BugDriver::addSources(const std::vector<std::string> &Filenames) { |
Craig Topper | c34a25d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 134 | assert(!Program && "Cannot call addSources multiple times!"); |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 135 | assert(!Filenames.empty() && "Must specify at least on input filename!"); |
| 136 | |
Nick Lewycky | 22ff748 | 2010-04-12 05:08:25 +0000 | [diff] [blame] | 137 | // Load the first input file. |
Rafael Espindola | cdac12c | 2018-02-14 21:44:34 +0000 | [diff] [blame] | 138 | Program = parseInputFile(Filenames[0], Context); |
Justin Bogner | 388e8b9 | 2016-09-02 01:21:37 +0000 | [diff] [blame] | 139 | if (!Program) |
| 140 | return true; |
Michael J. Spencer | 56584fc | 2011-03-31 13:06:39 +0000 | [diff] [blame] | 141 | |
Rafael Espindola | 7f99f74b | 2010-08-07 23:03:21 +0000 | [diff] [blame] | 142 | outs() << "Read input file : '" << Filenames[0] << "'\n"; |
Nick Lewycky | 22ff748 | 2010-04-12 05:08:25 +0000 | [diff] [blame] | 143 | |
| 144 | for (unsigned i = 1, e = Filenames.size(); i != e; ++i) { |
Rafael Espindola | 1bfd87a | 2014-08-26 17:19:03 +0000 | [diff] [blame] | 145 | std::unique_ptr<Module> M = parseInputFile(Filenames[i], Context); |
Justin Bogner | 388e8b9 | 2016-09-02 01:21:37 +0000 | [diff] [blame] | 146 | if (!M.get()) |
| 147 | return true; |
Nick Lewycky | 22ff748 | 2010-04-12 05:08:25 +0000 | [diff] [blame] | 148 | |
Rafael Espindola | 7f99f74b | 2010-08-07 23:03:21 +0000 | [diff] [blame] | 149 | outs() << "Linking in input file: '" << Filenames[i] << "'\n"; |
Rafael Espindola | d912be9 | 2015-12-16 23:16:33 +0000 | [diff] [blame] | 150 | if (Linker::linkModules(*Program, std::move(M))) |
Nick Lewycky | 22ff748 | 2010-04-12 05:08:25 +0000 | [diff] [blame] | 151 | return true; |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Rafael Espindola | 7f99f74b | 2010-08-07 23:03:21 +0000 | [diff] [blame] | 154 | outs() << "*** All input ok\n"; |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 155 | |
| 156 | // All input files read successfully! |
| 157 | return false; |
| 158 | } |
| 159 | |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 160 | /// run - The top level method that is invoked after all of the instance |
| 161 | /// variables are set up from command line arguments. |
| 162 | /// |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 163 | Error BugDriver::run() { |
Patrick Jenkins | 6a3f31c | 2006-08-15 16:40:49 +0000 | [diff] [blame] | 164 | if (run_find_bugs) { |
| 165 | // Rearrange the passes and apply them to the program. Repeat this process |
| 166 | // until the user kills the program or we find a bug. |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 167 | return runManyPasses(PassesToRun); |
Patrick Jenkins | 6a3f31c | 2006-08-15 16:40:49 +0000 | [diff] [blame] | 168 | } |
Reid Spencer | c4bb052 | 2005-12-22 20:02:55 +0000 | [diff] [blame] | 169 | |
Michael J. Spencer | 56584fc | 2011-03-31 13:06:39 +0000 | [diff] [blame] | 170 | // If we're not running as a child, the first thing that we must do is |
| 171 | // determine what the problem is. Does the optimization series crash the |
| 172 | // compiler, or does it produce illegal code? We make the top-level |
Sylvestre Ledru | c8e41c5 | 2012-07-23 08:51:15 +0000 | [diff] [blame] | 173 | // decision by trying to run all of the passes on the input program, |
Michael J. Spencer | 56584fc | 2011-03-31 13:06:39 +0000 | [diff] [blame] | 174 | // which should generate a bitcode file. If it does generate a bitcode |
| 175 | // file, then we know the compiler didn't crash, so try to diagnose a |
Reid Spencer | c4bb052 | 2005-12-22 20:02:55 +0000 | [diff] [blame] | 176 | // miscompilation. |
Chris Lattner | 99b8533 | 2003-10-13 21:04:26 +0000 | [diff] [blame] | 177 | if (!PassesToRun.empty()) { |
Dan Gohman | ac95cc7 | 2009-07-16 15:30:09 +0000 | [diff] [blame] | 178 | outs() << "Running selected passes on program to test for crash: "; |
Rafael Espindola | cdac12c | 2018-02-14 21:44:34 +0000 | [diff] [blame] | 179 | if (runPasses(*Program, PassesToRun)) |
Chris Lattner | 0252626 | 2004-02-18 21:02:04 +0000 | [diff] [blame] | 180 | return debugOptimizerCrash(); |
Chris Lattner | 99b8533 | 2003-10-13 21:04:26 +0000 | [diff] [blame] | 181 | } |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 182 | |
Gabor Greif | 8ff70c2 | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 183 | // Set up the execution environment, selecting a method to run LLVM bitcode. |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 184 | if (Error E = initializeExecutionEnvironment()) |
| 185 | return E; |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 186 | |
Chris Lattner | 7c955fd | 2004-02-19 17:03:49 +0000 | [diff] [blame] | 187 | // Test to see if we have a code generator crash. |
Dan Gohman | ac95cc7 | 2009-07-16 15:30:09 +0000 | [diff] [blame] | 188 | outs() << "Running the code generator to test for a crash: "; |
Rafael Espindola | cdac12c | 2018-02-14 21:44:34 +0000 | [diff] [blame] | 189 | if (Error E = compileProgram(*Program)) { |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 190 | outs() << toString(std::move(E)); |
| 191 | return debugCodeGeneratorCrash(); |
Chris Lattner | 7c955fd | 2004-02-19 17:03:49 +0000 | [diff] [blame] | 192 | } |
Nick Lewycky | 22ff748 | 2010-04-12 05:08:25 +0000 | [diff] [blame] | 193 | outs() << '\n'; |
Chris Lattner | 7c955fd | 2004-02-19 17:03:49 +0000 | [diff] [blame] | 194 | |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 195 | // Run the raw input to see where we are coming from. If a reference output |
| 196 | // was specified, make sure that the raw output matches it. If not, it's a |
| 197 | // problem in the front-end or the code generator. |
| 198 | // |
Chris Lattner | c28c1d3 | 2003-08-22 18:57:43 +0000 | [diff] [blame] | 199 | bool CreatedOutput = false; |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 200 | if (ReferenceOutputFile.empty()) { |
Dan Gohman | ac95cc7 | 2009-07-16 15:30:09 +0000 | [diff] [blame] | 201 | outs() << "Generating reference output from raw program: "; |
Rafael Espindola | cdac12c | 2018-02-14 21:44:34 +0000 | [diff] [blame] | 202 | if (Error E = createReferenceFile(*Program)) { |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 203 | errs() << toString(std::move(E)); |
| 204 | return debugCodeGeneratorCrash(); |
Chris Lattner | 0252626 | 2004-02-18 21:02:04 +0000 | [diff] [blame] | 205 | } |
Patrick Jenkins | 6a3f31c | 2006-08-15 16:40:49 +0000 | [diff] [blame] | 206 | CreatedOutput = true; |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Chris Lattner | a5a96a9 | 2003-10-14 20:52:55 +0000 | [diff] [blame] | 209 | // Make sure the reference output file gets deleted on exit from this |
| 210 | // function, if appropriate. |
Rafael Espindola | 3b9eb80 | 2013-06-18 16:21:54 +0000 | [diff] [blame] | 211 | std::string ROF(ReferenceOutputFile); |
| 212 | FileRemover RemoverInstance(ROF, CreatedOutput && !SaveTemps); |
Chris Lattner | a5a96a9 | 2003-10-14 20:52:55 +0000 | [diff] [blame] | 213 | |
| 214 | // Diff the output of the raw program against the reference output. If it |
Michael J. Spencer | 56584fc | 2011-03-31 13:06:39 +0000 | [diff] [blame] | 215 | // matches, then we assume there is a miscompilation bug and try to |
Patrick Jenkins | 6a3f31c | 2006-08-15 16:40:49 +0000 | [diff] [blame] | 216 | // diagnose it. |
Dan Gohman | ac95cc7 | 2009-07-16 15:30:09 +0000 | [diff] [blame] | 217 | outs() << "*** Checking the code generator...\n"; |
Rafael Espindola | cdac12c | 2018-02-14 21:44:34 +0000 | [diff] [blame] | 218 | Expected<bool> Diff = diffProgram(*Program, "", "", false); |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 219 | if (Error E = Diff.takeError()) { |
| 220 | errs() << toString(std::move(E)); |
| 221 | return debugCodeGeneratorCrash(); |
Nick Lewycky | 22ff748 | 2010-04-12 05:08:25 +0000 | [diff] [blame] | 222 | } |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 223 | if (!*Diff) { |
Nick Lewycky | 22ff748 | 2010-04-12 05:08:25 +0000 | [diff] [blame] | 224 | outs() << "\n*** Output matches: Debugging miscompilation!\n"; |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 225 | if (Error E = debugMiscompilation()) { |
| 226 | errs() << toString(std::move(E)); |
| 227 | return debugCodeGeneratorCrash(); |
Chris Lattner | 0252626 | 2004-02-18 21:02:04 +0000 | [diff] [blame] | 228 | } |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 229 | return Error::success(); |
Chris Lattner | a5a96a9 | 2003-10-14 20:52:55 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Dan Gohman | ac95cc7 | 2009-07-16 15:30:09 +0000 | [diff] [blame] | 232 | outs() << "\n*** Input program does not match reference diff!\n"; |
| 233 | outs() << "Debugging code generator problem!\n"; |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 234 | if (Error E = debugCodeGenerator()) { |
| 235 | errs() << toString(std::move(E)); |
| 236 | return debugCodeGeneratorCrash(); |
Chris Lattner | 7c955fd | 2004-02-19 17:03:49 +0000 | [diff] [blame] | 237 | } |
Justin Bogner | d8090ae | 2016-09-06 17:18:22 +0000 | [diff] [blame] | 238 | return Error::success(); |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Justin Bogner | 388e8b9 | 2016-09-02 01:21:37 +0000 | [diff] [blame] | 241 | void llvm::PrintFunctionList(const std::vector<Function *> &Funcs) { |
Chris Lattner | efdc0b5 | 2004-03-14 20:50:42 +0000 | [diff] [blame] | 242 | unsigned NumPrint = Funcs.size(); |
Justin Bogner | 388e8b9 | 2016-09-02 01:21:37 +0000 | [diff] [blame] | 243 | if (NumPrint > 10) |
| 244 | NumPrint = 10; |
Chris Lattner | efdc0b5 | 2004-03-14 20:50:42 +0000 | [diff] [blame] | 245 | for (unsigned i = 0; i != NumPrint; ++i) |
Dan Gohman | ac95cc7 | 2009-07-16 15:30:09 +0000 | [diff] [blame] | 246 | outs() << " " << Funcs[i]->getName(); |
Chris Lattner | efdc0b5 | 2004-03-14 20:50:42 +0000 | [diff] [blame] | 247 | if (NumPrint < Funcs.size()) |
Dan Gohman | ac95cc7 | 2009-07-16 15:30:09 +0000 | [diff] [blame] | 248 | outs() << "... <" << Funcs.size() << " total>"; |
| 249 | outs().flush(); |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 250 | } |
Bill Wendling | 4e3be89 | 2006-10-25 18:36:14 +0000 | [diff] [blame] | 251 | |
Justin Bogner | 388e8b9 | 2016-09-02 01:21:37 +0000 | [diff] [blame] | 252 | void llvm::PrintGlobalVariableList(const std::vector<GlobalVariable *> &GVs) { |
Bill Wendling | 4e3be89 | 2006-10-25 18:36:14 +0000 | [diff] [blame] | 253 | unsigned NumPrint = GVs.size(); |
Justin Bogner | 388e8b9 | 2016-09-02 01:21:37 +0000 | [diff] [blame] | 254 | if (NumPrint > 10) |
| 255 | NumPrint = 10; |
Bill Wendling | 4e3be89 | 2006-10-25 18:36:14 +0000 | [diff] [blame] | 256 | for (unsigned i = 0; i != NumPrint; ++i) |
Dan Gohman | ac95cc7 | 2009-07-16 15:30:09 +0000 | [diff] [blame] | 257 | outs() << " " << GVs[i]->getName(); |
Bill Wendling | 4e3be89 | 2006-10-25 18:36:14 +0000 | [diff] [blame] | 258 | if (NumPrint < GVs.size()) |
Dan Gohman | ac95cc7 | 2009-07-16 15:30:09 +0000 | [diff] [blame] | 259 | outs() << "... <" << GVs.size() << " total>"; |
| 260 | outs().flush(); |
Bill Wendling | 4e3be89 | 2006-10-25 18:36:14 +0000 | [diff] [blame] | 261 | } |