blob: bcc9de95686de766e70af0c5bc5293963d4a2f45 [file] [log] [blame]
Ruchira Sasanka683847f2001-07-24 17:14:13 +00001#include "llvm/Analysis/LiveVar/LiveVarSet.h"
Ruchira Sasankae27c3442001-08-20 21:12:49 +00002#include "llvm/CodeGen/MachineInstr.h"
Ruchira Sasanka683847f2001-07-24 17:14:13 +00003
4
Ruchira Sasankae27c3442001-08-20 21:12:49 +00005// 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 Sasanka683847f2001-07-24 17:14:13 +000010
Ruchira Sasankae27c3442001-08-20 21:12:49 +000011
12void LiveVarSet::applyTranferFuncForMInst(const MachineInstr *const MInst)
13{
14
Chris Lattner7a176752001-12-04 00:03:30 +000015 for( MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done() ; OpI++) {
Ruchira Sasankae27c3442001-08-20 21:12:49 +000016
Ruchira Sasankab8354a82001-10-15 16:58:50 +000017 if( OpI.isDef() ) // kill only if this operand is a def
Ruchira Sasankae27c3442001-08-20 21:12:49 +000018 remove(*OpI); // this definition kills any uses
Ruchira Sasankae27c3442001-08-20 21:12:49 +000019 }
20
Ruchira Sasankab8354a82001-10-15 16:58:50 +000021 // 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 Lattner7a176752001-12-04 00:03:30 +000028 for( MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done() ; OpI++) {
Ruchira Sasankae27c3442001-08-20 21:12:49 +000029
30 if ( ((*OpI)->getType())->isLabelType()) continue; // don't process labels
Ruchira Sasankab8354a82001-10-15 16:58:50 +000031
32 if( ! OpI.isDef() ) // add only if this operand is a use
Ruchira Sasankae27c3442001-08-20 21:12:49 +000033 add( *OpI ); // An operand is a use - so add to use set
Ruchira Sasankae27c3442001-08-20 21:12:49 +000034 }
Ruchira Sasankab8354a82001-10-15 16:58:50 +000035
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 Sasankae27c3442001-08-20 21:12:49 +000042}
43
44
45
Ruchira Sasankae27c3442001-08-20 21:12:49 +000046#if 0
Ruchira Sasanka683847f2001-07-24 17:14:13 +000047void 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 Lattner7a176752001-12-04 00:03:30 +000053 Instruction::const_op_iterator OpI = Inst->op_begin(); // get operand iterat
Ruchira Sasanka683847f2001-07-24 17:14:13 +000054
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 Sasankae27c3442001-08-20 21:12:49 +000061#endif