blob: 8623aa86549242d35c4f36d5afaec26c483a8d42 [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"
Chris Lattner56cf02d2002-02-03 07:25:25 +00003#include "llvm/Type.h"
Ruchira Sasanka683847f2001-07-24 17:14:13 +00004
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
Chris Lattner56cf02d2002-02-03 07:25:25 +000012void 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 Sasankae27c3442001-08-20 21:12:49 +000015 remove(*OpI); // this definition kills any uses
Ruchira Sasankae27c3442001-08-20 21:12:49 +000016 }
17
Ruchira Sasankab8354a82001-10-15 16:58:50 +000018 // do for implicit operands as well
Chris Lattner56cf02d2002-02-03 07:25:25 +000019 for ( unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
20 if (MInst->implicitRefIsDefined(i))
21 remove(MInst->getImplicitRef(i));
Ruchira Sasankab8354a82001-10-15 16:58:50 +000022 }
23
24
Chris Lattner56cf02d2002-02-03 07:25:25 +000025 for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done(); ++OpI) {
26 if ((*OpI)->getType()->isLabelType()) continue; // don't process labels
Ruchira Sasankab8354a82001-10-15 16:58:50 +000027
Chris Lattner56cf02d2002-02-03 07:25:25 +000028 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 Sasankae27c3442001-08-20 21:12:49 +000030 }
Ruchira Sasankab8354a82001-10-15 16:58:50 +000031
32 // do for implicit operands as well
Chris Lattner56cf02d2002-02-03 07:25:25 +000033 for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
34 if (!MInst->implicitRefIsDefined(i))
35 add(MInst->getImplicitRef(i));
Ruchira Sasankab8354a82001-10-15 16:58:50 +000036 }
Ruchira Sasankae27c3442001-08-20 21:12:49 +000037}