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

Side by Side Diff: src/llvm2ice.cpp

Issue 870653002: Subzero: Initial implementation of multithreaded translation. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes, continued Created 5 years, 11 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
OLDNEW
1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===//
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 // This file defines a driver that uses LLVM capabilities to parse a 10 // This file defines a driver that uses LLVM capabilities to parse a
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 static cl::opt<bool> AlwaysExitSuccess( 196 static cl::opt<bool> AlwaysExitSuccess(
197 "exit-success", cl::desc("Exit with success status, even if errors found"), 197 "exit-success", cl::desc("Exit with success status, even if errors found"),
198 cl::init(false)); 198 cl::init(false));
199 199
200 static cl::opt<bool> 200 static cl::opt<bool>
201 GenerateBuildAtts("build-atts", 201 GenerateBuildAtts("build-atts",
202 cl::desc("Generate list of build attributes associated with " 202 cl::desc("Generate list of build attributes associated with "
203 "this executable."), 203 "this executable."),
204 cl::init(false)); 204 cl::init(false));
205 205
206 // Number of translation threads (in addition to the parser thread and
207 // the emitter thread). The special case of 0 means purely
208 // sequential, i.e. parser, translator, and emitter all within the
209 // same single thread. (This may need a slight rework if we expand to
210 // multiple parser or emitter threads.)
211 static cl::opt<uint32_t>
212 NumThreads("threads",
213 cl::desc("Number of translation threads (0 for purely sequential)"),
214 // TODO(stichnot): Settle on a good default. Consider
215 // something related to std::thread::hardware_concurrency().
216 cl::init(0));
217
206 static int GetReturnValue(int Val) { 218 static int GetReturnValue(int Val) {
207 if (AlwaysExitSuccess) 219 if (AlwaysExitSuccess)
208 return 0; 220 return 0;
209 return Val; 221 return Val;
210 } 222 }
211 223
212 static struct { 224 static struct {
213 const char *FlagName; 225 const char *FlagName;
214 int FlagValue; 226 int FlagValue;
215 } ConditionalBuildAttributes[] = {{"dump", ALLOW_DUMP}, 227 } ConditionalBuildAttributes[] = {{"dump", ALLOW_DUMP},
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 << "ALLOW_DISABLE_IR_GEN!\n"; 293 << "ALLOW_DISABLE_IR_GEN!\n";
282 return GetReturnValue(1); 294 return GetReturnValue(1);
283 } 295 }
284 296
285 Ice::ClFlags Flags; 297 Ice::ClFlags Flags;
286 Flags.DisableInternal = DisableInternal; 298 Flags.DisableInternal = DisableInternal;
287 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; 299 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled;
288 Flags.DisableTranslation = DisableTranslation; 300 Flags.DisableTranslation = DisableTranslation;
289 Flags.FunctionSections = FunctionSections; 301 Flags.FunctionSections = FunctionSections;
290 Flags.DataSections = DataSections; 302 Flags.DataSections = DataSections;
303 Flags.UseELFWriter = UseELFWriter;
291 Flags.UseIntegratedAssembler = UseIntegratedAssembler; 304 Flags.UseIntegratedAssembler = UseIntegratedAssembler;
292 Flags.UseELFWriter = UseELFWriter;
293 Flags.UseSandboxing = UseSandboxing; 305 Flags.UseSandboxing = UseSandboxing;
294 Flags.PhiEdgeSplit = EnablePhiEdgeSplit; 306 Flags.PhiEdgeSplit = EnablePhiEdgeSplit;
295 Flags.DecorateAsm = DecorateAsm; 307 Flags.DecorateAsm = DecorateAsm;
296 Flags.DumpStats = DumpStats; 308 Flags.DumpStats = DumpStats;
297 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals; 309 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals;
298 Flags.TimeEachFunction = TimeEachFunction; 310 Flags.TimeEachFunction = TimeEachFunction;
311 Flags.NumTranslationThreads = NumThreads;
299 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix; 312 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix;
300 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix; 313 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix;
301 Flags.TimingFocusOn = TimingFocusOn; 314 Flags.TimingFocusOn = TimingFocusOn;
302 Flags.VerboseFocusOn = VerboseFocusOn; 315 Flags.VerboseFocusOn = VerboseFocusOn;
303 Flags.TranslateOnly = TranslateOnly; 316 Flags.TranslateOnly = TranslateOnly;
304 Flags.DisableIRGeneration = DisableIRGeneration; 317 Flags.DisableIRGeneration = DisableIRGeneration;
305 Flags.AllowErrorRecovery = AllowErrorRecovery; 318 Flags.AllowErrorRecovery = AllowErrorRecovery;
306 319
307 // Force -build-on-read=0 for .ll files. 320 // Force -build-on-read=0 for .ll files.
308 const std::string LLSuffix = ".ll"; 321 const std::string LLSuffix = ".ll";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 Ice::GlobalContext Ctx(Ls.get(), Os.get(), ELFStr.get(), VMask, TargetArch, 357 Ice::GlobalContext Ctx(Ls.get(), Os.get(), ELFStr.get(), VMask, TargetArch,
345 OptLevel, TestPrefix, Flags); 358 OptLevel, TestPrefix, Flags);
346 359
347 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); 360 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx);
348 361
349 if (UseELFWriter) { 362 if (UseELFWriter) {
350 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx); 363 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx);
351 Ctx.getObjectWriter()->writeInitialELFHeader(); 364 Ctx.getObjectWriter()->writeInitialELFHeader();
352 } 365 }
353 366
354 int ErrorStatus = 0; 367 Ctx.startWorkerThreads();
368
369 std::unique_ptr<Ice::Translator> Translator;
355 if (BuildOnRead) { 370 if (BuildOnRead) {
356 Ice::PNaClTranslator Translator(&Ctx, Flags); 371 std::unique_ptr<Ice::PNaClTranslator> PTranslator(
357 Translator.translate(IRFilename); 372 new Ice::PNaClTranslator(&Ctx, Flags));
358 ErrorStatus = Translator.getErrorStatus(); 373 PTranslator->translate(IRFilename);
374 Translator.reset(PTranslator.release());
359 } else if (ALLOW_LLVM_IR) { 375 } else if (ALLOW_LLVM_IR) {
360 // Parse the input LLVM IR file into a module. 376 // Parse the input LLVM IR file into a module.
361 SMDiagnostic Err; 377 SMDiagnostic Err;
362 Ice::TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); 378 Ice::TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx);
363 raw_ostream *Verbose = LLVMVerboseErrors ? &errs() : nullptr; 379 raw_ostream *Verbose = LLVMVerboseErrors ? &errs() : nullptr;
364 Module *Mod = 380 Module *Mod =
365 NaClParseIRFile(IRFilename, InputFileFormat, Err, Verbose, 381 NaClParseIRFile(IRFilename, InputFileFormat, Err, Verbose,
366 getGlobalContext()); 382 getGlobalContext());
367 383
368 if (!Mod) { 384 if (!Mod) {
369 Err.print(argv[0], errs()); 385 Err.print(argv[0], errs());
370 return GetReturnValue(1); 386 return GetReturnValue(1);
371 } 387 }
372 388
373 Ice::Converter Converter(Mod, &Ctx, Flags); 389 std::unique_ptr<Ice::Converter> Converter(
374 Converter.convertToIce(); 390 new Ice::Converter(Mod, &Ctx, Flags));
375 ErrorStatus = Converter.getErrorStatus(); 391 Converter->convertToIce();
392 Translator.reset(Converter.release());
376 } else { 393 } else {
377 *Ls << "Error: Build doesn't allow LLVM IR, " 394 *Ls << "Error: Build doesn't allow LLVM IR, "
378 << "--build-on-read=0 not allowed\n"; 395 << "--build-on-read=0 not allowed\n";
379 return GetReturnValue(1); 396 return GetReturnValue(1);
380 } 397 }
398
399 Ctx.waitForWorkerThreads();
400 Translator->emitConstants();
401 // Error status is the combination of the bitcode parser's error
jvoung (off chromium) 2015/01/23 22:56:37 Seems like this could be a bit confusing but "tran
Jim Stichnoth 2015/01/25 07:29:39 Good point. Originally, each function tracked its
402 // status and the translation error status.
403 std::error_code ErrorStatus = Translator->getErrorStatus();
404 if (!ErrorStatus)
405 ErrorStatus = Ctx.getErrorStatus();
406
381 if (UseELFWriter) { 407 if (UseELFWriter) {
382 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx); 408 Ice::TimerMarker T1(Ice::TimerStack::TT_emit, &Ctx);
383 Ctx.getObjectWriter()->writeNonUserSections(); 409 Ctx.getObjectWriter()->writeNonUserSections();
384 } 410 }
385 if (SubzeroTimingEnabled) 411 if (SubzeroTimingEnabled)
386 Ctx.dumpTimers(); 412 Ctx.dumpTimers();
387 if (TimeEachFunction) { 413 if (TimeEachFunction) {
388 const bool DumpCumulative = false; 414 const bool DumpCumulative = false;
389 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); 415 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative);
390 } 416 }
391 const bool FinalStats = true; 417 const bool FinalStats = true;
392 Ctx.dumpStats("_FINAL_", FinalStats); 418 Ctx.dumpStats("_FINAL_", FinalStats);
393 return GetReturnValue(ErrorStatus); 419 return GetReturnValue(ErrorStatus.value());
394 } 420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698