mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 19:52:54 +01:00
Factorize (and generalize) the code promoting SELECT
and BRCOND conditions. Reorder a few methods while there. llvm-svn: 61547
This commit is contained in:
parent
361188d5bc
commit
0fca32114b
@ -726,44 +726,10 @@ SDValue DAGTypeLegalizer::PromoteIntOp_BR_CC(SDNode *N, unsigned OpNo) {
|
|||||||
|
|
||||||
SDValue DAGTypeLegalizer::PromoteIntOp_BRCOND(SDNode *N, unsigned OpNo) {
|
SDValue DAGTypeLegalizer::PromoteIntOp_BRCOND(SDNode *N, unsigned OpNo) {
|
||||||
assert(OpNo == 1 && "only know how to promote condition");
|
assert(OpNo == 1 && "only know how to promote condition");
|
||||||
SDValue Cond = GetPromotedInteger(N->getOperand(1)); // Promote condition.
|
|
||||||
|
|
||||||
// Promote all the way up to SVT, the canonical SetCC type.
|
// Promote all the way up to the canonical SetCC type.
|
||||||
MVT SVT = TLI.getSetCCResultType(MVT::Other);
|
MVT SVT = TLI.getSetCCResultType(MVT::Other);
|
||||||
assert(isTypeLegal(SVT) && "Illegal SetCC type!");
|
SDValue Cond = PromoteTargetBoolean(N->getOperand(1), SVT);
|
||||||
assert(Cond.getValueType().bitsLE(SVT) && "Unexpected SetCC type!");
|
|
||||||
|
|
||||||
// Make sure the extra bits conform to getBooleanContents. There are
|
|
||||||
// two sets of extra bits: those in Cond, which come from type promotion,
|
|
||||||
// and those we need to add to have the final type be SVT (for most targets
|
|
||||||
// this last set of bits is empty).
|
|
||||||
unsigned CondBits = Cond.getValueSizeInBits();
|
|
||||||
ISD::NodeType ExtendCode;
|
|
||||||
switch (TLI.getBooleanContents()) {
|
|
||||||
default:
|
|
||||||
assert(false && "Unknown BooleanContent!");
|
|
||||||
case TargetLowering::UndefinedBooleanContent:
|
|
||||||
// Extend to SVT by adding rubbish.
|
|
||||||
ExtendCode = ISD::ANY_EXTEND;
|
|
||||||
break;
|
|
||||||
case TargetLowering::ZeroOrOneBooleanContent:
|
|
||||||
ExtendCode = ISD::ZERO_EXTEND;
|
|
||||||
if (!DAG.MaskedValueIsZero(Cond,APInt::getHighBitsSet(CondBits,CondBits-1)))
|
|
||||||
// All extra bits need to be cleared. Do this by zero extending the
|
|
||||||
// original condition value all the way to SVT.
|
|
||||||
Cond = N->getOperand(1);
|
|
||||||
break;
|
|
||||||
case TargetLowering::ZeroOrNegativeOneBooleanContent: {
|
|
||||||
ExtendCode = ISD::SIGN_EXTEND;
|
|
||||||
unsigned SignBits = DAG.ComputeNumSignBits(Cond);
|
|
||||||
if (SignBits != CondBits)
|
|
||||||
// All extra bits need to be sign extended. Do this by sign extending the
|
|
||||||
// original condition value all the way to SVT.
|
|
||||||
Cond = N->getOperand(1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Cond = DAG.getNode(ExtendCode, SVT, Cond);
|
|
||||||
|
|
||||||
// The chain (Op#0) and basic block destination (Op#2) are always legal types.
|
// The chain (Op#0) and basic block destination (Op#2) are always legal types.
|
||||||
return DAG.UpdateNodeOperands(SDValue(N, 0), N->getOperand(0), Cond,
|
return DAG.UpdateNodeOperands(SDValue(N, 0), N->getOperand(0), Cond,
|
||||||
@ -865,44 +831,10 @@ SDValue DAGTypeLegalizer::PromoteIntOp_MEMBARRIER(SDNode *N) {
|
|||||||
|
|
||||||
SDValue DAGTypeLegalizer::PromoteIntOp_SELECT(SDNode *N, unsigned OpNo) {
|
SDValue DAGTypeLegalizer::PromoteIntOp_SELECT(SDNode *N, unsigned OpNo) {
|
||||||
assert(OpNo == 0 && "Only know how to promote condition");
|
assert(OpNo == 0 && "Only know how to promote condition");
|
||||||
SDValue Cond = GetPromotedInteger(N->getOperand(0));
|
|
||||||
|
|
||||||
// Promote all the way up to SVT, the canonical SetCC type.
|
// Promote all the way up to the canonical SetCC type.
|
||||||
MVT SVT = TLI.getSetCCResultType(N->getOperand(1).getValueType());
|
MVT SVT = TLI.getSetCCResultType(N->getOperand(1).getValueType());
|
||||||
assert(isTypeLegal(SVT) && "Illegal SetCC type!");
|
SDValue Cond = PromoteTargetBoolean(N->getOperand(0), SVT);
|
||||||
assert(Cond.getValueType().bitsLE(SVT) && "Unexpected SetCC type!");
|
|
||||||
|
|
||||||
// Make sure the extra bits conform to getBooleanContents. There are
|
|
||||||
// two sets of extra bits: those in Cond, which come from type promotion,
|
|
||||||
// and those we need to add to have the final type be SVT (for most targets
|
|
||||||
// this last set of bits is empty).
|
|
||||||
unsigned CondBits = Cond.getValueSizeInBits();
|
|
||||||
ISD::NodeType ExtendCode;
|
|
||||||
switch (TLI.getBooleanContents()) {
|
|
||||||
default:
|
|
||||||
assert(false && "Unknown BooleanContent!");
|
|
||||||
case TargetLowering::UndefinedBooleanContent:
|
|
||||||
// Extend to SVT by adding rubbish.
|
|
||||||
ExtendCode = ISD::ANY_EXTEND;
|
|
||||||
break;
|
|
||||||
case TargetLowering::ZeroOrOneBooleanContent:
|
|
||||||
ExtendCode = ISD::ZERO_EXTEND;
|
|
||||||
if (!DAG.MaskedValueIsZero(Cond,APInt::getHighBitsSet(CondBits,CondBits-1)))
|
|
||||||
// All extra bits need to be cleared. Do this by zero extending the
|
|
||||||
// original condition value all the way to SVT.
|
|
||||||
Cond = N->getOperand(0);
|
|
||||||
break;
|
|
||||||
case TargetLowering::ZeroOrNegativeOneBooleanContent: {
|
|
||||||
ExtendCode = ISD::SIGN_EXTEND;
|
|
||||||
unsigned SignBits = DAG.ComputeNumSignBits(Cond);
|
|
||||||
if (SignBits != CondBits)
|
|
||||||
// All extra bits need to be sign extended. Do this by sign extending the
|
|
||||||
// original condition value all the way to SVT.
|
|
||||||
Cond = N->getOperand(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Cond = DAG.getNode(ExtendCode, SVT, Cond);
|
|
||||||
|
|
||||||
return DAG.UpdateNodeOperands(SDValue(N, 0), Cond,
|
return DAG.UpdateNodeOperands(SDValue(N, 0), Cond,
|
||||||
N->getOperand(1), N->getOperand(2));
|
N->getOperand(1), N->getOperand(2));
|
||||||
|
@ -869,6 +869,42 @@ bool DAGTypeLegalizer::CustomLowerResults(SDNode *N, unsigned ResNo) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// GetSplitDestVTs - Compute the VTs needed for the low/hi parts of a type
|
||||||
|
/// which is split into two not necessarily identical pieces.
|
||||||
|
void DAGTypeLegalizer::GetSplitDestVTs(MVT InVT, MVT &LoVT, MVT &HiVT) {
|
||||||
|
if (!InVT.isVector()) {
|
||||||
|
LoVT = HiVT = TLI.getTypeToTransformTo(InVT);
|
||||||
|
} else {
|
||||||
|
MVT NewEltVT = InVT.getVectorElementType();
|
||||||
|
unsigned NumElements = InVT.getVectorNumElements();
|
||||||
|
if ((NumElements & (NumElements-1)) == 0) { // Simple power of two vector.
|
||||||
|
NumElements >>= 1;
|
||||||
|
LoVT = HiVT = MVT::getVectorVT(NewEltVT, NumElements);
|
||||||
|
} else { // Non-power-of-two vectors.
|
||||||
|
unsigned NewNumElts_Lo = 1 << Log2_32(NumElements);
|
||||||
|
unsigned NewNumElts_Hi = NumElements - NewNumElts_Lo;
|
||||||
|
LoVT = MVT::getVectorVT(NewEltVT, NewNumElts_Lo);
|
||||||
|
HiVT = MVT::getVectorVT(NewEltVT, NewNumElts_Hi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDValue DAGTypeLegalizer::GetVectorElementPointer(SDValue VecPtr, MVT EltVT,
|
||||||
|
SDValue Index) {
|
||||||
|
// Make sure the index type is big enough to compute in.
|
||||||
|
if (Index.getValueType().bitsGT(TLI.getPointerTy()))
|
||||||
|
Index = DAG.getNode(ISD::TRUNCATE, TLI.getPointerTy(), Index);
|
||||||
|
else
|
||||||
|
Index = DAG.getNode(ISD::ZERO_EXTEND, TLI.getPointerTy(), Index);
|
||||||
|
|
||||||
|
// Calculate the element offset and add it to the pointer.
|
||||||
|
unsigned EltSize = EltVT.getSizeInBits() / 8; // FIXME: should be ABI size.
|
||||||
|
|
||||||
|
Index = DAG.getNode(ISD::MUL, Index.getValueType(), Index,
|
||||||
|
DAG.getConstant(EltSize, Index.getValueType()));
|
||||||
|
return DAG.getNode(ISD::ADD, Index.getValueType(), Index, VecPtr);
|
||||||
|
}
|
||||||
|
|
||||||
/// JoinIntegers - Build an integer with low bits Lo and high bits Hi.
|
/// JoinIntegers - Build an integer with low bits Lo and high bits Hi.
|
||||||
SDValue DAGTypeLegalizer::JoinIntegers(SDValue Lo, SDValue Hi) {
|
SDValue DAGTypeLegalizer::JoinIntegers(SDValue Lo, SDValue Hi) {
|
||||||
MVT LVT = Lo.getValueType();
|
MVT LVT = Lo.getValueType();
|
||||||
@ -882,26 +918,24 @@ SDValue DAGTypeLegalizer::JoinIntegers(SDValue Lo, SDValue Hi) {
|
|||||||
return DAG.getNode(ISD::OR, NVT, Lo, Hi);
|
return DAG.getNode(ISD::OR, NVT, Lo, Hi);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SplitInteger - Return the lower LoVT bits of Op in Lo and the upper HiVT
|
/// LibCallify - Convert the node into a libcall with the same prototype.
|
||||||
/// bits in Hi.
|
SDValue DAGTypeLegalizer::LibCallify(RTLIB::Libcall LC, SDNode *N,
|
||||||
void DAGTypeLegalizer::SplitInteger(SDValue Op,
|
bool isSigned) {
|
||||||
MVT LoVT, MVT HiVT,
|
unsigned NumOps = N->getNumOperands();
|
||||||
SDValue &Lo, SDValue &Hi) {
|
if (NumOps == 0) {
|
||||||
assert(LoVT.getSizeInBits() + HiVT.getSizeInBits() ==
|
return MakeLibCall(LC, N->getValueType(0), 0, 0, isSigned);
|
||||||
Op.getValueType().getSizeInBits() && "Invalid integer splitting!");
|
} else if (NumOps == 1) {
|
||||||
Lo = DAG.getNode(ISD::TRUNCATE, LoVT, Op);
|
SDValue Op = N->getOperand(0);
|
||||||
Hi = DAG.getNode(ISD::SRL, Op.getValueType(), Op,
|
return MakeLibCall(LC, N->getValueType(0), &Op, 1, isSigned);
|
||||||
DAG.getConstant(LoVT.getSizeInBits(),
|
} else if (NumOps == 2) {
|
||||||
TLI.getShiftAmountTy()));
|
SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
|
||||||
Hi = DAG.getNode(ISD::TRUNCATE, HiVT, Hi);
|
return MakeLibCall(LC, N->getValueType(0), Ops, 2, isSigned);
|
||||||
}
|
}
|
||||||
|
SmallVector<SDValue, 8> Ops(NumOps);
|
||||||
|
for (unsigned i = 0; i < NumOps; ++i)
|
||||||
|
Ops[i] = N->getOperand(i);
|
||||||
|
|
||||||
/// SplitInteger - Return the lower and upper halves of Op's bits in a value
|
return MakeLibCall(LC, N->getValueType(0), &Ops[0], NumOps, isSigned);
|
||||||
/// type half the size of Op's.
|
|
||||||
void DAGTypeLegalizer::SplitInteger(SDValue Op,
|
|
||||||
SDValue &Lo, SDValue &Hi) {
|
|
||||||
MVT HalfVT = MVT::getIntegerVT(Op.getValueType().getSizeInBits()/2);
|
|
||||||
SplitInteger(Op, HalfVT, HalfVT, Lo, Hi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// MakeLibCall - Generate a libcall taking the given operands as arguments and
|
/// MakeLibCall - Generate a libcall taking the given operands as arguments and
|
||||||
@ -930,60 +964,51 @@ SDValue DAGTypeLegalizer::MakeLibCall(RTLIB::Libcall LC, MVT RetVT,
|
|||||||
return CallInfo.first;
|
return CallInfo.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// LibCallify - Convert the node into a libcall with the same prototype.
|
/// PromoteTargetBoolean - Promote the given target boolean to a target boolean
|
||||||
SDValue DAGTypeLegalizer::LibCallify(RTLIB::Libcall LC, SDNode *N,
|
/// of the given type. A target boolean is an integer value, not necessarily of
|
||||||
bool isSigned) {
|
/// type i1, the bits of which conform to getBooleanContents.
|
||||||
unsigned NumOps = N->getNumOperands();
|
SDValue DAGTypeLegalizer::PromoteTargetBoolean(SDValue Bool, MVT VT) {
|
||||||
if (NumOps == 0) {
|
ISD::NodeType ExtendCode;
|
||||||
return MakeLibCall(LC, N->getValueType(0), 0, 0, isSigned);
|
switch (TLI.getBooleanContents()) {
|
||||||
} else if (NumOps == 1) {
|
default:
|
||||||
SDValue Op = N->getOperand(0);
|
assert(false && "Unknown BooleanContent!");
|
||||||
return MakeLibCall(LC, N->getValueType(0), &Op, 1, isSigned);
|
case TargetLowering::UndefinedBooleanContent:
|
||||||
} else if (NumOps == 2) {
|
// Extend to VT by adding rubbish bits.
|
||||||
SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
|
ExtendCode = ISD::ANY_EXTEND;
|
||||||
return MakeLibCall(LC, N->getValueType(0), Ops, 2, isSigned);
|
break;
|
||||||
|
case TargetLowering::ZeroOrOneBooleanContent:
|
||||||
|
// Extend to VT by adding zero bits.
|
||||||
|
ExtendCode = ISD::ZERO_EXTEND;
|
||||||
|
break;
|
||||||
|
case TargetLowering::ZeroOrNegativeOneBooleanContent: {
|
||||||
|
// Extend to VT by copying the sign bit.
|
||||||
|
ExtendCode = ISD::SIGN_EXTEND;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
SmallVector<SDValue, 8> Ops(NumOps);
|
}
|
||||||
for (unsigned i = 0; i < NumOps; ++i)
|
return DAG.getNode(ExtendCode, VT, Bool);
|
||||||
Ops[i] = N->getOperand(i);
|
|
||||||
|
|
||||||
return MakeLibCall(LC, N->getValueType(0), &Ops[0], NumOps, isSigned);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDValue DAGTypeLegalizer::GetVectorElementPointer(SDValue VecPtr, MVT EltVT,
|
/// SplitInteger - Return the lower LoVT bits of Op in Lo and the upper HiVT
|
||||||
SDValue Index) {
|
/// bits in Hi.
|
||||||
// Make sure the index type is big enough to compute in.
|
void DAGTypeLegalizer::SplitInteger(SDValue Op,
|
||||||
if (Index.getValueType().bitsGT(TLI.getPointerTy()))
|
MVT LoVT, MVT HiVT,
|
||||||
Index = DAG.getNode(ISD::TRUNCATE, TLI.getPointerTy(), Index);
|
SDValue &Lo, SDValue &Hi) {
|
||||||
else
|
assert(LoVT.getSizeInBits() + HiVT.getSizeInBits() ==
|
||||||
Index = DAG.getNode(ISD::ZERO_EXTEND, TLI.getPointerTy(), Index);
|
Op.getValueType().getSizeInBits() && "Invalid integer splitting!");
|
||||||
|
Lo = DAG.getNode(ISD::TRUNCATE, LoVT, Op);
|
||||||
// Calculate the element offset and add it to the pointer.
|
Hi = DAG.getNode(ISD::SRL, Op.getValueType(), Op,
|
||||||
unsigned EltSize = EltVT.getSizeInBits() / 8; // FIXME: should be ABI size.
|
DAG.getConstant(LoVT.getSizeInBits(),
|
||||||
|
TLI.getShiftAmountTy()));
|
||||||
Index = DAG.getNode(ISD::MUL, Index.getValueType(), Index,
|
Hi = DAG.getNode(ISD::TRUNCATE, HiVT, Hi);
|
||||||
DAG.getConstant(EltSize, Index.getValueType()));
|
|
||||||
return DAG.getNode(ISD::ADD, Index.getValueType(), Index, VecPtr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GetSplitDestVTs - Compute the VTs needed for the low/hi parts of a type
|
/// SplitInteger - Return the lower and upper halves of Op's bits in a value
|
||||||
/// which is split into two not necessarily identical pieces.
|
/// type half the size of Op's.
|
||||||
void DAGTypeLegalizer::GetSplitDestVTs(MVT InVT, MVT &LoVT, MVT &HiVT) {
|
void DAGTypeLegalizer::SplitInteger(SDValue Op,
|
||||||
if (!InVT.isVector()) {
|
SDValue &Lo, SDValue &Hi) {
|
||||||
LoVT = HiVT = TLI.getTypeToTransformTo(InVT);
|
MVT HalfVT = MVT::getIntegerVT(Op.getValueType().getSizeInBits()/2);
|
||||||
} else {
|
SplitInteger(Op, HalfVT, HalfVT, Lo, Hi);
|
||||||
MVT NewEltVT = InVT.getVectorElementType();
|
|
||||||
unsigned NumElements = InVT.getVectorNumElements();
|
|
||||||
if ((NumElements & (NumElements-1)) == 0) { // Simple power of two vector.
|
|
||||||
NumElements >>= 1;
|
|
||||||
LoVT = HiVT = MVT::getVectorVT(NewEltVT, NumElements);
|
|
||||||
} else { // Non-power-of-two vectors.
|
|
||||||
unsigned NewNumElts_Lo = 1 << Log2_32(NumElements);
|
|
||||||
unsigned NewNumElts_Hi = NumElements - NewNumElts_Lo;
|
|
||||||
LoVT = MVT::getVectorVT(NewEltVT, NewNumElts_Lo);
|
|
||||||
HiVT = MVT::getVectorVT(NewEltVT, NewNumElts_Hi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -191,25 +191,21 @@ private:
|
|||||||
void RemapValue(SDValue &N);
|
void RemapValue(SDValue &N);
|
||||||
|
|
||||||
// Common routines.
|
// Common routines.
|
||||||
void ReplaceValueWith(SDValue From, SDValue To);
|
SDValue BitConvertToInteger(SDValue Op);
|
||||||
|
|
||||||
bool CustomLowerResults(SDNode *N, unsigned ResNo);
|
|
||||||
|
|
||||||
SDValue CreateStackStoreLoad(SDValue Op, MVT DestVT);
|
SDValue CreateStackStoreLoad(SDValue Op, MVT DestVT);
|
||||||
|
bool CustomLowerResults(SDNode *N, unsigned ResNo);
|
||||||
|
SDValue GetVectorElementPointer(SDValue VecPtr, MVT EltVT, SDValue Index);
|
||||||
|
SDValue JoinIntegers(SDValue Lo, SDValue Hi);
|
||||||
|
SDValue LibCallify(RTLIB::Libcall LC, SDNode *N, bool isSigned);
|
||||||
SDValue MakeLibCall(RTLIB::Libcall LC, MVT RetVT,
|
SDValue MakeLibCall(RTLIB::Libcall LC, MVT RetVT,
|
||||||
const SDValue *Ops, unsigned NumOps, bool isSigned);
|
const SDValue *Ops, unsigned NumOps, bool isSigned);
|
||||||
SDValue LibCallify(RTLIB::Libcall LC, SDNode *N, bool isSigned);
|
SDValue PromoteTargetBoolean(SDValue Bool, MVT VT);
|
||||||
|
void ReplaceValueWith(SDValue From, SDValue To);
|
||||||
SDValue BitConvertToInteger(SDValue Op);
|
void SetIgnoredNodeResult(SDNode* N);
|
||||||
SDValue JoinIntegers(SDValue Lo, SDValue Hi);
|
|
||||||
void SplitInteger(SDValue Op, SDValue &Lo, SDValue &Hi);
|
void SplitInteger(SDValue Op, SDValue &Lo, SDValue &Hi);
|
||||||
void SplitInteger(SDValue Op, MVT LoVT, MVT HiVT,
|
void SplitInteger(SDValue Op, MVT LoVT, MVT HiVT,
|
||||||
SDValue &Lo, SDValue &Hi);
|
SDValue &Lo, SDValue &Hi);
|
||||||
|
|
||||||
SDValue GetVectorElementPointer(SDValue VecPtr, MVT EltVT, SDValue Index);
|
|
||||||
|
|
||||||
void SetIgnoredNodeResult(SDNode* N);
|
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Integer Promotion Support: LegalizeIntegerTypes.cpp
|
// Integer Promotion Support: LegalizeIntegerTypes.cpp
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
|
Loading…
Reference in New Issue
Block a user