Chromium Code Reviews| Index: tools/llc/llc.cpp |
| diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp |
| index 1694e01cdfc41a3cf53d4614a2a2a5fab7758a39..d30bfe3b821768933d74a0abf7e14e88b1a9a03c 100644 |
| --- a/tools/llc/llc.cpp |
| +++ b/tools/llc/llc.cpp |
| @@ -18,6 +18,7 @@ |
| #include "llvm/PassManager.h" |
| #include "llvm/Pass.h" |
| #include "llvm/ADT/Triple.h" |
| +#include "llvm/Bitcode/BitcodeStream.h" |
| #include "llvm/Support/IRReader.h" |
| #include "llvm/CodeGen/LinkAllAsmWriterComponents.h" |
| #include "llvm/CodeGen/LinkAllCodegenComponents.h" |
| @@ -141,6 +142,10 @@ DisableRedZone("disable-red-zone", |
| cl::desc("Do not emit code that uses the red zone."), |
| cl::init(false)); |
| +static cl::opt<bool> |
| +LazyBitcode("streaming-bitcode", |
| + cl::desc("Use lazy bitcode streaming"), cl::init(true)); |
| + |
| // GetFileNameRoot - Helper function to get the basename of a filename. |
| static inline std::string |
| GetFileNameRoot(const std::string &InputFilename) { |
| @@ -248,7 +253,19 @@ int main(int argc, char **argv) { |
| SMDiagnostic Err; |
| std::auto_ptr<Module> M; |
| - M.reset(ParseIRFile(InputFilename, Err, Context)); |
| + if (LazyBitcode) { |
| + std::string StrError; |
| + BitcodeStreamer* streamer = getBitcodeFileStreamer(InputFilename,&StrError); |
| + if (streamer) { |
| + M.reset(getStreamedBitcodeModule(InputFilename, streamer, Context, |
| + &StrError)); |
| + } |
| + if (!StrError.empty()) { |
| + Err = SMDiagnostic(InputFilename, SourceMgr::DK_Error, StrError); |
| + } |
| + } else { |
| + M.reset(ParseIRFile(InputFilename, Err, Context)); |
| + } |
| if (M.get() == 0) { |
| Err.print(argv[0], errs()); |
| return 1; |
| @@ -345,13 +362,18 @@ int main(int argc, char **argv) { |
| } |
| // Build up all of the passes that we want to do to the module. |
| - PassManager PM; |
| + 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.
|
| + if (LazyBitcode) |
| + PM = new FunctionPassManager(&mod); |
| + else |
| + PM = new PassManager(); |
| + |
| // Add the target data from the target machine, if it exists, or the module. |
| if (const TargetData *TD = Target.getTargetData()) |
| - PM.add(new TargetData(*TD)); |
| + PM->add(new TargetData(*TD)); |
| else |
| - PM.add(new TargetData(&mod)); |
| + PM->add(new TargetData(&mod)); |
| // Override default to generate verbose assembly. |
| Target.setAsmVerbosityDefault(true); |
| @@ -368,7 +390,7 @@ int main(int argc, char **argv) { |
| formatted_raw_ostream FOS(Out->os()); |
| // Ask the target to add backend passes as necessary. |
| - if (Target.addPassesToEmitFile(PM, FOS, FileType, OLvl, NoVerify)) { |
| + if (Target.addPassesToEmitFile(*PM, FOS, FileType, OLvl, NoVerify)) { |
| errs() << argv[0] << ": target does not support generation of this" |
| << " file type!\n"; |
| return 1; |
| @@ -377,7 +399,16 @@ int main(int argc, char **argv) { |
| // Before executing passes, print the final values of the LLVM options. |
| cl::PrintOptionValues(); |
| - PM.run(mod); |
| + if (LazyBitcode) { |
| + FunctionPassManager* P = static_cast<FunctionPassManager*>(PM); |
| + P->doInitialization(); |
| + for (Module::iterator I = mod.begin(), E = mod.end(); I != E; ++I) { |
| + P->run(*I); |
| + } |
| + P->doFinalization(); |
| + } else { |
| + static_cast<PassManager*>(PM)->run(mod); |
| + } |
| } |
| // Declare success. |