Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 1 | #include "llvm/Analysis/LiveVar/LiveVarSet.h" |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 2 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | 56cf02d | 2002-02-03 07:25:25 +0000 | [diff] [blame] | 3 | #include "llvm/Type.h" |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 4 | |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 5 | // This function applies a machine instr to a live var set (accepts OutSet) and |
| 6 | // makes necessary changes to it (produces InSet). Note that two for loops are |
| 7 | // used to first kill all defs and then to add all uses. This is because there |
| 8 | // can be instructions like Val = Val + 1 since we allow multipe defs to a |
| 9 | // machine instruction operand. |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 10 | |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 11 | |
Chris Lattner | 56cf02d | 2002-02-03 07:25:25 +0000 | [diff] [blame] | 12 | void LiveVarSet::applyTranferFuncForMInst(const MachineInstr *MInst) { |
| 13 | for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done(); ++OpI) { |
| 14 | if (OpI.isDef()) // kill only if this operand is a def |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 15 | remove(*OpI); // this definition kills any uses |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 16 | } |
| 17 | |
Ruchira Sasanka | b8354a8 | 2001-10-15 16:58:50 +0000 | [diff] [blame] | 18 | // do for implicit operands as well |
Chris Lattner | 56cf02d | 2002-02-03 07:25:25 +0000 | [diff] [blame] | 19 | for ( unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) { |
| 20 | if (MInst->implicitRefIsDefined(i)) |
| 21 | remove(MInst->getImplicitRef(i)); |
Ruchira Sasanka | b8354a8 | 2001-10-15 16:58:50 +0000 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | |
Chris Lattner | 56cf02d | 2002-02-03 07:25:25 +0000 | [diff] [blame] | 25 | for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done(); ++OpI) { |
| 26 | if ((*OpI)->getType()->isLabelType()) continue; // don't process labels |
Ruchira Sasanka | b8354a8 | 2001-10-15 16:58:50 +0000 | [diff] [blame] | 27 | |
Chris Lattner | 56cf02d | 2002-02-03 07:25:25 +0000 | [diff] [blame] | 28 | if (!OpI.isDef()) // add only if this operand is a use |
| 29 | add(*OpI); // An operand is a use - so add to use set |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 30 | } |
Ruchira Sasanka | b8354a8 | 2001-10-15 16:58:50 +0000 | [diff] [blame] | 31 | |
| 32 | // do for implicit operands as well |
Chris Lattner | 56cf02d | 2002-02-03 07:25:25 +0000 | [diff] [blame] | 33 | for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) { |
| 34 | if (!MInst->implicitRefIsDefined(i)) |
| 35 | add(MInst->getImplicitRef(i)); |
Ruchira Sasanka | b8354a8 | 2001-10-15 16:58:50 +0000 | [diff] [blame] | 36 | } |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 37 | } |