| 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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 Str << "\t.type\t" << MangledName << ",%function\n"; | 547 Str << "\t.type\t" << MangledName << ",%function\n"; |
| 548 } | 548 } |
| 549 Str << "\t" << Asm->getNonExecPadDirective() << " " | 549 Str << "\t" << Asm->getNonExecPadDirective() << " " |
| 550 << Asm->getBundleAlignLog2Bytes() << ",0x"; | 550 << Asm->getBundleAlignLog2Bytes() << ",0x"; |
| 551 for (uint8_t I : Asm->getNonExecBundlePadding()) | 551 for (uint8_t I : Asm->getNonExecBundlePadding()) |
| 552 Str.write_hex(I); | 552 Str.write_hex(I); |
| 553 Str << "\n"; | 553 Str << "\n"; |
| 554 Str << MangledName << ":\n"; | 554 Str << MangledName << ":\n"; |
| 555 } | 555 } |
| 556 | 556 |
| 557 void Cfg::deleteJumpTableInsts() { |
| 558 for (InstJumpTable *JumpTable : JumpTables) |
| 559 JumpTable->setDeleted(); |
| 560 } |
| 561 |
| 562 void Cfg::emitJumpTables() { |
| 563 switch (Ctx->getFlags().getOutFileType()) { |
| 564 case FT_Elf: |
| 565 case FT_Iasm: { |
| 566 // The emission needs to be delayed until the after the text section so save |
| 567 // the offsets in the global context. |
| 568 for (const InstJumpTable *JumpTable : JumpTables) { |
| 569 SizeT NumTargets = JumpTable->getNumTargets(); |
| 570 JumpTableData &JT = |
| 571 Ctx->addJumpTable(getFunctionName(), JumpTable->getId(), NumTargets); |
| 572 for (SizeT I = 0; I < NumTargets; ++I) { |
| 573 SizeT Index = JumpTable->getTarget(I)->getIndex(); |
| 574 JT.pushTarget( |
| 575 getAssembler()->getOrCreateCfgNodeLabel(Index)->getPosition()); |
| 576 } |
| 577 } |
| 578 } break; |
| 579 case FT_Asm: { |
| 580 // Emit the assembly directly so we don't need to hang on to all the names |
| 581 for (const InstJumpTable *JumpTable : JumpTables) |
| 582 getTarget()->emitJumpTable(this, JumpTable); |
| 583 } break; |
| 584 default: |
| 585 llvm::report_fatal_error("Invalid out file type."); |
| 586 break; |
| 587 } |
| 588 } |
| 589 |
| 557 void Cfg::emit() { | 590 void Cfg::emit() { |
| 558 if (!BuildDefs::dump()) | 591 if (!BuildDefs::dump()) |
| 559 return; | 592 return; |
| 560 TimerMarker T(TimerStack::TT_emit, this); | 593 TimerMarker T(TimerStack::TT_emit, this); |
| 561 if (Ctx->getFlags().getDecorateAsm()) { | 594 if (Ctx->getFlags().getDecorateAsm()) { |
| 562 renumberInstructions(); | 595 renumberInstructions(); |
| 563 getVMetadata()->init(VMK_Uses); | 596 getVMetadata()->init(VMK_Uses); |
| 564 liveness(Liveness_Basic); | 597 liveness(Liveness_Basic); |
| 565 dump("After recomputing liveness for -decorate-asm"); | 598 dump("After recomputing liveness for -decorate-asm"); |
| 566 } | 599 } |
| 567 OstreamLocker L(Ctx); | 600 OstreamLocker L(Ctx); |
| 568 Ostream &Str = Ctx->getStrEmit(); | 601 Ostream &Str = Ctx->getStrEmit(); |
| 569 IceString MangledName = getContext()->mangleName(getFunctionName()); | 602 IceString MangledName = getContext()->mangleName(getFunctionName()); |
| 570 emitTextHeader(MangledName, Ctx, getAssembler<>()); | 603 emitTextHeader(MangledName, Ctx, getAssembler<>()); |
| 571 for (CfgNode *Node : Nodes) | 604 deleteJumpTableInsts(); |
| 605 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); |
| 606 for (CfgNode *Node : Nodes) { |
| 607 if (NeedSandboxing && Node->needsAlignment()) |
| 608 getAssembler()->alignCfgNode(); |
| 572 Node->emit(this); | 609 Node->emit(this); |
| 610 } |
| 611 emitJumpTables(); |
| 573 Str << "\n"; | 612 Str << "\n"; |
| 574 } | 613 } |
| 575 | 614 |
| 576 void Cfg::emitIAS() { | 615 void Cfg::emitIAS() { |
| 577 TimerMarker T(TimerStack::TT_emit, this); | 616 TimerMarker T(TimerStack::TT_emit, this); |
| 578 // The emitIAS() routines emit into the internal assembler buffer, | 617 // The emitIAS() routines emit into the internal assembler buffer, |
| 579 // so there's no need to lock the streams. | 618 // so there's no need to lock the streams. |
| 580 for (CfgNode *Node : Nodes) | 619 deleteJumpTableInsts(); |
| 620 for (CfgNode *Node : Nodes) { |
| 621 if (Node->needsAlignment()) |
| 622 getAssembler()->alignCfgNode(); |
| 581 Node->emitIAS(this); | 623 Node->emitIAS(this); |
| 624 } |
| 625 emitJumpTables(); |
| 582 } | 626 } |
| 583 | 627 |
| 584 // Dumps the IR with an optional introductory message. | 628 // Dumps the IR with an optional introductory message. |
| 585 void Cfg::dump(const IceString &Message) { | 629 void Cfg::dump(const IceString &Message) { |
| 586 if (!BuildDefs::dump()) | 630 if (!BuildDefs::dump()) |
| 587 return; | 631 return; |
| 588 if (!isVerbose()) | 632 if (!isVerbose()) |
| 589 return; | 633 return; |
| 590 OstreamLocker L(Ctx); | 634 OstreamLocker L(Ctx); |
| 591 Ostream &Str = Ctx->getStrDump(); | 635 Ostream &Str = Ctx->getStrDump(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 621 } | 665 } |
| 622 } | 666 } |
| 623 // Print each basic block | 667 // Print each basic block |
| 624 for (CfgNode *Node : Nodes) | 668 for (CfgNode *Node : Nodes) |
| 625 Node->dump(this); | 669 Node->dump(this); |
| 626 if (isVerbose(IceV_Instructions)) | 670 if (isVerbose(IceV_Instructions)) |
| 627 Str << "}\n"; | 671 Str << "}\n"; |
| 628 } | 672 } |
| 629 | 673 |
| 630 } // end of namespace Ice | 674 } // end of namespace Ice |
| OLD | NEW |