PR4795: Remove EEVT::isFP, isInt and isVec types used by TableGen's type

inferencing.  As far as I can tell, these are equivalent to the existing
MVT::fAny, iAny and vAny types, and having both of them makes it harder
to reason about and modify the type inferencing code.

The specific problem in PR4795 occurs when updating a vAny type to be fAny
or iAny, or vice versa.  Both iAny and fAny include vector types -- they
intersect with the set of types represented by vAny.  When merging them,
choose fAny/iAny to represent the intersection.  This is not perfect, since
fAny/iAny also include scalar types, but it is good enough for TableGen's
type inferencing.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80423 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bob Wilson 2009-08-29 05:53:25 +00:00
parent 6fefcebc4f
commit cdfa01bf0f
2 changed files with 46 additions and 35 deletions

View File

@ -78,24 +78,24 @@ static bool LHSIsSubsetOfRHS(const std::vector<unsigned char> &LHS,
namespace llvm { namespace llvm {
namespace EEVT { namespace EEVT {
/// isExtIntegerInVTs - Return true if the specified extended value type vector /// isExtIntegerInVTs - Return true if the specified extended value type vector
/// contains isInt or an integer value type. /// contains iAny or an integer value type.
bool isExtIntegerInVTs(const std::vector<unsigned char> &EVTs) { bool isExtIntegerInVTs(const std::vector<unsigned char> &EVTs) {
assert(!EVTs.empty() && "Cannot check for integer in empty ExtVT list!"); assert(!EVTs.empty() && "Cannot check for integer in empty ExtVT list!");
return EVTs[0] == isInt || !(FilterEVTs(EVTs, isInteger).empty()); return EVTs[0] == MVT::iAny || !(FilterEVTs(EVTs, isInteger).empty());
} }
/// isExtFloatingPointInVTs - Return true if the specified extended value type /// isExtFloatingPointInVTs - Return true if the specified extended value type
/// vector contains isFP or a FP value type. /// vector contains fAny or a FP value type.
bool isExtFloatingPointInVTs(const std::vector<unsigned char> &EVTs) { bool isExtFloatingPointInVTs(const std::vector<unsigned char> &EVTs) {
assert(!EVTs.empty() && "Cannot check for FP in empty ExtVT list!"); assert(!EVTs.empty() && "Cannot check for FP in empty ExtVT list!");
return EVTs[0] == isFP || !(FilterEVTs(EVTs, isFloatingPoint).empty()); return EVTs[0] == MVT::fAny || !(FilterEVTs(EVTs, isFloatingPoint).empty());
} }
/// isExtVectorInVTs - Return true if the specified extended value type /// isExtVectorInVTs - Return true if the specified extended value type
/// vector contains a vector value type. /// vector contains vAny or a vector value type.
bool isExtVectorInVTs(const std::vector<unsigned char> &EVTs) { bool isExtVectorInVTs(const std::vector<unsigned char> &EVTs) {
assert(!EVTs.empty() && "Cannot check for vector in empty ExtVT list!"); assert(!EVTs.empty() && "Cannot check for vector in empty ExtVT list!");
return EVTs[0] == isVec || !(FilterEVTs(EVTs, isVector).empty()); return EVTs[0] == MVT::vAny || !(FilterEVTs(EVTs, isVector).empty());
} }
} // end namespace EEVT. } // end namespace EEVT.
} // end namespace llvm. } // end namespace llvm.
@ -276,7 +276,7 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
// If we found exactly one supported integer type, apply it. // If we found exactly one supported integer type, apply it.
if (IntVTs.size() == 1) if (IntVTs.size() == 1)
return NodeToApply->UpdateNodeType(IntVTs[0], TP); return NodeToApply->UpdateNodeType(IntVTs[0], TP);
return NodeToApply->UpdateNodeType(EEVT::isInt, TP); return NodeToApply->UpdateNodeType(MVT::iAny, TP);
} }
case SDTCisFP: { case SDTCisFP: {
// If there is only one FP type supported, this must be it. // If there is only one FP type supported, this must be it.
@ -286,7 +286,7 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
// If we found exactly one supported FP type, apply it. // If we found exactly one supported FP type, apply it.
if (FPVTs.size() == 1) if (FPVTs.size() == 1)
return NodeToApply->UpdateNodeType(FPVTs[0], TP); return NodeToApply->UpdateNodeType(FPVTs[0], TP);
return NodeToApply->UpdateNodeType(EEVT::isFP, TP); return NodeToApply->UpdateNodeType(MVT::fAny, TP);
} }
case SDTCisVec: { case SDTCisVec: {
// If there is only one vector type supported, this must be it. // If there is only one vector type supported, this must be it.
@ -296,7 +296,7 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
// If we found exactly one supported vector type, apply it. // If we found exactly one supported vector type, apply it.
if (VecVTs.size() == 1) if (VecVTs.size() == 1)
return NodeToApply->UpdateNodeType(VecVTs[0], TP); return NodeToApply->UpdateNodeType(VecVTs[0], TP);
return NodeToApply->UpdateNodeType(EEVT::isVec, TP); return NodeToApply->UpdateNodeType(MVT::vAny, TP);
} }
case SDTCisSameAs: { case SDTCisSameAs: {
TreePatternNode *OtherNode = TreePatternNode *OtherNode =
@ -322,7 +322,7 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
// It must be integer. // It must be integer.
bool MadeChange = false; bool MadeChange = false;
MadeChange |= OtherNode->UpdateNodeType(EEVT::isInt, TP); MadeChange |= OtherNode->UpdateNodeType(MVT::iAny, TP);
// This code only handles nodes that have one type set. Assert here so // This code only handles nodes that have one type set. Assert here so
// that we can change this if we ever need to deal with multiple value // that we can change this if we ever need to deal with multiple value
@ -348,13 +348,13 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
EEVT::isExtFloatingPointInVTs(BigOperand->getExtTypes())) && EEVT::isExtFloatingPointInVTs(BigOperand->getExtTypes())) &&
"SDTCisOpSmallerThanOp does not handle mixed int/fp types!"); "SDTCisOpSmallerThanOp does not handle mixed int/fp types!");
if (EEVT::isExtIntegerInVTs(NodeToApply->getExtTypes())) if (EEVT::isExtIntegerInVTs(NodeToApply->getExtTypes()))
MadeChange |= BigOperand->UpdateNodeType(EEVT::isInt, TP); MadeChange |= BigOperand->UpdateNodeType(MVT::iAny, TP);
else if (EEVT::isExtFloatingPointInVTs(NodeToApply->getExtTypes())) else if (EEVT::isExtFloatingPointInVTs(NodeToApply->getExtTypes()))
MadeChange |= BigOperand->UpdateNodeType(EEVT::isFP, TP); MadeChange |= BigOperand->UpdateNodeType(MVT::fAny, TP);
if (EEVT::isExtIntegerInVTs(BigOperand->getExtTypes())) if (EEVT::isExtIntegerInVTs(BigOperand->getExtTypes()))
MadeChange |= NodeToApply->UpdateNodeType(EEVT::isInt, TP); MadeChange |= NodeToApply->UpdateNodeType(MVT::iAny, TP);
else if (EEVT::isExtFloatingPointInVTs(BigOperand->getExtTypes())) else if (EEVT::isExtFloatingPointInVTs(BigOperand->getExtTypes()))
MadeChange |= NodeToApply->UpdateNodeType(EEVT::isFP, TP); MadeChange |= NodeToApply->UpdateNodeType(MVT::fAny, TP);
std::vector<MVT::SimpleValueType> VTs = CGT.getLegalValueTypes(); std::vector<MVT::SimpleValueType> VTs = CGT.getLegalValueTypes();
@ -476,7 +476,7 @@ bool TreePatternNode::UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
if (getExtTypeNum(0) == MVT::iPTR || getExtTypeNum(0) == MVT::iPTRAny) { if (getExtTypeNum(0) == MVT::iPTR || getExtTypeNum(0) == MVT::iPTRAny) {
if (ExtVTs[0] == MVT::iPTR || ExtVTs[0] == MVT::iPTRAny || if (ExtVTs[0] == MVT::iPTR || ExtVTs[0] == MVT::iPTRAny ||
ExtVTs[0] == EEVT::isInt) ExtVTs[0] == MVT::iAny)
return false; return false;
if (EEVT::isExtIntegerInVTs(ExtVTs)) { if (EEVT::isExtIntegerInVTs(ExtVTs)) {
std::vector<unsigned char> FVTs = FilterEVTs(ExtVTs, isInteger); std::vector<unsigned char> FVTs = FilterEVTs(ExtVTs, isInteger);
@ -487,7 +487,18 @@ bool TreePatternNode::UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
} }
} }
if ((ExtVTs[0] == EEVT::isInt || ExtVTs[0] == MVT::iAny) && // Merge vAny with iAny/fAny. The latter include vector types so keep them
// as the more specific information.
if (ExtVTs[0] == MVT::vAny &&
(getExtTypeNum(0) == MVT::iAny || getExtTypeNum(0) == MVT::fAny))
return false;
if (getExtTypeNum(0) == MVT::vAny &&
(ExtVTs[0] == MVT::iAny || ExtVTs[0] == MVT::fAny)) {
setTypes(ExtVTs);
return true;
}
if (ExtVTs[0] == MVT::iAny &&
EEVT::isExtIntegerInVTs(getExtTypes())) { EEVT::isExtIntegerInVTs(getExtTypes())) {
assert(hasTypeSet() && "should be handled above!"); assert(hasTypeSet() && "should be handled above!");
std::vector<unsigned char> FVTs = FilterEVTs(getExtTypes(), isInteger); std::vector<unsigned char> FVTs = FilterEVTs(getExtTypes(), isInteger);
@ -507,7 +518,7 @@ bool TreePatternNode::UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
return true; return true;
} }
} }
if ((ExtVTs[0] == EEVT::isFP || ExtVTs[0] == MVT::fAny) && if (ExtVTs[0] == MVT::fAny &&
EEVT::isExtFloatingPointInVTs(getExtTypes())) { EEVT::isExtFloatingPointInVTs(getExtTypes())) {
assert(hasTypeSet() && "should be handled above!"); assert(hasTypeSet() && "should be handled above!");
std::vector<unsigned char> FVTs = std::vector<unsigned char> FVTs =
@ -517,7 +528,7 @@ bool TreePatternNode::UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
setTypes(FVTs); setTypes(FVTs);
return true; return true;
} }
if ((ExtVTs[0] == EEVT::isVec || ExtVTs[0] == MVT::vAny) && if (ExtVTs[0] == MVT::vAny &&
EEVT::isExtVectorInVTs(getExtTypes())) { EEVT::isExtVectorInVTs(getExtTypes())) {
assert(hasTypeSet() && "should be handled above!"); assert(hasTypeSet() && "should be handled above!");
std::vector<unsigned char> FVTs = FilterEVTs(getExtTypes(), isVector); std::vector<unsigned char> FVTs = FilterEVTs(getExtTypes(), isVector);
@ -526,22 +537,22 @@ bool TreePatternNode::UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
setTypes(FVTs); setTypes(FVTs);
return true; return true;
} }
// If we know this is an int, FP, or vector type, and we are told it is a // If we know this is an int, FP, or vector type, and we are told it is a
// specific one, take the advice. // specific one, take the advice.
// //
// Similarly, we should probably set the type here to the intersection of // Similarly, we should probably set the type here to the intersection of
// {isInt|isFP|isVec} and ExtVTs // {iAny|fAny|vAny} and ExtVTs
if (((getExtTypeNum(0) == EEVT::isInt || getExtTypeNum(0) == MVT::iAny) && if ((getExtTypeNum(0) == MVT::iAny &&
EEVT::isExtIntegerInVTs(ExtVTs)) || EEVT::isExtIntegerInVTs(ExtVTs)) ||
((getExtTypeNum(0) == EEVT::isFP || getExtTypeNum(0) == MVT::fAny) && (getExtTypeNum(0) == MVT::fAny &&
EEVT::isExtFloatingPointInVTs(ExtVTs)) || EEVT::isExtFloatingPointInVTs(ExtVTs)) ||
((getExtTypeNum(0) == EEVT::isVec || getExtTypeNum(0) == MVT::vAny) && (getExtTypeNum(0) == MVT::vAny &&
EEVT::isExtVectorInVTs(ExtVTs))) { EEVT::isExtVectorInVTs(ExtVTs))) {
setTypes(ExtVTs); setTypes(ExtVTs);
return true; return true;
} }
if (getExtTypeNum(0) == EEVT::isInt && if (getExtTypeNum(0) == MVT::iAny &&
(ExtVTs[0] == MVT::iPTR || ExtVTs[0] == MVT::iPTRAny)) { (ExtVTs[0] == MVT::iPTR || ExtVTs[0] == MVT::iPTRAny)) {
setTypes(ExtVTs); setTypes(ExtVTs);
return true; return true;
@ -570,9 +581,9 @@ void TreePatternNode::print(raw_ostream &OS) const {
// nodes that are multiply typed. // nodes that are multiply typed.
switch (getExtTypeNum(0)) { switch (getExtTypeNum(0)) {
case MVT::Other: OS << ":Other"; break; case MVT::Other: OS << ":Other"; break;
case EEVT::isInt: OS << ":isInt"; break; case MVT::iAny: OS << ":iAny"; break;
case EEVT::isFP : OS << ":isFP"; break; case MVT::fAny : OS << ":fAny"; break;
case EEVT::isVec: OS << ":isVec"; break; case MVT::vAny: OS << ":vAny"; break;
case EEVT::isUnknown: ; /*OS << ":?";*/ break; case EEVT::isUnknown: ; /*OS << ":?";*/ break;
case MVT::iPTR: OS << ":iPTR"; break; case MVT::iPTR: OS << ":iPTR"; break;
case MVT::iPTRAny: OS << ":iPTRAny"; break; case MVT::iPTRAny: OS << ":iPTRAny"; break;
@ -837,7 +848,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
return UpdateNodeType(getImplicitType(DI->getDef(), NotRegisters, TP),TP); return UpdateNodeType(getImplicitType(DI->getDef(), NotRegisters, TP),TP);
} else if (IntInit *II = dynamic_cast<IntInit*>(getLeafValue())) { } else if (IntInit *II = dynamic_cast<IntInit*>(getLeafValue())) {
// Int inits are always integers. :) // Int inits are always integers. :)
bool MadeChange = UpdateNodeType(EEVT::isInt, TP); bool MadeChange = UpdateNodeType(MVT::iAny, TP);
if (hasTypeSet()) { if (hasTypeSet()) {
// At some point, it may make sense for this tree pattern to have // At some point, it may make sense for this tree pattern to have

View File

@ -35,24 +35,24 @@ namespace llvm {
/// EEVT::DAGISelGenValueType - These are some extended forms of /// EEVT::DAGISelGenValueType - These are some extended forms of
/// MVT::SimpleValueType that we use as lattice values during type inference. /// MVT::SimpleValueType that we use as lattice values during type inference.
/// The existing MVT iAny, fAny and vAny types suffice to represent
/// arbitrary integer, floating-point, and vector types, so only an unknown
/// value is needed.
namespace EEVT { namespace EEVT {
enum DAGISelGenValueType { enum DAGISelGenValueType {
isFP = MVT::LAST_VALUETYPE, isUnknown = MVT::LAST_VALUETYPE
isInt,
isVec,
isUnknown
}; };
/// isExtIntegerInVTs - Return true if the specified extended value type /// isExtIntegerInVTs - Return true if the specified extended value type
/// vector contains isInt or an integer value type. /// vector contains iAny or an integer value type.
bool isExtIntegerInVTs(const std::vector<unsigned char> &EVTs); bool isExtIntegerInVTs(const std::vector<unsigned char> &EVTs);
/// isExtFloatingPointInVTs - Return true if the specified extended value /// isExtFloatingPointInVTs - Return true if the specified extended value
/// type vector contains isFP or a FP value type. /// type vector contains fAny or a FP value type.
bool isExtFloatingPointInVTs(const std::vector<unsigned char> &EVTs); bool isExtFloatingPointInVTs(const std::vector<unsigned char> &EVTs);
/// isExtVectorinVTs - Return true if the specified extended value type /// isExtVectorinVTs - Return true if the specified extended value type
/// vector contains isVec or a vector value type. /// vector contains vAny or a vector value type.
bool isExtVectorInVTs(const std::vector<unsigned char> &EVTs); bool isExtVectorInVTs(const std::vector<unsigned char> &EVTs);
} }