Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(775)

Side by Side Diff: src/IceCompiler.cpp

Issue 1837663002: Initial Subzero WASM prototype. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review feedback and merging master Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceClFlags.def ('k') | src/IceDefs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "WasmTranslator.h"
28 29
29 #ifdef __clang__ 30 #ifdef __clang__
30 #pragma clang diagnostic push 31 #pragma clang diagnostic push
31 #pragma clang diagnostic ignored "-Wunused-parameter" 32 #pragma clang diagnostic ignored "-Wunused-parameter"
32 #endif // __clang__ 33 #endif // __clang__
33 34
34 #include "llvm/ADT/STLExtras.h" 35 #include "llvm/ADT/STLExtras.h"
35 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" 36 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
36 #include "llvm/IR/LLVMContext.h" 37 #include "llvm/IR/LLVMContext.h"
37 #include "llvm/IR/Module.h" 38 #include "llvm/IR/Module.h"
38 #include "llvm/IRReader/IRReader.h" 39 #include "llvm/IRReader/IRReader.h"
39 #include "llvm/Support/SourceMgr.h" 40 #include "llvm/Support/SourceMgr.h"
40 #include "llvm/Support/StreamingMemoryObject.h" 41 #include "llvm/Support/StreamingMemoryObject.h"
41 42
42 #ifdef __clang__ 43 #ifdef __clang__
43 #pragma clang diagnostic pop 44 #pragma clang diagnostic pop
44 #endif // __clang__ 45 #endif // __clang__
45 46
46 #include <regex> 47 #include <regex>
47 48
48 namespace Ice { 49 namespace Ice {
49 50
50 namespace { 51 namespace {
51 52
52 bool llvmIRInput(const std::string &Filename) { 53 bool llvmIRInput(const std::string &Filename) {
53 return BuildDefs::llvmIrAsInput() && 54 return BuildDefs::llvmIrAsInput() &&
54 std::regex_match(Filename, std::regex(".*\\.ll")); 55 std::regex_match(Filename, std::regex(".*\\.ll"));
55 } 56 }
56 57
58 bool wasmInput(const std::string &Filename) {
59 return BuildDefs::llvmIrAsInput() &&
60 std::regex_match(Filename, std::regex(".*\\.wasm"));
61 }
62
57 } // end of anonymous namespace 63 } // end of anonymous namespace
58 64
59 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx, 65 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx,
60 std::unique_ptr<llvm::DataStreamer> &&InputStream) { 66 std::unique_ptr<llvm::DataStreamer> &&InputStream) {
61 // The Minimal build (specifically, when dump()/emit() are not implemented) 67 // The Minimal build (specifically, when dump()/emit() are not implemented)
62 // allows only --filetype=obj. Check here to avoid cryptic error messages 68 // allows only --filetype=obj. Check here to avoid cryptic error messages
63 // downstream. 69 // downstream.
64 if (!BuildDefs::dump() && getFlags().getOutFileType() != FT_Elf) { 70 if (!BuildDefs::dump() && getFlags().getOutFileType() != FT_Elf) {
65 Ctx.getStrError() 71 Ctx.getStrError()
66 << "Error: only --filetype=obj is supported in this build.\n"; 72 << "Error: only --filetype=obj is supported in this build.\n";
67 Ctx.getErrorStatus()->assign(EC_Args); 73 Ctx.getErrorStatus()->assign(EC_Args);
68 return; 74 return;
69 } 75 }
70 76
71 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); 77 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx);
72 78
73 Ctx.emitFileHeader(); 79 Ctx.emitFileHeader();
74 Ctx.startWorkerThreads(); 80 Ctx.startWorkerThreads();
75 81
76 std::unique_ptr<Translator> Translator; 82 std::unique_ptr<Translator> Translator;
77 const std::string IRFilename = Flags.getIRFilename(); 83 const std::string IRFilename = Flags.getIRFilename();
78 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename); 84 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename) &&
85 !wasmInput(IRFilename);
86 const bool WasmBuildOnRead = Flags.getBuildOnRead() && wasmInput(IRFilename);
79 if (BuildOnRead) { 87 if (BuildOnRead) {
80 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); 88 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx));
81 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( 89 std::unique_ptr<llvm::StreamingMemoryObject> MemObj(
82 new llvm::StreamingMemoryObjectImpl(InputStream.release())); 90 new llvm::StreamingMemoryObjectImpl(InputStream.release()));
83 PTranslator->translate(IRFilename, std::move(MemObj)); 91 PTranslator->translate(IRFilename, std::move(MemObj));
84 Translator.reset(PTranslator.release()); 92 Translator.reset(PTranslator.release());
93 } else if (WasmBuildOnRead) {
94 if (BuildDefs::wasm()) {
95 std::unique_ptr<WasmTranslator> WTranslator(new WasmTranslator(&Ctx));
96
97 WTranslator->translate(IRFilename, std::move(InputStream));
98
99 Translator.reset(WTranslator.release());
100 } else {
101 Ctx.getStrError() << "WASM support not enabled\n";
102 Ctx.getErrorStatus()->assign(EC_Args);
103 return;
104 }
85 } else if (BuildDefs::llvmIr()) { 105 } else if (BuildDefs::llvmIr()) {
86 if (BuildDefs::browser()) { 106 if (BuildDefs::browser()) {
87 Ctx.getStrError() 107 Ctx.getStrError()
88 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; 108 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n";
89 Ctx.getErrorStatus()->assign(EC_Args); 109 Ctx.getErrorStatus()->assign(EC_Args);
90 Ctx.waitForWorkerThreads(); 110 Ctx.waitForWorkerThreads();
91 return; 111 return;
92 } 112 }
93 // Globals must be kept alive after lowering when converting from LLVM to 113 // Globals must be kept alive after lowering when converting from LLVM to
94 // Ice. 114 // Ice.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 Ctx.dumpTimers(); 161 Ctx.dumpTimers();
142 162
143 if (getFlags().getTimeEachFunction()) { 163 if (getFlags().getTimeEachFunction()) {
144 constexpr bool NoDumpCumulative = false; 164 constexpr bool NoDumpCumulative = false;
145 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); 165 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative);
146 } 166 }
147 Ctx.dumpStats(); 167 Ctx.dumpStats();
148 } 168 }
149 169
150 } // end of namespace Ice 170 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceClFlags.def ('k') | src/IceDefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698