Rename the operation of turning a float type into an

integer of the same type.  Before it was "promotion",
but this is confusing because it is quite different
to promotion of integers.  Call it "softening" instead,
inspired by "soft float".

llvm-svn: 52546
This commit is contained in:
Duncan Sands 2008-06-20 17:49:55 +00:00
parent 3792c470d5
commit 49295b48eb
5 changed files with 76 additions and 77 deletions

View File

@ -7,13 +7,12 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// //
// This file implements float type expansion and conversion of float types to // This file implements float type expansion and softening for LegalizeTypes.
// integer types on behalf of LegalizeTypes. // Softening is the act of turning a computation in an illegal floating point
// Converting to integer is the act of turning a computation in an illegal // type into a computation in an integer type of the same size; also known as
// floating point type into a computation in an integer type of the same size. // "soft float". For example, turning f32 arithmetic into operations using i32.
// For example, turning f32 arithmetic into operations using i32. Also known as // The resulting integer value is the same as what you would get by performing
// "soft float". The result is equivalent to bitcasting the float value to the // the floating point operation and bitcasting the result to the integer type.
// integer type.
// Expansion is the act of changing a computation in an illegal type to be a // Expansion is the act of changing a computation in an illegal type to be a
// computation in multiple registers of a smaller type. For example, // computation in multiple registers of a smaller type. For example,
// implementing ppcf128 arithmetic in two f64 registers. // implementing ppcf128 arithmetic in two f64 registers.
@ -44,8 +43,8 @@ static RTLIB::Libcall GetFPLibCall(MVT VT,
// Result Float to Integer Conversion. // Result Float to Integer Conversion.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void DAGTypeLegalizer::PromoteFloatResult(SDNode *N, unsigned ResNo) { void DAGTypeLegalizer::SoftenFloatResult(SDNode *N, unsigned ResNo) {
DEBUG(cerr << "Promote float result " << ResNo << ": "; N->dump(&DAG); DEBUG(cerr << "Soften float result " << ResNo << ": "; N->dump(&DAG);
cerr << "\n"); cerr << "\n");
SDOperand R = SDOperand(); SDOperand R = SDOperand();
@ -67,37 +66,37 @@ void DAGTypeLegalizer::PromoteFloatResult(SDNode *N, unsigned ResNo) {
switch (N->getOpcode()) { switch (N->getOpcode()) {
default: default:
#ifndef NDEBUG #ifndef NDEBUG
cerr << "PromoteFloatResult #" << ResNo << ": "; cerr << "SoftenFloatResult #" << ResNo << ": ";
N->dump(&DAG); cerr << "\n"; N->dump(&DAG); cerr << "\n";
#endif #endif
assert(0 && "Do not know how to convert the result of this operator!"); assert(0 && "Do not know how to convert the result of this operator!");
abort(); abort();
case ISD::BIT_CONVERT: R = PromoteFloatRes_BIT_CONVERT(N); break; case ISD::BIT_CONVERT: R = SoftenFloatRes_BIT_CONVERT(N); break;
case ISD::BUILD_PAIR: R = PromoteFloatRes_BUILD_PAIR(N); break; case ISD::BUILD_PAIR: R = SoftenFloatRes_BUILD_PAIR(N); break;
case ISD::ConstantFP: case ISD::ConstantFP:
R = PromoteFloatRes_ConstantFP(cast<ConstantFPSDNode>(N)); R = SoftenFloatRes_ConstantFP(cast<ConstantFPSDNode>(N));
break; break;
case ISD::FCOPYSIGN: R = PromoteFloatRes_FCOPYSIGN(N); break; case ISD::FCOPYSIGN: R = SoftenFloatRes_FCOPYSIGN(N); break;
case ISD::LOAD: R = PromoteFloatRes_LOAD(N); break; case ISD::LOAD: R = SoftenFloatRes_LOAD(N); break;
case ISD::SINT_TO_FP: case ISD::SINT_TO_FP:
case ISD::UINT_TO_FP: R = PromoteFloatRes_XINT_TO_FP(N); break; case ISD::UINT_TO_FP: R = SoftenFloatRes_XINT_TO_FP(N); break;
case ISD::FADD: R = PromoteFloatRes_FADD(N); break; case ISD::FADD: R = SoftenFloatRes_FADD(N); break;
case ISD::FMUL: R = PromoteFloatRes_FMUL(N); break; case ISD::FMUL: R = SoftenFloatRes_FMUL(N); break;
case ISD::FSUB: R = PromoteFloatRes_FSUB(N); break; case ISD::FSUB: R = SoftenFloatRes_FSUB(N); break;
} }
// If R is null, the sub-method took care of registering the result. // If R is null, the sub-method took care of registering the result.
if (R.Val) if (R.Val)
SetPromotedFloat(SDOperand(N, ResNo), R); SetSoftenedFloat(SDOperand(N, ResNo), R);
} }
SDOperand DAGTypeLegalizer::PromoteFloatRes_BIT_CONVERT(SDNode *N) { SDOperand DAGTypeLegalizer::SoftenFloatRes_BIT_CONVERT(SDNode *N) {
return BitConvertToInteger(N->getOperand(0)); return BitConvertToInteger(N->getOperand(0));
} }
SDOperand DAGTypeLegalizer::PromoteFloatRes_BUILD_PAIR(SDNode *N) { SDOperand DAGTypeLegalizer::SoftenFloatRes_BUILD_PAIR(SDNode *N) {
// Convert the inputs to integers, and build a new pair out of them. // Convert the inputs to integers, and build a new pair out of them.
return DAG.getNode(ISD::BUILD_PAIR, return DAG.getNode(ISD::BUILD_PAIR,
TLI.getTypeToTransformTo(N->getValueType(0)), TLI.getTypeToTransformTo(N->getValueType(0)),
@ -105,15 +104,15 @@ SDOperand DAGTypeLegalizer::PromoteFloatRes_BUILD_PAIR(SDNode *N) {
BitConvertToInteger(N->getOperand(1))); BitConvertToInteger(N->getOperand(1)));
} }
SDOperand DAGTypeLegalizer::PromoteFloatRes_ConstantFP(ConstantFPSDNode *N) { SDOperand DAGTypeLegalizer::SoftenFloatRes_ConstantFP(ConstantFPSDNode *N) {
return DAG.getConstant(N->getValueAPF().convertToAPInt(), return DAG.getConstant(N->getValueAPF().convertToAPInt(),
TLI.getTypeToTransformTo(N->getValueType(0))); TLI.getTypeToTransformTo(N->getValueType(0)));
} }
SDOperand DAGTypeLegalizer::PromoteFloatRes_FADD(SDNode *N) { SDOperand DAGTypeLegalizer::SoftenFloatRes_FADD(SDNode *N) {
MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0)); MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
SDOperand Ops[2] = { GetPromotedFloat(N->getOperand(0)), SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
GetPromotedFloat(N->getOperand(1)) }; GetSoftenedFloat(N->getOperand(1)) };
return MakeLibCall(GetFPLibCall(N->getValueType(0), return MakeLibCall(GetFPLibCall(N->getValueType(0),
RTLIB::ADD_F32, RTLIB::ADD_F32,
RTLIB::ADD_F64, RTLIB::ADD_F64,
@ -122,8 +121,8 @@ SDOperand DAGTypeLegalizer::PromoteFloatRes_FADD(SDNode *N) {
NVT, Ops, 2, false/*sign irrelevant*/); NVT, Ops, 2, false/*sign irrelevant*/);
} }
SDOperand DAGTypeLegalizer::PromoteFloatRes_FCOPYSIGN(SDNode *N) { SDOperand DAGTypeLegalizer::SoftenFloatRes_FCOPYSIGN(SDNode *N) {
SDOperand LHS = GetPromotedFloat(N->getOperand(0)); SDOperand LHS = GetSoftenedFloat(N->getOperand(0));
SDOperand RHS = BitConvertToInteger(N->getOperand(1)); SDOperand RHS = BitConvertToInteger(N->getOperand(1));
MVT LVT = LHS.getValueType(); MVT LVT = LHS.getValueType();
@ -161,10 +160,10 @@ SDOperand DAGTypeLegalizer::PromoteFloatRes_FCOPYSIGN(SDNode *N) {
return DAG.getNode(ISD::OR, LVT, LHS, SignBit); return DAG.getNode(ISD::OR, LVT, LHS, SignBit);
} }
SDOperand DAGTypeLegalizer::PromoteFloatRes_FMUL(SDNode *N) { SDOperand DAGTypeLegalizer::SoftenFloatRes_FMUL(SDNode *N) {
MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0)); MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
SDOperand Ops[2] = { GetPromotedFloat(N->getOperand(0)), SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
GetPromotedFloat(N->getOperand(1)) }; GetSoftenedFloat(N->getOperand(1)) };
return MakeLibCall(GetFPLibCall(N->getValueType(0), return MakeLibCall(GetFPLibCall(N->getValueType(0),
RTLIB::MUL_F32, RTLIB::MUL_F32,
RTLIB::MUL_F64, RTLIB::MUL_F64,
@ -173,10 +172,10 @@ SDOperand DAGTypeLegalizer::PromoteFloatRes_FMUL(SDNode *N) {
NVT, Ops, 2, false/*sign irrelevant*/); NVT, Ops, 2, false/*sign irrelevant*/);
} }
SDOperand DAGTypeLegalizer::PromoteFloatRes_FSUB(SDNode *N) { SDOperand DAGTypeLegalizer::SoftenFloatRes_FSUB(SDNode *N) {
MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0)); MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
SDOperand Ops[2] = { GetPromotedFloat(N->getOperand(0)), SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
GetPromotedFloat(N->getOperand(1)) }; GetSoftenedFloat(N->getOperand(1)) };
return MakeLibCall(GetFPLibCall(N->getValueType(0), return MakeLibCall(GetFPLibCall(N->getValueType(0),
RTLIB::SUB_F32, RTLIB::SUB_F32,
RTLIB::SUB_F64, RTLIB::SUB_F64,
@ -185,7 +184,7 @@ SDOperand DAGTypeLegalizer::PromoteFloatRes_FSUB(SDNode *N) {
NVT, Ops, 2, false/*sign irrelevant*/); NVT, Ops, 2, false/*sign irrelevant*/);
} }
SDOperand DAGTypeLegalizer::PromoteFloatRes_LOAD(SDNode *N) { SDOperand DAGTypeLegalizer::SoftenFloatRes_LOAD(SDNode *N) {
LoadSDNode *L = cast<LoadSDNode>(N); LoadSDNode *L = cast<LoadSDNode>(N);
MVT VT = N->getValueType(0); MVT VT = N->getValueType(0);
MVT NVT = TLI.getTypeToTransformTo(VT); MVT NVT = TLI.getTypeToTransformTo(VT);
@ -206,7 +205,7 @@ SDOperand DAGTypeLegalizer::PromoteFloatRes_LOAD(SDNode *N) {
return BitConvertToInteger(DAG.getNode(ISD::FP_EXTEND, VT, NL)); return BitConvertToInteger(DAG.getNode(ISD::FP_EXTEND, VT, NL));
} }
SDOperand DAGTypeLegalizer::PromoteFloatRes_XINT_TO_FP(SDNode *N) { SDOperand DAGTypeLegalizer::SoftenFloatRes_XINT_TO_FP(SDNode *N) {
bool isSigned = N->getOpcode() == ISD::SINT_TO_FP; bool isSigned = N->getOpcode() == ISD::SINT_TO_FP;
MVT DestVT = N->getValueType(0); MVT DestVT = N->getValueType(0);
SDOperand Op = N->getOperand(0); SDOperand Op = N->getOperand(0);
@ -311,8 +310,8 @@ SDOperand DAGTypeLegalizer::PromoteFloatRes_XINT_TO_FP(SDNode *N) {
// Operand Float to Integer Conversion.. // Operand Float to Integer Conversion..
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
bool DAGTypeLegalizer::PromoteFloatOperand(SDNode *N, unsigned OpNo) { bool DAGTypeLegalizer::SoftenFloatOperand(SDNode *N, unsigned OpNo) {
DEBUG(cerr << "Promote float operand " << OpNo << ": "; N->dump(&DAG); DEBUG(cerr << "Soften float operand " << OpNo << ": "; N->dump(&DAG);
cerr << "\n"); cerr << "\n");
SDOperand Res(0, 0); SDOperand Res(0, 0);
@ -327,13 +326,13 @@ bool DAGTypeLegalizer::PromoteFloatOperand(SDNode *N, unsigned OpNo) {
switch (N->getOpcode()) { switch (N->getOpcode()) {
default: default:
#ifndef NDEBUG #ifndef NDEBUG
cerr << "PromoteFloatOperand Op #" << OpNo << ": "; cerr << "SoftenFloatOperand Op #" << OpNo << ": ";
N->dump(&DAG); cerr << "\n"; N->dump(&DAG); cerr << "\n";
#endif #endif
assert(0 && "Do not know how to convert this operator's operand!"); assert(0 && "Do not know how to convert this operator's operand!");
abort(); abort();
case ISD::BIT_CONVERT: Res = PromoteFloatOp_BIT_CONVERT(N); break; case ISD::BIT_CONVERT: Res = SoftenFloatOp_BIT_CONVERT(N); break;
} }
} }
@ -357,9 +356,9 @@ bool DAGTypeLegalizer::PromoteFloatOperand(SDNode *N, unsigned OpNo) {
return false; return false;
} }
SDOperand DAGTypeLegalizer::PromoteFloatOp_BIT_CONVERT(SDNode *N) { SDOperand DAGTypeLegalizer::SoftenFloatOp_BIT_CONVERT(SDNode *N) {
return DAG.getNode(ISD::BIT_CONVERT, N->getValueType(0), return DAG.getNode(ISD::BIT_CONVERT, N->getValueType(0),
GetPromotedFloat(N->getOperand(0))); GetSoftenedFloat(N->getOperand(0)));
} }

View File

@ -232,9 +232,9 @@ SDOperand DAGTypeLegalizer::PromoteIntRes_BIT_CONVERT(SDNode *N) {
// The input promotes to the same size. Convert the promoted value. // The input promotes to the same size. Convert the promoted value.
return DAG.getNode(ISD::BIT_CONVERT, OutVT, GetPromotedInteger(InOp)); return DAG.getNode(ISD::BIT_CONVERT, OutVT, GetPromotedInteger(InOp));
break; break;
case PromoteFloat: case SoftenFloat:
// Promote the integer operand by hand. // Promote the integer operand by hand.
return DAG.getNode(ISD::ANY_EXTEND, OutVT, GetPromotedFloat(InOp)); return DAG.getNode(ISD::ANY_EXTEND, OutVT, GetSoftenedFloat(InOp));
case ExpandInteger: case ExpandInteger:
case ExpandFloat: case ExpandFloat:
break; break;
@ -963,9 +963,9 @@ void DAGTypeLegalizer::ExpandIntRes_BIT_CONVERT(SDNode *N,
case Legal: case Legal:
case PromoteInteger: case PromoteInteger:
break; break;
case PromoteFloat: case SoftenFloat:
// Convert the integer operand instead. // Convert the integer operand instead.
SplitInteger(GetPromotedFloat(InOp), Lo, Hi); SplitInteger(GetSoftenedFloat(InOp), Lo, Hi);
Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Lo); Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Lo);
Hi = DAG.getNode(ISD::BIT_CONVERT, NVT, Hi); Hi = DAG.getNode(ISD::BIT_CONVERT, NVT, Hi);
return; return;

View File

@ -80,8 +80,8 @@ void DAGTypeLegalizer::run() {
case ExpandInteger: case ExpandInteger:
ExpandIntegerResult(N, i); ExpandIntegerResult(N, i);
goto NodeDone; goto NodeDone;
case PromoteFloat: case SoftenFloat:
PromoteFloatResult(N, i); SoftenFloatResult(N, i);
goto NodeDone; goto NodeDone;
case ExpandFloat: case ExpandFloat:
ExpandFloatResult(N, i); ExpandFloatResult(N, i);
@ -113,8 +113,8 @@ void DAGTypeLegalizer::run() {
case ExpandInteger: case ExpandInteger:
NeedsRevisit = ExpandIntegerOperand(N, i); NeedsRevisit = ExpandIntegerOperand(N, i);
break; break;
case PromoteFloat: case SoftenFloat:
NeedsRevisit = PromoteFloatOperand(N, i); NeedsRevisit = SoftenFloatOperand(N, i);
break; break;
case ExpandFloat: case ExpandFloat:
NeedsRevisit = ExpandFloatOperand(N, i); NeedsRevisit = ExpandFloatOperand(N, i);
@ -393,8 +393,8 @@ void DAGTypeLegalizer::ExpungeNode(SDOperand N) {
I->second = Replacement; I->second = Replacement;
} }
for (DenseMap<SDOperand, SDOperand>::iterator I = PromotedFloats.begin(), for (DenseMap<SDOperand, SDOperand>::iterator I = SoftenedFloats.begin(),
E = PromotedFloats.end(); I != E; ++I) { E = SoftenedFloats.end(); I != E; ++I) {
assert(I->first != N); assert(I->first != N);
if (I->second == N) if (I->second == N)
I->second = Replacement; I->second = Replacement;
@ -446,11 +446,11 @@ void DAGTypeLegalizer::SetPromotedInteger(SDOperand Op, SDOperand Result) {
OpEntry = Result; OpEntry = Result;
} }
void DAGTypeLegalizer::SetPromotedFloat(SDOperand Op, SDOperand Result) { void DAGTypeLegalizer::SetSoftenedFloat(SDOperand Op, SDOperand Result) {
ExpungeNode(Result); ExpungeNode(Result);
AnalyzeNewNode(Result.Val); AnalyzeNewNode(Result.Val);
SDOperand &OpEntry = PromotedFloats[Op]; SDOperand &OpEntry = SoftenedFloats[Op];
assert(OpEntry.Val == 0 && "Node is already converted to integer!"); assert(OpEntry.Val == 0 && "Node is already converted to integer!");
OpEntry = Result; OpEntry = Result;
} }

View File

@ -62,7 +62,7 @@ private:
Legal, // The target natively supports this type. Legal, // The target natively supports this type.
PromoteInteger, // Replace this integer type with a larger one. PromoteInteger, // Replace this integer type with a larger one.
ExpandInteger, // Split this integer type into two of half the size. ExpandInteger, // Split this integer type into two of half the size.
PromoteFloat, // Convert this float type to a same size integer type. SoftenFloat, // Convert this float type to a same size integer type.
ExpandFloat, // Split this float type into two of half the size. ExpandFloat, // Split this float type into two of half the size.
Scalarize, // Replace this one-element vector type with its element type. Scalarize, // Replace this one-element vector type with its element type.
Split // This vector type should be split into smaller vectors. Split // This vector type should be split into smaller vectors.
@ -95,7 +95,7 @@ private:
return ExpandInteger; return ExpandInteger;
else if (VT.getSizeInBits() == else if (VT.getSizeInBits() ==
TLI.getTypeToTransformTo(VT).getSizeInBits()) TLI.getTypeToTransformTo(VT).getSizeInBits())
return PromoteFloat; return SoftenFloat;
else else
return ExpandFloat; return ExpandFloat;
} else if (VT.getVectorNumElements() == 1) { } else if (VT.getVectorNumElements() == 1) {
@ -119,9 +119,9 @@ private:
/// indicates which operands are the expanded version of the input. /// indicates which operands are the expanded version of the input.
DenseMap<SDOperand, std::pair<SDOperand, SDOperand> > ExpandedIntegers; DenseMap<SDOperand, std::pair<SDOperand, SDOperand> > ExpandedIntegers;
/// PromotedFloats - For floating point nodes converted to integers of /// SoftenedFloats - For floating point nodes converted to integers of
/// the same size, this map indicates the converted value to use. /// the same size, this map indicates the converted value to use.
DenseMap<SDOperand, SDOperand> PromotedFloats; DenseMap<SDOperand, SDOperand> SoftenedFloats;
/// ExpandedFloats - For float nodes that need to be expanded this map /// ExpandedFloats - For float nodes that need to be expanded this map
/// indicates which operands are the expanded version of the input. /// indicates which operands are the expanded version of the input.
@ -321,29 +321,29 @@ private:
// Float to Integer Conversion Support: LegalizeFloatTypes.cpp // Float to Integer Conversion Support: LegalizeFloatTypes.cpp
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
SDOperand GetPromotedFloat(SDOperand Op) { SDOperand GetSoftenedFloat(SDOperand Op) {
SDOperand &PromotedOp = PromotedFloats[Op]; SDOperand &SoftenedOp = SoftenedFloats[Op];
RemapNode(PromotedOp); RemapNode(SoftenedOp);
assert(PromotedOp.Val && "Operand wasn't converted to integer?"); assert(SoftenedOp.Val && "Operand wasn't converted to integer?");
return PromotedOp; return SoftenedOp;
} }
void SetPromotedFloat(SDOperand Op, SDOperand Result); void SetSoftenedFloat(SDOperand Op, SDOperand Result);
// Result Float to Integer Conversion. // Result Float to Integer Conversion.
void PromoteFloatResult(SDNode *N, unsigned OpNo); void SoftenFloatResult(SDNode *N, unsigned OpNo);
SDOperand PromoteFloatRes_BIT_CONVERT(SDNode *N); SDOperand SoftenFloatRes_BIT_CONVERT(SDNode *N);
SDOperand PromoteFloatRes_BUILD_PAIR(SDNode *N); SDOperand SoftenFloatRes_BUILD_PAIR(SDNode *N);
SDOperand PromoteFloatRes_ConstantFP(ConstantFPSDNode *N); SDOperand SoftenFloatRes_ConstantFP(ConstantFPSDNode *N);
SDOperand PromoteFloatRes_FADD(SDNode *N); SDOperand SoftenFloatRes_FADD(SDNode *N);
SDOperand PromoteFloatRes_FCOPYSIGN(SDNode *N); SDOperand SoftenFloatRes_FCOPYSIGN(SDNode *N);
SDOperand PromoteFloatRes_FMUL(SDNode *N); SDOperand SoftenFloatRes_FMUL(SDNode *N);
SDOperand PromoteFloatRes_FSUB(SDNode *N); SDOperand SoftenFloatRes_FSUB(SDNode *N);
SDOperand PromoteFloatRes_LOAD(SDNode *N); SDOperand SoftenFloatRes_LOAD(SDNode *N);
SDOperand PromoteFloatRes_XINT_TO_FP(SDNode *N); SDOperand SoftenFloatRes_XINT_TO_FP(SDNode *N);
// Operand Float to Integer Conversion. // Operand Float to Integer Conversion.
bool PromoteFloatOperand(SDNode *N, unsigned OpNo); bool SoftenFloatOperand(SDNode *N, unsigned OpNo);
SDOperand PromoteFloatOp_BIT_CONVERT(SDNode *N); SDOperand SoftenFloatOp_BIT_CONVERT(SDNode *N);
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// Float Expansion Support: LegalizeFloatTypes.cpp // Float Expansion Support: LegalizeFloatTypes.cpp

View File

@ -503,7 +503,7 @@ void DAGTypeLegalizer::SplitRes_BIT_CONVERT(SDNode *N,
assert(false && "Unknown type action!"); assert(false && "Unknown type action!");
case Legal: case Legal:
case PromoteInteger: case PromoteInteger:
case PromoteFloat: case SoftenFloat:
case Scalarize: case Scalarize:
break; break;
case ExpandInteger: case ExpandInteger: