Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 /// \file | 10 /// \file |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 } | 522 } |
| 523 | 523 |
| 524 void Cfg::doBranchOpt() { | 524 void Cfg::doBranchOpt() { |
| 525 TimerMarker T(TimerStack::TT_doBranchOpt, this); | 525 TimerMarker T(TimerStack::TT_doBranchOpt, this); |
| 526 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { | 526 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { |
| 527 auto NextNode = I + 1; | 527 auto NextNode = I + 1; |
| 528 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode); | 528 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 void Cfg::markNodesForSandboxing() { | |
| 533 for (const InstJumpTable *JT : JumpTables) | |
| 534 for (SizeT I = 0; I < JT->getNumTargets(); ++I) | |
| 535 JT->getTarget(I)->setNeedsAlignment(); | |
| 536 } | |
| 537 | |
| 532 // ======================== Dump routines ======================== // | 538 // ======================== Dump routines ======================== // |
| 533 | 539 |
| 534 // emitTextHeader() is not target-specific (apart from what is | 540 // emitTextHeader() is not target-specific (apart from what is |
| 535 // abstracted by the Assembler), so it is defined here rather than in | 541 // abstracted by the Assembler), so it is defined here rather than in |
| 536 // the target lowering class. | 542 // the target lowering class. |
| 537 void Cfg::emitTextHeader(const IceString &MangledName, GlobalContext *Ctx, | 543 void Cfg::emitTextHeader(const IceString &MangledName, GlobalContext *Ctx, |
| 538 const Assembler *Asm) { | 544 const Assembler *Asm) { |
| 539 if (!BuildDefs::dump()) | 545 if (!BuildDefs::dump()) |
| 540 return; | 546 return; |
| 541 Ostream &Str = Ctx->getStrEmit(); | 547 Ostream &Str = Ctx->getStrEmit(); |
| 542 Str << "\t.text\n"; | 548 Str << "\t.text\n"; |
| 543 if (Ctx->getFlags().getFunctionSections()) | 549 if (Ctx->getFlags().getFunctionSections()) |
| 544 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n"; | 550 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n"; |
| 545 if (!Asm->getInternal() || Ctx->getFlags().getDisableInternal()) { | 551 if (!Asm->getInternal() || Ctx->getFlags().getDisableInternal()) { |
| 546 Str << "\t.globl\t" << MangledName << "\n"; | 552 Str << "\t.globl\t" << MangledName << "\n"; |
| 547 Str << "\t.type\t" << MangledName << ",%function\n"; | 553 Str << "\t.type\t" << MangledName << ",%function\n"; |
| 548 } | 554 } |
| 549 Str << "\t" << Asm->getNonExecPadDirective() << " " | 555 Str << "\t" << Asm->getNonExecPadDirective() << " " |
| 550 << Asm->getBundleAlignLog2Bytes() << ",0x"; | 556 << Asm->getBundleAlignLog2Bytes() << ",0x"; |
| 551 for (uint8_t I : Asm->getNonExecBundlePadding()) | 557 for (uint8_t I : Asm->getNonExecBundlePadding()) |
| 552 Str.write_hex(I); | 558 Str.write_hex(I); |
| 553 Str << "\n"; | 559 Str << "\n"; |
| 554 Str << MangledName << ":\n"; | 560 Str << MangledName << ":\n"; |
| 555 } | 561 } |
| 556 | 562 |
| 563 void Cfg::deleteJumpTableInsts() { | |
| 564 for (InstJumpTable *JumpTable : JumpTables) | |
| 565 JumpTable->setDeleted(); | |
| 566 } | |
| 567 | |
| 568 void Cfg::emitJumpTables() { | |
| 569 switch (Ctx->getFlags().getOutFileType()) { | |
| 570 case FT_Elf: | |
| 571 case FT_Iasm: { | |
| 572 // The emission needs to be delayed until the after the text section so save | |
| 573 // the offsets in the global context. | |
| 574 IceString MangledName = Ctx->mangleName(getFunctionName()); | |
| 575 for (const InstJumpTable *JumpTable : JumpTables) { | |
| 576 SizeT NumTargets = JumpTable->getNumTargets(); | |
| 577 JumpTableData &JT = | |
| 578 Ctx->addJumpTable(MangledName, JumpTable->getId(), NumTargets); | |
| 579 for (SizeT I = 0; I < NumTargets; ++I) { | |
| 580 SizeT Index = JumpTable->getTarget(I)->getIndex(); | |
| 581 JT.pushTarget( | |
| 582 getAssembler()->getOrCreateCfgNodeLabel(Index)->getPosition()); | |
| 583 } | |
| 584 } | |
| 585 } break; | |
| 586 case FT_Asm: { | |
| 587 // Emit the assembly directly so we don't need to hang on to all the names | |
| 588 for (const InstJumpTable *JumpTable : JumpTables) | |
| 589 getTarget()->emitJumpTable(this, JumpTable); | |
| 590 } break; | |
| 591 default: | |
| 592 llvm::report_fatal_error("Invalid out file type."); | |
| 593 break; | |
| 594 } | |
| 595 } | |
| 596 | |
| 557 void Cfg::emit() { | 597 void Cfg::emit() { |
| 558 if (!BuildDefs::dump()) | 598 if (!BuildDefs::dump()) |
| 559 return; | 599 return; |
| 560 TimerMarker T(TimerStack::TT_emit, this); | 600 TimerMarker T(TimerStack::TT_emit, this); |
| 561 if (Ctx->getFlags().getDecorateAsm()) { | 601 if (Ctx->getFlags().getDecorateAsm()) { |
| 562 renumberInstructions(); | 602 renumberInstructions(); |
| 563 getVMetadata()->init(VMK_Uses); | 603 getVMetadata()->init(VMK_Uses); |
| 564 liveness(Liveness_Basic); | 604 liveness(Liveness_Basic); |
| 565 dump("After recomputing liveness for -decorate-asm"); | 605 dump("After recomputing liveness for -decorate-asm"); |
| 566 } | 606 } |
| 567 OstreamLocker L(Ctx); | 607 OstreamLocker L(Ctx); |
| 568 Ostream &Str = Ctx->getStrEmit(); | 608 Ostream &Str = Ctx->getStrEmit(); |
| 569 IceString MangledName = getContext()->mangleName(getFunctionName()); | 609 IceString MangledName = Ctx->mangleName(getFunctionName()); |
| 570 emitTextHeader(MangledName, Ctx, getAssembler<>()); | 610 const Assembler *Asm = getAssembler<>(); |
| 571 for (CfgNode *Node : Nodes) | 611 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); |
| 612 | |
| 613 emitTextHeader(MangledName, Ctx, Asm); | |
| 614 deleteJumpTableInsts(); | |
| 615 for (CfgNode *Node : Nodes) { | |
| 616 if (NeedSandboxing && Node->needsAlignment()) { | |
| 617 Str << "\t" << Asm->getNonExecPadDirective() << " " | |
|
jvoung (off chromium)
2015/07/29 21:31:17
Maybe just rename this from getNonExecPadDirective
ascull
2015/07/29 22:43:04
Done.
| |
| 618 << Asm->getBundleAlignLog2Bytes() << "\n"; | |
| 619 } | |
| 572 Node->emit(this); | 620 Node->emit(this); |
| 621 } | |
| 622 emitJumpTables(); | |
| 573 Str << "\n"; | 623 Str << "\n"; |
| 574 } | 624 } |
| 575 | 625 |
| 576 void Cfg::emitIAS() { | 626 void Cfg::emitIAS() { |
| 577 TimerMarker T(TimerStack::TT_emit, this); | 627 TimerMarker T(TimerStack::TT_emit, this); |
| 578 // The emitIAS() routines emit into the internal assembler buffer, | 628 // The emitIAS() routines emit into the internal assembler buffer, |
| 579 // so there's no need to lock the streams. | 629 // so there's no need to lock the streams. |
| 580 for (CfgNode *Node : Nodes) | 630 deleteJumpTableInsts(); |
| 631 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); | |
| 632 for (CfgNode *Node : Nodes) { | |
| 633 if (NeedSandboxing && Node->needsAlignment()) | |
| 634 getAssembler()->alignCfgNode(); | |
| 581 Node->emitIAS(this); | 635 Node->emitIAS(this); |
| 636 } | |
| 637 emitJumpTables(); | |
| 582 } | 638 } |
| 583 | 639 |
| 584 // Dumps the IR with an optional introductory message. | 640 // Dumps the IR with an optional introductory message. |
| 585 void Cfg::dump(const IceString &Message) { | 641 void Cfg::dump(const IceString &Message) { |
| 586 if (!BuildDefs::dump()) | 642 if (!BuildDefs::dump()) |
| 587 return; | 643 return; |
| 588 if (!isVerbose()) | 644 if (!isVerbose()) |
| 589 return; | 645 return; |
| 590 OstreamLocker L(Ctx); | 646 OstreamLocker L(Ctx); |
| 591 Ostream &Str = Ctx->getStrDump(); | 647 Ostream &Str = Ctx->getStrDump(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 621 } | 677 } |
| 622 } | 678 } |
| 623 // Print each basic block | 679 // Print each basic block |
| 624 for (CfgNode *Node : Nodes) | 680 for (CfgNode *Node : Nodes) |
| 625 Node->dump(this); | 681 Node->dump(this); |
| 626 if (isVerbose(IceV_Instructions)) | 682 if (isVerbose(IceV_Instructions)) |
| 627 Str << "}\n"; | 683 Str << "}\n"; |
| 628 } | 684 } |
| 629 | 685 |
| 630 } // end of namespace Ice | 686 } // end of namespace Ice |
| OLD | NEW |