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

Side by Side Diff: src/IceCfg.cpp

Issue 876083007: Subzero: Emit functions and global initializers in a separate thread. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: More code review changes Created 5 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 | « src/IceCfg.h ('k') | src/IceCfgNode.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/IceCfg.cpp - Control flow graph implementation ---------===// 1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===//
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 implements the Cfg class, including constant pool 10 // This file implements the Cfg class, including constant pool
(...skipping 13 matching lines...) Expand all
24 #include "IceTargetLowering.h" 24 #include "IceTargetLowering.h"
25 25
26 namespace Ice { 26 namespace Ice {
27 27
28 ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg); 28 ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg);
29 29
30 ArenaAllocator<> *getCurrentCfgAllocator() { 30 ArenaAllocator<> *getCurrentCfgAllocator() {
31 return Cfg::getCurrentCfgAllocator(); 31 return Cfg::getCurrentCfgAllocator();
32 } 32 }
33 33
34 Cfg::Cfg(GlobalContext *Ctx) 34 Cfg::Cfg(GlobalContext *Ctx, uint32_t SequenceNumber)
35 : Ctx(Ctx), VMask(Ctx->getVerbose()), FunctionName(""), 35 : Ctx(Ctx), SequenceNumber(SequenceNumber), VMask(Ctx->getVerbose()),
36 ReturnType(IceType_void), IsInternalLinkage(false), HasError(false), 36 FunctionName(""), ReturnType(IceType_void), IsInternalLinkage(false),
37 FocusedTiming(false), ErrorMessage(""), Entry(nullptr), 37 HasError(false), FocusedTiming(false), ErrorMessage(""), Entry(nullptr),
38 NextInstNumber(Inst::NumberInitial), Allocator(new ArenaAllocator<>()), 38 NextInstNumber(Inst::NumberInitial), Allocator(new ArenaAllocator<>()),
39 Live(nullptr), 39 Live(nullptr),
40 Target(TargetLowering::createLowering(Ctx->getTargetArch(), this)), 40 Target(TargetLowering::createLowering(Ctx->getTargetArch(), this)),
41 VMetadata(new VariablesMetadata(this)), 41 VMetadata(new VariablesMetadata(this)),
42 TargetAssembler( 42 TargetAssembler(
43 TargetLowering::createAssembler(Ctx->getTargetArch(), this)), 43 TargetLowering::createAssembler(Ctx->getTargetArch(), this)),
44 CurrentNode(nullptr) { 44 CurrentNode(nullptr) {
45 assert(!Ctx->isIRGenerationDisabled() && 45 assert(!Ctx->isIRGenerationDisabled() &&
46 "Attempt to build cfg when IR generation disabled"); 46 "Attempt to build cfg when IR generation disabled");
47 } 47 }
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 TimerMarker T(TimerStack::TT_doBranchOpt, this); 410 TimerMarker T(TimerStack::TT_doBranchOpt, this);
411 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { 411 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
412 auto NextNode = I; 412 auto NextNode = I;
413 ++NextNode; 413 ++NextNode;
414 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode); 414 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode);
415 } 415 }
416 } 416 }
417 417
418 // ======================== Dump routines ======================== // 418 // ======================== Dump routines ======================== //
419 419
420 void Cfg::emitTextHeader(const IceString &MangledName) { 420 // emitTextHeader() is not target-specific (apart from what is
421 // abstracted by the Assembler), so it is defined here rather than in
422 // the target lowering class.
423 void Cfg::emitTextHeader(const IceString &MangledName, GlobalContext *Ctx,
424 Assembler *Asm) {
421 // Note: Still used by emit IAS. 425 // Note: Still used by emit IAS.
422 Ostream &Str = Ctx->getStrEmit(); 426 Ostream &Str = Ctx->getStrEmit();
423 Str << "\t.text\n"; 427 Str << "\t.text\n";
424 if (Ctx->getFlags().FunctionSections) 428 if (Ctx->getFlags().FunctionSections)
425 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n"; 429 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n";
426 if (!getInternal() || Ctx->getFlags().DisableInternal) { 430 if (!Asm->getInternal() || Ctx->getFlags().DisableInternal) {
427 Str << "\t.globl\t" << MangledName << "\n"; 431 Str << "\t.globl\t" << MangledName << "\n";
428 Str << "\t.type\t" << MangledName << ",@function\n"; 432 Str << "\t.type\t" << MangledName << ",@function\n";
429 } 433 }
430 Assembler *Asm = getAssembler<Assembler>();
431 Str << "\t.p2align " << Asm->getBundleAlignLog2Bytes() << ",0x"; 434 Str << "\t.p2align " << Asm->getBundleAlignLog2Bytes() << ",0x";
432 for (uint8_t I : Asm->getNonExecBundlePadding()) 435 for (uint8_t I : Asm->getNonExecBundlePadding())
433 Str.write_hex(I); 436 Str.write_hex(I);
434 Str << "\n"; 437 Str << "\n";
435 Str << MangledName << ":\n"; 438 Str << MangledName << ":\n";
436 } 439 }
437 440
438 void Cfg::emit() { 441 void Cfg::emit() {
439 if (!ALLOW_DUMP) 442 if (!ALLOW_DUMP)
440 return; 443 return;
441 TimerMarker T(TimerStack::TT_emit, this); 444 TimerMarker T(TimerStack::TT_emit, this);
442 if (Ctx->getFlags().DecorateAsm) { 445 if (Ctx->getFlags().DecorateAsm) {
443 renumberInstructions(); 446 renumberInstructions();
444 getVMetadata()->init(VMK_Uses); 447 getVMetadata()->init(VMK_Uses);
445 liveness(Liveness_Basic); 448 liveness(Liveness_Basic);
446 dump("After recomputing liveness for -decorate-asm"); 449 dump("After recomputing liveness for -decorate-asm");
447 } 450 }
448 OstreamLocker L(Ctx); 451 OstreamLocker L(Ctx);
449 Ostream &Str = Ctx->getStrEmit(); 452 Ostream &Str = Ctx->getStrEmit();
450 IceString MangledName = getContext()->mangleName(getFunctionName()); 453 IceString MangledName = getContext()->mangleName(getFunctionName());
451 emitTextHeader(MangledName); 454 emitTextHeader(MangledName, Ctx, getAssembler<>());
452 for (CfgNode *Node : Nodes) 455 for (CfgNode *Node : Nodes)
453 Node->emit(this); 456 Node->emit(this);
454 Str << "\n"; 457 Str << "\n";
455 } 458 }
456 459
457 void Cfg::emitIAS() { 460 void Cfg::emitIAS() {
458 TimerMarker T(TimerStack::TT_emit, this); 461 TimerMarker T(TimerStack::TT_emit, this);
459 assert(!Ctx->getFlags().DecorateAsm); 462 assert(!Ctx->getFlags().DecorateAsm);
460 IceString MangledName = getContext()->mangleName(getFunctionName());
461 // The emitIAS() routines emit into the internal assembler buffer, 463 // The emitIAS() routines emit into the internal assembler buffer,
462 // so there's no need to lock the streams until we're ready to call 464 // so there's no need to lock the streams.
463 // emitIASBytes().
464 for (CfgNode *Node : Nodes) 465 for (CfgNode *Node : Nodes)
465 Node->emitIAS(this); 466 Node->emitIAS(this);
466 // Now write the function to the file and track.
467 if (Ctx->getFlags().UseELFWriter) {
468 getAssembler<Assembler>()->alignFunction();
469 Ctx->getObjectWriter()->writeFunctionCode(MangledName, getInternal(),
470 getAssembler<Assembler>());
471 } else {
472 OstreamLocker L(Ctx);
473 emitTextHeader(MangledName);
474 getAssembler<Assembler>()->emitIASBytes(Ctx);
475 }
476 } 467 }
477 468
478 // Dumps the IR with an optional introductory message. 469 // Dumps the IR with an optional introductory message.
479 void Cfg::dump(const IceString &Message) { 470 void Cfg::dump(const IceString &Message) {
480 if (!ALLOW_DUMP) 471 if (!ALLOW_DUMP)
481 return; 472 return;
482 if (!isVerbose()) 473 if (!isVerbose())
483 return; 474 return;
484 OstreamLocker L(Ctx); 475 OstreamLocker L(Ctx);
485 Ostream &Str = Ctx->getStrDump(); 476 Ostream &Str = Ctx->getStrDump();
(...skipping 29 matching lines...) Expand all
515 } 506 }
516 } 507 }
517 // Print each basic block 508 // Print each basic block
518 for (CfgNode *Node : Nodes) 509 for (CfgNode *Node : Nodes)
519 Node->dump(this); 510 Node->dump(this);
520 if (isVerbose(IceV_Instructions)) 511 if (isVerbose(IceV_Instructions))
521 Str << "}\n"; 512 Str << "}\n";
522 } 513 }
523 514
524 } // end of namespace Ice 515 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfg.h ('k') | src/IceCfgNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698