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" |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 3 | |
| 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 | |
| 12 | void LiveVarSet::applyTranferFuncForMInst(const MachineInstr *const MInst) |
| 13 | { |
| 14 | |
Chris Lattner | 7a17675 | 2001-12-04 00:03:30 +0000 | [diff] [blame] | 15 | for( MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done() ; OpI++) { |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 16 | |
Ruchira Sasanka | b8354a8 | 2001-10-15 16:58:50 +0000 | [diff] [blame] | 17 | if( OpI.isDef() ) // kill only if this operand is a def |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 18 | remove(*OpI); // this definition kills any uses |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Ruchira Sasanka | b8354a8 | 2001-10-15 16:58:50 +0000 | [diff] [blame] | 21 | // do for implicit operands as well |
| 22 | for( unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) { |
| 23 | if( MInst->implicitRefIsDefined(i) ) |
| 24 | remove( MInst->getImplicitRef(i) ); |
| 25 | } |
| 26 | |
| 27 | |
Chris Lattner | 7a17675 | 2001-12-04 00:03:30 +0000 | [diff] [blame] | 28 | for( MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done() ; OpI++) { |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 29 | |
| 30 | if ( ((*OpI)->getType())->isLabelType()) continue; // don't process labels |
Ruchira Sasanka | b8354a8 | 2001-10-15 16:58:50 +0000 | [diff] [blame] | 31 | |
| 32 | if( ! OpI.isDef() ) // add only if this operand is a use |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 33 | add( *OpI ); // An operand is a use - so add to use set |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 34 | } |
Ruchira Sasanka | b8354a8 | 2001-10-15 16:58:50 +0000 | [diff] [blame] | 35 | |
| 36 | // do for implicit operands as well |
| 37 | for( unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) { |
| 38 | if( ! MInst->implicitRefIsDefined(i) ) |
| 39 | add( MInst->getImplicitRef(i) ); |
| 40 | } |
| 41 | |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | |
| 45 | |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 46 | #if 0 |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 47 | void LiveVarSet::applyTranferFuncForInst(const Instruction *const Inst) |
| 48 | { |
| 49 | |
| 50 | if( Inst->isDefinition() ) { // add to Defs iff this instr is a definition |
| 51 | remove(Inst); // this definition kills any uses |
| 52 | } |
Chris Lattner | 7a17675 | 2001-12-04 00:03:30 +0000 | [diff] [blame] | 53 | Instruction::const_op_iterator OpI = Inst->op_begin(); // get operand iterat |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 54 | |
| 55 | for( ; OpI != Inst->op_end() ; OpI++) { // iterate over operands |
| 56 | if ( ((*OpI)->getType())->isLabelType()) continue; // don't process labels |
| 57 | add( *OpI ); // An operand is a use - so add to use set |
| 58 | } |
| 59 | |
| 60 | } |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 61 | #endif |