OLD | NEW |
---|---|
1 //===-- llc.cpp - Implement the LLVM Native Code Generator ----------------===// | 1 //===-- llc.cpp - Implement the LLVM Native Code Generator ----------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This is the llc code generator driver. It provides a convenient | 10 // This is the llc code generator driver. It provides a convenient |
11 // command-line interface for generating native assembly-language code | 11 // command-line interface for generating native assembly-language code |
12 // or C code, given LLVM bitcode. | 12 // or C code, given LLVM bitcode. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #include "llvm/LLVMContext.h" | 16 #include "llvm/LLVMContext.h" |
17 #include "llvm/Module.h" | 17 #include "llvm/Module.h" |
18 #include "llvm/PassManager.h" | 18 #include "llvm/PassManager.h" |
19 #include "llvm/Pass.h" | 19 #include "llvm/Pass.h" |
20 #include "llvm/ADT/Triple.h" | 20 #include "llvm/ADT/Triple.h" |
21 #include "llvm/Bitcode/BitcodeStream.h" | |
21 #include "llvm/Support/IRReader.h" | 22 #include "llvm/Support/IRReader.h" |
22 #include "llvm/CodeGen/LinkAllAsmWriterComponents.h" | 23 #include "llvm/CodeGen/LinkAllAsmWriterComponents.h" |
23 #include "llvm/CodeGen/LinkAllCodegenComponents.h" | 24 #include "llvm/CodeGen/LinkAllCodegenComponents.h" |
24 #include "llvm/Config/config.h" | 25 #include "llvm/Config/config.h" |
25 #include "llvm/MC/SubtargetFeature.h" | 26 #include "llvm/MC/SubtargetFeature.h" |
26 #include "llvm/Support/CommandLine.h" | 27 #include "llvm/Support/CommandLine.h" |
27 #include "llvm/Support/Debug.h" | 28 #include "llvm/Support/Debug.h" |
28 #include "llvm/Support/FormattedStream.h" | 29 #include "llvm/Support/FormattedStream.h" |
29 #include "llvm/Support/ManagedStatic.h" | 30 #include "llvm/Support/ManagedStatic.h" |
30 #include "llvm/Support/PluginLoader.h" | 31 #include "llvm/Support/PluginLoader.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 cl::desc("Do not use .cfi_* directives")); | 135 cl::desc("Do not use .cfi_* directives")); |
135 | 136 |
136 cl::opt<bool> EnableDwarfDirectory("enable-dwarf-directory", cl::Hidden, | 137 cl::opt<bool> EnableDwarfDirectory("enable-dwarf-directory", cl::Hidden, |
137 cl::desc("Use .file directives with an explicit directory.")); | 138 cl::desc("Use .file directives with an explicit directory.")); |
138 | 139 |
139 static cl::opt<bool> | 140 static cl::opt<bool> |
140 DisableRedZone("disable-red-zone", | 141 DisableRedZone("disable-red-zone", |
141 cl::desc("Do not emit code that uses the red zone."), | 142 cl::desc("Do not emit code that uses the red zone."), |
142 cl::init(false)); | 143 cl::init(false)); |
143 | 144 |
145 static cl::opt<bool> | |
146 LazyBitcode("streaming-bitcode", | |
147 cl::desc("Use lazy bitcode streaming"), cl::init(true)); | |
148 | |
144 // GetFileNameRoot - Helper function to get the basename of a filename. | 149 // GetFileNameRoot - Helper function to get the basename of a filename. |
145 static inline std::string | 150 static inline std::string |
146 GetFileNameRoot(const std::string &InputFilename) { | 151 GetFileNameRoot(const std::string &InputFilename) { |
147 std::string IFN = InputFilename; | 152 std::string IFN = InputFilename; |
148 std::string outputFilename; | 153 std::string outputFilename; |
149 int Len = IFN.length(); | 154 int Len = IFN.length(); |
150 if ((Len > 2) && | 155 if ((Len > 2) && |
151 IFN[Len-3] == '.' && | 156 IFN[Len-3] == '.' && |
152 ((IFN[Len-2] == 'b' && IFN[Len-1] == 'c') || | 157 ((IFN[Len-2] == 'b' && IFN[Len-1] == 'c') || |
153 (IFN[Len-2] == 'l' && IFN[Len-1] == 'l'))) { | 158 (IFN[Len-2] == 'l' && IFN[Len-1] == 'l'))) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 | 246 |
242 // Register the target printer for --version. | 247 // Register the target printer for --version. |
243 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); | 248 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); |
244 | 249 |
245 cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n"); | 250 cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n"); |
246 | 251 |
247 // Load the module to be compiled... | 252 // Load the module to be compiled... |
248 SMDiagnostic Err; | 253 SMDiagnostic Err; |
249 std::auto_ptr<Module> M; | 254 std::auto_ptr<Module> M; |
250 | 255 |
251 M.reset(ParseIRFile(InputFilename, Err, Context)); | 256 if (LazyBitcode) { |
257 std::string StrError; | |
258 BitcodeStreamer* streamer = getBitcodeFileStreamer(InputFilename,&StrError); | |
259 if (streamer) { | |
260 M.reset(getStreamedBitcodeModule(InputFilename, streamer, Context, | |
261 &StrError)); | |
262 } | |
263 if (!StrError.empty()) { | |
264 Err = SMDiagnostic(InputFilename, SourceMgr::DK_Error, StrError); | |
265 } | |
266 } else { | |
267 M.reset(ParseIRFile(InputFilename, Err, Context)); | |
268 } | |
252 if (M.get() == 0) { | 269 if (M.get() == 0) { |
253 Err.print(argv[0], errs()); | 270 Err.print(argv[0], errs()); |
254 return 1; | 271 return 1; |
255 } | 272 } |
256 Module &mod = *M.get(); | 273 Module &mod = *M.get(); |
257 | 274 |
258 // If we are supposed to override the target triple, do so now. | 275 // If we are supposed to override the target triple, do so now. |
259 if (!TargetTriple.empty()) | 276 if (!TargetTriple.empty()) |
260 mod.setTargetTriple(Triple::normalize(TargetTriple)); | 277 mod.setTargetTriple(Triple::normalize(TargetTriple)); |
261 | 278 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 errs() << argv[0] << ": invalid optimization level.\n"; | 355 errs() << argv[0] << ": invalid optimization level.\n"; |
339 return 1; | 356 return 1; |
340 case ' ': break; | 357 case ' ': break; |
341 case '0': OLvl = CodeGenOpt::None; break; | 358 case '0': OLvl = CodeGenOpt::None; break; |
342 case '1': OLvl = CodeGenOpt::Less; break; | 359 case '1': OLvl = CodeGenOpt::Less; break; |
343 case '2': OLvl = CodeGenOpt::Default; break; | 360 case '2': OLvl = CodeGenOpt::Default; break; |
344 case '3': OLvl = CodeGenOpt::Aggressive; break; | 361 case '3': OLvl = CodeGenOpt::Aggressive; break; |
345 } | 362 } |
346 | 363 |
347 // Build up all of the passes that we want to do to the module. | 364 // Build up all of the passes that we want to do to the module. |
348 PassManager PM; | 365 PassManagerBase *PM; |
jvoung - send to chromium...
2011/11/07 19:01:55
Is there a scoped-pointer class that you can use?
(google.com) Derek Schuff
2011/11/07 22:33:50
Done.
| |
366 if (LazyBitcode) | |
367 PM = new FunctionPassManager(&mod); | |
368 else | |
369 PM = new PassManager(); | |
370 | |
349 | 371 |
350 // Add the target data from the target machine, if it exists, or the module. | 372 // Add the target data from the target machine, if it exists, or the module. |
351 if (const TargetData *TD = Target.getTargetData()) | 373 if (const TargetData *TD = Target.getTargetData()) |
352 PM.add(new TargetData(*TD)); | 374 PM->add(new TargetData(*TD)); |
353 else | 375 else |
354 PM.add(new TargetData(&mod)); | 376 PM->add(new TargetData(&mod)); |
355 | 377 |
356 // Override default to generate verbose assembly. | 378 // Override default to generate verbose assembly. |
357 Target.setAsmVerbosityDefault(true); | 379 Target.setAsmVerbosityDefault(true); |
358 | 380 |
359 if (RelaxAll) { | 381 if (RelaxAll) { |
360 if (FileType != TargetMachine::CGFT_ObjectFile) | 382 if (FileType != TargetMachine::CGFT_ObjectFile) |
361 errs() << argv[0] | 383 errs() << argv[0] |
362 << ": warning: ignoring -mc-relax-all because filetype != obj"; | 384 << ": warning: ignoring -mc-relax-all because filetype != obj"; |
363 else | 385 else |
364 Target.setMCRelaxAll(true); | 386 Target.setMCRelaxAll(true); |
365 } | 387 } |
366 | 388 |
367 { | 389 { |
368 formatted_raw_ostream FOS(Out->os()); | 390 formatted_raw_ostream FOS(Out->os()); |
369 | 391 |
370 // Ask the target to add backend passes as necessary. | 392 // Ask the target to add backend passes as necessary. |
371 if (Target.addPassesToEmitFile(PM, FOS, FileType, OLvl, NoVerify)) { | 393 if (Target.addPassesToEmitFile(*PM, FOS, FileType, OLvl, NoVerify)) { |
372 errs() << argv[0] << ": target does not support generation of this" | 394 errs() << argv[0] << ": target does not support generation of this" |
373 << " file type!\n"; | 395 << " file type!\n"; |
374 return 1; | 396 return 1; |
375 } | 397 } |
376 | 398 |
377 // Before executing passes, print the final values of the LLVM options. | 399 // Before executing passes, print the final values of the LLVM options. |
378 cl::PrintOptionValues(); | 400 cl::PrintOptionValues(); |
379 | 401 |
380 PM.run(mod); | 402 if (LazyBitcode) { |
403 FunctionPassManager* P = static_cast<FunctionPassManager*>(PM); | |
404 P->doInitialization(); | |
405 for (Module::iterator I = mod.begin(), E = mod.end(); I != E; ++I) { | |
406 P->run(*I); | |
407 } | |
408 P->doFinalization(); | |
409 } else { | |
410 static_cast<PassManager*>(PM)->run(mod); | |
411 } | |
381 } | 412 } |
382 | 413 |
383 // Declare success. | 414 // Declare success. |
384 Out->keep(); | 415 Out->keep(); |
385 | 416 |
386 return 0; | 417 return 0; |
387 } | 418 } |
OLD | NEW |