Chromium Code Reviews| 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 "IceConverter.h" | 25 #include "IceConverter.h" |
| 26 #include "IceELFObjectWriter.h" | 26 #include "IceELFObjectWriter.h" |
| 27 #include "PNaClTranslator.h" | 27 #include "PNaClTranslator.h" |
| 28 | 28 |
|
Jim Stichnoth
2016/04/01 01:46:44
remove blank line?
Eric Holk
2016/04/01 19:15:01
Done.
| |
| 29 #include "WasmTranslator.h" | |
| 30 | |
| 29 #ifdef __clang__ | 31 #ifdef __clang__ |
| 30 #pragma clang diagnostic push | 32 #pragma clang diagnostic push |
| 31 #pragma clang diagnostic ignored "-Wunused-parameter" | 33 #pragma clang diagnostic ignored "-Wunused-parameter" |
| 32 #endif // __clang__ | 34 #endif // __clang__ |
| 33 | 35 |
| 34 #include "llvm/ADT/STLExtras.h" | 36 #include "llvm/ADT/STLExtras.h" |
| 35 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" | 37 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" |
| 36 #include "llvm/IR/LLVMContext.h" | 38 #include "llvm/IR/LLVMContext.h" |
| 37 #include "llvm/IR/Module.h" | 39 #include "llvm/IR/Module.h" |
| 38 #include "llvm/IRReader/IRReader.h" | 40 #include "llvm/IRReader/IRReader.h" |
| 39 #include "llvm/Support/SourceMgr.h" | 41 #include "llvm/Support/SourceMgr.h" |
| 40 #include "llvm/Support/StreamingMemoryObject.h" | 42 #include "llvm/Support/StreamingMemoryObject.h" |
| 41 | 43 |
| 42 #ifdef __clang__ | 44 #ifdef __clang__ |
| 43 #pragma clang diagnostic pop | 45 #pragma clang diagnostic pop |
| 44 #endif // __clang__ | 46 #endif // __clang__ |
| 45 | 47 |
| 46 #include <regex> | 48 #include <regex> |
| 47 | 49 |
| 48 namespace Ice { | 50 namespace Ice { |
| 49 | 51 |
| 50 namespace { | 52 namespace { |
| 51 | 53 |
| 52 bool llvmIRInput(const std::string &Filename) { | 54 bool llvmIRInput(const std::string &Filename) { |
| 53 return BuildDefs::llvmIrAsInput() && | 55 return BuildDefs::llvmIrAsInput() && |
| 54 std::regex_match(Filename, std::regex(".*\\.ll")); | 56 std::regex_match(Filename, std::regex(".*\\.ll")); |
| 55 } | 57 } |
| 56 | 58 |
| 59 bool wasmInput(const std::string &Filename) { | |
| 60 return BuildDefs::llvmIrAsInput() && | |
| 61 std::regex_match(Filename, std::regex(".*\\.wasm")); | |
| 62 } | |
| 63 | |
| 57 } // end of anonymous namespace | 64 } // end of anonymous namespace |
| 58 | 65 |
| 59 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx, | 66 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx, |
| 60 std::unique_ptr<llvm::DataStreamer> &&InputStream) { | 67 std::unique_ptr<llvm::DataStreamer> &&InputStream) { |
| 61 // The Minimal build (specifically, when dump()/emit() are not implemented) | 68 // The Minimal build (specifically, when dump()/emit() are not implemented) |
| 62 // allows only --filetype=obj. Check here to avoid cryptic error messages | 69 // allows only --filetype=obj. Check here to avoid cryptic error messages |
| 63 // downstream. | 70 // downstream. |
| 64 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { | 71 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { |
| 65 // TODO(stichnot): Access the actual command-line argument via | 72 // TODO(stichnot): Access the actual command-line argument via |
| 66 // llvm::Option.ArgStr and .ValueStr . | 73 // llvm::Option.ArgStr and .ValueStr . |
| 67 Ctx.getStrError() | 74 Ctx.getStrError() |
| 68 << "Error: only --filetype=obj is supported in this build.\n"; | 75 << "Error: only --filetype=obj is supported in this build.\n"; |
| 69 Ctx.getErrorStatus()->assign(EC_Args); | 76 Ctx.getErrorStatus()->assign(EC_Args); |
| 70 return; | 77 return; |
| 71 } | 78 } |
| 72 | 79 |
| 73 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 80 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
| 74 | 81 |
| 75 Ctx.emitFileHeader(); | 82 Ctx.emitFileHeader(); |
| 76 Ctx.startWorkerThreads(); | 83 Ctx.startWorkerThreads(); |
| 77 | 84 |
| 78 std::unique_ptr<Translator> Translator; | 85 std::unique_ptr<Translator> Translator; |
| 79 const std::string IRFilename = Flags.getIRFilename(); | 86 const std::string &IRFilename = Flags.getIRFilename(); |
| 80 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename); | 87 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename) && |
| 88 !wasmInput(IRFilename); | |
| 89 const bool WasmBuildOnRead = Flags.getBuildOnRead() && wasmInput(IRFilename); | |
| 81 if (BuildOnRead) { | 90 if (BuildOnRead) { |
| 82 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); | 91 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); |
| 83 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( | 92 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( |
| 84 new llvm::StreamingMemoryObjectImpl(InputStream.release())); | 93 new llvm::StreamingMemoryObjectImpl(InputStream.release())); |
| 85 PTranslator->translate(IRFilename, std::move(MemObj)); | 94 PTranslator->translate(IRFilename, std::move(MemObj)); |
| 86 Translator.reset(PTranslator.release()); | 95 Translator.reset(PTranslator.release()); |
| 96 } else if (WasmBuildOnRead) { | |
| 97 if (BuildDefs::wasm()) { | |
| 98 std::unique_ptr<WasmTranslator> WTranslator(new WasmTranslator(&Ctx)); | |
| 99 | |
| 100 WTranslator->translate(IRFilename, std::move(InputStream)); | |
| 101 | |
| 102 Translator.reset(WTranslator.release()); | |
| 103 } else { | |
| 104 Ctx.getStrError() << "WASM support not enabled\n"; | |
| 105 Ctx.getErrorStatus()->assign(EC_Args); | |
| 106 return; | |
| 107 } | |
| 87 } else if (BuildDefs::llvmIr()) { | 108 } else if (BuildDefs::llvmIr()) { |
| 88 if (BuildDefs::browser()) { | 109 if (BuildDefs::browser()) { |
| 89 Ctx.getStrError() | 110 Ctx.getStrError() |
| 90 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; | 111 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; |
| 91 Ctx.getErrorStatus()->assign(EC_Args); | 112 Ctx.getErrorStatus()->assign(EC_Args); |
| 92 return; | 113 return; |
| 93 } | 114 } |
| 94 // Globals must be kept alive after lowering when converting from LLVM to | 115 // Globals must be kept alive after lowering when converting from LLVM to |
| 95 // Ice. | 116 // Ice. |
| 96 Ctx.setDisposeGlobalVariablesAfterLowering(false); | 117 Ctx.setDisposeGlobalVariablesAfterLowering(false); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 | 162 |
| 142 if (Ctx.getFlags().getTimeEachFunction()) { | 163 if (Ctx.getFlags().getTimeEachFunction()) { |
| 143 constexpr bool NoDumpCumulative = false; | 164 constexpr bool NoDumpCumulative = false; |
| 144 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); | 165 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); |
| 145 } | 166 } |
| 146 constexpr bool FinalStats = true; | 167 constexpr bool FinalStats = true; |
| 147 Ctx.dumpStats("_FINAL_", FinalStats); | 168 Ctx.dumpStats("_FINAL_", FinalStats); |
| 148 } | 169 } |
| 149 | 170 |
| 150 } // end of namespace Ice | 171 } // end of namespace Ice |
| OLD | NEW |