| 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 |
| 11 /// This file implements the Cfg class, including constant pool | 11 /// This file implements the Cfg class, including constant pool |
| 12 /// management. | 12 /// management. |
| 13 /// | 13 /// |
| 14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
| 15 | 15 |
| 16 #include "IceCfg.h" | 16 #include "IceCfg.h" |
| 17 | 17 |
| 18 #include "IceAssembler.h" | 18 #include "IceAssembler.h" |
| 19 #include "IceCfgNode.h" | 19 #include "IceCfgNode.h" |
| 20 #include "IceClFlags.h" | 20 #include "IceClFlags.h" |
| 21 #include "IceDefs.h" | 21 #include "IceDefs.h" |
| 22 #include "IceELFObjectWriter.h" | 22 #include "IceELFObjectWriter.h" |
| 23 #include "IceGlobalInits.h" | 23 #include "IceGlobalInits.h" |
| 24 #include "IceInst.h" | 24 #include "IceInst.h" |
| 25 #include "IceLiveness.h" | 25 #include "IceLiveness.h" |
| 26 #include "IceLoopAnalyzer.h" |
| 26 #include "IceOperand.h" | 27 #include "IceOperand.h" |
| 27 #include "IceTargetLowering.h" | 28 #include "IceTargetLowering.h" |
| 28 | 29 |
| 29 namespace Ice { | 30 namespace Ice { |
| 30 | 31 |
| 31 ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg); | 32 ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg); |
| 32 | 33 |
| 33 ArenaAllocator<> *getCurrentCfgAllocator() { | 34 ArenaAllocator<> *getCurrentCfgAllocator() { |
| 34 return Cfg::getCurrentCfgAllocator(); | 35 return Cfg::getCurrentCfgAllocator(); |
| 35 } | 36 } |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 | 456 |
| 456 // Compute the stack frame layout. | 457 // Compute the stack frame layout. |
| 457 void Cfg::genFrame() { | 458 void Cfg::genFrame() { |
| 458 TimerMarker T(TimerStack::TT_genFrame, this); | 459 TimerMarker T(TimerStack::TT_genFrame, this); |
| 459 getTarget()->addProlog(Entry); | 460 getTarget()->addProlog(Entry); |
| 460 for (CfgNode *Node : Nodes) | 461 for (CfgNode *Node : Nodes) |
| 461 if (Node->getHasReturn()) | 462 if (Node->getHasReturn()) |
| 462 getTarget()->addEpilog(Node); | 463 getTarget()->addEpilog(Node); |
| 463 } | 464 } |
| 464 | 465 |
| 465 // This is a lightweight version of live-range-end calculation. Marks | 466 void Cfg::computeLoopNestDepth() { |
| 466 // the last use of only those variables whose definition and uses are | 467 TimerMarker T(TimerStack::TT_computeLoopNestDepth, this); |
| 467 // completely with a single block. It is a quick single pass and | 468 LoopAnalyzer LA(this); |
| 468 // doesn't need to iterate until convergence. | 469 LA.computeLoopNestDepth(); |
| 470 } |
| 471 |
| 472 // This is a lightweight version of live-range-end calculation. Marks the last |
| 473 // use of only those variables whose definition and uses are completely with a |
| 474 // single block. It is a quick single pass and doesn't need to iterate until |
| 475 // convergence. |
| 469 void Cfg::livenessLightweight() { | 476 void Cfg::livenessLightweight() { |
| 470 TimerMarker T(TimerStack::TT_livenessLightweight, this); | 477 TimerMarker T(TimerStack::TT_livenessLightweight, this); |
| 471 getVMetadata()->init(VMK_Uses); | 478 getVMetadata()->init(VMK_Uses); |
| 472 for (CfgNode *Node : Nodes) | 479 for (CfgNode *Node : Nodes) |
| 473 Node->livenessLightweight(); | 480 Node->livenessLightweight(); |
| 474 } | 481 } |
| 475 | 482 |
| 476 void Cfg::liveness(LivenessMode Mode) { | 483 void Cfg::liveness(LivenessMode Mode) { |
| 477 TimerMarker T(TimerStack::TT_liveness, this); | 484 TimerMarker T(TimerStack::TT_liveness, this); |
| 478 Live.reset(new Liveness(this, Mode)); | 485 Live.reset(new Liveness(this, Mode)); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 Str << " live range " << Var->getLiveRange() << "\n"; | 606 Str << " live range " << Var->getLiveRange() << "\n"; |
| 600 } | 607 } |
| 601 } | 608 } |
| 602 } | 609 } |
| 603 } | 610 } |
| 604 } | 611 } |
| 605 return Valid; | 612 return Valid; |
| 606 } | 613 } |
| 607 | 614 |
| 608 void Cfg::contractEmptyNodes() { | 615 void Cfg::contractEmptyNodes() { |
| 609 // If we're decorating the asm output with register liveness info, | 616 // If we're decorating the asm output with register liveness info, this |
| 610 // this information may become corrupted or incorrect after | 617 // information may become corrupted or incorrect after contracting nodes that |
| 611 // contracting nodes that contain only redundant assignments. As | 618 // contain only redundant assignments. As such, we disable this pass when |
| 612 // such, we disable this pass when DecorateAsm is specified. This | 619 // DecorateAsm is specified. This may make the resulting code look more |
| 613 // may make the resulting code look more branchy, but it should have | 620 // branchy, but it should have no effect on the register assignments. |
| 614 // no effect on the register assignments. | |
| 615 if (Ctx->getFlags().getDecorateAsm()) | 621 if (Ctx->getFlags().getDecorateAsm()) |
| 616 return; | 622 return; |
| 617 for (CfgNode *Node : Nodes) { | 623 for (CfgNode *Node : Nodes) { |
| 618 Node->contractIfEmpty(); | 624 Node->contractIfEmpty(); |
| 619 } | 625 } |
| 620 } | 626 } |
| 621 | 627 |
| 622 void Cfg::doBranchOpt() { | 628 void Cfg::doBranchOpt() { |
| 623 TimerMarker T(TimerStack::TT_doBranchOpt, this); | 629 TimerMarker T(TimerStack::TT_doBranchOpt, this); |
| 624 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { | 630 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 } | 777 } |
| 772 } | 778 } |
| 773 // Print each basic block | 779 // Print each basic block |
| 774 for (CfgNode *Node : Nodes) | 780 for (CfgNode *Node : Nodes) |
| 775 Node->dump(this); | 781 Node->dump(this); |
| 776 if (isVerbose(IceV_Instructions)) | 782 if (isVerbose(IceV_Instructions)) |
| 777 Str << "}\n"; | 783 Str << "}\n"; |
| 778 } | 784 } |
| 779 | 785 |
| 780 } // end of namespace Ice | 786 } // end of namespace Ice |
| OLD | NEW |