blob: a5b0511fd980fd0735d6e6fb89976524bc463272 [file] [log] [blame]
Chris Lattner76351aa2004-04-02 05:06:57 +00001//===- opt.cpp - The LLVM Modular Optimizer -------------------------------===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
John Criswell7c0e0222003-10-20 17:47:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner21c62da2007-12-29 20:44:31 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman3da94ae2005-04-22 00:00:37 +00007//
John Criswell7c0e0222003-10-20 17:47:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner00950542001-06-06 20:29:01 +00009//
Chris Lattner00950542001-06-06 20:29:01 +000010// Optimizations may be specified an arbitrary number of times on the command
Reid Spencerfd90dd52006-08-18 06:34:30 +000011// line, They are run in the order specified.
Chris Lattner00950542001-06-06 20:29:01 +000012//
Chris Lattner0eafc312001-10-18 06:05:15 +000013//===----------------------------------------------------------------------===//
Chris Lattner00950542001-06-06 20:29:01 +000014
Owen Anderson8b477ed2009-07-01 16:58:40 +000015#include "llvm/LLVMContext.h"
Chris Lattner00950542001-06-06 20:29:01 +000016#include "llvm/Module.h"
Chris Lattnerfb1b3f12002-01-31 00:47:12 +000017#include "llvm/PassManager.h"
Devang Patel28552da2007-06-28 23:09:25 +000018#include "llvm/CallGraphSCCPass.h"
Chris Lattnerb330e382007-05-06 02:42:03 +000019#include "llvm/Bitcode/ReaderWriter.h"
Chris Lattnerffa6f9c2001-10-19 15:39:14 +000020#include "llvm/Assembly/PrintModulePass.h"
Devang Patelf5f23002010-12-07 00:33:43 +000021#include "llvm/Analysis/DebugInfo.h"
Chris Lattner22d26d72002-02-20 17:56:53 +000022#include "llvm/Analysis/Verifier.h"
Devang Patel1bc89362007-03-07 00:26:10 +000023#include "llvm/Analysis/LoopPass.h"
Tobias Grosser65513602010-10-20 01:54:44 +000024#include "llvm/Analysis/RegionPass.h"
Devang Patel28552da2007-06-28 23:09:25 +000025#include "llvm/Analysis/CallGraph.h"
Owen Anderson07000c62006-05-12 06:33:49 +000026#include "llvm/Target/TargetData.h"
Chris Lattner2a66aca2011-02-18 22:13:01 +000027#include "llvm/Target/TargetLibraryInfo.h"
Vikram S. Adve18fdfc42002-09-16 16:09:43 +000028#include "llvm/Target/TargetMachine.h"
Devang Patel1be99802011-04-04 19:51:17 +000029#include "llvm/ADT/StringSet.h"
Chris Lattner2a66aca2011-02-18 22:13:01 +000030#include "llvm/ADT/Triple.h"
Chris Lattner2053a2a2002-07-26 21:09:32 +000031#include "llvm/Support/PassNameParser.h"
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000032#include "llvm/Support/Signals.h"
David Greene08fc0d32010-01-05 01:30:32 +000033#include "llvm/Support/Debug.h"
Dan Gohman99ed4162009-09-03 16:00:08 +000034#include "llvm/Support/IRReader.h"
Chris Lattnerc30598b2006-12-06 01:18:01 +000035#include "llvm/Support/ManagedStatic.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000036#include "llvm/Support/PluginLoader.h"
Chris Lattnerc0d91b72009-12-09 00:41:28 +000037#include "llvm/Support/PrettyStackTrace.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000038#include "llvm/Support/SystemUtils.h"
Dan Gohmane4f1a9b2010-10-07 20:32:40 +000039#include "llvm/Support/ToolOutputFile.h"
Reid Spencer62c51052006-08-21 05:34:03 +000040#include "llvm/LinkAllPasses.h"
Reid Spenceraf303d52006-06-07 23:03:13 +000041#include "llvm/LinkAllVMCore.h"
Rafael Espindola3d453ac2011-08-02 21:50:24 +000042#include "llvm/Transforms/IPO/PassManagerBuilder.h"
Chris Lattner63202322001-11-26 19:22:39 +000043#include <memory>
Chris Lattnerc0ce68b2002-07-23 18:12:22 +000044#include <algorithm>
Brian Gaeked0fde302003-11-11 22:41:34 +000045using namespace llvm;
Chris Lattner9d6e7eb2002-04-12 18:21:13 +000046
Chris Lattnerc0ce68b2002-07-23 18:12:22 +000047// The OptimizationList is automatically populated with registered Passes by the
48// PassNameParser.
49//
Chris Lattner7f500f72006-08-27 22:07:01 +000050static cl::list<const PassInfo*, bool, PassNameParser>
51PassList(cl::desc("Optimizations available:"));
Chris Lattnerc0ce68b2002-07-23 18:12:22 +000052
Chris Lattnerc0ce68b2002-07-23 18:12:22 +000053// Other command line options...
Chris Lattnerfb1b3f12002-01-31 00:47:12 +000054//
Chris Lattner6c8103f2003-05-22 20:13:16 +000055static cl::opt<std::string>
Eric Christophera887ae42009-08-21 23:29:40 +000056InputFilename(cl::Positional, cl::desc("<input bitcode file>"),
Reid Spencerfd90dd52006-08-18 06:34:30 +000057 cl::init("-"), cl::value_desc("filename"));
Chris Lattner5ff62e92002-07-22 02:10:13 +000058
Chris Lattner6c8103f2003-05-22 20:13:16 +000059static cl::opt<std::string>
Chris Lattner5ff62e92002-07-22 02:10:13 +000060OutputFilename("o", cl::desc("Override output filename"),
Dan Gohman86cbc1b2010-08-18 17:40:10 +000061 cl::value_desc("filename"));
Chris Lattner5ff62e92002-07-22 02:10:13 +000062
63static cl::opt<bool>
Dan Gohmanbaa26392009-08-25 15:34:52 +000064Force("f", cl::desc("Enable binary output on terminals"));
Chris Lattner5ff62e92002-07-22 02:10:13 +000065
66static cl::opt<bool>
67PrintEachXForm("p", cl::desc("Print module after each transformation"));
68
69static cl::opt<bool>
Chris Lattnerddd5b412003-02-26 20:00:41 +000070NoOutput("disable-output",
Gabor Greifa99be512007-07-05 17:07:56 +000071 cl::desc("Do not write result bitcode file"), cl::Hidden);
Chris Lattnerd70b68e2003-02-12 18:43:33 +000072
73static cl::opt<bool>
Duncan Sands81b0b642009-10-14 20:01:39 +000074OutputAssembly("S", cl::desc("Write output as LLVM assembly"));
Daniel Dunbar8c042c22009-09-05 11:34:53 +000075
76static cl::opt<bool>
Chris Lattnerddd5b412003-02-26 20:00:41 +000077NoVerify("disable-verify", cl::desc("Do not verify result module"), cl::Hidden);
Chris Lattnerf3bafc12003-02-12 18:45:08 +000078
79static cl::opt<bool>
Reid Spencer74ed9972007-02-02 14:46:29 +000080VerifyEach("verify-each", cl::desc("Verify after each transform"));
81
82static cl::opt<bool>
83StripDebug("strip-debug",
84 cl::desc("Strip debugger symbol info from translation unit"));
85
86static cl::opt<bool>
87DisableInline("disable-inlining", cl::desc("Do not run the inliner pass"));
88
Eric Christophera887ae42009-08-21 23:29:40 +000089static cl::opt<bool>
90DisableOptimizations("disable-opt",
Reid Spencer74ed9972007-02-02 14:46:29 +000091 cl::desc("Do not run any optimization passes"));
92
Eric Christophera887ae42009-08-21 23:29:40 +000093static cl::opt<bool>
Daniel Dunbaradc82882009-07-17 18:09:39 +000094DisableInternalize("disable-internalize",
95 cl::desc("Do not mark all symbols as internal"));
96
Reid Spencer74ed9972007-02-02 14:46:29 +000097static cl::opt<bool>
Eric Christophera887ae42009-08-21 23:29:40 +000098StandardCompileOpts("std-compile-opts",
Reid Spencer74ed9972007-02-02 14:46:29 +000099 cl::desc("Include the standard compile time optimizations"));
100
101static cl::opt<bool>
Eric Christophera887ae42009-08-21 23:29:40 +0000102StandardLinkOpts("std-link-opts",
Daniel Dunbaradc82882009-07-17 18:09:39 +0000103 cl::desc("Include the standard link time optimizations"));
104
105static cl::opt<bool>
Devang Patel2d7551c2008-09-16 22:25:14 +0000106OptLevelO1("O1",
107 cl::desc("Optimization level 1. Similar to llvm-gcc -O1"));
108
109static cl::opt<bool>
110OptLevelO2("O2",
Devang Pateld9424ed2008-09-17 00:01:04 +0000111 cl::desc("Optimization level 2. Similar to llvm-gcc -O2"));
Devang Patel2d7551c2008-09-16 22:25:14 +0000112
113static cl::opt<bool>
114OptLevelO3("O3",
Devang Pateld9424ed2008-09-17 00:01:04 +0000115 cl::desc("Optimization level 3. Similar to llvm-gcc -O3"));
Devang Patel2d7551c2008-09-16 22:25:14 +0000116
Joe Groffe652b522012-04-17 23:05:48 +0000117static cl::opt<std::string>
118TargetTriple("mtriple", cl::desc("Override target triple for module"));
119
Devang Patel2d7551c2008-09-16 22:25:14 +0000120static cl::opt<bool>
121UnitAtATime("funit-at-a-time",
Eric Christopherc4769ba2009-08-21 23:30:30 +0000122 cl::desc("Enable IPO. This is same as llvm-gcc's -funit-at-a-time"),
Duncan Sands34727662010-07-12 08:16:59 +0000123 cl::init(true));
Devang Patel2d7551c2008-09-16 22:25:14 +0000124
125static cl::opt<bool>
126DisableSimplifyLibCalls("disable-simplify-libcalls",
Devang Patel442b1aa2008-09-17 16:01:39 +0000127 cl::desc("Disable simplify-libcalls"));
Devang Patel2d7551c2008-09-16 22:25:14 +0000128
129static cl::opt<bool>
Chris Lattner3153e4f2004-05-27 20:32:10 +0000130Quiet("q", cl::desc("Obsolete option"), cl::Hidden);
Chris Lattner5ff62e92002-07-22 02:10:13 +0000131
Reid Spencerec7eb452004-05-27 16:28:54 +0000132static cl::alias
133QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet));
134
Reid Spencerfd90dd52006-08-18 06:34:30 +0000135static cl::opt<bool>
136AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization"));
137
Devang Patelf5f23002010-12-07 00:33:43 +0000138static cl::opt<bool>
Andrew Tricka41af7a2011-04-05 18:41:31 +0000139PrintBreakpoints("print-breakpoints-for-testing",
Devang Patelf5f23002010-12-07 00:33:43 +0000140 cl::desc("Print select breakpoints location for testing"));
141
Chris Lattnerd331cb32009-10-22 00:44:10 +0000142static cl::opt<std::string>
Andrew Tricka41af7a2011-04-05 18:41:31 +0000143DefaultDataLayout("default-data-layout",
Chris Lattnerd331cb32009-10-22 00:44:10 +0000144 cl::desc("data layout string to use if not specified by module"),
145 cl::value_desc("layout-string"), cl::init(""));
146
Reid Spencerfd90dd52006-08-18 06:34:30 +0000147// ---------- Define Printers for module and function passes ------------
148namespace {
149
Devang Patel28552da2007-06-28 23:09:25 +0000150struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
151 static char ID;
152 const PassInfo *PassToPrint;
Dan Gohman4931b312010-08-18 17:42:59 +0000153 raw_ostream &Out;
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000154 std::string PassName;
155
Dan Gohman4931b312010-08-18 17:42:59 +0000156 CallGraphSCCPassPrinter(const PassInfo *PI, raw_ostream &out) :
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000157 CallGraphSCCPass(ID), PassToPrint(PI), Out(out) {
158 std::string PassToPrintName = PassToPrint->getPassName();
159 PassName = "CallGraphSCCPass Printer: " + PassToPrintName;
160 }
Devang Patel28552da2007-06-28 23:09:25 +0000161
Chris Lattner2decb222010-04-16 22:42:17 +0000162 virtual bool runOnSCC(CallGraphSCC &SCC) {
Tobias Grossere9dcd032010-09-08 15:02:51 +0000163 if (!Quiet)
Dan Gohman4931b312010-08-18 17:42:59 +0000164 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
Devang Patel28552da2007-06-28 23:09:25 +0000165
Devang Patel28552da2007-06-28 23:09:25 +0000166 // Get and print pass...
Tobias Grossere9dcd032010-09-08 15:02:51 +0000167 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
168 Function *F = (*I)->getFunction();
169 if (F)
170 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
171 F->getParent());
172 }
Devang Patel28552da2007-06-28 23:09:25 +0000173 return false;
174 }
Eric Christophera887ae42009-08-21 23:29:40 +0000175
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000176 virtual const char *getPassName() const { return PassName.c_str(); }
Devang Patel28552da2007-06-28 23:09:25 +0000177
178 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Owen Anderson90c579d2010-08-06 18:33:48 +0000179 AU.addRequiredID(PassToPrint->getTypeInfo());
Devang Patel28552da2007-06-28 23:09:25 +0000180 AU.setPreservesAll();
181 }
182};
183
184char CallGraphSCCPassPrinter::ID = 0;
185
Reid Spencerfd90dd52006-08-18 06:34:30 +0000186struct ModulePassPrinter : public ModulePass {
Devang Patel19974732007-05-03 01:11:54 +0000187 static char ID;
Reid Spencerfd90dd52006-08-18 06:34:30 +0000188 const PassInfo *PassToPrint;
Dan Gohman4931b312010-08-18 17:42:59 +0000189 raw_ostream &Out;
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000190 std::string PassName;
191
Dan Gohman4931b312010-08-18 17:42:59 +0000192 ModulePassPrinter(const PassInfo *PI, raw_ostream &out)
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000193 : ModulePass(ID), PassToPrint(PI), Out(out) {
194 std::string PassToPrintName = PassToPrint->getPassName();
195 PassName = "ModulePass Printer: " + PassToPrintName;
196 }
Reid Spencerfd90dd52006-08-18 06:34:30 +0000197
198 virtual bool runOnModule(Module &M) {
Tobias Grossere9dcd032010-09-08 15:02:51 +0000199 if (!Quiet)
Dan Gohman4931b312010-08-18 17:42:59 +0000200 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
Reid Spencerfd90dd52006-08-18 06:34:30 +0000201
202 // Get and print pass...
Tobias Grossere9dcd032010-09-08 15:02:51 +0000203 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, &M);
Reid Spencerfd90dd52006-08-18 06:34:30 +0000204 return false;
205 }
206
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000207 virtual const char *getPassName() const { return PassName.c_str(); }
Reid Spencerfd90dd52006-08-18 06:34:30 +0000208
209 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Owen Anderson90c579d2010-08-06 18:33:48 +0000210 AU.addRequiredID(PassToPrint->getTypeInfo());
Reid Spencerfd90dd52006-08-18 06:34:30 +0000211 AU.setPreservesAll();
212 }
213};
214
Devang Patel19974732007-05-03 01:11:54 +0000215char ModulePassPrinter::ID = 0;
Reid Spencerfd90dd52006-08-18 06:34:30 +0000216struct FunctionPassPrinter : public FunctionPass {
217 const PassInfo *PassToPrint;
Dan Gohman4931b312010-08-18 17:42:59 +0000218 raw_ostream &Out;
Devang Patel19974732007-05-03 01:11:54 +0000219 static char ID;
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000220 std::string PassName;
221
Dan Gohman4931b312010-08-18 17:42:59 +0000222 FunctionPassPrinter(const PassInfo *PI, raw_ostream &out)
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000223 : FunctionPass(ID), PassToPrint(PI), Out(out) {
224 std::string PassToPrintName = PassToPrint->getPassName();
225 PassName = "FunctionPass Printer: " + PassToPrintName;
226 }
Reid Spencerfd90dd52006-08-18 06:34:30 +0000227
228 virtual bool runOnFunction(Function &F) {
Tobias Grossere9dcd032010-09-08 15:02:51 +0000229 if (!Quiet)
Dan Gohman4931b312010-08-18 17:42:59 +0000230 Out << "Printing analysis '" << PassToPrint->getPassName()
231 << "' for function '" << F.getName() << "':\n";
Tobias Grossere9dcd032010-09-08 15:02:51 +0000232
Reid Spencerfd90dd52006-08-18 06:34:30 +0000233 // Get and print pass...
Dan Gohman4931b312010-08-18 17:42:59 +0000234 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
Owen Anderson90c579d2010-08-06 18:33:48 +0000235 F.getParent());
Reid Spencerfd90dd52006-08-18 06:34:30 +0000236 return false;
237 }
238
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000239 virtual const char *getPassName() const { return PassName.c_str(); }
Reid Spencerfd90dd52006-08-18 06:34:30 +0000240
241 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Owen Anderson90c579d2010-08-06 18:33:48 +0000242 AU.addRequiredID(PassToPrint->getTypeInfo());
Reid Spencerfd90dd52006-08-18 06:34:30 +0000243 AU.setPreservesAll();
244 }
245};
246
Devang Patel19974732007-05-03 01:11:54 +0000247char FunctionPassPrinter::ID = 0;
Devang Patel56fb1642007-07-05 15:32:03 +0000248
249struct LoopPassPrinter : public LoopPass {
250 static char ID;
251 const PassInfo *PassToPrint;
Dan Gohman4931b312010-08-18 17:42:59 +0000252 raw_ostream &Out;
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000253 std::string PassName;
254
Dan Gohman4931b312010-08-18 17:42:59 +0000255 LoopPassPrinter(const PassInfo *PI, raw_ostream &out) :
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000256 LoopPass(ID), PassToPrint(PI), Out(out) {
257 std::string PassToPrintName = PassToPrint->getPassName();
258 PassName = "LoopPass Printer: " + PassToPrintName;
259 }
260
Devang Patel56fb1642007-07-05 15:32:03 +0000261
262 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
Tobias Grossere9dcd032010-09-08 15:02:51 +0000263 if (!Quiet)
Dan Gohman4931b312010-08-18 17:42:59 +0000264 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
Tobias Grossere9dcd032010-09-08 15:02:51 +0000265
Devang Patel56fb1642007-07-05 15:32:03 +0000266 // Get and print pass...
Tobias Grossere9dcd032010-09-08 15:02:51 +0000267 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
268 L->getHeader()->getParent()->getParent());
Devang Patel56fb1642007-07-05 15:32:03 +0000269 return false;
270 }
Eric Christophera887ae42009-08-21 23:29:40 +0000271
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000272 virtual const char *getPassName() const { return PassName.c_str(); }
Devang Patel56fb1642007-07-05 15:32:03 +0000273
274 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Owen Anderson90c579d2010-08-06 18:33:48 +0000275 AU.addRequiredID(PassToPrint->getTypeInfo());
Devang Patel56fb1642007-07-05 15:32:03 +0000276 AU.setPreservesAll();
277 }
278};
279
280char LoopPassPrinter::ID = 0;
281
Tobias Grosser65513602010-10-20 01:54:44 +0000282struct RegionPassPrinter : public RegionPass {
283 static char ID;
284 const PassInfo *PassToPrint;
285 raw_ostream &Out;
286 std::string PassName;
287
288 RegionPassPrinter(const PassInfo *PI, raw_ostream &out) : RegionPass(ID),
289 PassToPrint(PI), Out(out) {
290 std::string PassToPrintName = PassToPrint->getPassName();
Tobias Grosser58396142011-01-20 21:03:20 +0000291 PassName = "RegionPass Printer: " + PassToPrintName;
Tobias Grosser65513602010-10-20 01:54:44 +0000292 }
293
294 virtual bool runOnRegion(Region *R, RGPassManager &RGM) {
295 if (!Quiet) {
296 Out << "Printing analysis '" << PassToPrint->getPassName() << "' for "
Benjamin Kramera7b0cb72011-11-15 16:27:03 +0000297 << "region: '" << R->getNameStr() << "' in function '"
298 << R->getEntry()->getParent()->getName() << "':\n";
Tobias Grosser65513602010-10-20 01:54:44 +0000299 }
300 // Get and print pass...
301 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
302 R->getEntry()->getParent()->getParent());
303 return false;
304 }
305
Tobias Grosser58396142011-01-20 21:03:20 +0000306 virtual const char *getPassName() const { return PassName.c_str(); }
Tobias Grosser65513602010-10-20 01:54:44 +0000307
308 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
309 AU.addRequiredID(PassToPrint->getTypeInfo());
310 AU.setPreservesAll();
311 }
312};
313
314char RegionPassPrinter::ID = 0;
315
Reid Spencerfd90dd52006-08-18 06:34:30 +0000316struct BasicBlockPassPrinter : public BasicBlockPass {
317 const PassInfo *PassToPrint;
Dan Gohman4931b312010-08-18 17:42:59 +0000318 raw_ostream &Out;
Devang Patel19974732007-05-03 01:11:54 +0000319 static char ID;
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000320 std::string PassName;
321
Dan Gohman4931b312010-08-18 17:42:59 +0000322 BasicBlockPassPrinter(const PassInfo *PI, raw_ostream &out)
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000323 : BasicBlockPass(ID), PassToPrint(PI), Out(out) {
324 std::string PassToPrintName = PassToPrint->getPassName();
325 PassName = "BasicBlockPass Printer: " + PassToPrintName;
326 }
Reid Spencerfd90dd52006-08-18 06:34:30 +0000327
328 virtual bool runOnBasicBlock(BasicBlock &BB) {
Tobias Grossere9dcd032010-09-08 15:02:51 +0000329 if (!Quiet)
Dan Gohman4931b312010-08-18 17:42:59 +0000330 Out << "Printing Analysis info for BasicBlock '" << BB.getName()
331 << "': Pass " << PassToPrint->getPassName() << ":\n";
Reid Spencerfd90dd52006-08-18 06:34:30 +0000332
333 // Get and print pass...
Andrew Tricka41af7a2011-04-05 18:41:31 +0000334 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
Owen Anderson90c579d2010-08-06 18:33:48 +0000335 BB.getParent()->getParent());
Reid Spencerfd90dd52006-08-18 06:34:30 +0000336 return false;
337 }
338
Tobias Grosser4207d6f2010-09-08 15:02:47 +0000339 virtual const char *getPassName() const { return PassName.c_str(); }
Reid Spencerfd90dd52006-08-18 06:34:30 +0000340
341 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Owen Anderson90c579d2010-08-06 18:33:48 +0000342 AU.addRequiredID(PassToPrint->getTypeInfo());
Reid Spencerfd90dd52006-08-18 06:34:30 +0000343 AU.setPreservesAll();
344 }
345};
346
Devang Patel19974732007-05-03 01:11:54 +0000347char BasicBlockPassPrinter::ID = 0;
Devang Patelf5f23002010-12-07 00:33:43 +0000348
Devang Patel1be99802011-04-04 19:51:17 +0000349struct BreakpointPrinter : public ModulePass {
Devang Patelf5f23002010-12-07 00:33:43 +0000350 raw_ostream &Out;
351 static char ID;
352
353 BreakpointPrinter(raw_ostream &out)
Devang Patel1be99802011-04-04 19:51:17 +0000354 : ModulePass(ID), Out(out) {
Devang Patelf5f23002010-12-07 00:33:43 +0000355 }
356
Devang Patel1be99802011-04-04 19:51:17 +0000357 void getContextName(DIDescriptor Context, std::string &N) {
358 if (Context.isNameSpace()) {
359 DINameSpace NS(Context);
360 if (!NS.getName().empty()) {
361 getContextName(NS.getContext(), N);
362 N = N + NS.getName().str() + "::";
Devang Patel97f6d5b2011-01-31 21:36:24 +0000363 }
Devang Patel1be99802011-04-04 19:51:17 +0000364 } else if (Context.isType()) {
365 DIType TY(Context);
366 if (!TY.getName().empty()) {
367 getContextName(TY.getContext(), N);
368 N = N + TY.getName().str() + "::";
369 }
370 }
371 }
372
373 virtual bool runOnModule(Module &M) {
374 StringSet<> Processed;
375 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
376 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
377 std::string Name;
378 DISubprogram SP(NMD->getOperand(i));
379 if (SP.Verify())
380 getContextName(SP.getContext(), Name);
381 Name = Name + SP.getDisplayName().str();
382 if (!Name.empty() && Processed.insert(Name)) {
383 Out << Name << "\n";
384 }
385 }
Devang Patelf5f23002010-12-07 00:33:43 +0000386 return false;
387 }
388
389 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
390 AU.setPreservesAll();
391 }
392};
Chris Lattner52b28892011-05-22 00:21:33 +0000393
394} // anonymous namespace
Devang Patelf5f23002010-12-07 00:33:43 +0000395
396char BreakpointPrinter::ID = 0;
397
Chris Lattner52b28892011-05-22 00:21:33 +0000398static inline void addPass(PassManagerBase &PM, Pass *P) {
Reid Spencer74ed9972007-02-02 14:46:29 +0000399 // Add the pass to the pass manager...
400 PM.add(P);
401
402 // If we are verifying all of the intermediate steps, add the verifier...
403 if (VerifyEach) PM.add(createVerifierPass());
404}
405
Eric Christophera887ae42009-08-21 23:29:40 +0000406/// AddOptimizationPasses - This routine adds optimization passes
407/// based on selected optimization level, OptLevel. This routine
Devang Patel2d7551c2008-09-16 22:25:14 +0000408/// duplicates llvm-gcc behaviour.
409///
410/// OptLevel - Optimization Level
Chris Lattner52b28892011-05-22 00:21:33 +0000411static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
412 unsigned OptLevel) {
Duncan Sandsa3e585d2011-12-07 17:14:20 +0000413 FPM.add(createVerifierPass()); // Verify that input is correct
414
Chris Lattner52b28892011-05-22 00:21:33 +0000415 PassManagerBuilder Builder;
416 Builder.OptLevel = OptLevel;
Devang Patel2d7551c2008-09-16 22:25:14 +0000417
Eli Friedman74733a72010-01-18 22:38:31 +0000418 if (DisableInline) {
419 // No inlining pass
Eli Friedman42d41fd2011-06-06 22:13:27 +0000420 } else if (OptLevel > 1) {
Jakob Stoklund Olesene6c6cec2010-11-02 23:40:28 +0000421 unsigned Threshold = 225;
Eli Friedman74733a72010-01-18 22:38:31 +0000422 if (OptLevel > 2)
Jakob Stoklund Olesene6c6cec2010-11-02 23:40:28 +0000423 Threshold = 275;
Chris Lattner52b28892011-05-22 00:21:33 +0000424 Builder.Inliner = createFunctionInliningPass(Threshold);
Eli Friedman74733a72010-01-18 22:38:31 +0000425 } else {
Chris Lattner52b28892011-05-22 00:21:33 +0000426 Builder.Inliner = createAlwaysInlinerPass();
Eli Friedman74733a72010-01-18 22:38:31 +0000427 }
Chris Lattner52b28892011-05-22 00:21:33 +0000428 Builder.DisableUnitAtATime = !UnitAtATime;
429 Builder.DisableUnrollLoops = OptLevel == 0;
430 Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
431
432 Builder.populateFunctionPassManager(FPM);
433 Builder.populateModulePassManager(MPM);
Devang Patel2d7551c2008-09-16 22:25:14 +0000434}
435
Chris Lattner52b28892011-05-22 00:21:33 +0000436static void AddStandardCompilePasses(PassManagerBase &PM) {
Reid Spencer74ed9972007-02-02 14:46:29 +0000437 PM.add(createVerifierPass()); // Verify that input is correct
438
Reid Spencer74ed9972007-02-02 14:46:29 +0000439 // If the -strip-debug command line option was specified, do it.
440 if (StripDebug)
441 addPass(PM, createStripSymbolsPass(true));
442
443 if (DisableOptimizations) return;
444
Daniel Dunbarca8131e2009-06-03 18:22:15 +0000445 // -std-compile-opts adds the same module passes as -O3.
Chris Lattner52b28892011-05-22 00:21:33 +0000446 PassManagerBuilder Builder;
447 if (!DisableInline)
448 Builder.Inliner = createFunctionInliningPass();
449 Builder.OptLevel = 3;
450 Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
451 Builder.populateModulePassManager(PM);
Reid Spencer74ed9972007-02-02 14:46:29 +0000452}
453
Chris Lattner52b28892011-05-22 00:21:33 +0000454static void AddStandardLinkPasses(PassManagerBase &PM) {
Daniel Dunbaradc82882009-07-17 18:09:39 +0000455 PM.add(createVerifierPass()); // Verify that input is correct
456
457 // If the -strip-debug command line option was specified, do it.
458 if (StripDebug)
459 addPass(PM, createStripSymbolsPass(true));
460
461 if (DisableOptimizations) return;
462
Chris Lattner52b28892011-05-22 00:21:33 +0000463 PassManagerBuilder Builder;
464 Builder.populateLTOPassManager(PM, /*Internalize=*/ !DisableInternalize,
465 /*RunInliner=*/ !DisableInline);
Daniel Dunbaradc82882009-07-17 18:09:39 +0000466}
467
Chris Lattner0be41012002-02-01 04:54:11 +0000468
Chris Lattnerc0ce68b2002-07-23 18:12:22 +0000469//===----------------------------------------------------------------------===//
470// main for opt
471//
Chris Lattner00950542001-06-06 20:29:01 +0000472int main(int argc, char **argv) {
Chris Lattnerc0d91b72009-12-09 00:41:28 +0000473 sys::PrintStackTraceOnErrorSignal();
474 llvm::PrettyStackTraceProgram X(argc, argv);
Dan Gohmand4c45432010-09-01 14:20:41 +0000475
David Greene08fc0d32010-01-05 01:30:32 +0000476 // Enable debug stream buffering.
477 EnableDebugBuffering = true;
478
Chris Lattnerc0d91b72009-12-09 00:41:28 +0000479 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
Owen Anderson0d7c6952009-07-15 22:16:10 +0000480 LLVMContext &Context = getGlobalContext();
Andrew Tricka41af7a2011-04-05 18:41:31 +0000481
Owen Anderson081c34b2010-10-19 17:21:58 +0000482 // Initialize passes
483 PassRegistry &Registry = *PassRegistry::getPassRegistry();
484 initializeCore(Registry);
485 initializeScalarOpts(Registry);
Hal Finkelde5e5ec2012-02-01 03:51:43 +0000486 initializeVectorization(Registry);
Owen Anderson081c34b2010-10-19 17:21:58 +0000487 initializeIPO(Registry);
488 initializeAnalysis(Registry);
489 initializeIPA(Registry);
490 initializeTransformUtils(Registry);
491 initializeInstCombine(Registry);
492 initializeInstrumentation(Registry);
493 initializeTarget(Registry);
Andrew Tricka41af7a2011-04-05 18:41:31 +0000494
Chris Lattner61db1a12009-10-22 00:46:41 +0000495 cl::ParseCommandLineOptions(argc, argv,
496 "llvm .bc -> .bc modular optimizer and analysis printer\n");
Chris Lattnerfb1b3f12002-01-31 00:47:12 +0000497
Tobias Grosser7593f342010-12-02 20:35:16 +0000498 if (AnalyzeOnly && NoOutput) {
499 errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
500 return 1;
501 }
502
Chris Lattner61db1a12009-10-22 00:46:41 +0000503 // Allocate a full target machine description only if necessary.
504 // FIXME: The choice of target should be controllable on the command line.
505 std::auto_ptr<TargetMachine> target;
Devang Patelff5d06d2008-08-27 20:51:49 +0000506
Chris Lattner61db1a12009-10-22 00:46:41 +0000507 SMDiagnostic Err;
Vikram S. Adve18fdfc42002-09-16 16:09:43 +0000508
Chris Lattner61db1a12009-10-22 00:46:41 +0000509 // Load the input module...
510 std::auto_ptr<Module> M;
511 M.reset(ParseIRFile(InputFilename, Err, Context));
Eric Christophera887ae42009-08-21 23:29:40 +0000512
Chris Lattner61db1a12009-10-22 00:46:41 +0000513 if (M.get() == 0) {
Chris Lattnerd8b7aa22011-10-16 04:47:35 +0000514 Err.print(argv[0], errs());
Chris Lattner61db1a12009-10-22 00:46:41 +0000515 return 1;
516 }
517
Joe Groffe652b522012-04-17 23:05:48 +0000518 // If we are supposed to override the target triple, do so now.
519 if (!TargetTriple.empty())
520 M->setTargetTriple(Triple::normalize(TargetTriple));
521
Chris Lattner61db1a12009-10-22 00:46:41 +0000522 // Figure out what stream we are supposed to write to...
Dan Gohmand5826a32010-08-20 01:07:01 +0000523 OwningPtr<tool_output_file> Out;
Dan Gohman4931b312010-08-18 17:42:59 +0000524 if (NoOutput) {
Dan Gohman86cbc1b2010-08-18 17:40:10 +0000525 if (!OutputFilename.empty())
526 errs() << "WARNING: The -o (output filename) option is ignored when\n"
Dan Gohman4931b312010-08-18 17:42:59 +0000527 "the --disable-output option is used.\n";
Dan Gohman86cbc1b2010-08-18 17:40:10 +0000528 } else {
529 // Default to standard output.
530 if (OutputFilename.empty())
531 OutputFilename = "-";
Chris Lattner61db1a12009-10-22 00:46:41 +0000532
Dan Gohman86cbc1b2010-08-18 17:40:10 +0000533 std::string ErrorInfo;
Dan Gohmand5826a32010-08-20 01:07:01 +0000534 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
535 raw_fd_ostream::F_Binary));
Dan Gohman86cbc1b2010-08-18 17:40:10 +0000536 if (!ErrorInfo.empty()) {
537 errs() << ErrorInfo << '\n';
Dan Gohman86cbc1b2010-08-18 17:40:10 +0000538 return 1;
Chris Lattner00950542001-06-06 20:29:01 +0000539 }
Chris Lattner61db1a12009-10-22 00:46:41 +0000540 }
Chris Lattner76d12292002-04-18 19:55:25 +0000541
Chris Lattner61db1a12009-10-22 00:46:41 +0000542 // If the output is set to be emitted to standard out, and standard out is a
543 // console, print out a warning message and refuse to do it. We don't
544 // impress anyone by spewing tons of binary goo to a terminal.
Dan Gohmanb56bf582010-01-17 17:47:24 +0000545 if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly)
Dan Gohmand4c45432010-09-01 14:20:41 +0000546 if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
Chris Lattner61db1a12009-10-22 00:46:41 +0000547 NoOutput = true;
Dan Gohmanec080462009-09-11 20:46:33 +0000548
Chris Lattner61db1a12009-10-22 00:46:41 +0000549 // Create a PassManager to hold and optimize the collection of passes we are
Chris Lattner2a66aca2011-02-18 22:13:01 +0000550 // about to build.
Chris Lattner61db1a12009-10-22 00:46:41 +0000551 //
552 PassManager Passes;
Chris Lattner00950542001-06-06 20:29:01 +0000553
Chris Lattner2a66aca2011-02-18 22:13:01 +0000554 // Add an appropriate TargetLibraryInfo pass for the module's triple.
Chris Lattner188a7e02011-02-18 22:34:03 +0000555 TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
Andrew Tricka41af7a2011-04-05 18:41:31 +0000556
Chris Lattner188a7e02011-02-18 22:34:03 +0000557 // The -disable-simplify-libcalls flag actually disables all builtin optzns.
558 if (DisableSimplifyLibCalls)
559 TLI->disableAllFunctions();
560 Passes.add(TLI);
Andrew Tricka41af7a2011-04-05 18:41:31 +0000561
Chris Lattner2a66aca2011-02-18 22:13:01 +0000562 // Add an appropriate TargetData instance for this module.
Chris Lattner61db1a12009-10-22 00:46:41 +0000563 TargetData *TD = 0;
564 const std::string &ModuleDataLayout = M.get()->getDataLayout();
565 if (!ModuleDataLayout.empty())
566 TD = new TargetData(ModuleDataLayout);
Kenneth Uildriksb908f8a2009-11-03 15:29:06 +0000567 else if (!DefaultDataLayout.empty())
Chris Lattner61db1a12009-10-22 00:46:41 +0000568 TD = new TargetData(DefaultDataLayout);
Chris Lattner9c3b55e2003-04-24 19:13:02 +0000569
Chris Lattner61db1a12009-10-22 00:46:41 +0000570 if (TD)
571 Passes.add(TD);
Reid Spencer1ef8bda2004-12-30 05:36:08 +0000572
Chris Lattner52b28892011-05-22 00:21:33 +0000573 OwningPtr<FunctionPassManager> FPasses;
Chris Lattner61db1a12009-10-22 00:46:41 +0000574 if (OptLevelO1 || OptLevelO2 || OptLevelO3) {
Chris Lattner52b28892011-05-22 00:21:33 +0000575 FPasses.reset(new FunctionPassManager(M.get()));
Chris Lattnerd331cb32009-10-22 00:44:10 +0000576 if (TD)
Chris Lattner61db1a12009-10-22 00:46:41 +0000577 FPasses->add(new TargetData(*TD));
578 }
Reid Spencer1ef8bda2004-12-30 05:36:08 +0000579
Devang Patelf5f23002010-12-07 00:33:43 +0000580 if (PrintBreakpoints) {
581 // Default to standard output.
582 if (!Out) {
583 if (OutputFilename.empty())
584 OutputFilename = "-";
Andrew Tricka41af7a2011-04-05 18:41:31 +0000585
Devang Patelf5f23002010-12-07 00:33:43 +0000586 std::string ErrorInfo;
587 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
588 raw_fd_ostream::F_Binary));
589 if (!ErrorInfo.empty()) {
590 errs() << ErrorInfo << '\n';
591 return 1;
592 }
593 }
594 Passes.add(new BreakpointPrinter(Out->os()));
595 NoOutput = true;
596 }
597
Chris Lattner61db1a12009-10-22 00:46:41 +0000598 // If the -strip-debug command line option was specified, add it. If
599 // -std-compile-opts was also specified, it will handle StripDebug.
600 if (StripDebug && !StandardCompileOpts)
601 addPass(Passes, createStripSymbolsPass(true));
Eric Christophera887ae42009-08-21 23:29:40 +0000602
Chris Lattner61db1a12009-10-22 00:46:41 +0000603 // Create a new optimization pass for each one specified on the command line
604 for (unsigned i = 0; i < PassList.size(); ++i) {
605 // Check to see if -std-compile-opts was specified before this option. If
606 // so, handle it.
607 if (StandardCompileOpts &&
608 StandardCompileOpts.getPosition() < PassList.getPosition(i)) {
Chris Lattner3dda08a2008-07-13 19:35:21 +0000609 AddStandardCompilePasses(Passes);
610 StandardCompileOpts = false;
Eric Christophera887ae42009-08-21 23:29:40 +0000611 }
Reid Spencer1ef8bda2004-12-30 05:36:08 +0000612
Chris Lattner61db1a12009-10-22 00:46:41 +0000613 if (StandardLinkOpts &&
614 StandardLinkOpts.getPosition() < PassList.getPosition(i)) {
Daniel Dunbaradc82882009-07-17 18:09:39 +0000615 AddStandardLinkPasses(Passes);
616 StandardLinkOpts = false;
Eric Christophera887ae42009-08-21 23:29:40 +0000617 }
Daniel Dunbaradc82882009-07-17 18:09:39 +0000618
Chris Lattner61db1a12009-10-22 00:46:41 +0000619 if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) {
Daniel Dunbaradc82882009-07-17 18:09:39 +0000620 AddOptimizationPasses(Passes, *FPasses, 1);
Chris Lattner61db1a12009-10-22 00:46:41 +0000621 OptLevelO1 = false;
Daniel Dunbaradc82882009-07-17 18:09:39 +0000622 }
Devang Patel2d7551c2008-09-16 22:25:14 +0000623
Chris Lattner61db1a12009-10-22 00:46:41 +0000624 if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) {
Daniel Dunbaradc82882009-07-17 18:09:39 +0000625 AddOptimizationPasses(Passes, *FPasses, 2);
Chris Lattner61db1a12009-10-22 00:46:41 +0000626 OptLevelO2 = false;
Daniel Dunbaradc82882009-07-17 18:09:39 +0000627 }
Devang Patel2d7551c2008-09-16 22:25:14 +0000628
Chris Lattner61db1a12009-10-22 00:46:41 +0000629 if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) {
Daniel Dunbaradc82882009-07-17 18:09:39 +0000630 AddOptimizationPasses(Passes, *FPasses, 3);
Chris Lattner61db1a12009-10-22 00:46:41 +0000631 OptLevelO3 = false;
Daniel Dunbaradc82882009-07-17 18:09:39 +0000632 }
Devang Patel2d7551c2008-09-16 22:25:14 +0000633
Chris Lattner61db1a12009-10-22 00:46:41 +0000634 const PassInfo *PassInf = PassList[i];
635 Pass *P = 0;
636 if (PassInf->getNormalCtor())
637 P = PassInf->getNormalCtor()();
638 else
639 errs() << argv[0] << ": cannot create pass: "
640 << PassInf->getPassName() << "\n";
641 if (P) {
Benjamin Kramer3460f222010-02-18 12:57:05 +0000642 PassKind Kind = P->getPassKind();
Chris Lattner61db1a12009-10-22 00:46:41 +0000643 addPass(Passes, P);
644
645 if (AnalyzeOnly) {
Benjamin Kramer3460f222010-02-18 12:57:05 +0000646 switch (Kind) {
Chris Lattner476e9bd2010-01-22 06:03:06 +0000647 case PT_BasicBlock:
Dan Gohmand4c45432010-09-01 14:20:41 +0000648 Passes.add(new BasicBlockPassPrinter(PassInf, Out->os()));
Chris Lattner476e9bd2010-01-22 06:03:06 +0000649 break;
Tobias Grosser65513602010-10-20 01:54:44 +0000650 case PT_Region:
651 Passes.add(new RegionPassPrinter(PassInf, Out->os()));
652 break;
Chris Lattner476e9bd2010-01-22 06:03:06 +0000653 case PT_Loop:
Dan Gohmand4c45432010-09-01 14:20:41 +0000654 Passes.add(new LoopPassPrinter(PassInf, Out->os()));
Chris Lattner476e9bd2010-01-22 06:03:06 +0000655 break;
656 case PT_Function:
Dan Gohmand4c45432010-09-01 14:20:41 +0000657 Passes.add(new FunctionPassPrinter(PassInf, Out->os()));
Chris Lattner476e9bd2010-01-22 06:03:06 +0000658 break;
659 case PT_CallGraphSCC:
Dan Gohmand4c45432010-09-01 14:20:41 +0000660 Passes.add(new CallGraphSCCPassPrinter(PassInf, Out->os()));
Chris Lattner476e9bd2010-01-22 06:03:06 +0000661 break;
662 default:
Dan Gohmand4c45432010-09-01 14:20:41 +0000663 Passes.add(new ModulePassPrinter(PassInf, Out->os()));
Chris Lattner476e9bd2010-01-22 06:03:06 +0000664 break;
665 }
Chris Lattner61db1a12009-10-22 00:46:41 +0000666 }
Devang Patel2d7551c2008-09-16 22:25:14 +0000667 }
668
Chris Lattner61db1a12009-10-22 00:46:41 +0000669 if (PrintEachXForm)
670 Passes.add(createPrintModulePass(&errs()));
Chris Lattnerfb1b3f12002-01-31 00:47:12 +0000671 }
Chris Lattner61db1a12009-10-22 00:46:41 +0000672
673 // If -std-compile-opts was specified at the end of the pass list, add them.
674 if (StandardCompileOpts) {
675 AddStandardCompilePasses(Passes);
676 StandardCompileOpts = false;
677 }
678
679 if (StandardLinkOpts) {
680 AddStandardLinkPasses(Passes);
681 StandardLinkOpts = false;
682 }
683
684 if (OptLevelO1)
685 AddOptimizationPasses(Passes, *FPasses, 1);
686
687 if (OptLevelO2)
688 AddOptimizationPasses(Passes, *FPasses, 2);
689
690 if (OptLevelO3)
691 AddOptimizationPasses(Passes, *FPasses, 3);
692
Chris Lattner3e8984a2011-05-22 06:44:19 +0000693 if (OptLevelO1 || OptLevelO2 || OptLevelO3) {
694 FPasses->doInitialization();
Chris Lattner52b28892011-05-22 00:21:33 +0000695 for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
696 FPasses->run(*F);
Chris Lattner3e8984a2011-05-22 06:44:19 +0000697 FPasses->doFinalization();
698 }
Chris Lattner61db1a12009-10-22 00:46:41 +0000699
700 // Check that the module is well formed on completion of optimization
701 if (!NoVerify && !VerifyEach)
702 Passes.add(createVerifierPass());
703
Dan Gohman4931b312010-08-18 17:42:59 +0000704 // Write bitcode or assembly to the output as the last step...
Chris Lattner61db1a12009-10-22 00:46:41 +0000705 if (!NoOutput && !AnalyzeOnly) {
706 if (OutputAssembly)
Dan Gohmand4c45432010-09-01 14:20:41 +0000707 Passes.add(createPrintModulePass(&Out->os()));
Chris Lattner61db1a12009-10-22 00:46:41 +0000708 else
Dan Gohmand4c45432010-09-01 14:20:41 +0000709 Passes.add(createBitcodeWriterPass(Out->os()));
Chris Lattner61db1a12009-10-22 00:46:41 +0000710 }
711
Andrew Trickce969022011-04-05 18:54:36 +0000712 // Before executing passes, print the final values of the LLVM options.
713 cl::PrintOptionValues();
714
Chris Lattner61db1a12009-10-22 00:46:41 +0000715 // Now that we have all of the passes ready, run them.
716 Passes.run(*M.get());
717
Dan Gohmand5826a32010-08-20 01:07:01 +0000718 // Declare success.
Devang Patelf5f23002010-12-07 00:33:43 +0000719 if (!NoOutput || PrintBreakpoints)
Dan Gohmand5826a32010-08-20 01:07:01 +0000720 Out->keep();
721
Chris Lattner61db1a12009-10-22 00:46:41 +0000722 return 0;
Chris Lattner00950542001-06-06 20:29:01 +0000723}