blob: b578202402ae6bd56542a6442bfa790966b7ba1e [file] [log] [blame]
Chris Lattner4a106452002-12-23 23:50:16 +00001//===- Miscompilation.cpp - Debug program miscompilations -----------------===//
John Criswell7c0e0222003-10-20 17:47:21 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner4a106452002-12-23 23:50:16 +00009//
Chris Lattnera57d86b2004-04-05 22:58:16 +000010// This file implements optimizer and code generation miscompilation debugging
11// support.
Chris Lattner4a106452002-12-23 23:50:16 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "BugDriver.h"
Chris Lattner126840f2003-04-24 20:16:29 +000016#include "ListReducer.h"
Chris Lattnera57d86b2004-04-05 22:58:16 +000017#include "llvm/Constants.h"
18#include "llvm/DerivedTypes.h"
19#include "llvm/Instructions.h"
Reid Spencer605b9e22004-11-14 23:00:08 +000020#include "llvm/Linker.h"
Chris Lattner4a106452002-12-23 23:50:16 +000021#include "llvm/Module.h"
Misha Brukmane49603d2003-08-07 21:19:30 +000022#include "llvm/Pass.h"
Chris Lattnera57d86b2004-04-05 22:58:16 +000023#include "llvm/Analysis/Verifier.h"
24#include "llvm/Support/Mangler.h"
Chris Lattner640f22e2003-04-24 17:02:17 +000025#include "llvm/Transforms/Utils/Cloning.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000026#include "llvm/Support/CommandLine.h"
27#include "llvm/Support/FileUtilities.h"
Chris Lattnerfa761832004-01-14 03:38:37 +000028using namespace llvm;
Chris Lattner4a106452002-12-23 23:50:16 +000029
Chris Lattnera57d86b2004-04-05 22:58:16 +000030namespace llvm {
31 extern cl::list<std::string> InputArgv;
32}
33
Chris Lattnerefdc0b52004-03-14 20:50:42 +000034namespace {
Chris Lattnerfa761832004-01-14 03:38:37 +000035 class ReduceMiscompilingPasses : public ListReducer<const PassInfo*> {
36 BugDriver &BD;
37 public:
38 ReduceMiscompilingPasses(BugDriver &bd) : BD(bd) {}
39
40 virtual TestResult doTest(std::vector<const PassInfo*> &Prefix,
41 std::vector<const PassInfo*> &Suffix);
42 };
43}
Chris Lattner640f22e2003-04-24 17:02:17 +000044
Misha Brukman8c194ea2004-04-21 18:36:43 +000045/// TestResult - After passes have been split into a test group and a control
46/// group, see if they still break the program.
47///
Chris Lattner640f22e2003-04-24 17:02:17 +000048ReduceMiscompilingPasses::TestResult
Chris Lattner39aebca2003-04-24 22:24:22 +000049ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
Chris Lattner06943ad2003-04-25 03:16:05 +000050 std::vector<const PassInfo*> &Suffix) {
51 // First, run the program with just the Suffix passes. If it is still broken
Chris Lattner640f22e2003-04-24 17:02:17 +000052 // with JUST the kept passes, discard the prefix passes.
Chris Lattner06943ad2003-04-25 03:16:05 +000053 std::cout << "Checking to see if '" << getPassesString(Suffix)
Chris Lattner640f22e2003-04-24 17:02:17 +000054 << "' compile correctly: ";
55
56 std::string BytecodeResult;
Chris Lattner06943ad2003-04-25 03:16:05 +000057 if (BD.runPasses(Suffix, BytecodeResult, false/*delete*/, true/*quiet*/)) {
Chris Lattner9f71e792003-10-18 00:05:05 +000058 std::cerr << " Error running this sequence of passes"
Chris Lattner640f22e2003-04-24 17:02:17 +000059 << " on the input program!\n";
Chris Lattner5ef681c2003-10-17 23:07:47 +000060 BD.setPassesToRun(Suffix);
61 BD.EmitProgressBytecode("pass-error", false);
Chris Lattner02526262004-02-18 21:02:04 +000062 exit(BD.debugOptimizerCrash());
Chris Lattner640f22e2003-04-24 17:02:17 +000063 }
64
65 // Check to see if the finished program matches the reference output...
Misha Brukman50733362003-07-24 18:17:43 +000066 if (BD.diffProgram(BytecodeResult, "", true /*delete bytecode*/)) {
Misha Brukman123f8fe2004-04-22 20:02:09 +000067 std::cout << " nope.\n";
68 return KeepSuffix; // Miscompilation detected!
Chris Lattner640f22e2003-04-24 17:02:17 +000069 }
Misha Brukman123f8fe2004-04-22 20:02:09 +000070 std::cout << " yup.\n"; // No miscompilation!
Chris Lattner640f22e2003-04-24 17:02:17 +000071
72 if (Prefix.empty()) return NoFailure;
73
Chris Lattner06943ad2003-04-25 03:16:05 +000074 // Next, see if the program is broken if we run the "prefix" passes first,
Misha Brukmanbc0e9982003-07-14 17:20:40 +000075 // then separately run the "kept" passes.
Chris Lattner640f22e2003-04-24 17:02:17 +000076 std::cout << "Checking to see if '" << getPassesString(Prefix)
77 << "' compile correctly: ";
78
79 // If it is not broken with the kept passes, it's possible that the prefix
80 // passes must be run before the kept passes to break it. If the program
81 // WORKS after the prefix passes, but then fails if running the prefix AND
82 // kept passes, we can update our bytecode file to include the result of the
83 // prefix passes, then discard the prefix passes.
84 //
85 if (BD.runPasses(Prefix, BytecodeResult, false/*delete*/, true/*quiet*/)) {
Chris Lattner9f71e792003-10-18 00:05:05 +000086 std::cerr << " Error running this sequence of passes"
Chris Lattner640f22e2003-04-24 17:02:17 +000087 << " on the input program!\n";
Chris Lattner9c6cfe12003-10-17 23:03:16 +000088 BD.setPassesToRun(Prefix);
89 BD.EmitProgressBytecode("pass-error", false);
Chris Lattner02526262004-02-18 21:02:04 +000090 exit(BD.debugOptimizerCrash());
Chris Lattner640f22e2003-04-24 17:02:17 +000091 }
92
93 // If the prefix maintains the predicate by itself, only keep the prefix!
Misha Brukman50733362003-07-24 18:17:43 +000094 if (BD.diffProgram(BytecodeResult)) {
Misha Brukman123f8fe2004-04-22 20:02:09 +000095 std::cout << " nope.\n";
Chris Lattner640f22e2003-04-24 17:02:17 +000096 removeFile(BytecodeResult);
97 return KeepPrefix;
98 }
Misha Brukman123f8fe2004-04-22 20:02:09 +000099 std::cout << " yup.\n"; // No miscompilation!
Chris Lattner640f22e2003-04-24 17:02:17 +0000100
101 // Ok, so now we know that the prefix passes work, try running the suffix
102 // passes on the result of the prefix passes.
103 //
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000104 Module *PrefixOutput = ParseInputFile(BytecodeResult);
Chris Lattner640f22e2003-04-24 17:02:17 +0000105 if (PrefixOutput == 0) {
106 std::cerr << BD.getToolName() << ": Error reading bytecode file '"
107 << BytecodeResult << "'!\n";
108 exit(1);
109 }
110 removeFile(BytecodeResult); // No longer need the file on disk
Chris Lattnerf4789e62004-04-23 20:36:51 +0000111
112 // Don't check if there are no passes in the suffix.
113 if (Suffix.empty())
114 return NoFailure;
115
Chris Lattner06943ad2003-04-25 03:16:05 +0000116 std::cout << "Checking to see if '" << getPassesString(Suffix)
Chris Lattner640f22e2003-04-24 17:02:17 +0000117 << "' passes compile correctly after the '"
118 << getPassesString(Prefix) << "' passes: ";
119
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000120 Module *OriginalInput = BD.swapProgramIn(PrefixOutput);
Chris Lattner06943ad2003-04-25 03:16:05 +0000121 if (BD.runPasses(Suffix, BytecodeResult, false/*delete*/, true/*quiet*/)) {
Chris Lattner9f71e792003-10-18 00:05:05 +0000122 std::cerr << " Error running this sequence of passes"
Chris Lattner640f22e2003-04-24 17:02:17 +0000123 << " on the input program!\n";
Chris Lattner5ef681c2003-10-17 23:07:47 +0000124 BD.setPassesToRun(Suffix);
Chris Lattner9c6cfe12003-10-17 23:03:16 +0000125 BD.EmitProgressBytecode("pass-error", false);
Chris Lattner02526262004-02-18 21:02:04 +0000126 exit(BD.debugOptimizerCrash());
Chris Lattner640f22e2003-04-24 17:02:17 +0000127 }
128
129 // Run the result...
Misha Brukman50733362003-07-24 18:17:43 +0000130 if (BD.diffProgram(BytecodeResult, "", true/*delete bytecode*/)) {
Misha Brukman123f8fe2004-04-22 20:02:09 +0000131 std::cout << " nope.\n";
Chris Lattner640f22e2003-04-24 17:02:17 +0000132 delete OriginalInput; // We pruned down the original input...
Chris Lattner06943ad2003-04-25 03:16:05 +0000133 return KeepSuffix;
Chris Lattner640f22e2003-04-24 17:02:17 +0000134 }
135
136 // Otherwise, we must not be running the bad pass anymore.
Misha Brukman123f8fe2004-04-22 20:02:09 +0000137 std::cout << " yup.\n"; // No miscompilation!
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000138 delete BD.swapProgramIn(OriginalInput); // Restore orig program & free test
Chris Lattner640f22e2003-04-24 17:02:17 +0000139 return NoFailure;
140}
141
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000142namespace {
Chris Lattnerfa761832004-01-14 03:38:37 +0000143 class ReduceMiscompilingFunctions : public ListReducer<Function*> {
144 BugDriver &BD;
Chris Lattnerb15825b2004-04-05 21:37:38 +0000145 bool (*TestFn)(BugDriver &, Module *, Module *);
Chris Lattnerfa761832004-01-14 03:38:37 +0000146 public:
Chris Lattnerb15825b2004-04-05 21:37:38 +0000147 ReduceMiscompilingFunctions(BugDriver &bd,
148 bool (*F)(BugDriver &, Module *, Module *))
149 : BD(bd), TestFn(F) {}
Chris Lattnerfa761832004-01-14 03:38:37 +0000150
151 virtual TestResult doTest(std::vector<Function*> &Prefix,
152 std::vector<Function*> &Suffix) {
Chris Lattnerbe21ca52004-03-14 19:27:19 +0000153 if (!Suffix.empty() && TestFuncs(Suffix))
Chris Lattnerfa761832004-01-14 03:38:37 +0000154 return KeepSuffix;
Chris Lattnerbe21ca52004-03-14 19:27:19 +0000155 if (!Prefix.empty() && TestFuncs(Prefix))
Chris Lattnerfa761832004-01-14 03:38:37 +0000156 return KeepPrefix;
157 return NoFailure;
158 }
159
Chris Lattnerbe21ca52004-03-14 19:27:19 +0000160 bool TestFuncs(const std::vector<Function*> &Prefix);
Chris Lattnerfa761832004-01-14 03:38:37 +0000161 };
162}
Chris Lattner640f22e2003-04-24 17:02:17 +0000163
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000164/// TestMergedProgram - Given two modules, link them together and run the
165/// program, checking to see if the program matches the diff. If the diff
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000166/// matches, return false, otherwise return true. If the DeleteInputs argument
167/// is set to true then this function deletes both input modules before it
168/// returns.
Misha Brukman8c194ea2004-04-21 18:36:43 +0000169///
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000170static bool TestMergedProgram(BugDriver &BD, Module *M1, Module *M2,
171 bool DeleteInputs) {
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000172 // Link the two portions of the program back to together.
173 std::string ErrorMsg;
Chris Lattner90c18c52004-11-16 06:31:38 +0000174 if (!DeleteInputs) {
175 M1 = CloneModule(M1);
176 M2 = CloneModule(M2);
177 }
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000178 if (LinkModules(M1, M2, &ErrorMsg)) {
179 std::cerr << BD.getToolName() << ": Error linking modules together:"
Misha Brukmaneed80e22004-07-23 01:30:49 +0000180 << ErrorMsg << '\n';
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000181 exit(1);
182 }
Chris Lattner90c18c52004-11-16 06:31:38 +0000183 delete M2; // We are done with this module.
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000184
185 Module *OldProgram = BD.swapProgramIn(M1);
186
187 // Execute the program. If it does not match the expected output, we must
188 // return true.
189 bool Broken = BD.diffProgram();
190
191 // Delete the linked module & restore the original
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000192 BD.swapProgramIn(OldProgram);
Chris Lattner5313f232004-04-02 06:32:17 +0000193 delete M1;
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000194 return Broken;
195}
196
Misha Brukman8c194ea2004-04-21 18:36:43 +0000197/// TestFuncs - split functions in a Module into two groups: those that are
198/// under consideration for miscompilation vs. those that are not, and test
199/// accordingly. Each group of functions becomes a separate Module.
200///
Chris Lattnerbe21ca52004-03-14 19:27:19 +0000201bool ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function*>&Funcs){
Chris Lattner640f22e2003-04-24 17:02:17 +0000202 // Test to see if the function is misoptimized if we ONLY run it on the
203 // functions listed in Funcs.
Chris Lattnerbe21ca52004-03-14 19:27:19 +0000204 std::cout << "Checking to see if the program is misoptimized when "
205 << (Funcs.size()==1 ? "this function is" : "these functions are")
206 << " run through the pass"
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000207 << (BD.getPassesToRun().size() == 1 ? "" : "es") << ":";
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000208 PrintFunctionList(Funcs);
Misha Brukmaneed80e22004-07-23 01:30:49 +0000209 std::cout << '\n';
Chris Lattner640f22e2003-04-24 17:02:17 +0000210
Chris Lattnerbe21ca52004-03-14 19:27:19 +0000211 // Split the module into the two halves of the program we want.
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000212 Module *ToNotOptimize = CloneModule(BD.getProgram());
213 Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, Funcs);
Chris Lattner640f22e2003-04-24 17:02:17 +0000214
Chris Lattnerb15825b2004-04-05 21:37:38 +0000215 // Run the predicate, not that the predicate will delete both input modules.
216 return TestFn(BD, ToOptimize, ToNotOptimize);
Chris Lattner640f22e2003-04-24 17:02:17 +0000217}
218
Misha Brukman8c194ea2004-04-21 18:36:43 +0000219/// DisambiguateGlobalSymbols - Mangle symbols to guarantee uniqueness by
220/// modifying predominantly internal symbols rather than external ones.
221///
Chris Lattner36ee07f2004-04-11 23:52:35 +0000222static void DisambiguateGlobalSymbols(Module *M) {
223 // Try not to cause collisions by minimizing chances of renaming an
224 // already-external symbol, so take in external globals and functions as-is.
225 // The code should work correctly without disambiguation (assuming the same
226 // mangler is used by the two code generators), but having symbols with the
227 // same name causes warnings to be emitted by the code generator.
228 Mangler Mang(*M);
229 for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
230 I->setName(Mang.getValueName(I));
231 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
232 I->setName(Mang.getValueName(I));
233}
234
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000235/// ExtractLoops - Given a reduced list of functions that still exposed the bug,
236/// check to see if we can extract the loops in the region without obscuring the
237/// bug. If so, it reduces the amount of code identified.
Misha Brukman8c194ea2004-04-21 18:36:43 +0000238///
Chris Lattnerb15825b2004-04-05 21:37:38 +0000239static bool ExtractLoops(BugDriver &BD,
240 bool (*TestFn)(BugDriver &, Module *, Module *),
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000241 std::vector<Function*> &MiscompiledFunctions) {
242 bool MadeChange = false;
243 while (1) {
244 Module *ToNotOptimize = CloneModule(BD.getProgram());
245 Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
246 MiscompiledFunctions);
247 Module *ToOptimizeLoopExtracted = BD.ExtractLoop(ToOptimize);
248 if (!ToOptimizeLoopExtracted) {
249 // If the loop extractor crashed or if there were no extractible loops,
250 // then this chapter of our odyssey is over with.
251 delete ToNotOptimize;
252 delete ToOptimize;
253 return MadeChange;
254 }
255
256 std::cerr << "Extracted a loop from the breaking portion of the program.\n";
257 delete ToOptimize;
258
259 // Bugpoint is intentionally not very trusting of LLVM transformations. In
260 // particular, we're not going to assume that the loop extractor works, so
261 // we're going to test the newly loop extracted program to make sure nothing
262 // has broken. If something broke, then we'll inform the user and stop
263 // extraction.
Chris Lattnera57d86b2004-04-05 22:58:16 +0000264 AbstractInterpreter *AI = BD.switchToCBE();
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000265 if (TestMergedProgram(BD, ToOptimizeLoopExtracted, ToNotOptimize, false)) {
Chris Lattnera57d86b2004-04-05 22:58:16 +0000266 BD.switchToInterpreter(AI);
267
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000268 // Merged program doesn't work anymore!
269 std::cerr << " *** ERROR: Loop extraction broke the program. :("
270 << " Please report a bug!\n";
271 std::cerr << " Continuing on with un-loop-extracted version.\n";
272 delete ToNotOptimize;
273 delete ToOptimizeLoopExtracted;
274 return MadeChange;
275 }
Chris Lattnera57d86b2004-04-05 22:58:16 +0000276 BD.switchToInterpreter(AI);
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000277
Chris Lattnerb15825b2004-04-05 21:37:38 +0000278 std::cout << " Testing after loop extraction:\n";
279 // Clone modules, the tester function will free them.
280 Module *TOLEBackup = CloneModule(ToOptimizeLoopExtracted);
281 Module *TNOBackup = CloneModule(ToNotOptimize);
282 if (!TestFn(BD, ToOptimizeLoopExtracted, ToNotOptimize)) {
283 std::cout << "*** Loop extraction masked the problem. Undoing.\n";
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000284 // If the program is not still broken, then loop extraction did something
285 // that masked the error. Stop loop extraction now.
Chris Lattnerb15825b2004-04-05 21:37:38 +0000286 delete TOLEBackup;
287 delete TNOBackup;
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000288 return MadeChange;
289 }
Chris Lattnerb15825b2004-04-05 21:37:38 +0000290 ToOptimizeLoopExtracted = TOLEBackup;
291 ToNotOptimize = TNOBackup;
292
293 std::cout << "*** Loop extraction successful!\n";
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000294
Chris Lattner90c18c52004-11-16 06:31:38 +0000295 std::vector<std::pair<std::string, const FunctionType*> > MisCompFunctions;
296 for (Module::iterator I = ToOptimizeLoopExtracted->begin(),
297 E = ToOptimizeLoopExtracted->end(); I != E; ++I)
298 MisCompFunctions.push_back(std::make_pair(I->getName(),
299 I->getFunctionType()));
300
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000301 // Okay, great! Now we know that we extracted a loop and that loop
302 // extraction both didn't break the program, and didn't mask the problem.
303 // Replace the current program with the loop extracted version, and try to
304 // extract another loop.
305 std::string ErrorMsg;
306 if (LinkModules(ToNotOptimize, ToOptimizeLoopExtracted, &ErrorMsg)) {
307 std::cerr << BD.getToolName() << ": Error linking modules together:"
Misha Brukmaneed80e22004-07-23 01:30:49 +0000308 << ErrorMsg << '\n';
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000309 exit(1);
310 }
Chris Lattner90c18c52004-11-16 06:31:38 +0000311 delete ToOptimizeLoopExtracted;
Chris Lattnerd3a533d2004-03-17 17:42:09 +0000312
313 // All of the Function*'s in the MiscompiledFunctions list are in the old
Chris Lattner5313f232004-04-02 06:32:17 +0000314 // module. Update this list to include all of the functions in the
315 // optimized and loop extracted module.
316 MiscompiledFunctions.clear();
Chris Lattner90c18c52004-11-16 06:31:38 +0000317 for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) {
318 Function *NewF = ToNotOptimize->getFunction(MisCompFunctions[i].first,
319 MisCompFunctions[i].second);
320 assert(NewF && "Function not found??");
321 MiscompiledFunctions.push_back(NewF);
Chris Lattnerd3a533d2004-03-17 17:42:09 +0000322 }
323
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000324 BD.setNewProgram(ToNotOptimize);
325 MadeChange = true;
326 }
327}
328
Chris Lattner5e783ab2004-05-11 21:54:13 +0000329namespace {
330 class ReduceMiscompiledBlocks : public ListReducer<BasicBlock*> {
331 BugDriver &BD;
332 bool (*TestFn)(BugDriver &, Module *, Module *);
333 std::vector<Function*> FunctionsBeingTested;
334 public:
335 ReduceMiscompiledBlocks(BugDriver &bd,
336 bool (*F)(BugDriver &, Module *, Module *),
337 const std::vector<Function*> &Fns)
338 : BD(bd), TestFn(F), FunctionsBeingTested(Fns) {}
339
340 virtual TestResult doTest(std::vector<BasicBlock*> &Prefix,
341 std::vector<BasicBlock*> &Suffix) {
342 if (!Suffix.empty() && TestFuncs(Suffix))
343 return KeepSuffix;
344 if (TestFuncs(Prefix))
345 return KeepPrefix;
346 return NoFailure;
347 }
348
349 bool TestFuncs(const std::vector<BasicBlock*> &Prefix);
350 };
351}
352
353/// TestFuncs - Extract all blocks for the miscompiled functions except for the
354/// specified blocks. If the problem still exists, return true.
355///
356bool ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock*> &BBs) {
357 // Test to see if the function is misoptimized if we ONLY run it on the
358 // functions listed in Funcs.
Chris Lattner68bee932004-05-12 16:08:01 +0000359 std::cout << "Checking to see if the program is misoptimized when all ";
360 if (!BBs.empty()) {
361 std::cout << "but these " << BBs.size() << " blocks are extracted: ";
362 for (unsigned i = 0, e = BBs.size() < 10 ? BBs.size() : 10; i != e; ++i)
363 std::cout << BBs[i]->getName() << " ";
364 if (BBs.size() > 10) std::cout << "...";
365 } else {
366 std::cout << "blocks are extracted.";
367 }
Misha Brukmaneed80e22004-07-23 01:30:49 +0000368 std::cout << '\n';
Chris Lattner5e783ab2004-05-11 21:54:13 +0000369
370 // Split the module into the two halves of the program we want.
371 Module *ToNotOptimize = CloneModule(BD.getProgram());
372 Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
373 FunctionsBeingTested);
374
375 // Try the extraction. If it doesn't work, then the block extractor crashed
376 // or something, in which case bugpoint can't chase down this possibility.
377 if (Module *New = BD.ExtractMappedBlocksFromModule(BBs, ToOptimize)) {
378 delete ToOptimize;
379 // Run the predicate, not that the predicate will delete both input modules.
380 return TestFn(BD, New, ToNotOptimize);
381 }
382 delete ToOptimize;
383 delete ToNotOptimize;
384 return false;
385}
386
387
388/// ExtractBlocks - Given a reduced list of functions that still expose the bug,
389/// extract as many basic blocks from the region as possible without obscuring
390/// the bug.
391///
392static bool ExtractBlocks(BugDriver &BD,
393 bool (*TestFn)(BugDriver &, Module *, Module *),
394 std::vector<Function*> &MiscompiledFunctions) {
Chris Lattner5e783ab2004-05-11 21:54:13 +0000395 std::vector<BasicBlock*> Blocks;
396 for (unsigned i = 0, e = MiscompiledFunctions.size(); i != e; ++i)
397 for (Function::iterator I = MiscompiledFunctions[i]->begin(),
398 E = MiscompiledFunctions[i]->end(); I != E; ++I)
399 Blocks.push_back(I);
400
401 // Use the list reducer to identify blocks that can be extracted without
402 // obscuring the bug. The Blocks list will end up containing blocks that must
403 // be retained from the original program.
404 unsigned OldSize = Blocks.size();
Chris Lattner68bee932004-05-12 16:08:01 +0000405
406 // Check to see if all blocks are extractible first.
407 if (ReduceMiscompiledBlocks(BD, TestFn,
408 MiscompiledFunctions).TestFuncs(std::vector<BasicBlock*>())) {
409 Blocks.clear();
410 } else {
411 ReduceMiscompiledBlocks(BD, TestFn,MiscompiledFunctions).reduceList(Blocks);
412 if (Blocks.size() == OldSize)
413 return false;
414 }
Chris Lattner5e783ab2004-05-11 21:54:13 +0000415
Chris Lattner2290e752004-05-12 02:43:24 +0000416 Module *ProgClone = CloneModule(BD.getProgram());
417 Module *ToExtract = SplitFunctionsOutOfModule(ProgClone,
418 MiscompiledFunctions);
419 Module *Extracted = BD.ExtractMappedBlocksFromModule(Blocks, ToExtract);
420 if (Extracted == 0) {
421 // Wierd, extraction should have worked.
422 std::cerr << "Nondeterministic problem extracting blocks??\n";
423 delete ProgClone;
424 delete ToExtract;
425 return false;
426 }
Chris Lattner5e783ab2004-05-11 21:54:13 +0000427
Chris Lattner2290e752004-05-12 02:43:24 +0000428 // Otherwise, block extraction succeeded. Link the two program fragments back
429 // together.
430 delete ToExtract;
Chris Lattner5e783ab2004-05-11 21:54:13 +0000431
Chris Lattner90c18c52004-11-16 06:31:38 +0000432 std::vector<std::pair<std::string, const FunctionType*> > MisCompFunctions;
433 for (Module::iterator I = Extracted->begin(), E = Extracted->end();
434 I != E; ++I)
435 MisCompFunctions.push_back(std::make_pair(I->getName(),
436 I->getFunctionType()));
437
Chris Lattner2290e752004-05-12 02:43:24 +0000438 std::string ErrorMsg;
439 if (LinkModules(ProgClone, Extracted, &ErrorMsg)) {
440 std::cerr << BD.getToolName() << ": Error linking modules together:"
Misha Brukmaneed80e22004-07-23 01:30:49 +0000441 << ErrorMsg << '\n';
Chris Lattner2290e752004-05-12 02:43:24 +0000442 exit(1);
443 }
Chris Lattner90c18c52004-11-16 06:31:38 +0000444 delete Extracted;
Chris Lattner5e783ab2004-05-11 21:54:13 +0000445
Chris Lattner2290e752004-05-12 02:43:24 +0000446 // Set the new program and delete the old one.
447 BD.setNewProgram(ProgClone);
Chris Lattner5e783ab2004-05-11 21:54:13 +0000448
Chris Lattner2290e752004-05-12 02:43:24 +0000449 // Update the list of miscompiled functions.
450 MiscompiledFunctions.clear();
Chris Lattner5e783ab2004-05-11 21:54:13 +0000451
Chris Lattner90c18c52004-11-16 06:31:38 +0000452 for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) {
453 Function *NewF = ProgClone->getFunction(MisCompFunctions[i].first,
454 MisCompFunctions[i].second);
455 assert(NewF && "Function not found??");
456 MiscompiledFunctions.push_back(NewF);
457 }
Chris Lattner2290e752004-05-12 02:43:24 +0000458
459 return true;
Chris Lattner5e783ab2004-05-11 21:54:13 +0000460}
461
462
Chris Lattnerb15825b2004-04-05 21:37:38 +0000463/// DebugAMiscompilation - This is a generic driver to narrow down
464/// miscompilations, either in an optimization or a code generator.
Misha Brukman8c194ea2004-04-21 18:36:43 +0000465///
Chris Lattnerb15825b2004-04-05 21:37:38 +0000466static std::vector<Function*>
467DebugAMiscompilation(BugDriver &BD,
468 bool (*TestFn)(BugDriver &, Module *, Module *)) {
469 // Okay, now that we have reduced the list of passes which are causing the
470 // failure, see if we can pin down which functions are being
471 // miscompiled... first build a list of all of the non-external functions in
472 // the program.
473 std::vector<Function*> MiscompiledFunctions;
474 Module *Prog = BD.getProgram();
475 for (Module::iterator I = Prog->begin(), E = Prog->end(); I != E; ++I)
476 if (!I->isExternal())
477 MiscompiledFunctions.push_back(I);
478
479 // Do the reduction...
480 ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions);
481
482 std::cout << "\n*** The following function"
483 << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
484 << " being miscompiled: ";
485 PrintFunctionList(MiscompiledFunctions);
Misha Brukmaneed80e22004-07-23 01:30:49 +0000486 std::cout << '\n';
Chris Lattnerb15825b2004-04-05 21:37:38 +0000487
488 // See if we can rip any loops out of the miscompiled functions and still
489 // trigger the problem.
490 if (ExtractLoops(BD, TestFn, MiscompiledFunctions)) {
491 // Okay, we extracted some loops and the problem still appears. See if we
492 // can eliminate some of the created functions from being candidates.
493
Chris Lattner36ee07f2004-04-11 23:52:35 +0000494 // Loop extraction can introduce functions with the same name (foo_code).
495 // Make sure to disambiguate the symbols so that when the program is split
496 // apart that we can link it back together again.
497 DisambiguateGlobalSymbols(BD.getProgram());
498
Chris Lattnerb15825b2004-04-05 21:37:38 +0000499 // Do the reduction...
500 ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions);
501
502 std::cout << "\n*** The following function"
503 << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
504 << " being miscompiled: ";
505 PrintFunctionList(MiscompiledFunctions);
Misha Brukmaneed80e22004-07-23 01:30:49 +0000506 std::cout << '\n';
Chris Lattnerb15825b2004-04-05 21:37:38 +0000507 }
508
Chris Lattner5e783ab2004-05-11 21:54:13 +0000509 if (ExtractBlocks(BD, TestFn, MiscompiledFunctions)) {
510 // Okay, we extracted some blocks and the problem still appears. See if we
511 // can eliminate some of the created functions from being candidates.
512
513 // Block extraction can introduce functions with the same name (foo_code).
514 // Make sure to disambiguate the symbols so that when the program is split
515 // apart that we can link it back together again.
516 DisambiguateGlobalSymbols(BD.getProgram());
517
518 // Do the reduction...
519 ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions);
520
521 std::cout << "\n*** The following function"
522 << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
523 << " being miscompiled: ";
524 PrintFunctionList(MiscompiledFunctions);
Misha Brukmaneed80e22004-07-23 01:30:49 +0000525 std::cout << '\n';
Chris Lattner5e783ab2004-05-11 21:54:13 +0000526 }
527
Chris Lattnerb15825b2004-04-05 21:37:38 +0000528 return MiscompiledFunctions;
529}
530
Chris Lattnera57d86b2004-04-05 22:58:16 +0000531/// TestOptimizer - This is the predicate function used to check to see if the
532/// "Test" portion of the program is misoptimized. If so, return true. In any
533/// case, both module arguments are deleted.
Misha Brukman8c194ea2004-04-21 18:36:43 +0000534///
Chris Lattnerb15825b2004-04-05 21:37:38 +0000535static bool TestOptimizer(BugDriver &BD, Module *Test, Module *Safe) {
536 // Run the optimization passes on ToOptimize, producing a transformed version
537 // of the functions being tested.
538 std::cout << " Optimizing functions being tested: ";
539 Module *Optimized = BD.runPassesOn(Test, BD.getPassesToRun(),
540 /*AutoDebugCrashes*/true);
541 std::cout << "done.\n";
542 delete Test;
543
544 std::cout << " Checking to see if the merged program executes correctly: ";
Chris Lattner2423db02004-04-09 22:28:33 +0000545 bool Broken = TestMergedProgram(BD, Optimized, Safe, true);
Chris Lattnerb15825b2004-04-05 21:37:38 +0000546 std::cout << (Broken ? " nope.\n" : " yup.\n");
547 return Broken;
548}
549
550
Chris Lattner4a106452002-12-23 23:50:16 +0000551/// debugMiscompilation - This method is used when the passes selected are not
552/// crashing, but the generated output is semantically different from the
553/// input.
554///
555bool BugDriver::debugMiscompilation() {
Chris Lattner4a106452002-12-23 23:50:16 +0000556 // Make sure something was miscompiled...
Misha Brukmanbe6bf562003-07-30 20:15:56 +0000557 if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) {
Chris Lattner4a106452002-12-23 23:50:16 +0000558 std::cerr << "*** Optimized program matches reference output! No problem "
559 << "detected...\nbugpoint can't help you with your problem!\n";
560 return false;
561 }
562
Chris Lattner640f22e2003-04-24 17:02:17 +0000563 std::cout << "\n*** Found miscompiling pass"
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000564 << (getPassesToRun().size() == 1 ? "" : "es") << ": "
Misha Brukmaneed80e22004-07-23 01:30:49 +0000565 << getPassesString(getPassesToRun()) << '\n';
Chris Lattner640f22e2003-04-24 17:02:17 +0000566 EmitProgressBytecode("passinput");
Chris Lattner4a106452002-12-23 23:50:16 +0000567
Chris Lattnerb15825b2004-04-05 21:37:38 +0000568 std::vector<Function*> MiscompiledFunctions =
569 DebugAMiscompilation(*this, TestOptimizer);
Chris Lattnera1cf1c82004-03-14 22:08:00 +0000570
Chris Lattner640f22e2003-04-24 17:02:17 +0000571 // Output a bunch of bytecode files for the user...
Chris Lattnerbe21ca52004-03-14 19:27:19 +0000572 std::cout << "Outputting reduced bytecode files which expose the problem:\n";
Chris Lattnerefdc0b52004-03-14 20:50:42 +0000573 Module *ToNotOptimize = CloneModule(getProgram());
574 Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
575 MiscompiledFunctions);
Chris Lattnerbe21ca52004-03-14 19:27:19 +0000576
577 std::cout << " Non-optimized portion: ";
Chris Lattnerb15825b2004-04-05 21:37:38 +0000578 ToNotOptimize = swapProgramIn(ToNotOptimize);
Chris Lattnerbe21ca52004-03-14 19:27:19 +0000579 EmitProgressBytecode("tonotoptimize", true);
580 setNewProgram(ToNotOptimize); // Delete hacked module.
581
582 std::cout << " Portion that is input to optimizer: ";
Chris Lattnerb15825b2004-04-05 21:37:38 +0000583 ToOptimize = swapProgramIn(ToOptimize);
Chris Lattnerbe21ca52004-03-14 19:27:19 +0000584 EmitProgressBytecode("tooptimize");
585 setNewProgram(ToOptimize); // Delete hacked module.
Chris Lattner4a106452002-12-23 23:50:16 +0000586
Chris Lattner4a106452002-12-23 23:50:16 +0000587 return false;
588}
Brian Gaeked0fde302003-11-11 22:41:34 +0000589
Chris Lattnera57d86b2004-04-05 22:58:16 +0000590/// CleanupAndPrepareModules - Get the specified modules ready for code
591/// generator testing.
Misha Brukman8c194ea2004-04-21 18:36:43 +0000592///
Chris Lattnera57d86b2004-04-05 22:58:16 +0000593static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
594 Module *Safe) {
595 // Clean up the modules, removing extra cruft that we don't need anymore...
596 Test = BD.performFinalCleanups(Test);
597
598 // If we are executing the JIT, we have several nasty issues to take care of.
599 if (!BD.isExecutingJIT()) return;
600
601 // First, if the main function is in the Safe module, we must add a stub to
602 // the Test module to call into it. Thus, we create a new function `main'
603 // which just calls the old one.
604 if (Function *oldMain = Safe->getNamedFunction("main"))
605 if (!oldMain->isExternal()) {
606 // Rename it
607 oldMain->setName("llvm_bugpoint_old_main");
608 // Create a NEW `main' function with same type in the test module.
609 Function *newMain = new Function(oldMain->getFunctionType(),
610 GlobalValue::ExternalLinkage,
611 "main", Test);
612 // Create an `oldmain' prototype in the test module, which will
613 // corresponds to the real main function in the same module.
614 Function *oldMainProto = new Function(oldMain->getFunctionType(),
615 GlobalValue::ExternalLinkage,
616 oldMain->getName(), Test);
617 // Set up and remember the argument list for the main function.
618 std::vector<Value*> args;
619 for (Function::aiterator I = newMain->abegin(), E = newMain->aend(),
620 OI = oldMain->abegin(); I != E; ++I, ++OI) {
621 I->setName(OI->getName()); // Copy argument names from oldMain
622 args.push_back(I);
623 }
624
625 // Call the old main function and return its result
626 BasicBlock *BB = new BasicBlock("entry", newMain);
627 CallInst *call = new CallInst(oldMainProto, args);
628 BB->getInstList().push_back(call);
629
630 // If the type of old function wasn't void, return value of call
631 new ReturnInst(oldMain->getReturnType() != Type::VoidTy ? call : 0, BB);
632 }
633
634 // The second nasty issue we must deal with in the JIT is that the Safe
635 // module cannot directly reference any functions defined in the test
636 // module. Instead, we use a JIT API call to dynamically resolve the
637 // symbol.
638
639 // Add the resolver to the Safe module.
640 // Prototype: void *getPointerToNamedFunction(const char* Name)
641 Function *resolverFunc =
642 Safe->getOrInsertFunction("getPointerToNamedFunction",
643 PointerType::get(Type::SByteTy),
644 PointerType::get(Type::SByteTy), 0);
645
646 // Use the function we just added to get addresses of functions we need.
Misha Brukmandc7fef82004-04-19 01:12:01 +0000647 for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) {
Chris Lattnera57d86b2004-04-05 22:58:16 +0000648 if (F->isExternal() && !F->use_empty() && &*F != resolverFunc &&
649 F->getIntrinsicID() == 0 /* ignore intrinsics */) {
Misha Brukmandc7fef82004-04-19 01:12:01 +0000650 Function *TestFn = Test->getFunction(F->getName(), F->getFunctionType());
Chris Lattnera57d86b2004-04-05 22:58:16 +0000651
652 // Don't forward functions which are external in the test module too.
653 if (TestFn && !TestFn->isExternal()) {
654 // 1. Add a string constant with its name to the global file
655 Constant *InitArray = ConstantArray::get(F->getName());
656 GlobalVariable *funcName =
657 new GlobalVariable(InitArray->getType(), true /*isConstant*/,
658 GlobalValue::InternalLinkage, InitArray,
659 F->getName() + "_name", Safe);
660
661 // 2. Use `GetElementPtr *funcName, 0, 0' to convert the string to an
662 // sbyte* so it matches the signature of the resolver function.
663
664 // GetElementPtr *funcName, ulong 0, ulong 0
665 std::vector<Constant*> GEPargs(2,Constant::getNullValue(Type::IntTy));
666 Value *GEP =
Reid Spencer518310c2004-07-18 00:44:37 +0000667 ConstantExpr::getGetElementPtr(funcName, GEPargs);
Chris Lattnera57d86b2004-04-05 22:58:16 +0000668 std::vector<Value*> ResolverArgs;
669 ResolverArgs.push_back(GEP);
670
Misha Brukmande4803d2004-04-19 03:36:47 +0000671 // Rewrite uses of F in global initializers, etc. to uses of a wrapper
672 // function that dynamically resolves the calls to F via our JIT API
673 if (F->use_begin() != F->use_end()) {
674 // Construct a new stub function that will re-route calls to F
Misha Brukmandc7fef82004-04-19 01:12:01 +0000675 const FunctionType *FuncTy = F->getFunctionType();
Misha Brukmande4803d2004-04-19 03:36:47 +0000676 Function *FuncWrapper = new Function(FuncTy,
677 GlobalValue::InternalLinkage,
Misha Brukmandc7fef82004-04-19 01:12:01 +0000678 F->getName() + "_wrapper",
679 F->getParent());
680 BasicBlock *Header = new BasicBlock("header", FuncWrapper);
681
Misha Brukmande4803d2004-04-19 03:36:47 +0000682 // Resolve the call to function F via the JIT API:
683 //
684 // call resolver(GetElementPtr...)
685 CallInst *resolve = new CallInst(resolverFunc, ResolverArgs,
686 "resolver");
687 Header->getInstList().push_back(resolve);
688 // cast the result from the resolver to correctly-typed function
689 CastInst *castResolver =
690 new CastInst(resolve, PointerType::get(F->getFunctionType()),
691 "resolverCast");
692 Header->getInstList().push_back(castResolver);
693
Misha Brukmandc7fef82004-04-19 01:12:01 +0000694 // Save the argument list
695 std::vector<Value*> Args;
696 for (Function::aiterator i = FuncWrapper->abegin(),
697 e = FuncWrapper->aend(); i != e; ++i)
698 Args.push_back(i);
699
700 // Pass on the arguments to the real function, return its result
701 if (F->getReturnType() == Type::VoidTy) {
Misha Brukmande4803d2004-04-19 03:36:47 +0000702 CallInst *Call = new CallInst(castResolver, Args);
Misha Brukmandc7fef82004-04-19 01:12:01 +0000703 Header->getInstList().push_back(Call);
704 ReturnInst *Ret = new ReturnInst();
705 Header->getInstList().push_back(Ret);
706 } else {
Misha Brukmande4803d2004-04-19 03:36:47 +0000707 CallInst *Call = new CallInst(castResolver, Args, "redir");
Misha Brukmandc7fef82004-04-19 01:12:01 +0000708 Header->getInstList().push_back(Call);
709 ReturnInst *Ret = new ReturnInst(Call);
710 Header->getInstList().push_back(Ret);
711 }
712
Misha Brukmande4803d2004-04-19 03:36:47 +0000713 // Use the wrapper function instead of the old function
714 F->replaceAllUsesWith(FuncWrapper);
Misha Brukmandc7fef82004-04-19 01:12:01 +0000715 }
Chris Lattnera57d86b2004-04-05 22:58:16 +0000716 }
717 }
718 }
719
720 if (verifyModule(*Test) || verifyModule(*Safe)) {
721 std::cerr << "Bugpoint has a bug, which corrupted a module!!\n";
722 abort();
723 }
724}
725
726
727
728/// TestCodeGenerator - This is the predicate function used to check to see if
729/// the "Test" portion of the program is miscompiled by the code generator under
730/// test. If so, return true. In any case, both module arguments are deleted.
Misha Brukman8c194ea2004-04-21 18:36:43 +0000731///
Chris Lattnera57d86b2004-04-05 22:58:16 +0000732static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe) {
733 CleanupAndPrepareModules(BD, Test, Safe);
734
735 std::string TestModuleBC = getUniqueFilename("bugpoint.test.bc");
736 if (BD.writeProgramToFile(TestModuleBC, Test)) {
737 std::cerr << "Error writing bytecode to `" << TestModuleBC << "'\nExiting.";
738 exit(1);
739 }
740 delete Test;
741
742 // Make the shared library
743 std::string SafeModuleBC = getUniqueFilename("bugpoint.safe.bc");
744
745 if (BD.writeProgramToFile(SafeModuleBC, Safe)) {
746 std::cerr << "Error writing bytecode to `" << SafeModuleBC << "'\nExiting.";
747 exit(1);
748 }
749 std::string SharedObject = BD.compileSharedObject(SafeModuleBC);
750 delete Safe;
751
752 // Run the code generator on the `Test' code, loading the shared library.
753 // The function returns whether or not the new output differs from reference.
754 int Result = BD.diffProgram(TestModuleBC, SharedObject, false);
755
756 if (Result)
757 std::cerr << ": still failing!\n";
758 else
759 std::cerr << ": didn't fail.\n";
760 removeFile(TestModuleBC);
761 removeFile(SafeModuleBC);
762 removeFile(SharedObject);
763
764 return Result;
765}
766
767
Misha Brukman8c194ea2004-04-21 18:36:43 +0000768/// debugCodeGenerator - debug errors in LLC, LLI, or CBE.
769///
Chris Lattnera57d86b2004-04-05 22:58:16 +0000770bool BugDriver::debugCodeGenerator() {
771 if ((void*)cbe == (void*)Interpreter) {
772 std::string Result = executeProgramWithCBE("bugpoint.cbe.out");
773 std::cout << "\n*** The C backend cannot match the reference diff, but it "
774 << "is used as the 'known good'\n code generator, so I can't"
775 << " debug it. Perhaps you have a front-end problem?\n As a"
776 << " sanity check, I left the result of executing the program "
777 << "with the C backend\n in this file for you: '"
778 << Result << "'.\n";
779 return true;
780 }
781
782 DisambiguateGlobalSymbols(Program);
783
784 std::vector<Function*> Funcs = DebugAMiscompilation(*this, TestCodeGenerator);
785
786 // Split the module into the two halves of the program we want.
787 Module *ToNotCodeGen = CloneModule(getProgram());
788 Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs);
789
790 // Condition the modules
791 CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen);
792
793 std::string TestModuleBC = getUniqueFilename("bugpoint.test.bc");
794 if (writeProgramToFile(TestModuleBC, ToCodeGen)) {
795 std::cerr << "Error writing bytecode to `" << TestModuleBC << "'\nExiting.";
796 exit(1);
797 }
798 delete ToCodeGen;
799
800 // Make the shared library
801 std::string SafeModuleBC = getUniqueFilename("bugpoint.safe.bc");
802 if (writeProgramToFile(SafeModuleBC, ToNotCodeGen)) {
803 std::cerr << "Error writing bytecode to `" << SafeModuleBC << "'\nExiting.";
804 exit(1);
805 }
806 std::string SharedObject = compileSharedObject(SafeModuleBC);
807 delete ToNotCodeGen;
808
809 std::cout << "You can reproduce the problem with the command line: \n";
810 if (isExecutingJIT()) {
811 std::cout << " lli -load " << SharedObject << " " << TestModuleBC;
812 } else {
813 std::cout << " llc " << TestModuleBC << " -o " << TestModuleBC << ".s\n";
814 std::cout << " gcc " << SharedObject << " " << TestModuleBC
815 << ".s -o " << TestModuleBC << ".exe -Wl,-R.\n";
816 std::cout << " " << TestModuleBC << ".exe";
817 }
818 for (unsigned i=0, e = InputArgv.size(); i != e; ++i)
819 std::cout << " " << InputArgv[i];
Misha Brukmaneed80e22004-07-23 01:30:49 +0000820 std::cout << '\n';
Chris Lattnera57d86b2004-04-05 22:58:16 +0000821 std::cout << "The shared object was created with:\n llc -march=c "
822 << SafeModuleBC << " -o temporary.c\n"
823 << " gcc -xc temporary.c -O2 -o " << SharedObject
824#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
825 << " -G" // Compile a shared library, `-G' for Sparc
826#else
827 << " -shared" // `-shared' for Linux/X86, maybe others
828#endif
829 << " -fno-strict-aliasing\n";
830
831 return false;
832}