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 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 TimerMarker T(TimerStack::TT_initUnhandled, Func); | 161 TimerMarker T(TimerStack::TT_initUnhandled, Func); |
| 162 FindPreference = false; | 162 FindPreference = false; |
| 163 FindOverlap = false; | 163 FindOverlap = false; |
| 164 SizeT NumVars = 0; | 164 SizeT NumVars = 0; |
| 165 const VarList &Vars = Func->getVariables(); | 165 const VarList &Vars = Func->getVariables(); |
| 166 | 166 |
| 167 // Iterate across all instructions and record the begin and end of the live | 167 // Iterate across all instructions and record the begin and end of the live |
| 168 // range for each variable that is pre-colored or infinite weight. | 168 // range for each variable that is pre-colored or infinite weight. |
| 169 CfgVector<InstNumberT> LRBegin(Vars.size(), Inst::NumberSentinel); | 169 CfgVector<InstNumberT> LRBegin(Vars.size(), Inst::NumberSentinel); |
| 170 CfgVector<InstNumberT> LREnd(Vars.size(), Inst::NumberSentinel); | 170 CfgVector<InstNumberT> LREnd(Vars.size(), Inst::NumberSentinel); |
| 171 llvm::SmallVector<SizeT, 10> DefWithoutUse, UseBeforeDef; | |
|
John
2015/09/25 23:02:16
Maybe plural? I.e., DefsWithoutUses
Jim Stichnoth
2015/09/25 23:56:01
Done.
| |
| 171 for (CfgNode *Node : Func->getNodes()) { | 172 for (CfgNode *Node : Func->getNodes()) { |
| 172 for (Inst &Inst : Node->getInsts()) { | 173 for (Inst &Inst : Node->getInsts()) { |
| 173 if (Inst.isDeleted()) | 174 if (Inst.isDeleted()) |
| 174 continue; | 175 continue; |
| 176 FOREACH_VAR_IN_INST(Var, Inst) { | |
| 177 if (Var->getIgnoreLiveness()) | |
| 178 continue; | |
| 179 if (Var->hasReg() || Var->mustHaveReg()) { | |
| 180 SizeT VarNum = Var->getIndex(); | |
| 181 LREnd[VarNum] = Inst.getNumber(); | |
| 182 if (!Var->getIsArg() && LRBegin[VarNum] == Inst::NumberSentinel) | |
| 183 UseBeforeDef.push_back(VarNum); | |
| 184 } | |
| 185 } | |
| 175 if (const Variable *Var = Inst.getDest()) { | 186 if (const Variable *Var = Inst.getDest()) { |
| 176 if (!Var->getIgnoreLiveness() && | 187 if (!Var->getIgnoreLiveness() && |
| 177 (Var->hasReg() || Var->mustHaveReg())) { | 188 (Var->hasReg() || Var->mustHaveReg())) { |
| 178 if (LRBegin[Var->getIndex()] == Inst::NumberSentinel) { | 189 if (LRBegin[Var->getIndex()] == Inst::NumberSentinel) { |
| 179 LRBegin[Var->getIndex()] = Inst.getNumber(); | 190 LRBegin[Var->getIndex()] = Inst.getNumber(); |
| 180 ++NumVars; | 191 ++NumVars; |
| 181 } | 192 } |
| 182 } | 193 } |
| 183 } | 194 } |
| 184 FOREACH_VAR_IN_INST(Var, Inst) { | |
| 185 if (Var->getIgnoreLiveness()) | |
| 186 continue; | |
| 187 if (Var->hasReg() || Var->mustHaveReg()) | |
| 188 LREnd[Var->getIndex()] = Inst.getNumber(); | |
| 189 } | |
| 190 } | 195 } |
| 191 } | 196 } |
| 192 | 197 |
| 193 Unhandled.reserve(NumVars); | 198 Unhandled.reserve(NumVars); |
| 194 UnhandledPrecolored.reserve(NumVars); | 199 UnhandledPrecolored.reserve(NumVars); |
| 195 for (SizeT i = 0; i < Vars.size(); ++i) { | 200 for (SizeT i = 0; i < Vars.size(); ++i) { |
| 196 Variable *Var = Vars[i]; | 201 Variable *Var = Vars[i]; |
| 197 if (LRBegin[i] != Inst::NumberSentinel) { | 202 if (LRBegin[i] != Inst::NumberSentinel) { |
| 198 assert(LREnd[i] != Inst::NumberSentinel); | 203 if (LREnd[i] == Inst::NumberSentinel) { |
| 204 DefWithoutUse.push_back(i); | |
| 205 continue; | |
| 206 } | |
| 199 Unhandled.push_back(Var); | 207 Unhandled.push_back(Var); |
| 200 Var->resetLiveRange(); | 208 Var->resetLiveRange(); |
| 201 Var->addLiveRange(LRBegin[i], LREnd[i]); | 209 Var->addLiveRange(LRBegin[i], LREnd[i]); |
| 202 Var->untrimLiveRange(); | 210 Var->untrimLiveRange(); |
| 203 if (Var->hasReg()) { | 211 if (Var->hasReg()) { |
| 204 Var->setRegNumTmp(Var->getRegNum()); | 212 Var->setRegNumTmp(Var->getRegNum()); |
| 205 Var->setMustHaveReg(); | 213 Var->setMustHaveReg(); |
| 206 UnhandledPrecolored.push_back(Var); | 214 UnhandledPrecolored.push_back(Var); |
| 207 } | 215 } |
| 208 --NumVars; | 216 --NumVars; |
| 209 } | 217 } |
| 210 } | 218 } |
| 219 if (!DefWithoutUse.empty() || !UseBeforeDef.empty()) { | |
| 220 if (BuildDefs::dump()) { | |
|
John
2015/09/25 23:02:16
same thing here
if (DefWithoutUse.empty() && UseB
Jim Stichnoth
2015/09/25 23:56:01
Done.
| |
| 221 OstreamLocker L(Ctx); | |
| 222 Ostream &Str = Ctx->getStrDump(); | |
| 223 for (SizeT i : DefWithoutUse) { | |
|
John
2015/09/25 23:02:16
'i' is weird here. I mostly see single-letter vari
Jim Stichnoth
2015/09/25 23:56:01
Done.
| |
| 224 Variable *Var = Vars[i]; | |
| 225 Str << "LR def without use, instruction " << LRBegin[i] << ", variable " | |
| 226 << Var->getName(Func) << "\n"; | |
| 227 } | |
| 228 for (SizeT i : UseBeforeDef) { | |
| 229 Variable *Var = Vars[i]; | |
| 230 Str << "LR use before def, instruction " << LREnd[i] << ", variable " | |
| 231 << Var->getName(Func) << "\n"; | |
| 232 } | |
| 233 } | |
| 234 llvm::report_fatal_error("initForInfOnly: Liveness error"); | |
| 235 } | |
| 211 // This isn't actually a fatal condition, but it would be nice to know if we | 236 // This isn't actually a fatal condition, but it would be nice to know if we |
| 212 // somehow pre-calculated Unhandled's size wrong. | 237 // somehow pre-calculated Unhandled's size wrong. |
| 213 assert(NumVars == 0); | 238 assert(NumVars == 0); |
| 214 | 239 |
| 215 // Don't build up the list of Kills because we know that no infinite-weight | 240 // Don't build up the list of Kills because we know that no infinite-weight |
| 216 // Variable has a live range spanning a call. | 241 // Variable has a live range spanning a call. |
| 217 Kills.clear(); | 242 Kills.clear(); |
| 218 } | 243 } |
| 219 | 244 |
| 220 void LinearScan::init(RegAllocKind Kind) { | 245 void LinearScan::init(RegAllocKind Kind) { |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 Str << "\n"; | 908 Str << "\n"; |
| 884 } | 909 } |
| 885 Str << "++++++ Inactive:\n"; | 910 Str << "++++++ Inactive:\n"; |
| 886 for (const Variable *Item : Inactive) { | 911 for (const Variable *Item : Inactive) { |
| 887 dumpLiveRange(Item, Func); | 912 dumpLiveRange(Item, Func); |
| 888 Str << "\n"; | 913 Str << "\n"; |
| 889 } | 914 } |
| 890 } | 915 } |
| 891 | 916 |
| 892 } // end of namespace Ice | 917 } // end of namespace Ice |
| OLD | NEW |