| OLD | NEW |
| 1 //===- subzero/src/IceRegAlloc.cpp - Linear-scan implementation -----------===// | 1 //===- subzero/src/IceRegAlloc.cpp - Linear-scan 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 LinearScan class, which performs the | 10 // This file implements the LinearScan class, which performs the |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 const InstDefList &Defs = VMetadata->getLatterDefinitions(Var); | 38 const InstDefList &Defs = VMetadata->getLatterDefinitions(Var); |
| 39 for (size_t i = 0; i < Defs.size(); ++i) { | 39 for (size_t i = 0; i < Defs.size(); ++i) { |
| 40 if (Item->getLiveRange().overlapsInst(Defs[i]->getNumber(), UseTrimmed)) | 40 if (Item->getLiveRange().overlapsInst(Defs[i]->getNumber(), UseTrimmed)) |
| 41 return true; | 41 return true; |
| 42 } | 42 } |
| 43 return false; | 43 return false; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void dumpDisableOverlap(const Cfg *Func, const Variable *Var, | 46 void dumpDisableOverlap(const Cfg *Func, const Variable *Var, |
| 47 const char *Reason) { | 47 const char *Reason) { |
| 48 if (!ALLOW_DUMP) |
| 49 return; |
| 48 if (Func->getContext()->isVerbose(IceV_LinearScan)) { | 50 if (Func->getContext()->isVerbose(IceV_LinearScan)) { |
| 49 VariablesMetadata *VMetadata = Func->getVMetadata(); | 51 VariablesMetadata *VMetadata = Func->getVMetadata(); |
| 50 Ostream &Str = Func->getContext()->getStrDump(); | 52 Ostream &Str = Func->getContext()->getStrDump(); |
| 51 Str << "Disabling Overlap due to " << Reason << " " << *Var | 53 Str << "Disabling Overlap due to " << Reason << " " << *Var |
| 52 << " LIVE=" << Var->getLiveRange() << " Defs="; | 54 << " LIVE=" << Var->getLiveRange() << " Defs="; |
| 53 if (const Inst *FirstDef = VMetadata->getFirstDefinition(Var)) | 55 if (const Inst *FirstDef = VMetadata->getFirstDefinition(Var)) |
| 54 Str << FirstDef->getNumber(); | 56 Str << FirstDef->getNumber(); |
| 55 const InstDefList &Defs = VMetadata->getLatterDefinitions(Var); | 57 const InstDefList &Defs = VMetadata->getLatterDefinitions(Var); |
| 56 for (size_t i = 0; i < Defs.size(); ++i) { | 58 for (size_t i = 0; i < Defs.size(); ++i) { |
| 57 Str << "," << Defs[i]->getNumber(); | 59 Str << "," << Defs[i]->getNumber(); |
| 58 } | 60 } |
| 59 Str << "\n"; | 61 Str << "\n"; |
| 60 } | 62 } |
| 61 } | 63 } |
| 62 | 64 |
| 63 void dumpLiveRange(const Variable *Var, const Cfg *Func) { | 65 void dumpLiveRange(const Variable *Var, const Cfg *Func) { |
| 66 if (!ALLOW_DUMP) |
| 67 return; |
| 64 Ostream &Str = Func->getContext()->getStrDump(); | 68 Ostream &Str = Func->getContext()->getStrDump(); |
| 65 const static size_t BufLen = 30; | 69 const static size_t BufLen = 30; |
| 66 char buf[BufLen]; | 70 char buf[BufLen]; |
| 67 snprintf(buf, BufLen, "%2d", Var->getRegNumTmp()); | 71 snprintf(buf, BufLen, "%2d", Var->getRegNumTmp()); |
| 68 Str << "R=" << buf << " V="; | 72 Str << "R=" << buf << " V="; |
| 69 Var->dump(Func); | 73 Var->dump(Func); |
| 70 Str << " Range=" << Var->getLiveRange(); | 74 Str << " Range=" << Var->getLiveRange(); |
| 71 } | 75 } |
| 72 | 76 |
| 73 } // end of anonymous namespace | 77 } // end of anonymous namespace |
| (...skipping 11 matching lines...) Expand all Loading... |
| 85 // Variable. | 89 // Variable. |
| 86 void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { | 90 void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { |
| 87 TimerMarker T(TimerStack::TT_linearScan, Func); | 91 TimerMarker T(TimerStack::TT_linearScan, Func); |
| 88 assert(RegMaskFull.any()); // Sanity check | 92 assert(RegMaskFull.any()); // Sanity check |
| 89 Unhandled.clear(); | 93 Unhandled.clear(); |
| 90 UnhandledPrecolored.clear(); | 94 UnhandledPrecolored.clear(); |
| 91 Handled.clear(); | 95 Handled.clear(); |
| 92 Inactive.clear(); | 96 Inactive.clear(); |
| 93 Active.clear(); | 97 Active.clear(); |
| 94 Ostream &Str = Func->getContext()->getStrDump(); | 98 Ostream &Str = Func->getContext()->getStrDump(); |
| 95 bool Verbose = Func->getContext()->isVerbose(IceV_LinearScan); | 99 const bool Verbose = |
| 100 ALLOW_DUMP && Func->getContext()->isVerbose(IceV_LinearScan); |
| 96 Func->resetCurrentNode(); | 101 Func->resetCurrentNode(); |
| 97 VariablesMetadata *VMetadata = Func->getVMetadata(); | 102 VariablesMetadata *VMetadata = Func->getVMetadata(); |
| 98 | 103 |
| 99 // Gather the live ranges of all variables and add them to the | 104 // Gather the live ranges of all variables and add them to the |
| 100 // Unhandled set. | 105 // Unhandled set. |
| 101 const VarList &Vars = Func->getVariables(); | 106 const VarList &Vars = Func->getVariables(); |
| 102 { | 107 { |
| 103 TimerMarker T(TimerStack::TT_initUnhandled, Func); | 108 TimerMarker T(TimerStack::TT_initUnhandled, Func); |
| 104 Unhandled.reserve(Vars.size()); | 109 Unhandled.reserve(Vars.size()); |
| 105 for (Variable *Var : Vars) { | 110 for (Variable *Var : Vars) { |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 // own slot. | 552 // own slot. |
| 548 // | 553 // |
| 549 // Another idea for coalescing stack slots is to initialize the | 554 // Another idea for coalescing stack slots is to initialize the |
| 550 // Unhandled list with just the unallocated variables, saving time | 555 // Unhandled list with just the unallocated variables, saving time |
| 551 // but not offering second-chance opportunities. | 556 // but not offering second-chance opportunities. |
| 552 } | 557 } |
| 553 | 558 |
| 554 // ======================== Dump routines ======================== // | 559 // ======================== Dump routines ======================== // |
| 555 | 560 |
| 556 void LinearScan::dump(Cfg *Func) const { | 561 void LinearScan::dump(Cfg *Func) const { |
| 562 if (!ALLOW_DUMP) |
| 563 return; |
| 557 Ostream &Str = Func->getContext()->getStrDump(); | 564 Ostream &Str = Func->getContext()->getStrDump(); |
| 558 if (!Func->getContext()->isVerbose(IceV_LinearScan)) | 565 if (!Func->getContext()->isVerbose(IceV_LinearScan)) |
| 559 return; | 566 return; |
| 560 Func->resetCurrentNode(); | 567 Func->resetCurrentNode(); |
| 561 Str << "**** Current regalloc state:\n"; | 568 Str << "**** Current regalloc state:\n"; |
| 562 Str << "++++++ Handled:\n"; | 569 Str << "++++++ Handled:\n"; |
| 563 for (const Variable *Item : Handled) { | 570 for (const Variable *Item : Handled) { |
| 564 dumpLiveRange(Item, Func); | 571 dumpLiveRange(Item, Func); |
| 565 Str << "\n"; | 572 Str << "\n"; |
| 566 } | 573 } |
| 567 Str << "++++++ Unhandled:\n"; | 574 Str << "++++++ Unhandled:\n"; |
| 568 for (auto I = Unhandled.rbegin(), E = Unhandled.rend(); I != E; ++I) { | 575 for (auto I = Unhandled.rbegin(), E = Unhandled.rend(); I != E; ++I) { |
| 569 dumpLiveRange(*I, Func); | 576 dumpLiveRange(*I, Func); |
| 570 Str << "\n"; | 577 Str << "\n"; |
| 571 } | 578 } |
| 572 Str << "++++++ Active:\n"; | 579 Str << "++++++ Active:\n"; |
| 573 for (const Variable *Item : Active) { | 580 for (const Variable *Item : Active) { |
| 574 dumpLiveRange(Item, Func); | 581 dumpLiveRange(Item, Func); |
| 575 Str << "\n"; | 582 Str << "\n"; |
| 576 } | 583 } |
| 577 Str << "++++++ Inactive:\n"; | 584 Str << "++++++ Inactive:\n"; |
| 578 for (const Variable *Item : Inactive) { | 585 for (const Variable *Item : Inactive) { |
| 579 dumpLiveRange(Item, Func); | 586 dumpLiveRange(Item, Func); |
| 580 Str << "\n"; | 587 Str << "\n"; |
| 581 } | 588 } |
| 582 } | 589 } |
| 583 | 590 |
| 584 } // end of namespace Ice | 591 } // end of namespace Ice |
| OLD | NEW |