1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

Switch to using Simplified ConstantFP::get API.

llvm-svn: 49977
This commit is contained in:
Chris Lattner 2008-04-20 00:41:09 +00:00
parent 0cda383725
commit f390d62b7f
9 changed files with 60 additions and 66 deletions

View File

@ -593,10 +593,9 @@ static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
}
if (Ty == Type::FloatTy)
return ConstantFP::get(Ty, APFloat((float)V));
return ConstantFP::get(APFloat((float)V));
if (Ty == Type::DoubleTy)
return ConstantFP::get(Ty, APFloat(V));
return ConstantFP::get(APFloat(V));
assert(0 && "Can only constant fold float/double");
}
@ -611,9 +610,9 @@ static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
}
if (Ty == Type::FloatTy)
return ConstantFP::get(Ty, APFloat((float)V));
return ConstantFP::get(APFloat((float)V));
if (Ty == Type::DoubleTy)
return ConstantFP::get(Ty, APFloat(V));
return ConstantFP::get(APFloat(V));
assert(0 && "Can only constant fold float/double");
}
@ -678,8 +677,7 @@ llvm::ConstantFoldCall(Function *F,
if (V >= -0.0)
return ConstantFoldFP(sqrt, V, Ty);
else // Undefined
return ConstantFP::get(Ty, Ty==Type::FloatTy ? APFloat(0.0f) :
APFloat(0.0));
return Constant::getNullValue(Ty);
}
break;
case 's':
@ -734,11 +732,11 @@ llvm::ConstantFoldCall(Function *F,
}
} else if (ConstantInt *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
if (!strcmp(Str, "llvm.powi.f32")) {
return ConstantFP::get(Ty, APFloat((float)std::pow((float)Op1V,
(int)Op2C->getZExtValue())));
return ConstantFP::get(APFloat((float)std::pow((float)Op1V,
(int)Op2C->getZExtValue())));
} else if (!strcmp(Str, "llvm.powi.f64")) {
return ConstantFP::get(Ty, APFloat((double)std::pow((double)Op1V,
(int)Op2C->getZExtValue())));
return ConstantFP::get(APFloat((double)std::pow((double)Op1V,
(int)Op2C->getZExtValue())));
}
}
}

View File

