OLD | NEW |
1 //===- subzero/src/IceOperand.cpp - High-level operand implementation -----===// | 1 //===- subzero/src/IceOperand.cpp - High-level operand 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 Operand class and its target-independent | 10 // This file implements the Operand class and its target-independent |
(...skipping 302 matching lines...) Loading... |
313 // Mark implicit args as being used in the entry node. | 313 // Mark implicit args as being used in the entry node. |
314 for (Variable *Var : Func->getImplicitArgs()) { | 314 for (Variable *Var : Func->getImplicitArgs()) { |
315 const Inst *NoInst = NULL; | 315 const Inst *NoInst = NULL; |
316 const CfgNode *EntryNode = Func->getEntryNode(); | 316 const CfgNode *EntryNode = Func->getEntryNode(); |
317 const bool IsFromDef = false; | 317 const bool IsFromDef = false; |
318 const bool IsImplicit = true; | 318 const bool IsImplicit = true; |
319 Metadata[Var->getIndex()] | 319 Metadata[Var->getIndex()] |
320 .markUse(Kind, NoInst, EntryNode, IsFromDef, IsImplicit); | 320 .markUse(Kind, NoInst, EntryNode, IsFromDef, IsImplicit); |
321 } | 321 } |
322 | 322 |
323 for (CfgNode *Node : Func->getNodes()) { | 323 for (CfgNode *Node : Func->getNodes()) |
324 for (Inst *I : Node->getInsts()) { | 324 addNode(Node); |
325 if (I->isDeleted()) | 325 } |
326 continue; | 326 |
327 if (InstFakeKill *Kill = llvm::dyn_cast<InstFakeKill>(I)) { | 327 void VariablesMetadata::addNode(CfgNode *Node) { |
328 // A FakeKill instruction indicates certain Variables (usually | 328 if (Func->getNumVariables() >= Metadata.size()) |
329 // physical scratch registers) are redefined, so we register | 329 Metadata.resize(Func->getNumVariables()); |
330 // them as defs. | 330 |
331 for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) { | 331 for (InstPhi *I : Node->getPhis()) { |
332 Variable *Var = llvm::cast<Variable>(I->getSrc(SrcNum)); | 332 if (I->isDeleted()) |
333 SizeT VarNum = Var->getIndex(); | 333 continue; |
334 assert(VarNum < Metadata.size()); | 334 if (Variable *Dest = I->getDest()) { |
335 Metadata[VarNum].markDef(Kind, Kill, Node); | 335 SizeT DestNum = Dest->getIndex(); |
336 } | 336 assert(DestNum < Metadata.size()); |
337 continue; // no point in executing the rest | 337 Metadata[DestNum].markDef(Kind, I, Node); |
338 } | 338 } |
339 if (Variable *Dest = I->getDest()) { | 339 for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) { |
340 SizeT DestNum = Dest->getIndex(); | 340 if (const Variable *Var = llvm::dyn_cast<Variable>(I->getSrc(SrcNum))) { |
341 assert(DestNum < Metadata.size()); | 341 SizeT VarNum = Var->getIndex(); |
342 Metadata[DestNum].markDef(Kind, I, Node); | 342 assert(VarNum < Metadata.size()); |
343 } | 343 const bool IsFromDef = false; |
344 for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) { | 344 const bool IsImplicit = false; |
345 Operand *Src = I->getSrc(SrcNum); | 345 Metadata[VarNum].markUse(Kind, I, Node, IsFromDef, IsImplicit); |
346 SizeT NumVars = Src->getNumVars(); | |
347 for (SizeT J = 0; J < NumVars; ++J) { | |
348 const Variable *Var = Src->getVar(J); | |
349 SizeT VarNum = Var->getIndex(); | |
350 assert(VarNum < Metadata.size()); | |
351 const bool IsFromDef = false; | |
352 const bool IsImplicit = false; | |
353 Metadata[VarNum].markUse(Kind, I, Node, IsFromDef, IsImplicit); | |
354 } | |
355 } | 346 } |
356 } | 347 } |
357 } | 348 } |
| 349 |
| 350 for (Inst *I : Node->getInsts()) { |
| 351 if (I->isDeleted()) |
| 352 continue; |
| 353 if (InstFakeKill *Kill = llvm::dyn_cast<InstFakeKill>(I)) { |
| 354 // A FakeKill instruction indicates certain Variables (usually |
| 355 // physical scratch registers) are redefined, so we register |
| 356 // them as defs. |
| 357 for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) { |
| 358 Variable *Var = llvm::cast<Variable>(I->getSrc(SrcNum)); |
| 359 SizeT VarNum = Var->getIndex(); |
| 360 assert(VarNum < Metadata.size()); |
| 361 Metadata[VarNum].markDef(Kind, Kill, Node); |
| 362 } |
| 363 continue; // no point in executing the rest |
| 364 } |
| 365 if (Variable *Dest = I->getDest()) { |
| 366 SizeT DestNum = Dest->getIndex(); |
| 367 assert(DestNum < Metadata.size()); |
| 368 Metadata[DestNum].markDef(Kind, I, Node); |
| 369 } |
| 370 for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) { |
| 371 Operand *Src = I->getSrc(SrcNum); |
| 372 SizeT NumVars = Src->getNumVars(); |
| 373 for (SizeT J = 0; J < NumVars; ++J) { |
| 374 const Variable *Var = Src->getVar(J); |
| 375 SizeT VarNum = Var->getIndex(); |
| 376 assert(VarNum < Metadata.size()); |
| 377 const bool IsFromDef = false; |
| 378 const bool IsImplicit = false; |
| 379 Metadata[VarNum].markUse(Kind, I, Node, IsFromDef, IsImplicit); |
| 380 } |
| 381 } |
| 382 } |
358 } | 383 } |
359 | 384 |
360 bool VariablesMetadata::isMultiDef(const Variable *Var) const { | 385 bool VariablesMetadata::isMultiDef(const Variable *Var) const { |
361 assert(Kind != VMK_Uses); | 386 assert(Kind != VMK_Uses); |
362 if (Var->getIsArg()) | 387 if (Var->getIsArg()) |
363 return false; | 388 return false; |
364 if (!isTracked(Var)) | 389 if (!isTracked(Var)) |
365 return true; // conservative answer | 390 return true; // conservative answer |
366 SizeT VarNum = Var->getIndex(); | 391 SizeT VarNum = Var->getIndex(); |
367 // Conservatively return true if the state is unknown. | 392 // Conservatively return true if the state is unknown. |
(...skipping 119 matching lines...) Loading... |
487 | 512 |
488 Ostream &operator<<(Ostream &Str, const RegWeight &W) { | 513 Ostream &operator<<(Ostream &Str, const RegWeight &W) { |
489 if (W.getWeight() == RegWeight::Inf) | 514 if (W.getWeight() == RegWeight::Inf) |
490 Str << "Inf"; | 515 Str << "Inf"; |
491 else | 516 else |
492 Str << W.getWeight(); | 517 Str << W.getWeight(); |
493 return Str; | 518 return Str; |
494 } | 519 } |
495 | 520 |
496 } // end of namespace Ice | 521 } // end of namespace Ice |
OLD | NEW |