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