| OLD | NEW |
| 1 //===- subzero/src/IceCompiler.cpp - Driver for bitcode translation -------===// | 1 //===- subzero/src/IceCompiler.cpp - Driver for bitcode translation -------===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 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 /// \file | 10 /// \file |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // end of anonymous namespace | 57 } // end of anonymous namespace |
| 58 | 58 |
| 59 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx, | 59 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx, |
| 60 std::unique_ptr<llvm::DataStreamer> &&InputStream) { | 60 std::unique_ptr<llvm::DataStreamer> &&InputStream) { |
| 61 // The Minimal build (specifically, when dump()/emit() are not implemented) | 61 // The Minimal build (specifically, when dump()/emit() are not implemented) |
| 62 // allows only --filetype=obj. Check here to avoid cryptic error messages | 62 // allows only --filetype=obj. Check here to avoid cryptic error messages |
| 63 // downstream. | 63 // downstream. |
| 64 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { | 64 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { |
| 65 // TODO(stichnot): Access the actual command-line argument via | |
| 66 // llvm::Option.ArgStr and .ValueStr . | |
| 67 Ctx.getStrError() | 65 Ctx.getStrError() |
| 68 << "Error: only --filetype=obj is supported in this build.\n"; | 66 << "Error: only --filetype=obj is supported in this build.\n"; |
| 69 Ctx.getErrorStatus()->assign(EC_Args); | 67 Ctx.getErrorStatus()->assign(EC_Args); |
| 70 return; | 68 return; |
| 71 } | 69 } |
| 72 | 70 |
| 73 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 71 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
| 74 | 72 |
| 75 Ctx.emitFileHeader(); | 73 Ctx.emitFileHeader(); |
| 76 Ctx.startWorkerThreads(); | 74 Ctx.startWorkerThreads(); |
| 77 | 75 |
| 78 std::unique_ptr<Translator> Translator; | 76 std::unique_ptr<Translator> Translator; |
| 79 const std::string IRFilename = Flags.getIRFilename(); | 77 const std::string IRFilename = Flags.getIRFilename(); |
| 80 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename); | 78 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename); |
| 81 if (BuildOnRead) { | 79 if (BuildOnRead) { |
| 82 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); | 80 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); |
| 83 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( | 81 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( |
| 84 new llvm::StreamingMemoryObjectImpl(InputStream.release())); | 82 new llvm::StreamingMemoryObjectImpl(InputStream.release())); |
| 85 PTranslator->translate(IRFilename, std::move(MemObj)); | 83 PTranslator->translate(IRFilename, std::move(MemObj)); |
| 86 Translator.reset(PTranslator.release()); | 84 Translator.reset(PTranslator.release()); |
| 87 } else if (BuildDefs::llvmIr()) { | 85 } else if (BuildDefs::llvmIr()) { |
| 88 if (BuildDefs::browser()) { | 86 if (BuildDefs::browser()) { |
| 89 Ctx.getStrError() | 87 Ctx.getStrError() |
| 90 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; | 88 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; |
| 91 Ctx.getErrorStatus()->assign(EC_Args); | 89 Ctx.getErrorStatus()->assign(EC_Args); |
| 90 Ctx.waitForWorkerThreads(); |
| 92 return; | 91 return; |
| 93 } | 92 } |
| 94 // Globals must be kept alive after lowering when converting from LLVM to | 93 // Globals must be kept alive after lowering when converting from LLVM to |
| 95 // Ice. | 94 // Ice. |
| 96 Ctx.setDisposeGlobalVariablesAfterLowering(false); | 95 Ctx.setDisposeGlobalVariablesAfterLowering(false); |
| 97 // Parse the input LLVM IR file into a module. | 96 // Parse the input LLVM IR file into a module. |
| 98 llvm::SMDiagnostic Err; | 97 llvm::SMDiagnostic Err; |
| 99 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); | 98 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); |
| 100 llvm::DiagnosticHandlerFunction DiagnosticHandler = | 99 llvm::DiagnosticHandlerFunction DiagnosticHandler = |
| 101 Flags.getLLVMVerboseErrors() | 100 Flags.getLLVMVerboseErrors() |
| 102 ? redirectNaClDiagnosticToStream(llvm::errs()) | 101 ? redirectNaClDiagnosticToStream(llvm::errs()) |
| 103 : nullptr; | 102 : nullptr; |
| 104 std::unique_ptr<llvm::Module> Mod = | 103 std::unique_ptr<llvm::Module> Mod = |
| 105 NaClParseIRFile(IRFilename, Flags.getInputFileFormat(), Err, | 104 NaClParseIRFile(IRFilename, Flags.getInputFileFormat(), Err, |
| 106 llvm::getGlobalContext(), DiagnosticHandler); | 105 llvm::getGlobalContext(), DiagnosticHandler); |
| 107 if (!Mod) { | 106 if (!Mod) { |
| 108 Err.print(Flags.getAppName().c_str(), llvm::errs()); | 107 Err.print(Flags.getAppName().c_str(), llvm::errs()); |
| 109 Ctx.getErrorStatus()->assign(EC_Bitcode); | 108 Ctx.getErrorStatus()->assign(EC_Bitcode); |
| 109 Ctx.waitForWorkerThreads(); |
| 110 return; | 110 return; |
| 111 } | 111 } |
| 112 | 112 |
| 113 std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx)); | 113 std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx)); |
| 114 Converter->convertToIce(); | 114 Converter->convertToIce(); |
| 115 Translator.reset(Converter.release()); | 115 Translator.reset(Converter.release()); |
| 116 } else { | 116 } else { |
| 117 Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, " | 117 Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, " |
| 118 << "--build-on-read=0 not allowed\n"; | 118 << "--build-on-read=0 not allowed\n"; |
| 119 Ctx.getErrorStatus()->assign(EC_Args); | 119 Ctx.getErrorStatus()->assign(EC_Args); |
| 120 Ctx.waitForWorkerThreads(); |
| 120 return; | 121 return; |
| 121 } | 122 } |
| 122 | 123 |
| 123 Ctx.waitForWorkerThreads(); | 124 Ctx.waitForWorkerThreads(); |
| 124 if (Translator->getErrorStatus()) { | 125 if (Translator->getErrorStatus()) { |
| 125 Ctx.getErrorStatus()->assign(Translator->getErrorStatus().value()); | 126 Ctx.getErrorStatus()->assign(Translator->getErrorStatus().value()); |
| 126 } else { | 127 } else { |
| 127 Ctx.lowerGlobals("last"); | 128 Ctx.lowerGlobals("last"); |
| 128 Ctx.lowerProfileData(); | 129 Ctx.lowerProfileData(); |
| 129 Ctx.lowerConstants(); | 130 Ctx.lowerConstants(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 141 | 142 |
| 142 if (Ctx.getFlags().getTimeEachFunction()) { | 143 if (Ctx.getFlags().getTimeEachFunction()) { |
| 143 constexpr bool NoDumpCumulative = false; | 144 constexpr bool NoDumpCumulative = false; |
| 144 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); | 145 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); |
| 145 } | 146 } |
| 146 constexpr bool FinalStats = true; | 147 constexpr bool FinalStats = true; |
| 147 Ctx.dumpStats("_FINAL_", FinalStats); | 148 Ctx.dumpStats("_FINAL_", FinalStats); |
| 148 } | 149 } |
| 149 | 150 |
| 150 } // end of namespace Ice | 151 } // end of namespace Ice |
| OLD | NEW |