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

Side by Side Diff: src/IceBrowserCompileServer.cpp

Issue 1696123003: Subzero: Set the correct target arch in the browser hookup. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Better bad-target error messages Created 4 years, 10 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 | « no previous file | src/IceTargetLowering.cpp » ('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/IceBrowserCompileServer.cpp - Browser compile server ---===// 1 //===- subzero/src/IceBrowserCompileServer.cpp - Browser compile server ---===//
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 the browser-based compile server. 11 /// \brief Defines the browser-based compile server.
12 /// 12 ///
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 // Can only compile this with the NaCl compiler (needs irt.h, and the 15 // Can only compile this with the NaCl compiler (needs irt.h, and the
16 // unsandboxed LLVM build using the trusted compiler does not have irt.h). 16 // unsandboxed LLVM build using the trusted compiler does not have irt.h).
17 #if PNACL_BROWSER_TRANSLATOR 17 #if PNACL_BROWSER_TRANSLATOR
18 18
19 #include "IceBrowserCompileServer.h" 19 #include "IceBrowserCompileServer.h"
20
21 // Headers which are not properly part of the SDK are included by their path in
22 // the NaCl tree.
23 #ifdef __pnacl__
24 #include "native_client/src/untrusted/nacl/pnacl.h"
25 #endif // __pnacl__
26
20 #include "llvm/Support/QueueStreamer.h" 27 #include "llvm/Support/QueueStreamer.h"
21 28
22 #include <cstring> 29 #include <cstring>
23 #include <irt.h> 30 #include <irt.h>
24 #include <irt_dev.h> 31 #include <irt_dev.h>
25 #include <pthread.h> 32 #include <pthread.h>
26 #include <thread> 33 #include <thread>
27 34
28 namespace Ice { 35 namespace Ice {
29 36
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // Only kill the current thread instead of the whole process. We need the 116 // Only kill the current thread instead of the whole process. We need the
110 // server thread to remain alive in order to respond with the error message. 117 // server thread to remain alive in order to respond with the error message.
111 // We could also try to pthread_kill all other worker threads, but 118 // We could also try to pthread_kill all other worker threads, but
112 // pthread_kill / raising signals is not supported by NaCl. We'll have to 119 // pthread_kill / raising signals is not supported by NaCl. We'll have to
113 // assume that the worker/emitter threads will be well behaved after a fatal 120 // assume that the worker/emitter threads will be well behaved after a fatal
114 // error in other threads, and either get stuck waiting on input from a 121 // error in other threads, and either get stuck waiting on input from a
115 // previous stage, or also call report_fatal_error. 122 // previous stage, or also call report_fatal_error.
116 pthread_exit(0); 123 pthread_exit(0);
117 } 124 }
118 125
126 /// Adapted from pnacl-llc's AddDefaultCPU() in srpc_main.cpp.
127 TargetArch getTargetArch() {
128 #if defined(__pnacl__)
129 switch (__builtin_nacl_target_arch()) {
John 2016/02/16 12:03:10 apparently __builtin_nacl_target_arch is deprecate
Jim Stichnoth 2016/02/16 13:52:12 Yeah, I noticed that, but I have no idea why the t
130 case PnaclTargetArchitectureX86_32:
131 case PnaclTargetArchitectureX86_32_NonSFI:
132 return Target_X8632;
133 case PnaclTargetArchitectureX86_64:
134 return Target_X8664;
135 case PnaclTargetArchitectureARM_32:
136 case PnaclTargetArchitectureARM_32_NonSFI:
137 return Target_ARM32;
138 case PnaclTargetArchitectureMips_32:
139 return Target_MIPS32;
140 default:
141 llvm::report_fatal_error("no target architecture match.");
142 }
143 #elif defined(__i386__)
144 return Target_X8632;
145 #elif defined(__x86_64__)
146 return Target_X8664;
147 #elif defined(__arm__)
148 return Target_ARM32;
149 #else
150 // TODO(stichnot): Add mips.
151 #error "Unknown architecture"
152 #endif
153 }
154
119 } // end of anonymous namespace 155 } // end of anonymous namespace
120 156
121 BrowserCompileServer::~BrowserCompileServer() = default; 157 BrowserCompileServer::~BrowserCompileServer() = default;
122 158
123 void BrowserCompileServer::run() { 159 void BrowserCompileServer::run() {
124 gCompileServer = this; 160 gCompileServer = this;
125 getIRTInterfaces(); 161 getIRTInterfaces();
126 gIRTFuncs.serve_translate_request(&SubzeroCallbacks); 162 gIRTFuncs.serve_translate_request(&SubzeroCallbacks);
127 } 163 }
128 164
129 void BrowserCompileServer::getParsedFlags(uint32_t NumThreads, int argc, 165 void BrowserCompileServer::getParsedFlags(uint32_t NumThreads, int argc,
130 char **argv) { 166 char **argv) {
131 ClFlags::parseFlags(argc, argv); 167 ClFlags::parseFlags(argc, argv);
132 ClFlags::getParsedClFlags(Flags); 168 ClFlags::getParsedClFlags(Flags);
133 ClFlags::getParsedClFlagsExtra(ExtraFlags); 169 ClFlags::getParsedClFlagsExtra(ExtraFlags);
134 // Set some defaults which aren't specified via the argv string. 170 // Set some defaults which aren't specified via the argv string.
135 Flags.setNumTranslationThreads(NumThreads); 171 Flags.setNumTranslationThreads(NumThreads);
136 Flags.setUseSandboxing(true); 172 Flags.setUseSandboxing(true);
137 Flags.setOutFileType(FT_Elf); 173 Flags.setOutFileType(FT_Elf);
138 // TODO(jvoung): allow setting different target arches. 174 Flags.setTargetArch(getTargetArch());
139 Flags.setTargetArch(Target_X8632);
140 ExtraFlags.setBuildOnRead(true); 175 ExtraFlags.setBuildOnRead(true);
141 ExtraFlags.setInputFileFormat(llvm::PNaClFormat); 176 ExtraFlags.setInputFileFormat(llvm::PNaClFormat);
142 } 177 }
143 178
144 bool BrowserCompileServer::pushInputBytes(const void *Data, size_t NumBytes) { 179 bool BrowserCompileServer::pushInputBytes(const void *Data, size_t NumBytes) {
145 // If there was an earlier error, do not attempt to push bytes to the 180 // If there was an earlier error, do not attempt to push bytes to the
146 // QueueStreamer. Otherwise the thread could become blocked. 181 // QueueStreamer. Otherwise the thread could become blocked.
147 if (HadError.load()) 182 if (HadError.load())
148 return true; 183 return true;
149 return InputStream->PutBytes( 184 return InputStream->PutBytes(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 this->getCompiler().run(ExtraFlags, *Ctx.get(), 224 this->getCompiler().run(ExtraFlags, *Ctx.get(),
190 // Retain original reference, but the compiler 225 // Retain original reference, but the compiler
191 // (LLVM's MemoryObject) wants to handle deletion. 226 // (LLVM's MemoryObject) wants to handle deletion.
192 std::unique_ptr<llvm::DataStreamer>(InputStream)); 227 std::unique_ptr<llvm::DataStreamer>(InputStream));
193 }); 228 });
194 } 229 }
195 230
196 } // end of namespace Ice 231 } // end of namespace Ice
197 232
198 #endif // PNACL_BROWSER_TRANSLATOR 233 #endif // PNACL_BROWSER_TRANSLATOR
OLDNEW
« no previous file with comments | « no previous file | src/IceTargetLowering.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698