blob: c630331d684c4beb21f2884045d4043a2fabd68a [file] [log] [blame]
Chris Lattner5b836c42003-06-20 15:49:04 +00001//===-- llc.cpp - Implement the LLVM Native Code Generator ----------------===//
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 Lattnere737c7a2001-09-07 22:20:50 +00009//
Brian Gaekee40eae72004-03-16 21:47:20 +000010// This is the llc code generator driver. It provides a convenient
Misha Brukman3da94ae2005-04-22 00:00:37 +000011// command-line interface for generating native assembly-language code
Gabor Greifa99be512007-07-05 17:07:56 +000012// or C code, given LLVM bitcode.
Chris Lattnere737c7a2001-09-07 22:20:50 +000013//
Chris Lattnerb79757c2001-10-04 01:40:53 +000014//===----------------------------------------------------------------------===//
Vikram S. Advecb465fc2001-07-21 12:42:29 +000015
Chris Lattner1a735402007-05-06 04:55:19 +000016#include "llvm/Bitcode/ReaderWriter.h"
Bill Wendling546d0fb2007-02-08 01:41:07 +000017#include "llvm/CodeGen/FileWriters.h"
Chris Lattnerd3a680a2006-08-01 22:34:35 +000018#include "llvm/CodeGen/LinkAllCodegenComponents.h"
Anton Korobeynikov2b110042008-08-17 14:33:01 +000019#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
Jim Laskeyb1e11802005-09-01 21:38:21 +000020#include "llvm/Target/SubtargetFeature.h"
Owen Anderson07000c62006-05-12 06:33:49 +000021#include "llvm/Target/TargetData.h"
Vikram S. Adve805eb962001-09-18 13:10:45 +000022#include "llvm/Target/TargetMachine.h"
Chris Lattnere45110e2004-07-11 04:03:24 +000023#include "llvm/Target/TargetMachineRegistry.h"
Chris Lattner65f1b892002-05-07 20:03:27 +000024#include "llvm/Transforms/Scalar.h"
Chris Lattner46ac43c2001-09-07 21:26:31 +000025#include "llvm/Module.h"
Chris Lattner744879e2007-05-06 09:32:02 +000026#include "llvm/ModuleProvider.h"
Chris Lattnercd50d3f2002-01-31 00:46:45 +000027#include "llvm/PassManager.h"
Vikram S. Adve7d0ba022002-09-16 16:35:34 +000028#include "llvm/Pass.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000029#include "llvm/Support/CommandLine.h"
Mikhail Glushenkov2388a582009-01-16 07:02:28 +000030#include "llvm/Support/FileUtilities.h"
Chris Lattnerc30598b2006-12-06 01:18:01 +000031#include "llvm/Support/ManagedStatic.h"
Chris Lattner1a735402007-05-06 04:55:19 +000032#include "llvm/Support/MemoryBuffer.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000033#include "llvm/Support/PluginLoader.h"
Chris Lattnercc14d252009-03-06 05:34:10 +000034#include "llvm/Support/PrettyStackTrace.h"
Mikhail Glushenkov2388a582009-01-16 07:02:28 +000035#include "llvm/Support/RegistryParser.h"
Owen Andersoncb371882008-08-21 00:14:44 +000036#include "llvm/Support/raw_ostream.h"
Reid Spencer4418c2b2005-07-28 02:25:30 +000037#include "llvm/Analysis/Verifier.h"
Chris Lattnerbed85ff2004-05-27 05:41:36 +000038#include "llvm/System/Signals.h"
Chris Lattner812125a2005-06-25 03:32:05 +000039#include "llvm/Config/config.h"
Reid Spenceraf303d52006-06-07 23:03:13 +000040#include "llvm/LinkAllVMCore.h"
Chris Lattner78f7e1a2001-09-19 16:52:09 +000041#include <fstream>
Reid Spencer86f42bd2004-07-04 12:20:55 +000042#include <iostream>
43#include <memory>
Brian Gaeked0fde302003-11-11 22:41:34 +000044using namespace llvm;
45
Vikram S. Adve7d0ba022002-09-16 16:35:34 +000046// General options for llc. Other pass-specific options are specified
47// within the corresponding llc passes, and target-specific options
48// and back-end code generation options are specified with the target machine.
Misha Brukman3da94ae2005-04-22 00:00:37 +000049//
Chris Lattnerb5881f12003-04-25 05:26:11 +000050static cl::opt<std::string>
Gabor Greifa99be512007-07-05 17:07:56 +000051InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
Chris Lattner5ff62e92002-07-22 02:10:13 +000052
Chris Lattnerb5881f12003-04-25 05:26:11 +000053static cl::opt<std::string>
Chris Lattner5ff62e92002-07-22 02:10:13 +000054OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"));
55
56static cl::opt<bool> Force("f", cl::desc("Overwrite output files"));
57
Evan Cheng712e80e2009-05-04 23:05:19 +000058// Determine optimization level.
Bill Wendling98a366d2009-04-29 23:29:43 +000059static cl::opt<char>
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000060OptLevel("O",
Evan Cheng712e80e2009-05-04 23:05:19 +000061 cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] "
62 "(default = '-O2')"),
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000063 cl::Prefix,
64 cl::ZeroOrMore,
Bill Wendling98a366d2009-04-29 23:29:43 +000065 cl::init(' '));
Chris Lattner178e0c42005-11-08 02:12:17 +000066
Chris Lattnerf33b8662005-12-16 04:59:57 +000067static cl::opt<std::string>
Chris Lattnerbe193832005-12-16 05:19:55 +000068TargetTriple("mtriple", cl::desc("Override target triple for module"));
Chris Lattner178e0c42005-11-08 02:12:17 +000069
Gordon Henriksen4b2b9402007-10-17 21:28:48 +000070static cl::opt<const TargetMachineRegistry::entry*, false,
Mikhail Glushenkov2388a582009-01-16 07:02:28 +000071 RegistryParser<TargetMachine> >
Chris Lattnercbb34a72005-06-25 03:00:34 +000072MArch("march", cl::desc("Architecture to generate code for:"));
Misha Brukman3da94ae2005-04-22 00:00:37 +000073
Jim Laskeyb1e11802005-09-01 21:38:21 +000074static cl::opt<std::string>
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +000075MCPU("mcpu",
Chris Lattner7b7593c2005-10-23 22:35:42 +000076 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
Jim Laskeyb1e11802005-09-01 21:38:21 +000077 cl::value_desc("cpu-name"),
78 cl::init(""));
79
80static cl::list<std::string>
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +000081MAttrs("mattr",
Jim Laskeyb1e11802005-09-01 21:38:21 +000082 cl::CommaSeparated,
Chris Lattner7b7593c2005-10-23 22:35:42 +000083 cl::desc("Target specific attributes (-mattr=help for details)"),
Chris Lattner20947252005-10-23 22:37:13 +000084 cl::value_desc("a1,+a2,-a3,..."));
Jim Laskeyb1e11802005-09-01 21:38:21 +000085
Chris Lattner812125a2005-06-25 03:32:05 +000086cl::opt<TargetMachine::CodeGenFileType>
87FileType("filetype", cl::init(TargetMachine::AssemblyFile),
88 cl::desc("Choose a file type (not all types are supported by all targets):"),
89 cl::values(
Misha Brukman262b05f2008-12-31 17:39:58 +000090 clEnumValN(TargetMachine::AssemblyFile, "asm",
Dan Gohmanb8cab922008-10-14 20:25:08 +000091 "Emit an assembly ('.s') file"),
Misha Brukman262b05f2008-12-31 17:39:58 +000092 clEnumValN(TargetMachine::ObjectFile, "obj",
Dan Gohmanb8cab922008-10-14 20:25:08 +000093 "Emit a native object ('.o') file [experimental]"),
Chris Lattner812125a2005-06-25 03:32:05 +000094 clEnumValN(TargetMachine::DynamicLibrary, "dynlib",
Dan Gohmanb8cab922008-10-14 20:25:08 +000095 "Emit a native dynamic library ('.so') file"
Nate Begeman712b8352006-08-23 21:29:52 +000096 " [experimental]"),
Chris Lattner812125a2005-06-25 03:32:05 +000097 clEnumValEnd));
98
Reid Spencer4418c2b2005-07-28 02:25:30 +000099cl::opt<bool> NoVerify("disable-verify", cl::Hidden,
Jeff Cohend29b6aa2005-07-30 18:33:25 +0000100 cl::desc("Do not verify input module"));
Reid Spencer4418c2b2005-07-28 02:25:30 +0000101
Chris Lattner812125a2005-06-25 03:32:05 +0000102
Devang Pateld18e31a2009-06-04 22:05:33 +0000103static cl::opt<bool>
104DisableRedZone("disable-red-zone",
105 cl::desc("Do not emit code that uses the red zone."),
106 cl::init(false));
107
Devang Patel578efa92009-06-05 21:57:13 +0000108static cl::opt<bool>
109NoImplicitFloats("no-implicit-float",
110 cl::desc("Don't generate implicit floating point instructions (x86-only)"),
111 cl::init(false));
112
Chris Lattner812125a2005-06-25 03:32:05 +0000113// GetFileNameRoot - Helper function to get the basename of a filename.
Chris Lattnerb5881f12003-04-25 05:26:11 +0000114static inline std::string
Chris Lattnere45110e2004-07-11 04:03:24 +0000115GetFileNameRoot(const std::string &InputFilename) {
Chris Lattnerb5881f12003-04-25 05:26:11 +0000116 std::string IFN = InputFilename;
117 std::string outputFilename;
Vikram S. Adve2f64f9f2001-10-14 23:29:28 +0000118 int Len = IFN.length();
John Criswellb5d09bf2003-08-28 21:42:29 +0000119 if ((Len > 2) &&
120 IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
Chris Lattnerb5881f12003-04-25 05:26:11 +0000121 outputFilename = std::string(IFN.begin(), IFN.end()-3); // s/.bc/.s/
Vikram S. Adve2f64f9f2001-10-14 23:29:28 +0000122 } else {
Chris Lattner3524fc22001-10-15 17:30:47 +0000123 outputFilename = IFN;
Vikram S. Adve2f64f9f2001-10-14 23:29:28 +0000124 }
125 return outputFilename;
126}
127
Owen Andersoncb371882008-08-21 00:14:44 +0000128static raw_ostream *GetOutputStream(const char *ProgName) {
Chris Lattner1911fd42006-09-04 04:14:57 +0000129 if (OutputFilename != "") {
130 if (OutputFilename == "-")
Owen Andersoncb371882008-08-21 00:14:44 +0000131 return &outs();
Chris Lattner1911fd42006-09-04 04:14:57 +0000132
133 // Specified an output filename?
134 if (!Force && std::ifstream(OutputFilename.c_str())) {
135 // If force is not specified, make sure not to overwrite a file!
136 std::cerr << ProgName << ": error opening '" << OutputFilename
137 << "': file exists!\n"
138 << "Use -f command line argument to force output\n";
139 return 0;
140 }
141 // Make sure that the Out file gets unlinked from the disk if we get a
142 // SIGINT
143 sys::RemoveFileOnSignal(sys::Path(OutputFilename));
144
Owen Andersoncb371882008-08-21 00:14:44 +0000145 std::string error;
Daniel Dunbar0d9eb9b2008-11-13 05:01:07 +0000146 raw_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), true, error);
Dan Gohmaned3e8b42008-08-21 15:33:45 +0000147 if (!error.empty()) {
148 std::cerr << error << '\n';
149 delete Out;
150 return 0;
151 }
152
153 return Out;
Chris Lattner1911fd42006-09-04 04:14:57 +0000154 }
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000155
Chris Lattner1911fd42006-09-04 04:14:57 +0000156 if (InputFilename == "-") {
157 OutputFilename = "-";
Owen Andersoncb371882008-08-21 00:14:44 +0000158 return &outs();
Chris Lattner1911fd42006-09-04 04:14:57 +0000159 }
160
161 OutputFilename = GetFileNameRoot(InputFilename);
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000162
Daniel Dunbar0d9eb9b2008-11-13 05:01:07 +0000163 bool Binary = false;
Chris Lattner1911fd42006-09-04 04:14:57 +0000164 switch (FileType) {
165 case TargetMachine::AssemblyFile:
Anton Korobeynikov50276522008-04-23 22:29:24 +0000166 if (MArch->Name[0] == 'c') {
167 if (MArch->Name[1] == 0)
168 OutputFilename += ".cbe.c";
169 else if (MArch->Name[1] == 'p' && MArch->Name[2] == 'p')
170 OutputFilename += ".cpp";
171 else
172 OutputFilename += ".s";
173 } else
Chris Lattner1911fd42006-09-04 04:14:57 +0000174 OutputFilename += ".s";
Chris Lattner1911fd42006-09-04 04:14:57 +0000175 break;
176 case TargetMachine::ObjectFile:
177 OutputFilename += ".o";
Daniel Dunbar0d9eb9b2008-11-13 05:01:07 +0000178 Binary = true;
Chris Lattner1911fd42006-09-04 04:14:57 +0000179 break;
180 case TargetMachine::DynamicLibrary:
181 OutputFilename += LTDL_SHLIB_EXT;
Daniel Dunbar0d9eb9b2008-11-13 05:01:07 +0000182 Binary = true;
Chris Lattner1911fd42006-09-04 04:14:57 +0000183 break;
184 }
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000185
Chris Lattner1911fd42006-09-04 04:14:57 +0000186 if (!Force && std::ifstream(OutputFilename.c_str())) {
187 // If force is not specified, make sure not to overwrite a file!
188 std::cerr << ProgName << ": error opening '" << OutputFilename
189 << "': file exists!\n"
190 << "Use -f command line argument to force output\n";
191 return 0;
192 }
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000193
Chris Lattner1911fd42006-09-04 04:14:57 +0000194 // Make sure that the Out file gets unlinked from the disk if we get a
195 // SIGINT
196 sys::RemoveFileOnSignal(sys::Path(OutputFilename));
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000197
Owen Andersoncb371882008-08-21 00:14:44 +0000198 std::string error;
Daniel Dunbar0d9eb9b2008-11-13 05:01:07 +0000199 raw_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), Binary, error);
Owen Andersoncb371882008-08-21 00:14:44 +0000200 if (!error.empty()) {
Dan Gohmaned3e8b42008-08-21 15:33:45 +0000201 std::cerr << error << '\n';
Chris Lattner1911fd42006-09-04 04:14:57 +0000202 delete Out;
203 return 0;
204 }
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000205
Chris Lattner1911fd42006-09-04 04:14:57 +0000206 return Out;
207}
Vikram S. Adve805eb962001-09-18 13:10:45 +0000208
Chris Lattner5b836c42003-06-20 15:49:04 +0000209// main - Entry point for the llc compiler.
210//
211int main(int argc, char **argv) {
Chris Lattner1a735402007-05-06 04:55:19 +0000212 sys::PrintStackTraceOnErrorSignal();
Chris Lattnercc14d252009-03-06 05:34:10 +0000213 PrettyStackTraceProgram X(argc, argv);
214 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
215 cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n");
Chris Lattner364d1202004-02-19 20:32:39 +0000216
Chris Lattner1a735402007-05-06 04:55:19 +0000217 // Load the module to be compiled...
218 std::string ErrorMessage;
219 std::auto_ptr<Module> M;
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000220
Chris Lattner744879e2007-05-06 09:32:02 +0000221 std::auto_ptr<MemoryBuffer> Buffer(
Chris Lattner065344d2007-05-06 23:45:49 +0000222 MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage));
Chris Lattner744879e2007-05-06 09:32:02 +0000223 if (Buffer.get())
224 M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
Chris Lattner1a735402007-05-06 04:55:19 +0000225 if (M.get() == 0) {
Gabor Greifa99be512007-07-05 17:07:56 +0000226 std::cerr << argv[0] << ": bitcode didn't read correctly.\n";
Chris Lattner1a735402007-05-06 04:55:19 +0000227 std::cerr << "Reason: " << ErrorMessage << "\n";
228 return 1;
229 }
230 Module &mod = *M.get();
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000231
Chris Lattner1a735402007-05-06 04:55:19 +0000232 // If we are supposed to override the target triple, do so now.
233 if (!TargetTriple.empty())
234 mod.setTargetTriple(TargetTriple);
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000235
Chris Lattner1a735402007-05-06 04:55:19 +0000236 // Allocate target machine. First, check whether the user has
237 // explicitly specified an architecture to compile for.
238 if (MArch == 0) {
239 std::string Err;
240 MArch = TargetMachineRegistry::getClosestStaticTargetForModule(mod, Err);
241 if (MArch == 0) {
242 std::cerr << argv[0] << ": error auto-selecting target for module '"
243 << Err << "'. Please use the -march option to explicitly "
244 << "pick a target.\n";
Chris Lattnerbb433502003-08-24 14:02:14 +0000245 return 1;
Chris Lattnere45110e2004-07-11 04:03:24 +0000246 }
Chris Lattner63342052002-10-29 21:12:46 +0000247 }
Chris Lattner1a735402007-05-06 04:55:19 +0000248
249 // Package up features to be passed to target/subtarget
250 std::string FeaturesStr;
251 if (MCPU.size() || MAttrs.size()) {
252 SubtargetFeatures Features;
253 Features.setCPU(MCPU);
254 for (unsigned i = 0; i != MAttrs.size(); ++i)
255 Features.AddFeature(MAttrs[i]);
256 FeaturesStr = Features.getString();
257 }
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000258
Chris Lattner1a735402007-05-06 04:55:19 +0000259 std::auto_ptr<TargetMachine> target(MArch->CtorFn(mod, FeaturesStr));
260 assert(target.get() && "Could not allocate target machine!");
261 TargetMachine &Target = *target.get();
262
263 // Figure out where we are going to send the output...
Owen Andersoncb371882008-08-21 00:14:44 +0000264 raw_ostream *Out = GetOutputStream(argv[0]);
Chris Lattner1a735402007-05-06 04:55:19 +0000265 if (Out == 0) return 1;
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000266
Evan Cheng712e80e2009-05-04 23:05:19 +0000267 CodeGenOpt::Level OLvl = CodeGenOpt::Default;
Bill Wendling98a366d2009-04-29 23:29:43 +0000268 switch (OptLevel) {
269 default:
Bill Wendling8dc85dd2009-04-29 23:46:43 +0000270 std::cerr << argv[0] << ": invalid optimization level.\n";
271 return 1;
Bill Wendling98a366d2009-04-29 23:29:43 +0000272 case ' ': break;
273 case '0': OLvl = CodeGenOpt::None; break;
Bill Wendling581b9342009-04-30 00:57:51 +0000274 case '1':
275 case '2': OLvl = CodeGenOpt::Default; break;
Bill Wendling98a366d2009-04-29 23:29:43 +0000276 case '3': OLvl = CodeGenOpt::Aggressive; break;
Bill Wendling98a366d2009-04-29 23:29:43 +0000277 }
278
Chris Lattner1a735402007-05-06 04:55:19 +0000279 // If this target requires addPassesToEmitWholeFile, do it now. This is
280 // used by strange things like the C backend.
281 if (Target.WantsWholeFile()) {
282 PassManager PM;
283 PM.add(new TargetData(*Target.getTargetData()));
284 if (!NoVerify)
285 PM.add(createVerifierPass());
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000286
Chris Lattner1a735402007-05-06 04:55:19 +0000287 // Ask the target to add backend passes as necessary.
Bill Wendling98a366d2009-04-29 23:29:43 +0000288 if (Target.addPassesToEmitWholeFile(PM, *Out, FileType, OLvl)) {
Chris Lattner1a735402007-05-06 04:55:19 +0000289 std::cerr << argv[0] << ": target does not support generation of this"
290 << " file type!\n";
Owen Andersoncb371882008-08-21 00:14:44 +0000291 if (Out != &outs()) delete Out;
Chris Lattner1a735402007-05-06 04:55:19 +0000292 // And the Out file is empty and useless, so remove it now.
293 sys::Path(OutputFilename).eraseFromDisk();
294 return 1;
295 }
296 PM.run(mod);
297 } else {
298 // Build up all of the passes that we want to do to the module.
Dan Gohman33ef2bb2008-04-16 15:56:26 +0000299 ExistingModuleProvider Provider(M.release());
300 FunctionPassManager Passes(&Provider);
Chris Lattner1a735402007-05-06 04:55:19 +0000301 Passes.add(new TargetData(*Target.getTargetData()));
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000302
Chris Lattner1a735402007-05-06 04:55:19 +0000303#ifndef NDEBUG
304 if (!NoVerify)
305 Passes.add(createVerifierPass());
306#endif
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000307
Chris Lattner1a735402007-05-06 04:55:19 +0000308 // Ask the target to add backend passes as necessary.
309 MachineCodeEmitter *MCE = 0;
310
Evan Cheng23120ba2009-03-25 01:48:21 +0000311 // Override default to generate verbose assembly.
312 Target.setAsmVerbosityDefault(true);
313
Bill Wendling98a366d2009-04-29 23:29:43 +0000314 switch (Target.addPassesToEmitFile(Passes, *Out, FileType, OLvl)) {
Chris Lattner1a735402007-05-06 04:55:19 +0000315 default:
316 assert(0 && "Invalid file model!");
317 return 1;
318 case FileModel::Error:
319 std::cerr << argv[0] << ": target does not support generation of this"
320 << " file type!\n";
Owen Andersoncb371882008-08-21 00:14:44 +0000321 if (Out != &outs()) delete Out;
Chris Lattner1a735402007-05-06 04:55:19 +0000322 // And the Out file is empty and useless, so remove it now.
323 sys::Path(OutputFilename).eraseFromDisk();
324 return 1;
325 case FileModel::AsmFile:
326 break;
327 case FileModel::MachOFile:
328 MCE = AddMachOWriter(Passes, *Out, Target);
329 break;
330 case FileModel::ElfFile:
331 MCE = AddELFWriter(Passes, *Out, Target);
332 break;
333 }
334
Bill Wendling98a366d2009-04-29 23:29:43 +0000335 if (Target.addPassesToEmitFileFinish(Passes, MCE, OLvl)) {
Chris Lattner1a735402007-05-06 04:55:19 +0000336 std::cerr << argv[0] << ": target does not support generation of this"
337 << " file type!\n";
Owen Andersoncb371882008-08-21 00:14:44 +0000338 if (Out != &outs()) delete Out;
Chris Lattner1a735402007-05-06 04:55:19 +0000339 // And the Out file is empty and useless, so remove it now.
340 sys::Path(OutputFilename).eraseFromDisk();
341 return 1;
342 }
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000343
Chris Lattner1a735402007-05-06 04:55:19 +0000344 Passes.doInitialization();
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000345
Chris Lattner1a735402007-05-06 04:55:19 +0000346 // Run our queue of passes all at once now, efficiently.
347 // TODO: this could lazily stream functions out of the module.
348 for (Module::iterator I = mod.begin(), E = mod.end(); I != E; ++I)
Devang Pateld18e31a2009-06-04 22:05:33 +0000349 if (!I->isDeclaration()) {
350 if (DisableRedZone)
351 I->addFnAttr(Attribute::NoRedZone);
Devang Patel578efa92009-06-05 21:57:13 +0000352 if (NoImplicitFloats)
353 I->addFnAttr(Attribute::NoImplicitFloat);
Chris Lattner1a735402007-05-06 04:55:19 +0000354 Passes.run(*I);
Devang Pateld18e31a2009-06-04 22:05:33 +0000355 }
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000356
Chris Lattner1a735402007-05-06 04:55:19 +0000357 Passes.doFinalization();
358 }
Mikhail Glushenkov5c1799b2009-01-16 06:53:46 +0000359
Chris Lattner1a735402007-05-06 04:55:19 +0000360 // Delete the ostream if it's not a stdout stream
Owen Andersoncb371882008-08-21 00:14:44 +0000361 if (Out != &outs()) delete Out;
Chris Lattner1a735402007-05-06 04:55:19 +0000362
363 return 0;
Vikram S. Adve2f64f9f2001-10-14 23:29:28 +0000364}