@ -494,8 +494,8 @@ SCEVHandle ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) {
if (Val == 0)
C = Constant::getNullValue(Ty);
else if (Ty->isFloatingPoint())
C = ConstantFP::get(Ty, APFloat(Ty==Type::FloatTy ? APFloat::IEEEsingle :
APFloat::IEEEdouble, Val));
C = ConstantFP::get(APFloat(Ty==Type::FloatTy ? APFloat::IEEEsingle :
APFloat::IEEEdouble, Val));
else
C = ConstantInt::get(Ty, Val);
return getUnknown(C);

View File

@ -408,12 +408,12 @@ static Value *getExistingVal(const Type *Ty, const ValID &D) {
GenerateError("FP constant invalid for type");
return 0;
}
// Lexer has no type info, so builds all float and double FP constants
// Lexer has no type info, so builds all float and double FP constants
// as double. Fix this here. Long double does not need this.
if (&D.ConstPoolFP->getSemantics() == &APFloat::IEEEdouble &&
Ty==Type::FloatTy)
D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
return ConstantFP::get(Ty, *D.ConstPoolFP);
return ConstantFP::get(*D.ConstPoolFP);
case ValID::ConstNullVal: // Is it a null value?
if (!isa<PointerType>(Ty)) {
@ -1867,7 +1867,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
// as double. Fix this here. Long double is done right.
if (&$2->getSemantics()==&APFloat::IEEEdouble && $1==Type::FloatTy)
$2->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
$$ = ConstantFP::get($1, *$2);
$$ = ConstantFP::get(*$2);
delete $2;
CHECK_FOR_ERROR
};

View File

@ -636,15 +636,15 @@ bool BitcodeReader::ParseConstants() {
if (Record.empty())
return Error("Invalid FLOAT record");
if (CurTy == Type::FloatTy)
V = ConstantFP::get(CurTy, APFloat(APInt(32, (uint32_t)Record[0])));
V = ConstantFP::get(APFloat(APInt(32, (uint32_t)Record[0])));
else if (CurTy == Type::DoubleTy)
V = ConstantFP::get(CurTy, APFloat(APInt(64, Record[0])));
V = ConstantFP::get(APFloat(APInt(64, Record[0])));
else if (CurTy == Type::X86_FP80Ty)
V = ConstantFP::get(CurTy, APFloat(APInt(80, 2, &Record[0])));
V = ConstantFP::get(APFloat(APInt(80, 2, &Record[0])));
else if (CurTy == Type::FP128Ty)
V = ConstantFP::get(CurTy, APFloat(APInt(128, 2, &Record[0]), true));
V = ConstantFP::get(APFloat(APInt(128, 2, &Record[0]), true));
else if (CurTy == Type::PPC_FP128Ty)
V = ConstantFP::get(CurTy, APFloat(APInt(128, 2, &Record[0])));
V = ConstantFP::get(APFloat(APInt(128, 2, &Record[0])));
else
V = UndefValue::get(CurTy);
break;

View File

@ -491,8 +491,7 @@ static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP,
// an FP extending load is the same cost as a normal load (such as on the x87
// fp stack or PPC FP unit).
MVT::ValueType VT = CFP->getValueType(0);
ConstantFP *LLVMC = ConstantFP::get(MVT::getTypeForValueType(VT),
CFP->getValueAPF());
ConstantFP *LLVMC = ConstantFP::get(CFP->getValueAPF());
if (!UseCP) {
if (VT!=MVT::f64 && VT!=MVT::f32)
assert(0 && "Invalid type expansion");
@ -4901,18 +4900,18 @@ SDOperand SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) {
// If all elements are constants, create a load from the constant pool.
if (isConstant) {
MVT::ValueType VT = Node->getValueType(0);
const Type *OpNTy =
MVT::getTypeForValueType(Node->getOperand(0).getValueType());
std::vector<Constant*> CV;
for (unsigned i = 0, e = NumElems; i != e; ++i) {
if (ConstantFPSDNode *V =
dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) {
CV.push_back(ConstantFP::get(OpNTy, V->getValueAPF()));
CV.push_back(ConstantFP::get(V->getValueAPF()));
} else if (ConstantSDNode *V =
dyn_cast<ConstantSDNode>(Node->getOperand(i))) {
CV.push_back(ConstantInt::get(OpNTy, V->getValue()));
dyn_cast<ConstantSDNode>(Node->getOperand(i))) {
CV.push_back(ConstantInt::get(V->getAPIntValue()));
} else {
assert(Node->getOperand(i).getOpcode() == ISD::UNDEF);
const Type *OpNTy =
MVT::getTypeForValueType(Node->getOperand(0).getValueType());
CV.push_back(UndefValue::get(OpNTy));
}
}

View File

@ -601,8 +601,7 @@ void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op,
} else if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
MI->addOperand(MachineOperand::CreateImm(C->getValue()));
} else if (ConstantFPSDNode *F = dyn_cast<ConstantFPSDNode>(Op)) {
const Type *FType = MVT::getTypeForValueType(Op.getValueType());
ConstantFP *CFP = ConstantFP::get(FType, F->getValueAPF());
ConstantFP *CFP = ConstantFP::get(F->getValueAPF());
MI->addOperand(MachineOperand::CreateFPImm(CFP));
} else if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Op)) {
MI->addOperand(MachineOperand::CreateReg(R->getReg(), false));

View File

@ -235,22 +235,26 @@ GenericValue JIT::runFunction(Function *F,
const GenericValue &AV = ArgValues[i];
switch (ArgTy->getTypeID()) {
default: assert(0 && "Unknown argument type for function call!");
case Type::IntegerTyID: C = ConstantInt::get(AV.IntVal); break;
case Type::FloatTyID: C = ConstantFP ::get(ArgTy, APFloat(AV.FloatVal));
break;
case Type::DoubleTyID: C = ConstantFP ::get(ArgTy, APFloat(AV.DoubleVal));
break;
case Type::IntegerTyID:
C = ConstantInt::get(AV.IntVal);
break;
case Type::FloatTyID:
C = ConstantFP::get(APFloat(AV.FloatVal));
break;
case Type::DoubleTyID:
C = ConstantFP::get(APFloat(AV.DoubleVal));
break;
case Type::PPC_FP128TyID:
case Type::X86_FP80TyID:
case Type::FP128TyID: C = ConstantFP ::get(ArgTy, APFloat(AV.IntVal));
break;
case Type::FP128TyID:
C = ConstantFP::get(APFloat(AV.IntVal));
break;
case Type::PointerTyID:
void *ArgPtr = GVTOP(AV);
if (sizeof(void*) == 4) {
if (sizeof(void*) == 4)
C = ConstantInt::get(Type::Int32Ty, (int)(intptr_t)ArgPtr);
} else {
else
C = ConstantInt::get(Type::Int64Ty, (intptr_t)ArgPtr);
}
C = ConstantExpr::getIntToPtr(C, ArgTy); // Cast the integer to pointer
break;
}

View File

@ -4368,14 +4368,13 @@ SDOperand X86TargetLowering::LowerFABS(SDOperand Op, SelectionDAG &DAG) {
MVT::ValueType EltVT = VT;
if (MVT::isVector(VT))
EltVT = MVT::getVectorElementType(VT);
const Type *OpNTy = MVT::getTypeForValueType(EltVT);
std::vector<Constant*> CV;
if (EltVT == MVT::f64) {
Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(64, ~(1ULL << 63))));
Constant *C = ConstantFP::get(APFloat(APInt(64, ~(1ULL << 63))));
CV.push_back(C);
CV.push_back(C);
} else {
Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(32, ~(1U << 31))));
Constant *C = ConstantFP::get(APFloat(APInt(32, ~(1U << 31))));
CV.push_back(C);
CV.push_back(C);
CV.push_back(C);
@ -4397,14 +4396,13 @@ SDOperand X86TargetLowering::LowerFNEG(SDOperand Op, SelectionDAG &DAG) {
EltVT = MVT::getVectorElementType(VT);
EltNum = MVT::getVectorNumElements(VT);
}
const Type *OpNTy = MVT::getTypeForValueType(EltVT);
std::vector<Constant*> CV;
if (EltVT == MVT::f64) {
Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(64, 1ULL << 63)));
Constant *C = ConstantFP::get(APFloat(APInt(64, 1ULL << 63)));
CV.push_back(C);
CV.push_back(C);
} else {
Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(32, 1U << 31)));
Constant *C = ConstantFP::get(APFloat(APInt(32, 1U << 31)));
CV.push_back(C);
CV.push_back(C);
CV.push_back(C);
@ -4430,19 +4428,16 @@ SDOperand X86TargetLowering::LowerFCOPYSIGN(SDOperand Op, SelectionDAG &DAG) {
SDOperand Op1 = Op.getOperand(1);
MVT::ValueType VT = Op.getValueType();
MVT::ValueType SrcVT = Op1.getValueType();
const Type *SrcTy = MVT::getTypeForValueType(SrcVT);
// If second operand is smaller, extend it first.
if (MVT::getSizeInBits(SrcVT) < MVT::getSizeInBits(VT)) {
Op1 = DAG.getNode(ISD::FP_EXTEND, VT, Op1);
SrcVT = VT;
SrcTy = MVT::getTypeForValueType(SrcVT);
}
// And if it is bigger, shrink it first.
if (MVT::getSizeInBits(SrcVT) > MVT::getSizeInBits(VT)) {
Op1 = DAG.getNode(ISD::FP_ROUND, VT, Op1, DAG.getIntPtrConstant(1));
SrcVT = VT;
SrcTy = MVT::getTypeForValueType(SrcVT);
}
// At this point the operands and the result should have the same
@ -4451,13 +4446,13 @@ SDOperand X86TargetLowering::LowerFCOPYSIGN(SDOperand Op, SelectionDAG &DAG) {
// First get the sign bit of second operand.
std::vector<Constant*> CV;
if (SrcVT == MVT::f64) {
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, 1ULL << 63))));
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, 0))));
CV.push_back(ConstantFP::get(APFloat(APInt(64, 1ULL << 63))));
CV.push_back(ConstantFP::get(APFloat(APInt(64, 0))));
} else {
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 1U << 31))));
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(APFloat(APInt(32, 1U << 31))));
CV.push_back(ConstantFP::get(APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(APFloat(APInt(32, 0))));
}
Constant *C = ConstantVector::get(CV);
SDOperand CPIdx = DAG.getConstantPool(C, getPointerTy(), 4);
@ -4480,13 +4475,13 @@ SDOperand X86TargetLowering::LowerFCOPYSIGN(SDOperand Op, SelectionDAG &DAG) {
// Clear first operand sign bit.
CV.clear();
if (VT == MVT::f64) {
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, ~(1ULL << 63)))));
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, 0))));
CV.push_back(ConstantFP::get(APFloat(APInt(64, ~(1ULL << 63)))));
CV.push_back(ConstantFP::get(APFloat(APInt(64, 0))));
} else {
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, ~(1U << 31)))));
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(APFloat(APInt(32, ~(1U << 31)))));
CV.push_back(ConstantFP::get(APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(APFloat(APInt(32, 0))));
CV.push_back(ConstantFP::get(APFloat(APInt(32, 0))));
}
C = ConstantVector::get(CV);
CPIdx = DAG.getConstantPool(C, getPointerTy(), 4);

