Renamed MachienOperand::opIsDef to MachineOperand::opIsDefOnly()

and related functions and flags.  Fixed several bugs where only
"isDef" was being checked, not "isDefAndUse".


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6342 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vikram S. Adve 2003-05-27 00:06:48 +00:00
parent 5f2180c533
commit a22eace55b
5 changed files with 49 additions and 66 deletions

View File

@ -88,13 +88,13 @@ struct MachineOperand {
private: private:
// Bit fields of the flags variable used for different operand properties // Bit fields of the flags variable used for different operand properties
enum { enum {
DEFFLAG = 0x01, // this is a def of the operand DEFONLYFLAG = 0x01, // this is a def but not a use of the operand
DEFUSEFLAG = 0x02, // this is both a def and a use DEFUSEFLAG = 0x02, // this is both a def and a use
HIFLAG32 = 0x04, // operand is %hi32(value_or_immedVal) HIFLAG32 = 0x04, // operand is %hi32(value_or_immedVal)
LOFLAG32 = 0x08, // operand is %lo32(value_or_immedVal) LOFLAG32 = 0x08, // operand is %lo32(value_or_immedVal)
HIFLAG64 = 0x10, // operand is %hi64(value_or_immedVal) HIFLAG64 = 0x10, // operand is %hi64(value_or_immedVal)
LOFLAG64 = 0x20, // operand is %lo64(value_or_immedVal) LOFLAG64 = 0x20, // operand is %lo64(value_or_immedVal)
PCRELATIVE = 0x40, // Operand is relative to PC, not a global address PCRELATIVE = 0x40, // Operand is relative to PC, not a global address
USEDEFMASK = 0x03, USEDEFMASK = 0x03,
}; };
@ -137,7 +137,7 @@ private:
regNum(Reg) { regNum(Reg) {
switch (UseTy) { switch (UseTy) {
case MOTy::Use: flags = 0; break; case MOTy::Use: flags = 0; break;
case MOTy::Def: flags = DEFFLAG; break; case MOTy::Def: flags = DEFONLYFLAG; break;
case MOTy::UseAndDef: flags = DEFUSEFLAG; break; case MOTy::UseAndDef: flags = DEFUSEFLAG; break;
default: assert(0 && "Invalid value for UseTy!"); default: assert(0 && "Invalid value for UseTy!");
} }
@ -148,7 +148,7 @@ private:
: value(V), opType(OpTy), regNum(-1) { : value(V), opType(OpTy), regNum(-1) {
switch (UseTy) { switch (UseTy) {
case MOTy::Use: flags = 0; break; case MOTy::Use: flags = 0; break;
case MOTy::Def: flags = DEFFLAG; break; case MOTy::Def: flags = DEFONLYFLAG; break;
case MOTy::UseAndDef: flags = DEFUSEFLAG; break; case MOTy::UseAndDef: flags = DEFUSEFLAG; break;
default: assert(0 && "Invalid value for UseTy!"); default: assert(0 && "Invalid value for UseTy!");
} }
@ -259,7 +259,7 @@ public:
} }
bool opIsUse () const { return (flags & USEDEFMASK) == 0; } bool opIsUse () const { return (flags & USEDEFMASK) == 0; }
bool opIsDef () const { return flags & DEFFLAG; } bool opIsDefOnly () const { return flags & DEFONLYFLAG; }
bool opIsDefAndUse () const { return flags & DEFUSEFLAG; } bool opIsDefAndUse () const { return flags & DEFUSEFLAG; }
bool opHiBits32 () const { return flags & HIFLAG32; } bool opHiBits32 () const { return flags & HIFLAG32; }
bool opLoBits32 () const { return flags & LOFLAG32; } bool opLoBits32 () const { return flags & LOFLAG32; }
@ -332,15 +332,6 @@ class MachineInstr: public NonCopyable { // Disable copy operations
std::vector<MachineOperand> operands; // the operands std::vector<MachineOperand> operands; // the operands
unsigned numImplicitRefs; // number of implicit operands unsigned numImplicitRefs; // number of implicit operands
MachineOperand& getImplicitOp(unsigned i) {
assert(i < numImplicitRefs && "implicit ref# out of range!");
return operands[i + operands.size() - numImplicitRefs];
}
const MachineOperand& getImplicitOp(unsigned i) const {
assert(i < numImplicitRefs && "implicit ref# out of range!");
return operands[i + operands.size() - numImplicitRefs];
}
// regsUsed - all machine registers used for this instruction, including regs // regsUsed - all machine registers used for this instruction, including regs
// used to save values across the instruction. This is a bitset of registers. // used to save values across the instruction. This is a bitset of registers.
std::vector<bool> regsUsed; std::vector<bool> regsUsed;
@ -371,7 +362,7 @@ public:
const MachineOpCode getOpCode() const { return opCode; } const MachineOpCode getOpCode() const { return opCode; }
// //
// Information about explicit operands of the instruction // Access to explicit operands of the instruction
// //
unsigned getNumOperands() const { return operands.size() - numImplicitRefs; } unsigned getNumOperands() const { return operands.size() - numImplicitRefs; }
@ -384,38 +375,27 @@ public:
return operands[i]; return operands[i];
} }
// FIXME: ELIMINATE
MachineOperand::MachineOperandType getOperandType(unsigned i) const {
return getOperand(i).getType();
}
// FIXME: ELIMINATE: Misleading name: Definition not defined.
bool operandIsDefined(unsigned i) const {
return getOperand(i).opIsDef();
}
bool operandIsDefinedAndUsed(unsigned i) const {
return getOperand(i).opIsDefAndUse();
}
// //
// Information about implicit operands of the instruction // Access to implicit operands of the instruction
// //
unsigned getNumImplicitRefs() const{ return numImplicitRefs; } unsigned getNumImplicitRefs() const{ return numImplicitRefs; }
const Value* getImplicitRef(unsigned i) const { MachineOperand& getImplicitOp(unsigned i) {
return getImplicitOp(i).getVRegValue(); assert(i < numImplicitRefs && "implicit ref# out of range!");
return operands[i + operands.size() - numImplicitRefs];
} }
const MachineOperand& getImplicitOp(unsigned i) const {
assert(i < numImplicitRefs && "implicit ref# out of range!");
return operands[i + operands.size() - numImplicitRefs];
}
Value* getImplicitRef(unsigned i) { Value* getImplicitRef(unsigned i) {
return getImplicitOp(i).getVRegValue(); return getImplicitOp(i).getVRegValue();
} }
const Value* getImplicitRef(unsigned i) const {
return getImplicitOp(i).getVRegValue();
}
bool implicitRefIsDefined(unsigned i) const {
return getImplicitOp(i).opIsDef();
}
bool implicitRefIsDefinedAndUsed(unsigned i) const {
return getImplicitOp(i).opIsDefAndUse();
}
inline void addImplicitRef (Value* V, inline void addImplicitRef (Value* V,
bool isDef=false,bool isDefAndUse=false); bool isDef=false,bool isDefAndUse=false);
inline void setImplicitRef (unsigned i, Value* V, inline void setImplicitRef (unsigned i, Value* V,
@ -647,8 +627,8 @@ public:
void skipToNextVal() { void skipToNextVal() {
while (i < MI->getNumOperands() && while (i < MI->getNumOperands() &&
!( (MI->getOperandType(i) == MachineOperand::MO_VirtualRegister || !( (MI->getOperand(i).getType() == MachineOperand::MO_VirtualRegister ||
MI->getOperandType(i) == MachineOperand::MO_CCRegister) MI->getOperand(i).getType() == MachineOperand::MO_CCRegister)
&& MI->getOperand(i).getVRegValue() != 0)) && MI->getOperand(i).getVRegValue() != 0))
++i; ++i;
} }
@ -669,7 +649,8 @@ public:
inline VTy operator->() const { return operator*(); } inline VTy operator->() const { return operator*(); }
inline bool isDef() const { return MI->getOperand(i).opIsDef(); } inline bool isUseOnly() const { return MI->getOperand(i).opIsUse(); }
inline bool isDefOnly() const { return MI->getOperand(i).opIsDefOnly(); }
inline bool isDefAndUse() const { return MI->getOperand(i).opIsDefAndUse();} inline bool isDefAndUse() const { return MI->getOperand(i).opIsDefAndUse();}
inline _Self& operator++() { i++; skipToNextVal(); return *this; } inline _Self& operator++() { i++; skipToNextVal(); return *this; }

View File

@ -64,12 +64,12 @@ void BBLiveVar::calcDefUseSets() {
// iterate over MI operands to find defs // iterate over MI operands to find defs
for (MachineInstr::const_val_op_iterator OpI = MI->begin(), OpE = MI->end(); for (MachineInstr::const_val_op_iterator OpI = MI->begin(), OpE = MI->end();
OpI != OpE; ++OpI) OpI != OpE; ++OpI)
if (OpI.isDef()) // add to Defs only if this operand is a def if (OpI.isDefOnly() || OpI.isDefAndUse()) // add to Defs if this operand is a def
addDef(*OpI); addDef(*OpI);
// do for implicit operands as well // do for implicit operands as well
for (unsigned i = 0; i < MI->getNumImplicitRefs(); ++i) for (unsigned i = 0; i < MI->getNumImplicitRefs(); ++i)
if (MI->implicitRefIsDefined(i)) if (MI->getImplicitOp(i).opIsDefOnly() || MI->getImplicitOp(i).opIsDefAndUse())
addDef(MI->getImplicitRef(i)); addDef(MI->getImplicitRef(i));
// iterate over MI operands to find uses // iterate over MI operands to find uses
@ -80,7 +80,7 @@ void BBLiveVar::calcDefUseSets() {
if (isa<BasicBlock>(Op)) if (isa<BasicBlock>(Op))
continue; // don't process labels continue; // don't process labels
if (!OpI.isDef() || OpI.isDefAndUse()) { if (OpI.isUseOnly() || OpI.isDefAndUse()) {
// add to Uses only if this operand is a use // add to Uses only if this operand is a use
// //
// *** WARNING: The following code for handling dummy PHI machine // *** WARNING: The following code for handling dummy PHI machine
@ -116,7 +116,7 @@ void BBLiveVar::calcDefUseSets() {
if (Op->getType() == Type::LabelTy) // don't process labels if (Op->getType() == Type::LabelTy) // don't process labels
continue; continue;
if (!MI->implicitRefIsDefined(i) || MI->implicitRefIsDefinedAndUsed(i) ) if (MI->getImplicitOp(i).opIsUse() || MI->getImplicitOp(i).opIsDefAndUse())
addUse(Op); addUse(Op);
} }
} // for all machine instructions } // for all machine instructions

View File

@ -213,13 +213,14 @@ FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI,
static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) { static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
for (MachineInstr::const_val_op_iterator OpI = MInst->begin(), for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
OpE = MInst->end(); OpI != OpE; ++OpI) { OpE = MInst->end(); OpI != OpE; ++OpI) {
if (OpI.isDef()) // kill only if this operand is a def if (OpI.isDefOnly() || OpI.isDefAndUse()) // kill if this operand is a def
LVS.erase(*OpI); // this definition kills any uses LVS.erase(*OpI); // this definition kills any uses
} }
// do for implicit operands as well // do for implicit operands as well
for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) { for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
if (MInst->implicitRefIsDefined(i)) if (MInst->getImplicitOp(i).opIsDefOnly() ||
MInst->getImplicitOp(i).opIsDefAndUse())
LVS.erase(MInst->getImplicitRef(i)); LVS.erase(MInst->getImplicitRef(i));
} }
@ -227,14 +228,14 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
OpE = MInst->end(); OpI != OpE; ++OpI) { OpE = MInst->end(); OpI != OpE; ++OpI) {
if (!isa<BasicBlock>(*OpI)) // don't process labels if (!isa<BasicBlock>(*OpI)) // don't process labels
// add only if this operand is a use // add only if this operand is a use
if (!OpI.isDef() || OpI.isDefAndUse() ) if (!OpI.isDefOnly() || OpI.isDefAndUse() )
LVS.insert(*OpI); // An operand is a use - so add to use set LVS.insert(*OpI); // An operand is a use - so add to use set
} }
// do for implicit operands as well // do for implicit operands as well
for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i) for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i)
if (!MInst->implicitRefIsDefined(i) || if (MInst->getImplicitOp(i).opIsUse() ||
MInst->implicitRefIsDefinedAndUsed(i)) MInst->getImplicitOp(i).opIsDefAndUse())
LVS.insert(MInst->getImplicitRef(i)); LVS.insert(MInst->getImplicitRef(i));
} }

