Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: src/IceCfg.cpp

Issue 652633002: Subzero: Improve performance of liveness analysis and live range construction. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix non-debug build Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // This file implements the Cfg class, including constant pool 10 // This file implements the Cfg class, including constant pool
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 198 }
199 } 199 }
200 if (Mode == Liveness_Intervals) { 200 if (Mode == Liveness_Intervals) {
201 // Reset each variable's live range. 201 // Reset each variable's live range.
202 for (Variable *Var : Variables) 202 for (Variable *Var : Variables)
203 Var->resetLiveRange(); 203 Var->resetLiveRange();
204 } 204 }
205 // Collect timing for just the portion that constructs the live 205 // Collect timing for just the portion that constructs the live
206 // range intervals based on the end-of-live-range computation, for a 206 // range intervals based on the end-of-live-range computation, for a
207 // finer breakdown of the cost. 207 // finer breakdown of the cost.
208 TimerMarker T1(TimerStack::TT_liveRange, this);
208 // Make a final pass over instructions to delete dead instructions 209 // Make a final pass over instructions to delete dead instructions
209 // and build each Variable's live range. 210 // and build each Variable's live range.
210 TimerMarker T1(TimerStack::TT_liveRange, this);
211 for (CfgNode *Node : Nodes) 211 for (CfgNode *Node : Nodes)
212 Node->livenessPostprocess(Mode, getLiveness()); 212 Node->livenessPostprocess(Mode, getLiveness());
213 if (Mode == Liveness_Intervals) { 213 if (Mode == Liveness_Intervals) {
214 // Special treatment for live in-args. Their liveness needs to 214 // Special treatment for live in-args. Their liveness needs to
215 // extend beyond the beginning of the function, otherwise an arg 215 // extend beyond the beginning of the function, otherwise an arg
216 // whose only use is in the first instruction will end up having 216 // whose only use is in the first instruction will end up having
217 // the trivial live range [1,1) and will *not* interfere with 217 // the trivial live range [1,1) and will *not* interfere with
218 // other arguments. So if the first instruction of the method is 218 // other arguments. So if the first instruction of the method is
219 // "r=arg1+arg2", both args may be assigned the same register. 219 // "r=arg1+arg2", both args may be assigned the same register.
220 for (SizeT I = 0; I < Args.size(); ++I) { 220 for (SizeT I = 0; I < Args.size(); ++I) {
(...skipping 18 matching lines...) Expand all
239 // Remove Variable::LiveRange and redirect to 239 // Remove Variable::LiveRange and redirect to
240 // Liveness::LiveRanges. TODO: make sure Variable weights 240 // Liveness::LiveRanges. TODO: make sure Variable weights
241 // are applied properly. 241 // are applied properly.
242 SizeT NumVars = Variables.size(); 242 SizeT NumVars = Variables.size();
243 for (SizeT i = 0; i < NumVars; ++i) { 243 for (SizeT i = 0; i < NumVars; ++i) {
244 Variable *Var = Variables[i]; 244 Variable *Var = Variables[i];
245 Var->setLiveRange(Live->getLiveRange(Var)); 245 Var->setLiveRange(Live->getLiveRange(Var));
246 if (Var->getWeight().isInf()) 246 if (Var->getWeight().isInf())
247 Var->setLiveRangeInfiniteWeight(); 247 Var->setLiveRangeInfiniteWeight();
248 } 248 }
249 dump();
250 } 249 }
251 } 250 }
252 251
253 // Traverse every Variable of every Inst and verify that it 252 // Traverse every Variable of every Inst and verify that it
254 // appears within the Variable's computed live range. 253 // appears within the Variable's computed live range.
255 bool Cfg::validateLiveness() const { 254 bool Cfg::validateLiveness() const {
256 TimerMarker T(TimerStack::TT_validateLiveness, this); 255 TimerMarker T(TimerStack::TT_validateLiveness, this);
257 bool Valid = true; 256 bool Valid = true;
258 Ostream &Str = Ctx->getStrDump(); 257 Ostream &Str = Ctx->getStrDump();
259 for (CfgNode *Node : Nodes) { 258 for (CfgNode *Node : Nodes) {
260 for (Inst *Inst : Node->getInsts()) { 259 for (Inst *Inst : Node->getInsts()) {
261 if (Inst->isDeleted()) 260 if (Inst->isDeleted())
262 continue; 261 continue;
263 if (llvm::isa<InstFakeKill>(Inst)) 262 if (llvm::isa<InstFakeKill>(Inst))
264 continue; 263 continue;
265 InstNumberT InstNumber = Inst->getNumber(); 264 InstNumberT InstNumber = Inst->getNumber();
266 Variable *Dest = Inst->getDest(); 265 if (Variable *Dest = Inst->getDest()) {
267 if (Dest) {
268 // TODO: This instruction should actually begin Dest's live 266 // TODO: This instruction should actually begin Dest's live
269 // range, so we could probably test that this instruction is 267 // range, so we could probably test that this instruction is
270 // the beginning of some segment of Dest's live range. But 268 // the beginning of some segment of Dest's live range. But
271 // this wouldn't work with non-SSA temporaries during 269 // this wouldn't work with non-SSA temporaries during
jvoung (off chromium) 2014/10/13 20:50:50 with the new flag for non-SSA temporaries, could t
Jim Stichnoth 2014/10/13 23:15:22 Cool, done. There's a minor problem when a phi te
jvoung (off chromium) 2014/10/13 23:38:29 Thanks! Can the TODO be removed then?
Jim Stichnoth 2014/10/14 00:15:01 Oops, done.
272 // lowering. 270 // lowering.
273 if (!Dest->getLiveRange().containsValue(InstNumber)) { 271 if (!Dest->getIgnoreLiveness() &&
272 !Dest->getLiveRange().containsValue(InstNumber)) {
274 Valid = false; 273 Valid = false;
275 Str << "Liveness error: inst " << Inst->getNumber() << " dest "; 274 Str << "Liveness error: inst " << Inst->getNumber() << " dest ";
276 Dest->dump(this); 275 Dest->dump(this);
277 Str << " live range " << Dest->getLiveRange() << "\n"; 276 Str << " live range " << Dest->getLiveRange() << "\n";
278 } 277 }
279 } 278 }
280 for (SizeT I = 0; I < Inst->getSrcSize(); ++I) { 279 for (SizeT I = 0; I < Inst->getSrcSize(); ++I) {
281 Operand *Src = Inst->getSrc(I); 280 Operand *Src = Inst->getSrc(I);
282 SizeT NumVars = Src->getNumVars(); 281 SizeT NumVars = Src->getNumVars();
283 for (SizeT J = 0; J < NumVars; ++J) { 282 for (SizeT J = 0; J < NumVars; ++J) {
284 const Variable *Var = Src->getVar(J); 283 const Variable *Var = Src->getVar(J);
285 if (!Var->getLiveRange().containsValue(InstNumber)) { 284 if (!Var->getIgnoreLiveness() &&
285 !Var->getLiveRange().containsValue(InstNumber)) {
286 Valid = false; 286 Valid = false;
287 Str << "Liveness error: inst " << Inst->getNumber() << " var "; 287 Str << "Liveness error: inst " << Inst->getNumber() << " var ";
288 Var->dump(this); 288 Var->dump(this);
289 Str << " live range " << Var->getLiveRange() << "\n"; 289 Str << " live range " << Var->getLiveRange() << "\n";
290 } 290 }
291 } 291 }
292 } 292 }
293 } 293 }
294 } 294 }
295 return Valid; 295 return Valid;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } 374 }
375 } 375 }
376 // Print each basic block 376 // Print each basic block
377 for (CfgNode *Node : Nodes) 377 for (CfgNode *Node : Nodes)
378 Node->dump(this); 378 Node->dump(this);
379 if (getContext()->isVerbose(IceV_Instructions)) 379 if (getContext()->isVerbose(IceV_Instructions))
380 Str << "}\n"; 380 Str << "}\n";
381 } 381 }
382 382
383 } // end of namespace Ice 383 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfg.h ('k') | src/IceCfgNode.h » ('j') | src/IceCfgNode.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698