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

Side by Side Diff: src/IceCfg.cpp

Issue 916653004: 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: Const change 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 TimerMarker T(TimerStack::TT_doBranchOpt, this); 411 TimerMarker T(TimerStack::TT_doBranchOpt, this);
412 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { 412 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
413 auto NextNode = I; 413 auto NextNode = I;
414 ++NextNode; 414 ++NextNode;
415 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode); 415 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode);
416 } 416 }
417 } 417 }
418 418
419 // ======================== Dump routines ======================== // 419 // ======================== Dump routines ======================== //
420 420
421 void Cfg::emitTextHeader(const IceString &MangledName) { 421 // emitTextHeader() is not target-specific (apart from what is
422 // abstracted by the Assembler), so it is defined here rather than in
423 // the target lowering class.
424 void Cfg::emitTextHeader(const IceString &MangledName, GlobalContext *Ctx,
425 const Assembler *Asm) {
422 // Note: Still used by emit IAS. 426 // Note: Still used by emit IAS.
423 Ostream &Str = Ctx->getStrEmit(); 427 Ostream &Str = Ctx->getStrEmit();
424 Str << "\t.text\n"; 428 Str << "\t.text\n";
425 if (Ctx->getFlags().getFunctionSections()) 429 if (Ctx->getFlags().getFunctionSections())
426 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n"; 430 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n";
427 if (!getInternal() || Ctx->getFlags().getDisableInternal()) { 431 if (!Asm->getInternal() || Ctx->getFlags().getDisableInternal()) {
428 Str << "\t.globl\t" << MangledName << "\n"; 432 Str << "\t.globl\t" << MangledName << "\n";
429 Str << "\t.type\t" << MangledName << ",@function\n"; 433 Str << "\t.type\t" << MangledName << ",@function\n";
430 } 434 }
431 Assembler *Asm = getAssembler<Assembler>();
432 Str << "\t.p2align " << Asm->getBundleAlignLog2Bytes() << ",0x"; 435 Str << "\t.p2align " << Asm->getBundleAlignLog2Bytes() << ",0x";
433 for (uint8_t I : Asm->getNonExecBundlePadding()) 436 for (uint8_t I : Asm->getNonExecBundlePadding())
434 Str.write_hex(I); 437 Str.write_hex(I);
435 Str << "\n"; 438 Str << "\n";
436 Str << MangledName << ":\n"; 439 Str << MangledName << ":\n";
437 } 440 }
438 441
439 void Cfg::emit() { 442 void Cfg::emit() {
440 if (!ALLOW_DUMP) 443 if (!ALLOW_DUMP)
441 return; 444 return;
442 TimerMarker T(TimerStack::TT_emit, this); 445 TimerMarker T(TimerStack::TT_emit, this);
443 if (Ctx->getFlags().getDecorateAsm()) { 446 if (Ctx->getFlags().getDecorateAsm()) {
444 renumberInstructions(); 447 renumberInstructions();
445 getVMetadata()->init(VMK_Uses); 448 getVMetadata()->init(VMK_Uses);
446 liveness(Liveness_Basic); 449 liveness(Liveness_Basic);
447 dump("After recomputing liveness for -decorate-asm"); 450 dump("After recomputing liveness for -decorate-asm");
448 } 451 }
449 OstreamLocker L(Ctx); 452 OstreamLocker L(Ctx);
450 Ostream &Str = Ctx->getStrEmit(); 453 Ostream &Str = Ctx->getStrEmit();
451 IceString MangledName = getContext()->mangleName(getFunctionName()); 454 IceString MangledName = getContext()->mangleName(getFunctionName());
452 emitTextHeader(MangledName); 455 emitTextHeader(MangledName, Ctx, getAssembler<>());
453 for (CfgNode *Node : Nodes) 456 for (CfgNode *Node : Nodes)
454 Node->emit(this); 457 Node->emit(this);
455 Str << "\n"; 458 Str << "\n";
456 } 459 }
457 460
458 void Cfg::emitIAS() { 461 void Cfg::emitIAS() {
459 TimerMarker T(TimerStack::TT_emit, this); 462 TimerMarker T(TimerStack::TT_emit, this);
460 assert(!Ctx->getFlags().getDecorateAsm()); 463 assert(!Ctx->getFlags().getDecorateAsm());
461 IceString MangledName = getContext()->mangleName(getFunctionName());
462 // The emitIAS() routines emit into the internal assembler buffer, 464 // The emitIAS() routines emit into the internal assembler buffer,
463 // so there's no need to lock the streams until we're ready to call 465 // so there's no need to lock the streams.
464 // emitIASBytes().
465 for (CfgNode *Node : Nodes) 466 for (CfgNode *Node : Nodes)
466 Node->emitIAS(this); 467 Node->emitIAS(this);
467 // Now write the function to the file and track.
468 if (Ctx->getFlags().getUseELFWriter()) {
469 getAssembler<Assembler>()->alignFunction();
470 Ctx->getObjectWriter()->writeFunctionCode(MangledName, getInternal(),
471 getAssembler<Assembler>());
472 } else {
473 OstreamLocker L(Ctx);
474 emitTextHeader(MangledName);
475 getAssembler<Assembler>()->emitIASBytes(Ctx);
476 }
477 } 468 }
478 469
479 // Dumps the IR with an optional introductory message. 470 // Dumps the IR with an optional introductory message.
480 void Cfg::dump(const IceString &Message) { 471 void Cfg::dump(const IceString &Message) {
481 if (!ALLOW_DUMP) 472 if (!ALLOW_DUMP)
482 return; 473 return;
483 if (!isVerbose()) 474 if (!isVerbose())
484 return; 475 return;
485 OstreamLocker L(Ctx); 476 OstreamLocker L(Ctx);
486 Ostream &Str = Ctx->getStrDump(); 477 Ostream &Str = Ctx->getStrDump();
(...skipping 29 matching lines...) Expand all
516 } 507 }
517 } 508 }
518 // Print each basic block 509 // Print each basic block
519 for (CfgNode *Node : Nodes) 510 for (CfgNode *Node : Nodes)
520 Node->dump(this); 511 Node->dump(this);
521 if (isVerbose(IceV_Instructions)) 512 if (isVerbose(IceV_Instructions))
522 Str << "}\n"; 513 Str << "}\n";
523 } 514 }
524 515
525 } // end of namespace Ice 516 } // 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