2001-07-24 17:14:13 +00:00
|
|
|
#include "llvm/Analysis/LiveVar/LiveVarSet.h"
|
2001-08-20 21:12:49 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2002-02-03 07:25:25 +00:00
|
|
|
#include "llvm/Type.h"
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-08-20 21:12:49 +00:00
|
|
|
// This function applies a machine instr to a live var set (accepts OutSet) and
|
|
|
|
// makes necessary changes to it (produces InSet). Note that two for loops are
|
|
|
|
// used to first kill all defs and then to add all uses. This is because there
|
|
|
|
// can be instructions like Val = Val + 1 since we allow multipe defs to a
|
|
|
|
// machine instruction operand.
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2001-08-20 21:12:49 +00:00
|
|
|
|
2002-02-03 07:25:25 +00:00
|
|
|
void LiveVarSet::applyTranferFuncForMInst(const MachineInstr *MInst) {
|
|
|
|
for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done(); ++OpI) {
|
|
|
|
if (OpI.isDef()) // kill only if this operand is a def
|
2001-08-20 21:12:49 +00:00
|
|
|
remove(*OpI); // this definition kills any uses
|
2001-10-15 16:58:50 +00:00
|
|
|
}
|
2001-08-20 21:12:49 +00:00
|
|
|
|
2001-10-15 16:58:50 +00:00
|
|
|
// do for implicit operands as well
|
2002-02-03 07:25:25 +00:00
|
|
|
for ( unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
|
|
|
|
if (MInst->implicitRefIsDefined(i))
|
|
|
|
remove(MInst->getImplicitRef(i));
|
2001-08-20 21:12:49 +00:00
|
|
|
}
|
|
|
|
|
2001-10-15 16:58:50 +00:00
|
|
|
|
2002-02-03 07:25:25 +00:00
|
|
|
for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done(); ++OpI) {
|
|
|
|
if ((*OpI)->getType()->isLabelType()) continue; // don't process labels
|
2001-10-15 16:58:50 +00:00
|
|
|
|
2002-02-03 07:25:25 +00:00
|
|
|
if (!OpI.isDef()) // add only if this operand is a use
|
|
|
|
add(*OpI); // An operand is a use - so add to use set
|
2001-08-20 21:12:49 +00:00
|
|
|
}
|
|
|
|
|
2001-10-15 16:58:50 +00:00
|
|
|
// do for implicit operands as well
|
2002-02-03 07:25:25 +00:00
|
|
|
for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
|
|
|
|
if (!MInst->implicitRefIsDefined(i))
|
|
|
|
add(MInst->getImplicitRef(i));
|
2001-10-15 16:58:50 +00:00
|
|
|
}
|
2001-07-24 17:14:13 +00:00
|
|
|
}
|