Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: tools/llc/llc.cpp

Issue 8393017: Bitcode streaming (Closed)
Patch Set: put destructors back, fix trailing whitespace Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/Support/BitcodeStream.cpp ('k') | tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/Support/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
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 // Using bitcode streaming has a couple of ramifications. Primarily it means
146 // that the module in the file will be compiled one function at a time rather
147 // than the whole module. This allows earlier functions to be compiled before
148 // later functions are read from the bitcode but of course means no whole-module
149 // optimizations. For now, streaming is only supported for files and stdin.
150 static cl::opt<bool>
151 LazyBitcode("streaming-bitcode",
152 cl::desc("Use lazy bitcode streaming for file inputs"),
153 cl::init(false));
154
144 // GetFileNameRoot - Helper function to get the basename of a filename. 155 // GetFileNameRoot - Helper function to get the basename of a filename.
145 static inline std::string 156 static inline std::string
146 GetFileNameRoot(const std::string &InputFilename) { 157 GetFileNameRoot(const std::string &InputFilename) {
147 std::string IFN = InputFilename; 158 std::string IFN = InputFilename;
148 std::string outputFilename; 159 std::string outputFilename;
149 int Len = IFN.length(); 160 int Len = IFN.length();
150 if ((Len > 2) && 161 if ((Len > 2) &&
151 IFN[Len-3] == '.' && 162 IFN[Len-3] == '.' &&
152 ((IFN[Len-2] == 'b' && IFN[Len-1] == 'c') || 163 ((IFN[Len-2] == 'b' && IFN[Len-1] == 'c') ||
153 (IFN[Len-2] == 'l' && IFN[Len-1] == 'l'))) { 164 (IFN[Len-2] == 'l' && IFN[Len-1] == 'l'))) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 252
242 // Register the target printer for --version. 253 // Register the target printer for --version.
243 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); 254 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
244 255
245 cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n"); 256 cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n");
246 257
247 // Load the module to be compiled... 258 // Load the module to be compiled...
248 SMDiagnostic Err; 259 SMDiagnostic Err;
249 std::auto_ptr<Module> M; 260 std::auto_ptr<Module> M;
250 261
251 M.reset(ParseIRFile(InputFilename, Err, Context)); 262 if (LazyBitcode) {
263 std::string StrError;
264 BitcodeStreamer *streamer = getBitcodeFileStreamer(InputFilename,&StrError);
265 if (streamer) {
266 M.reset(getStreamedBitcodeModule(InputFilename, streamer, Context,
267 &StrError));
268 }
269 if (!StrError.empty()) {
270 Err = SMDiagnostic(InputFilename, SourceMgr::DK_Error, StrError);
271 }
272 } else {
273 M.reset(ParseIRFile(InputFilename, Err, Context));
274 }
252 if (M.get() == 0) { 275 if (M.get() == 0) {
253 Err.print(argv[0], errs()); 276 Err.print(argv[0], errs());
254 return 1; 277 return 1;
255 } 278 }
256 Module &mod = *M.get(); 279 Module &mod = *M.get();
257 280
258 // If we are supposed to override the target triple, do so now. 281 // If we are supposed to override the target triple, do so now.
259 if (!TargetTriple.empty()) 282 if (!TargetTriple.empty())
260 mod.setTargetTriple(Triple::normalize(TargetTriple)); 283 mod.setTargetTriple(Triple::normalize(TargetTriple));
261 284
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if (TheTriple.isMacOSX() && 361 if (TheTriple.isMacOSX() &&
339 TheTriple.isMacOSXVersionLT(10, 6)) 362 TheTriple.isMacOSXVersionLT(10, 6))
340 Target.setMCUseLoc(false); 363 Target.setMCUseLoc(false);
341 364
342 // Figure out where we are going to send the output... 365 // Figure out where we are going to send the output...
343 OwningPtr<tool_output_file> Out 366 OwningPtr<tool_output_file> Out
344 (GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0])); 367 (GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]));
345 if (!Out) return 1; 368 if (!Out) return 1;
346 369
347 // Build up all of the passes that we want to do to the module. 370 // Build up all of the passes that we want to do to the module.
348 PassManager PM; 371 OwningPtr<PassManagerBase> PM;
372 if (LazyBitcode)
373 PM.reset(new FunctionPassManager(&mod));
374 else
375 PM.reset(new PassManager());
376
349 377
350 // Add the target data from the target machine, if it exists, or the module. 378 // Add the target data from the target machine, if it exists, or the module.
351 if (const TargetData *TD = Target.getTargetData()) 379 if (const TargetData *TD = Target.getTargetData())
352 PM.add(new TargetData(*TD)); 380 PM->add(new TargetData(*TD));
353 else 381 else
354 PM.add(new TargetData(&mod)); 382 PM->add(new TargetData(&mod));
355 383
356 // Override default to generate verbose assembly. 384 // Override default to generate verbose assembly.
357 Target.setAsmVerbosityDefault(true); 385 Target.setAsmVerbosityDefault(true);
358 386
359 if (RelaxAll) { 387 if (RelaxAll) {
360 if (FileType != TargetMachine::CGFT_ObjectFile) 388 if (FileType != TargetMachine::CGFT_ObjectFile)
361 errs() << argv[0] 389 errs() << argv[0]
362 << ": warning: ignoring -mc-relax-all because filetype != obj"; 390 << ": warning: ignoring -mc-relax-all because filetype != obj";
363 else 391 else
364 Target.setMCRelaxAll(true); 392 Target.setMCRelaxAll(true);
365 } 393 }
366 394
367 { 395 {
368 formatted_raw_ostream FOS(Out->os()); 396 formatted_raw_ostream FOS(Out->os());
369 397
370 // Ask the target to add backend passes as necessary. 398 // Ask the target to add backend passes as necessary.
371 if (Target.addPassesToEmitFile(PM, FOS, FileType, NoVerify)) { 399 if (Target.addPassesToEmitFile(*PM, FOS, FileType, NoVerify)) {
372 errs() << argv[0] << ": target does not support generation of this" 400 errs() << argv[0] << ": target does not support generation of this"
373 << " file type!\n"; 401 << " file type!\n";
374 return 1; 402 return 1;
375 } 403 }
376 404
377 // Before executing passes, print the final values of the LLVM options. 405 // Before executing passes, print the final values of the LLVM options.
378 cl::PrintOptionValues(); 406 cl::PrintOptionValues();
379 407
380 PM.run(mod); 408 if (LazyBitcode) {
409 FunctionPassManager *P = static_cast<FunctionPassManager*>(PM.get());
410 P->doInitialization();
411 for (Module::iterator I = mod.begin(), E = mod.end(); I != E; ++I) {
412 P->run(*I);
413 }
414 P->doFinalization();
415 } else {
416 static_cast<PassManager*>(PM.get())->run(mod);
417 }
381 } 418 }
382 419
383 // Declare success. 420 // Declare success.
384 Out->keep(); 421 Out->keep();
385 422
386 return 0; 423 return 0;
387 } 424 }
OLDNEW
« no previous file with comments | « lib/Support/BitcodeStream.cpp ('k') | tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698