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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 const InstDefList &Defs = VMetadata->getLatterDefinitions(Var); | 43 const InstDefList &Defs = VMetadata->getLatterDefinitions(Var); |
44 for (size_t i = 0; i < Defs.size(); ++i) { | 44 for (size_t i = 0; i < Defs.size(); ++i) { |
45 if (Item->getLiveRange().overlapsInst(Defs[i]->getNumber(), UseTrimmed)) | 45 if (Item->getLiveRange().overlapsInst(Defs[i]->getNumber(), UseTrimmed)) |
46 return true; | 46 return true; |
47 } | 47 } |
48 return false; | 48 return false; |
49 } | 49 } |
50 | 50 |
51 void dumpDisableOverlap(const Cfg *Func, const Variable *Var, | 51 void dumpDisableOverlap(const Cfg *Func, const Variable *Var, |
52 const char *Reason) { | 52 const char *Reason) { |
53 if (!ALLOW_DUMP) | 53 if (!buildAllowsDump()) |
54 return; | 54 return; |
55 if (Func->isVerbose(IceV_LinearScan)) { | 55 if (Func->isVerbose(IceV_LinearScan)) { |
56 VariablesMetadata *VMetadata = Func->getVMetadata(); | 56 VariablesMetadata *VMetadata = Func->getVMetadata(); |
57 Ostream &Str = Func->getContext()->getStrDump(); | 57 Ostream &Str = Func->getContext()->getStrDump(); |
58 Str << "Disabling Overlap due to " << Reason << " " << *Var | 58 Str << "Disabling Overlap due to " << Reason << " " << *Var |
59 << " LIVE=" << Var->getLiveRange() << " Defs="; | 59 << " LIVE=" << Var->getLiveRange() << " Defs="; |
60 if (const Inst *FirstDef = VMetadata->getFirstDefinition(Var)) | 60 if (const Inst *FirstDef = VMetadata->getFirstDefinition(Var)) |
61 Str << FirstDef->getNumber(); | 61 Str << FirstDef->getNumber(); |
62 const InstDefList &Defs = VMetadata->getLatterDefinitions(Var); | 62 const InstDefList &Defs = VMetadata->getLatterDefinitions(Var); |
63 for (size_t i = 0; i < Defs.size(); ++i) { | 63 for (size_t i = 0; i < Defs.size(); ++i) { |
64 Str << "," << Defs[i]->getNumber(); | 64 Str << "," << Defs[i]->getNumber(); |
65 } | 65 } |
66 Str << "\n"; | 66 Str << "\n"; |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 void dumpLiveRange(const Variable *Var, const Cfg *Func) { | 70 void dumpLiveRange(const Variable *Var, const Cfg *Func) { |
71 if (!ALLOW_DUMP) | 71 if (!buildAllowsDump()) |
72 return; | 72 return; |
73 Ostream &Str = Func->getContext()->getStrDump(); | 73 Ostream &Str = Func->getContext()->getStrDump(); |
74 const static size_t BufLen = 30; | 74 const static size_t BufLen = 30; |
75 char buf[BufLen]; | 75 char buf[BufLen]; |
76 snprintf(buf, BufLen, "%2d", Var->getRegNumTmp()); | 76 snprintf(buf, BufLen, "%2d", Var->getRegNumTmp()); |
77 Str << "R=" << buf << " V="; | 77 Str << "R=" << buf << " V="; |
78 Var->dump(Func); | 78 Var->dump(Func); |
79 Str << " Range=" << Var->getLiveRange(); | 79 Str << " Range=" << Var->getLiveRange(); |
80 } | 80 } |
81 | 81 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // cases. | 258 // cases. |
259 // | 259 // |
260 // Requires running Cfg::liveness(Liveness_Intervals) in | 260 // Requires running Cfg::liveness(Liveness_Intervals) in |
261 // preparation. Results are assigned to Variable::RegNum for each | 261 // preparation. Results are assigned to Variable::RegNum for each |
262 // Variable. | 262 // Variable. |
263 void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull, | 263 void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull, |
264 bool Randomized) { | 264 bool Randomized) { |
265 TimerMarker T(TimerStack::TT_linearScan, Func); | 265 TimerMarker T(TimerStack::TT_linearScan, Func); |
266 assert(RegMaskFull.any()); // Sanity check | 266 assert(RegMaskFull.any()); // Sanity check |
267 GlobalContext *Ctx = Func->getContext(); | 267 GlobalContext *Ctx = Func->getContext(); |
268 const bool Verbose = ALLOW_DUMP && Func->isVerbose(IceV_LinearScan); | 268 const bool Verbose = buildAllowsDump() && Func->isVerbose(IceV_LinearScan); |
269 if (Verbose) | 269 if (Verbose) |
270 Ctx->lockStr(); | 270 Ctx->lockStr(); |
271 Func->resetCurrentNode(); | 271 Func->resetCurrentNode(); |
272 VariablesMetadata *VMetadata = Func->getVMetadata(); | 272 VariablesMetadata *VMetadata = Func->getVMetadata(); |
273 const size_t NumRegisters = RegMaskFull.size(); | 273 const size_t NumRegisters = RegMaskFull.size(); |
274 llvm::SmallBitVector PreDefinedRegisters(NumRegisters); | 274 llvm::SmallBitVector PreDefinedRegisters(NumRegisters); |
275 if (Randomized) { | 275 if (Randomized) { |
276 for (Variable *Var : UnhandledPrecolored) { | 276 for (Variable *Var : UnhandledPrecolored) { |
277 PreDefinedRegisters[Var->getRegNum()] = true; | 277 PreDefinedRegisters[Var->getRegNum()] = true; |
278 } | 278 } |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 // Unhandled list with just the unallocated variables, saving time | 728 // Unhandled list with just the unallocated variables, saving time |
729 // but not offering second-chance opportunities. | 729 // but not offering second-chance opportunities. |
730 | 730 |
731 if (Verbose) | 731 if (Verbose) |
732 Ctx->unlockStr(); | 732 Ctx->unlockStr(); |
733 } | 733 } |
734 | 734 |
735 // ======================== Dump routines ======================== // | 735 // ======================== Dump routines ======================== // |
736 | 736 |
737 void LinearScan::dump(Cfg *Func) const { | 737 void LinearScan::dump(Cfg *Func) const { |
738 if (!ALLOW_DUMP) | 738 if (!buildAllowsDump()) |
739 return; | 739 return; |
740 if (!Func->isVerbose(IceV_LinearScan)) | 740 if (!Func->isVerbose(IceV_LinearScan)) |
741 return; | 741 return; |
742 Ostream &Str = Func->getContext()->getStrDump(); | 742 Ostream &Str = Func->getContext()->getStrDump(); |
743 Func->resetCurrentNode(); | 743 Func->resetCurrentNode(); |
744 Str << "**** Current regalloc state:\n"; | 744 Str << "**** Current regalloc state:\n"; |
745 Str << "++++++ Handled:\n"; | 745 Str << "++++++ Handled:\n"; |
746 for (const Variable *Item : Handled) { | 746 for (const Variable *Item : Handled) { |
747 dumpLiveRange(Item, Func); | 747 dumpLiveRange(Item, Func); |
748 Str << "\n"; | 748 Str << "\n"; |
749 } | 749 } |
750 Str << "++++++ Unhandled:\n"; | 750 Str << "++++++ Unhandled:\n"; |
751 for (const Variable *Item : reverse_range(Unhandled)) { | 751 for (const Variable *Item : reverse_range(Unhandled)) { |
752 dumpLiveRange(Item, Func); | 752 dumpLiveRange(Item, Func); |
753 Str << "\n"; | 753 Str << "\n"; |
754 } | 754 } |
755 Str << "++++++ Active:\n"; | 755 Str << "++++++ Active:\n"; |
756 for (const Variable *Item : Active) { | 756 for (const Variable *Item : Active) { |
757 dumpLiveRange(Item, Func); | 757 dumpLiveRange(Item, Func); |
758 Str << "\n"; | 758 Str << "\n"; |
759 } | 759 } |
760 Str << "++++++ Inactive:\n"; | 760 Str << "++++++ Inactive:\n"; |
761 for (const Variable *Item : Inactive) { | 761 for (const Variable *Item : Inactive) { |
762 dumpLiveRange(Item, Func); | 762 dumpLiveRange(Item, Func); |
763 Str << "\n"; | 763 Str << "\n"; |
764 } | 764 } |
765 } | 765 } |
766 | 766 |
767 } // end of namespace Ice | 767 } // end of namespace Ice |
OLD | NEW |