View File

@ -64,12 +64,12 @@ void BBLiveVar::calcDefUseSets() {
// iterate over MI operands to find defs // iterate over MI operands to find defs
for (MachineInstr::const_val_op_iterator OpI = MI->begin(), OpE = MI->end(); for (MachineInstr::const_val_op_iterator OpI = MI->begin(), OpE = MI->end();
OpI != OpE; ++OpI) OpI != OpE; ++OpI)
if (OpI.isDef()) // add to Defs only if this operand is a def if (OpI.isDefOnly() || OpI.isDefAndUse()) // add to Defs if this operand is a def
addDef(*OpI); addDef(*OpI);
// do for implicit operands as well // do for implicit operands as well
for (unsigned i = 0; i < MI->getNumImplicitRefs(); ++i) for (unsigned i = 0; i < MI->getNumImplicitRefs(); ++i)
if (MI->implicitRefIsDefined(i)) if (MI->getImplicitOp(i).opIsDefOnly() || MI->getImplicitOp(i).opIsDefAndUse())
addDef(MI->getImplicitRef(i)); addDef(MI->getImplicitRef(i));
// iterate over MI operands to find uses // iterate over MI operands to find uses
@ -80,7 +80,7 @@ void BBLiveVar::calcDefUseSets() {
if (isa<BasicBlock>(Op)) if (isa<BasicBlock>(Op))
continue; // don't process labels continue; // don't process labels
if (!OpI.isDef() || OpI.isDefAndUse()) { if (OpI.isUseOnly() || OpI.isDefAndUse()) {
// add to Uses only if this operand is a use // add to Uses only if this operand is a use
// //
// *** WARNING: The following code for handling dummy PHI machine // *** WARNING: The following code for handling dummy PHI machine
@ -116,7 +116,7 @@ void BBLiveVar::calcDefUseSets() {
if (Op->getType() == Type::LabelTy) // don't process labels if (Op->getType() == Type::LabelTy) // don't process labels
continue; continue;
if (!MI->implicitRefIsDefined(i) || MI->implicitRefIsDefinedAndUsed(i) ) if (MI->getImplicitOp(i).opIsUse() || MI->getImplicitOp(i).opIsDefAndUse())
addUse(Op); addUse(Op);
} }
} // for all machine instructions } // for all machine instructions

View File

@ -213,13 +213,14 @@ FunctionLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI,
static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) { static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
for (MachineInstr::const_val_op_iterator OpI = MInst->begin(), for (MachineInstr::const_val_op_iterator OpI = MInst->begin(),
OpE = MInst->end(); OpI != OpE; ++OpI) { OpE = MInst->end(); OpI != OpE; ++OpI) {
if (OpI.isDef()) // kill only if this operand is a def if (OpI.isDefOnly() || OpI.isDefAndUse()) // kill if this operand is a def
LVS.erase(*OpI); // this definition kills any uses LVS.erase(*OpI); // this definition kills any uses
} }
// do for implicit operands as well // do for implicit operands as well
for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) { for (unsigned i=0; i < MInst->getNumImplicitRefs(); ++i) {
if (MInst->implicitRefIsDefined(i)) if (MInst->getImplicitOp(i).opIsDefOnly() ||
MInst->getImplicitOp(i).opIsDefAndUse())
LVS.erase(MInst->getImplicitRef(i)); LVS.erase(MInst->getImplicitRef(i));
} }
@ -227,14 +228,14 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
OpE = MInst->end(); OpI != OpE; ++OpI) { OpE = MInst->end(); OpI != OpE; ++OpI) {
if (!isa<BasicBlock>(*OpI)) // don't process labels if (!isa<BasicBlock>(*OpI)) // don't process labels
// add only if this operand is a use // add only if this operand is a use
if (!OpI.isDef() || OpI.isDefAndUse() ) if (!OpI.isDefOnly() || OpI.isDefAndUse() )
LVS.insert(*OpI); // An operand is a use - so add to use set LVS.insert(*OpI); // An operand is a use - so add to use set
} }
// do for implicit operands as well // do for implicit operands as well
for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i) for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i)
if (!MInst->implicitRefIsDefined(i) || if (MInst->getImplicitOp(i).opIsUse() ||
MInst->implicitRefIsDefinedAndUsed(i)) MInst->getImplicitOp(i).opIsDefAndUse())
LVS.insert(MInst->getImplicitRef(i)); LVS.insert(MInst->getImplicitRef(i));
} }