Chromium Code Reviews| 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 /// \file | 10 /// \file |
| 11 /// This file implements the LinearScan class, which performs the linear-scan | 11 /// This file implements the LinearScan class, which performs the linear-scan |
| 12 /// register allocation after liveness analysis has been performed. | 12 /// register allocation after liveness analysis has been performed. |
| 13 /// | 13 /// |
| 14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
| 15 | 15 |
| 16 #include "IceRegAlloc.h" | 16 #include "IceRegAlloc.h" |
| 17 | 17 |
| 18 #include "IceCfg.h" | 18 #include "IceCfg.h" |
| 19 #include "IceCfgNode.h" | 19 #include "IceCfgNode.h" |
| 20 #include "IceInst.h" | 20 #include "IceInst.h" |
| 21 #include "IceInstVarIter.h" | |
| 21 #include "IceOperand.h" | 22 #include "IceOperand.h" |
| 22 #include "IceTargetLowering.h" | 23 #include "IceTargetLowering.h" |
| 23 | 24 |
| 24 namespace Ice { | 25 namespace Ice { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // Returns true if Var has any definitions within Item's live range. | 29 // Returns true if Var has any definitions within Item's live range. |
| 29 // TODO(stichnot): Consider trimming the Definitions list similar to how the | 30 // TODO(stichnot): Consider trimming the Definitions list similar to how the |
| 30 // live ranges are trimmed, since all the overlapsDefs() tests are whether some | 31 // live ranges are trimmed, since all the overlapsDefs() tests are whether some |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 continue; | 174 continue; |
| 174 if (const Variable *Var = Inst.getDest()) { | 175 if (const Variable *Var = Inst.getDest()) { |
| 175 if (!Var->getIgnoreLiveness() && | 176 if (!Var->getIgnoreLiveness() && |
| 176 (Var->hasReg() || Var->mustHaveReg())) { | 177 (Var->hasReg() || Var->mustHaveReg())) { |
| 177 if (LRBegin[Var->getIndex()] == Inst::NumberSentinel) { | 178 if (LRBegin[Var->getIndex()] == Inst::NumberSentinel) { |
| 178 LRBegin[Var->getIndex()] = Inst.getNumber(); | 179 LRBegin[Var->getIndex()] = Inst.getNumber(); |
| 179 ++NumVars; | 180 ++NumVars; |
| 180 } | 181 } |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 for (SizeT I = 0; I < Inst.getSrcSize(); ++I) { | 184 FOREACH_VAR_IN_INST(Var, Inst) { |
|
ascull
2015/08/31 19:03:17
Looking at how this is used I was a bit confused a
John
2015/08/31 19:11:05
The header file declaring the macros states that V
ascull
2015/08/31 19:28:05
It's not redundant as it shows the declaration of
John
2015/08/31 22:07:03
It is redundant -- Types in variable declarations
ascull
2015/08/31 22:31:56
#define remove_variable(decl) abc##decl
#define ab
| |
| 184 Operand *Src = Inst.getSrc(I); | 185 if (Var->getIgnoreLiveness()) |
| 185 SizeT NumVars = Src->getNumVars(); | 186 continue; |
| 186 for (SizeT J = 0; J < NumVars; ++J) { | 187 if (Var->hasReg() || Var->mustHaveReg()) |
| 187 const Variable *Var = Src->getVar(J); | 188 LREnd[Var->getIndex()] = Inst.getNumber(); |
| 188 if (Var->getIgnoreLiveness()) | |
| 189 continue; | |
| 190 if (Var->hasReg() || Var->mustHaveReg()) | |
| 191 LREnd[Var->getIndex()] = Inst.getNumber(); | |
| 192 } | |
| 193 } | 189 } |
| 194 } | 190 } |
| 195 } | 191 } |
| 196 | 192 |
| 197 Unhandled.reserve(NumVars); | 193 Unhandled.reserve(NumVars); |
| 198 UnhandledPrecolored.reserve(NumVars); | 194 UnhandledPrecolored.reserve(NumVars); |
| 199 for (SizeT i = 0; i < Vars.size(); ++i) { | 195 for (SizeT i = 0; i < Vars.size(); ++i) { |
| 200 Variable *Var = Vars[i]; | 196 Variable *Var = Vars[i]; |
| 201 if (LRBegin[i] != Inst::NumberSentinel) { | 197 if (LRBegin[i] != Inst::NumberSentinel) { |
| 202 assert(LREnd[i] != Inst::NumberSentinel); | 198 assert(LREnd[i] != Inst::NumberSentinel); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 for (auto I = Insts.begin(), E = Insts.end(); | 287 for (auto I = Insts.begin(), E = Insts.end(); |
| 292 I != E && (SpillPoint == E || FillPoint == E); ++I) { | 288 I != E && (SpillPoint == E || FillPoint == E); ++I) { |
| 293 if (I->getNumber() == Start) | 289 if (I->getNumber() == Start) |
| 294 SpillPoint = I; | 290 SpillPoint = I; |
| 295 if (I->getNumber() == End) | 291 if (I->getNumber() == End) |
| 296 FillPoint = I; | 292 FillPoint = I; |
| 297 if (SpillPoint != E) { | 293 if (SpillPoint != E) { |
| 298 // Remove from RegMask any physical registers referenced during Cur's live | 294 // Remove from RegMask any physical registers referenced during Cur's live |
| 299 // range. Start looking after SpillPoint gets set, i.e. once Cur's live | 295 // range. Start looking after SpillPoint gets set, i.e. once Cur's live |
| 300 // range begins. | 296 // range begins. |
| 301 for (SizeT i = 0; i < I->getSrcSize(); ++i) { | 297 FOREACH_VAR_IN_INST(Var, *I) { |
| 302 Operand *Src = I->getSrc(i); | 298 if (Var->hasRegTmp()) |
| 303 SizeT NumVars = Src->getNumVars(); | 299 Iter.RegMask[Var->getRegNumTmp()] = false; |
| 304 for (SizeT j = 0; j < NumVars; ++j) { | |
| 305 const Variable *Var = Src->getVar(j); | |
| 306 if (Var->hasRegTmp()) | |
| 307 Iter.RegMask[Var->getRegNumTmp()] = false; | |
| 308 } | |
| 309 } | 300 } |
| 310 } | 301 } |
| 311 } | 302 } |
| 312 assert(SpillPoint != Insts.end()); | 303 assert(SpillPoint != Insts.end()); |
| 313 assert(FillPoint != Insts.end()); | 304 assert(FillPoint != Insts.end()); |
| 314 ++FillPoint; | 305 ++FillPoint; |
| 315 // TODO(stichnot): Randomize instead of find_first(). | 306 // TODO(stichnot): Randomize instead of find_first(). |
| 316 int32_t RegNum = Iter.RegMask.find_first(); | 307 int32_t RegNum = Iter.RegMask.find_first(); |
| 317 assert(RegNum != -1); | 308 assert(RegNum != -1); |
| 318 Iter.Cur->setRegNumTmp(RegNum); | 309 Iter.Cur->setRegNumTmp(RegNum); |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 837 Str << "\n"; | 828 Str << "\n"; |
| 838 } | 829 } |
| 839 Str << "++++++ Inactive:\n"; | 830 Str << "++++++ Inactive:\n"; |
| 840 for (const Variable *Item : Inactive) { | 831 for (const Variable *Item : Inactive) { |
| 841 dumpLiveRange(Item, Func); | 832 dumpLiveRange(Item, Func); |
| 842 Str << "\n"; | 833 Str << "\n"; |
| 843 } | 834 } |
| 844 } | 835 } |
| 845 | 836 |
| 846 } // end of namespace Ice | 837 } // end of namespace Ice |
| OLD | NEW |