| 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 |
| 11 /// \brief Defines a driver for translating PNaCl bitcode into native code. | 11 /// \brief Defines a driver for translating PNaCl bitcode into native code. |
| 12 /// | 12 /// |
| 13 /// The driver can either directly parse the binary bitcode file, or use LLVM | 13 /// The driver can either directly parse the binary bitcode file, or use LLVM |
| 14 /// routines to parse a textual bitcode file into LLVM IR and then convert LLVM | 14 /// routines to parse a textual bitcode file into LLVM IR and then convert LLVM |
| 15 /// IR into ICE. In either case, the high-level ICE is then compiled down to | 15 /// IR into ICE. In either case, the high-level ICE is then compiled down to |
| 16 /// native code, as either an ELF object file or a textual asm file. | 16 /// native code, as either an ELF object file or a textual asm file. |
| 17 /// | 17 /// |
| 18 //===----------------------------------------------------------------------===// | 18 //===----------------------------------------------------------------------===// |
| 19 | 19 |
| 20 #include "IceCompiler.h" | 20 #include "IceCompiler.h" |
| 21 | 21 |
| 22 #include "IceBuildDefs.h" | 22 #include "IceBuildDefs.h" |
| 23 #include "IceCfg.h" | 23 #include "IceCfg.h" |
| 24 #include "IceClFlags.h" | 24 #include "IceClFlags.h" |
| 25 #include "IceClFlagsExtra.h" | 25 #include "IceClFlags.h" |
| 26 #include "IceConverter.h" | 26 #include "IceConverter.h" |
| 27 #include "IceELFObjectWriter.h" | 27 #include "IceELFObjectWriter.h" |
| 28 #include "PNaClTranslator.h" | 28 #include "PNaClTranslator.h" |
| 29 | 29 |
| 30 #ifdef __clang__ | 30 #ifdef __clang__ |
| 31 #pragma clang diagnostic push | 31 #pragma clang diagnostic push |
| 32 #pragma clang diagnostic ignored "-Wunused-parameter" | 32 #pragma clang diagnostic ignored "-Wunused-parameter" |
| 33 #endif // __clang__ | 33 #endif // __clang__ |
| 34 | 34 |
| 35 #include "llvm/ADT/STLExtras.h" | 35 #include "llvm/ADT/STLExtras.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 50 | 50 |
| 51 namespace { | 51 namespace { |
| 52 | 52 |
| 53 bool llvmIRInput(const IceString &Filename) { | 53 bool llvmIRInput(const IceString &Filename) { |
| 54 return BuildDefs::llvmIrAsInput() && | 54 return BuildDefs::llvmIrAsInput() && |
| 55 std::regex_match(Filename, std::regex(".*\\.ll")); | 55 std::regex_match(Filename, std::regex(".*\\.ll")); |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // end of anonymous namespace | 58 } // end of anonymous namespace |
| 59 | 59 |
| 60 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx, | 60 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx, |
| 61 std::unique_ptr<llvm::DataStreamer> &&InputStream) { | 61 std::unique_ptr<llvm::DataStreamer> &&InputStream) { |
| 62 // The Minimal build (specifically, when dump()/emit() are not implemented) | 62 // The Minimal build (specifically, when dump()/emit() are not implemented) |
| 63 // allows only --filetype=obj. Check here to avoid cryptic error messages | 63 // allows only --filetype=obj. Check here to avoid cryptic error messages |
| 64 // downstream. | 64 // downstream. |
| 65 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { | 65 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { |
| 66 // TODO(stichnot): Access the actual command-line argument via | 66 // TODO(stichnot): Access the actual command-line argument via |
| 67 // llvm::Option.ArgStr and .ValueStr . | 67 // llvm::Option.ArgStr and .ValueStr . |
| 68 Ctx.getStrError() | 68 Ctx.getStrError() |
| 69 << "Error: only --filetype=obj is supported in this build.\n"; | 69 << "Error: only --filetype=obj is supported in this build.\n"; |
| 70 Ctx.getErrorStatus()->assign(EC_Args); | 70 Ctx.getErrorStatus()->assign(EC_Args); |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 | 73 |
| 74 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 74 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
| 75 | 75 |
| 76 Ctx.emitFileHeader(); | 76 Ctx.emitFileHeader(); |
| 77 Ctx.startWorkerThreads(); | 77 Ctx.startWorkerThreads(); |
| 78 | 78 |
| 79 std::unique_ptr<Translator> Translator; | 79 std::unique_ptr<Translator> Translator; |
| 80 const IceString &IRFilename = ExtraFlags.getIRFilename(); | 80 const IceString &IRFilename = Flags.getIRFilename(); |
| 81 const bool BuildOnRead = | 81 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename); |
| 82 ExtraFlags.getBuildOnRead() && !llvmIRInput(IRFilename); | |
| 83 if (BuildOnRead) { | 82 if (BuildOnRead) { |
| 84 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); | 83 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); |
| 85 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( | 84 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( |
| 86 new llvm::StreamingMemoryObjectImpl(InputStream.release())); | 85 new llvm::StreamingMemoryObjectImpl(InputStream.release())); |
| 87 PTranslator->translate(IRFilename, std::move(MemObj)); | 86 PTranslator->translate(IRFilename, std::move(MemObj)); |
| 88 Translator.reset(PTranslator.release()); | 87 Translator.reset(PTranslator.release()); |
| 89 } else if (BuildDefs::llvmIr()) { | 88 } else if (BuildDefs::llvmIr()) { |
| 90 if (BuildDefs::browser()) { | 89 if (BuildDefs::browser()) { |
| 91 Ctx.getStrError() | 90 Ctx.getStrError() |
| 92 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; | 91 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; |
| 93 Ctx.getErrorStatus()->assign(EC_Args); | 92 Ctx.getErrorStatus()->assign(EC_Args); |
| 94 return; | 93 return; |
| 95 } | 94 } |
| 96 // Globals must be kept alive after lowering when converting from LLVM to | 95 // Globals must be kept alive after lowering when converting from LLVM to |
| 97 // Ice. | 96 // Ice. |
| 98 Ctx.setDisposeGlobalVariablesAfterLowering(false); | 97 Ctx.setDisposeGlobalVariablesAfterLowering(false); |
| 99 // Parse the input LLVM IR file into a module. | 98 // Parse the input LLVM IR file into a module. |
| 100 llvm::SMDiagnostic Err; | 99 llvm::SMDiagnostic Err; |
| 101 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); | 100 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); |
| 102 llvm::DiagnosticHandlerFunction DiagnosticHandler = | 101 llvm::DiagnosticHandlerFunction DiagnosticHandler = |
| 103 ExtraFlags.getLLVMVerboseErrors() | 102 Flags.getLLVMVerboseErrors() |
| 104 ? redirectNaClDiagnosticToStream(llvm::errs()) | 103 ? redirectNaClDiagnosticToStream(llvm::errs()) |
| 105 : nullptr; | 104 : nullptr; |
| 106 std::unique_ptr<llvm::Module> Mod = | 105 std::unique_ptr<llvm::Module> Mod = |
| 107 NaClParseIRFile(IRFilename, ExtraFlags.getInputFileFormat(), Err, | 106 NaClParseIRFile(IRFilename, Flags.getInputFileFormat(), Err, |
| 108 llvm::getGlobalContext(), DiagnosticHandler); | 107 llvm::getGlobalContext(), DiagnosticHandler); |
| 109 if (!Mod) { | 108 if (!Mod) { |
| 110 Err.print(ExtraFlags.getAppName().c_str(), llvm::errs()); | 109 Err.print(Flags.getAppName().c_str(), llvm::errs()); |
| 111 Ctx.getErrorStatus()->assign(EC_Bitcode); | 110 Ctx.getErrorStatus()->assign(EC_Bitcode); |
| 112 return; | 111 return; |
| 113 } | 112 } |
| 114 | 113 |
| 115 std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx)); | 114 std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx)); |
| 116 Converter->convertToIce(); | 115 Converter->convertToIce(); |
| 117 Translator.reset(Converter.release()); | 116 Translator.reset(Converter.release()); |
| 118 } else { | 117 } else { |
| 119 Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, " | 118 Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, " |
| 120 << "--build-on-read=0 not allowed\n"; | 119 << "--build-on-read=0 not allowed\n"; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 143 | 142 |
| 144 if (Ctx.getFlags().getTimeEachFunction()) { | 143 if (Ctx.getFlags().getTimeEachFunction()) { |
| 145 constexpr bool NoDumpCumulative = false; | 144 constexpr bool NoDumpCumulative = false; |
| 146 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); | 145 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); |
| 147 } | 146 } |
| 148 constexpr bool FinalStats = true; | 147 constexpr bool FinalStats = true; |
| 149 Ctx.dumpStats("_FINAL_", FinalStats); | 148 Ctx.dumpStats("_FINAL_", FinalStats); |
| 150 } | 149 } |
| 151 | 150 |
| 152 } // end of namespace Ice | 151 } // end of namespace Ice |
| OLD | NEW |