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 "IceClFlags.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 SUBZERO_WASM | |
| 31 #include "WasmTranslator.h" | |
| 32 #endif | |
|
JF
2016/03/28 18:17:13
Why not put the #if in the other header?
Eric Holk
2016/03/29 19:54:08
Done.
| |
| 33 | |
| 30 #ifdef __clang__ | 34 #ifdef __clang__ |
| 31 #pragma clang diagnostic push | 35 #pragma clang diagnostic push |
| 32 #pragma clang diagnostic ignored "-Wunused-parameter" | 36 #pragma clang diagnostic ignored "-Wunused-parameter" |
| 33 #endif // __clang__ | 37 #endif // __clang__ |
| 34 | 38 |
| 35 #include "llvm/ADT/STLExtras.h" | 39 #include "llvm/ADT/STLExtras.h" |
| 36 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" | 40 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" |
| 37 #include "llvm/IR/LLVMContext.h" | 41 #include "llvm/IR/LLVMContext.h" |
| 38 #include "llvm/IR/Module.h" | 42 #include "llvm/IR/Module.h" |
| 39 #include "llvm/IRReader/IRReader.h" | 43 #include "llvm/IRReader/IRReader.h" |
| 40 #include "llvm/Support/SourceMgr.h" | 44 #include "llvm/Support/SourceMgr.h" |
| 41 #include "llvm/Support/StreamingMemoryObject.h" | 45 #include "llvm/Support/StreamingMemoryObject.h" |
| 42 | 46 |
| 43 #ifdef __clang__ | 47 #ifdef __clang__ |
| 44 #pragma clang diagnostic pop | 48 #pragma clang diagnostic pop |
| 45 #endif // __clang__ | 49 #endif // __clang__ |
| 46 | 50 |
| 47 #include <regex> | 51 #include <regex> |
| 48 | 52 |
| 49 namespace Ice { | 53 namespace Ice { |
| 50 | 54 |
| 51 namespace { | 55 namespace { |
| 52 | 56 |
| 53 bool llvmIRInput(const IceString &Filename) { | 57 bool llvmIRInput(const IceString &Filename) { |
| 54 return BuildDefs::llvmIrAsInput() && | 58 return BuildDefs::llvmIrAsInput() && |
| 55 std::regex_match(Filename, std::regex(".*\\.ll")); | 59 std::regex_match(Filename, std::regex(".*\\.ll")); |
| 56 } | 60 } |
| 57 | 61 |
| 62 bool wasmInput(const IceString &Filename) { | |
| 63 return BuildDefs::llvmIrAsInput() && | |
| 64 std::regex_match(Filename, std::regex(".*\\.wasm")); | |
|
JF
2016/03/28 18:17:13
Eek, I wouldn't use regex for this. It's a huge ha
Eric Holk
2016/03/29 19:54:08
I just cargo-culted from the previous llvmIRInput
| |
| 65 } | |
| 66 | |
| 58 } // end of anonymous namespace | 67 } // end of anonymous namespace |
| 59 | 68 |
| 60 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx, | 69 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx, |
| 61 std::unique_ptr<llvm::DataStreamer> &&InputStream) { | 70 std::unique_ptr<llvm::DataStreamer> &&InputStream) { |
| 62 // The Minimal build (specifically, when dump()/emit() are not implemented) | 71 // The Minimal build (specifically, when dump()/emit() are not implemented) |
| 63 // allows only --filetype=obj. Check here to avoid cryptic error messages | 72 // allows only --filetype=obj. Check here to avoid cryptic error messages |
| 64 // downstream. | 73 // downstream. |
| 65 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { | 74 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { |
| 66 // TODO(stichnot): Access the actual command-line argument via | 75 // TODO(stichnot): Access the actual command-line argument via |
| 67 // llvm::Option.ArgStr and .ValueStr . | 76 // llvm::Option.ArgStr and .ValueStr . |
| 68 Ctx.getStrError() | 77 Ctx.getStrError() |
| 69 << "Error: only --filetype=obj is supported in this build.\n"; | 78 << "Error: only --filetype=obj is supported in this build.\n"; |
| 70 Ctx.getErrorStatus()->assign(EC_Args); | 79 Ctx.getErrorStatus()->assign(EC_Args); |
| 71 return; | 80 return; |
| 72 } | 81 } |
| 73 | 82 |
| 74 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 83 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
| 75 | 84 |
| 76 Ctx.emitFileHeader(); | 85 Ctx.emitFileHeader(); |
| 77 Ctx.startWorkerThreads(); | 86 Ctx.startWorkerThreads(); |
| 78 | 87 |
| 79 std::unique_ptr<Translator> Translator; | 88 std::unique_ptr<Translator> Translator; |
| 80 const IceString &IRFilename = Flags.getIRFilename(); | 89 const IceString &IRFilename = Flags.getIRFilename(); |
| 81 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename); | 90 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename) && |
| 91 !wasmInput(IRFilename); | |
| 92 const bool WasmBuildOnRead = Flags.getBuildOnRead() && wasmInput(IRFilename); | |
| 82 if (BuildOnRead) { | 93 if (BuildOnRead) { |
| 83 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); | 94 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); |
| 84 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( | 95 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( |
| 85 new llvm::StreamingMemoryObjectImpl(InputStream.release())); | 96 new llvm::StreamingMemoryObjectImpl(InputStream.release())); |
| 86 PTranslator->translate(IRFilename, std::move(MemObj)); | 97 PTranslator->translate(IRFilename, std::move(MemObj)); |
| 87 Translator.reset(PTranslator.release()); | 98 Translator.reset(PTranslator.release()); |
| 99 } else if (WasmBuildOnRead) { | |
| 100 #ifdef SUBZERO_WASM | |
|
Jim Stichnoth
2016/03/29 17:49:57
We try to minimize the use of #ifdef code. Where
Eric Holk
2016/03/29 22:58:07
My latest update should have basically no #ifdef c
| |
| 101 std::unique_ptr<WasmTranslator> WTranslator(new WasmTranslator(&Ctx)); | |
| 102 | |
| 103 WTranslator->translate(IRFilename, std::move(InputStream)); | |
| 104 | |
| 105 Translator.reset(WTranslator.release()); | |
| 106 #else | |
| 107 Ctx.getStrError() | |
| 108 << "WASM support not enabled\n"; | |
| 109 Ctx.getErrorStatus()->assign(EC_Args); | |
| 110 return; | |
| 111 #endif | |
|
JF
2016/03/28 18:17:13
Would be nice if this switch were only visible fro
Eric Holk
2016/03/29 19:54:08
Done.
| |
| 88 } else if (BuildDefs::llvmIr()) { | 112 } else if (BuildDefs::llvmIr()) { |
| 89 if (BuildDefs::browser()) { | 113 if (BuildDefs::browser()) { |
| 90 Ctx.getStrError() | 114 Ctx.getStrError() |
| 91 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; | 115 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; |
| 92 Ctx.getErrorStatus()->assign(EC_Args); | 116 Ctx.getErrorStatus()->assign(EC_Args); |
| 93 return; | 117 return; |
| 94 } | 118 } |
| 95 // Globals must be kept alive after lowering when converting from LLVM to | 119 // Globals must be kept alive after lowering when converting from LLVM to |
| 96 // Ice. | 120 // Ice. |
| 97 Ctx.setDisposeGlobalVariablesAfterLowering(false); | 121 Ctx.setDisposeGlobalVariablesAfterLowering(false); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 | 166 |
| 143 if (Ctx.getFlags().getTimeEachFunction()) { | 167 if (Ctx.getFlags().getTimeEachFunction()) { |
| 144 constexpr bool NoDumpCumulative = false; | 168 constexpr bool NoDumpCumulative = false; |
| 145 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); | 169 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); |
| 146 } | 170 } |
| 147 constexpr bool FinalStats = true; | 171 constexpr bool FinalStats = true; |
| 148 Ctx.dumpStats("_FINAL_", FinalStats); | 172 Ctx.dumpStats("_FINAL_", FinalStats); |
| 149 } | 173 } |
| 150 | 174 |
| 151 } // end of namespace Ice | 175 } // end of namespace Ice |
| OLD | NEW |