View File

@ -7560,11 +7560,10 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) {
/// FitsInFPType - Return a Constant* for the specified FP constant if it fits
/// in the specified FP type without changing its value.
static Constant *FitsInFPType(ConstantFP *CFP, const Type *FPTy,
const fltSemantics &Sem) {
static Constant *FitsInFPType(ConstantFP *CFP, const fltSemantics &Sem) {
APFloat F = CFP->getValueAPF();
if (F.convert(Sem, APFloat::rmNearestTiesToEven) == APFloat::opOK)
return ConstantFP::get(FPTy, F);
return ConstantFP::get(F);
return 0;
}
@ -7582,11 +7581,11 @@ static Value *LookThroughFPExtensions(Value *V) {
if (CFP->getType() == Type::PPC_FP128Ty)
return V; // No constant folding of this.
// See if the value can be truncated to float and then reextended.
if (Value *V = FitsInFPType(CFP, Type::FloatTy, APFloat::IEEEsingle))
if (Value *V = FitsInFPType(CFP, APFloat::IEEEsingle))
return V;
if (CFP->getType() == Type::DoubleTy)
return V; // Won't shrink.
if (Value *V = FitsInFPType(CFP, Type::DoubleTy, APFloat::IEEEdouble))
if (Value *V = FitsInFPType(CFP, APFloat::IEEEdouble))
return V;
// Don't try to shrink to various long double types.
}