[llvm-commits] [llvm] r77247 - in /llvm/trunk: docs/tutorial/ examples/Kaleidoscope/ include/llvm/ include/llvm/Support/ lib/Analysis/ lib/AsmParser/ lib/Bitcode/Reader/ lib/CodeGen/SelectionDAG/ lib/ExecutionEngine/JIT/ lib/Target/X86/ lib/Transforms/Scalar/ lib/VMCore/
Owen Anderson
resistor at mac.com
Mon Jul 27 13:59:44 PDT 2009
Author: resistor
Date: Mon Jul 27 15:59:43 2009
New Revision: 77247
URL: http://llvm.org/viewvc/llvm-project?rev=77247&view=rev
Log:
Move ConstantFP construction back to the 2.5-ish API.
Modified:
llvm/trunk/docs/tutorial/LangImpl3.html
llvm/trunk/docs/tutorial/LangImpl4.html
llvm/trunk/docs/tutorial/LangImpl5.html
llvm/trunk/docs/tutorial/LangImpl6.html
llvm/trunk/docs/tutorial/LangImpl7.html
llvm/trunk/examples/Kaleidoscope/toy.cpp
llvm/trunk/include/llvm/Constants.h
llvm/trunk/include/llvm/LLVMContext.h
llvm/trunk/include/llvm/Support/PatternMatch.h
llvm/trunk/lib/Analysis/ConstantFolding.cpp
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
llvm/trunk/lib/VMCore/ConstantFold.cpp
llvm/trunk/lib/VMCore/Constants.cpp
llvm/trunk/lib/VMCore/Core.cpp
llvm/trunk/lib/VMCore/Instructions.cpp
llvm/trunk/lib/VMCore/LLVMContext.cpp
llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
llvm/trunk/lib/VMCore/LLVMContextImpl.h
Modified: llvm/trunk/docs/tutorial/LangImpl3.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/LangImpl3.html?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/docs/tutorial/LangImpl3.html (original)
+++ llvm/trunk/docs/tutorial/LangImpl3.html Mon Jul 27 15:59:43 2009
@@ -159,7 +159,7 @@
<div class="doc_code">
<pre>
Value *NumberExprAST::Codegen() {
- return getGlobalContext().getConstantFP(APFloat(Val));
+ return ConstantFP::get(getGlobalContext(), APFloat(Val));
}
</pre>
</div>
@@ -1034,7 +1034,7 @@
Value *ErrorV(const char *Str) { Error(Str); return 0; }
Value *NumberExprAST::Codegen() {
- return getGlobalContext().getConstantFP(APFloat(Val));
+ return ConstantFP::get(getGlobalContext(), APFloat(Val));
}
Value *VariableExprAST::Codegen() {
Modified: llvm/trunk/docs/tutorial/LangImpl4.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/LangImpl4.html?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/docs/tutorial/LangImpl4.html (original)
+++ llvm/trunk/docs/tutorial/LangImpl4.html Mon Jul 27 15:59:43 2009
@@ -869,7 +869,7 @@
Value *ErrorV(const char *Str) { Error(Str); return 0; }
Value *NumberExprAST::Codegen() {
- return getGlobalContext().getConstantFP(APFloat(Val));
+ return ConstantFP::get(getGlobalContext(), APFloat(Val));
}
Value *VariableExprAST::Codegen() {
Modified: llvm/trunk/docs/tutorial/LangImpl5.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/LangImpl5.html?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/docs/tutorial/LangImpl5.html (original)
+++ llvm/trunk/docs/tutorial/LangImpl5.html Mon Jul 27 15:59:43 2009
@@ -364,7 +364,7 @@
// Convert condition to a bool by comparing equal to 0.0.
CondV = Builder.CreateFCmpONE(CondV,
- getGlobalContext().getConstantFP(APFloat(0.0)),
+ ConstantFP::get(getGlobalContext(), APFloat(0.0)),
"ifcond");
</pre>
</div>
@@ -796,7 +796,7 @@
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = getGlobalContext().getConstantFP(APFloat(1.0));
+ StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
}
Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar");
@@ -815,7 +815,7 @@
// Convert condition to a bool by comparing equal to 0.0.
EndCond = Builder.CreateFCmpONE(EndCond,
- getGlobalContext().getConstantFP(APFloat(0.0)),
+ ConstantFP::get(getGlobalContext(), APFloat(0.0)),
"loopcond");
</pre>
</div>
@@ -1360,7 +1360,7 @@
Value *ErrorV(const char *Str) { Error(Str); return 0; }
Value *NumberExprAST::Codegen() {
- return getGlobalContext().getConstantFP(APFloat(Val));
+ return ConstantFP::get(getGlobalContext(), APFloat(Val));
}
Value *VariableExprAST::Codegen() {
@@ -1411,7 +1411,7 @@
// Convert condition to a bool by comparing equal to 0.0.
CondV = Builder.CreateFCmpONE(CondV,
- getGlobalContext().getConstantFP(APFloat(0.0)),
+ ConstantFP::get(getGlobalContext(), APFloat(0.0)),
"ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
@@ -1510,7 +1510,7 @@
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = getGlobalContext().getConstantFP(APFloat(1.0));
+ StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
}
Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar");
@@ -1521,7 +1521,7 @@
// Convert condition to a bool by comparing equal to 0.0.
EndCond = Builder.CreateFCmpONE(EndCond,
- getGlobalContext().getConstantFP(APFloat(0.0)),
+ ConstantFP::get(getGlobalContext(), APFloat(0.0)),
"loopcond");
// Create the "after loop" block and insert it.
Modified: llvm/trunk/docs/tutorial/LangImpl6.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/LangImpl6.html?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/docs/tutorial/LangImpl6.html (original)
+++ llvm/trunk/docs/tutorial/LangImpl6.html Mon Jul 27 15:59:43 2009
@@ -1365,7 +1365,7 @@
Value *ErrorV(const char *Str) { Error(Str); return 0; }
Value *NumberExprAST::Codegen() {
- return getGlobalContext().getConstantFP(APFloat(Val));
+ return ConstantFP::get(getGlobalContext(), APFloat(Val));
}
Value *VariableExprAST::Codegen() {
@@ -1436,7 +1436,7 @@
// Convert condition to a bool by comparing equal to 0.0.
CondV = Builder.CreateFCmpONE(CondV,
- getGlobalContext().getConstantFP(APFloat(0.0)),
+ ConstantFP::get(getGlobalContext(), APFloat(0.0)),
"ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
@@ -1535,7 +1535,7 @@
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = getGlobalContext().getConstantFP(APFloat(1.0));
+ StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
}
Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar");
@@ -1546,7 +1546,7 @@
// Convert condition to a bool by comparing equal to 0.0.
EndCond = Builder.CreateFCmpONE(EndCond,
- getGlobalContext().getConstantFP(APFloat(0.0)),
+ ConstantFP::get(getGlobalContext(), APFloat(0.0)),
"loopcond");
// Create the "after loop" block and insert it.
Modified: llvm/trunk/docs/tutorial/LangImpl7.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/LangImpl7.html?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/docs/tutorial/LangImpl7.html (original)
+++ llvm/trunk/docs/tutorial/LangImpl7.html Mon Jul 27 15:59:43 2009
@@ -923,7 +923,7 @@
InitVal = Init->Codegen();
if (InitVal == 0) return 0;
} else { // If not specified, use 0.0.
- InitVal = getGlobalContext().getConstantFP(APFloat(0.0));
+ InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
@@ -1623,7 +1623,7 @@
Value *NumberExprAST::Codegen() {
- return getGlobalContext().getConstantFP(APFloat(Val));
+ return ConstantFP::get(getGlobalContext(), APFloat(Val));
}
Value *VariableExprAST::Codegen() {
@@ -1716,7 +1716,7 @@
// Convert condition to a bool by comparing equal to 0.0.
CondV = Builder.CreateFCmpONE(CondV,
- getGlobalContext().getConstantFP(APFloat(0.0)),
+ ConstantFP::get(getGlobalContext(), APFloat(0.0)),
"ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
@@ -1822,7 +1822,7 @@
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = getGlobalContext().getConstantFP(APFloat(1.0));
+ StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
}
// Compute the end condition.
@@ -1837,7 +1837,7 @@
// Convert condition to a bool by comparing equal to 0.0.
EndCond = Builder.CreateFCmpONE(EndCond,
- getGlobalContext().getConstantFP(APFloat(0.0)),
+ ConstantFP::get(getGlobalContext(), APFloat(0.0)),
"loopcond");
// Create the "after loop" block and insert it.
@@ -1881,7 +1881,7 @@
InitVal = Init->Codegen();
if (InitVal == 0) return 0;
} else { // If not specified, use 0.0.
- InitVal = getGlobalContext().getConstantFP(APFloat(0.0));
+ InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
Modified: llvm/trunk/examples/Kaleidoscope/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/toy.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/toy.cpp Mon Jul 27 15:59:43 2009
@@ -623,7 +623,7 @@
Value *NumberExprAST::Codegen() {
- return getGlobalContext().getConstantFP(APFloat(Val));
+ return ConstantFP::get(getGlobalContext(), APFloat(Val));
}
Value *VariableExprAST::Codegen() {
@@ -716,7 +716,7 @@
// Convert condition to a bool by comparing equal to 0.0.
CondV = Builder.CreateFCmpONE(CondV,
- getGlobalContext().getConstantFP(APFloat(0.0)),
+ ConstantFP::get(getGlobalContext(), APFloat(0.0)),
"ifcond");
Function *TheFunction = Builder.GetInsertBlock()->getParent();
@@ -821,7 +821,7 @@
if (StepVal == 0) return 0;
} else {
// If not specified, use 1.0.
- StepVal = getGlobalContext().getConstantFP(APFloat(1.0));
+ StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
}
// Compute the end condition.
@@ -836,7 +836,7 @@
// Convert condition to a bool by comparing equal to 0.0.
EndCond = Builder.CreateFCmpONE(EndCond,
- getGlobalContext().getConstantFP(APFloat(0.0)),
+ ConstantFP::get(getGlobalContext(), APFloat(0.0)),
"loopcond");
// Create the "after loop" block and insert it.
@@ -879,7 +879,7 @@
InitVal = Init->Codegen();
if (InitVal == 0) return 0;
} else { // If not specified, use 0.0.
- InitVal = getGlobalContext().getConstantFP(APFloat(0.0));
+ InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
}
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Mon Jul 27 15:59:43 2009
@@ -50,7 +50,6 @@
ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
ConstantInt(const IntegerType *Ty, const APInt& V);
APInt Val;
- friend class LLVMContextImpl;
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
@@ -238,6 +237,19 @@
return User::operator new(s, 0);
}
public:
+ /// Floating point negation must be implemented with f(x) = -0.0 - x. This
+ /// method returns the negative zero constant for floating point or vector
+ /// floating point types; for all other types, it returns the null value.
+ static Constant* getZeroValueForNegation(const Type* Ty);
+
+ /// get() - This returns a ConstantFP, or a vector containing a splat of a
+ /// ConstantFP, for the specified value in the specified type. This should
+ /// only be used for simple constant values like 2.0/1.0 etc, that are
+ /// known-valid both as host double and as the target format.
+ static Constant* get(const Type* Ty, double V);
+ static ConstantFP* get(LLVMContext &Context, const APFloat& V);
+ static ConstantFP* getNegativeZero(const Type* Ty);
+
/// isValueValidForType - return true if Ty is big enough to represent V.
static bool isValueValidForType(const Type *Ty, const APFloat& V);
inline const APFloat& getValueAPF() const { return Val; }
Modified: llvm/trunk/include/llvm/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LLVMContext.h?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/LLVMContext.h Mon Jul 27 15:59:43 2009
@@ -56,6 +56,7 @@
LLVMContextImpl* pImpl;
friend class ConstantInt;
+ friend class ConstantFP;
public:
LLVMContext();
~LLVMContext();
@@ -180,21 +181,6 @@
///
Constant* getConstantExprSizeOf(const Type* Ty);
- /// Floating point negation must be implemented with f(x) = -0.0 - x. This
- /// method returns the negative zero constant for floating point or vector
- /// floating point types; for all other types, it returns the null value.
- Constant* getZeroValueForNegation(const Type* Ty);
-
- // ConstantFP accessors
- ConstantFP* getConstantFP(const APFloat& V);
-
- /// get() - This returns a ConstantFP, or a vector containing a splat of a
- /// ConstantFP, for the specified value in the specified type. This should
- /// only be used for simple constant values like 2.0/1.0 etc, that are
- /// known-valid both as host double and as the target format.
- Constant* getConstantFP(const Type* Ty, double V);
- ConstantFP* getConstantFPNegativeZero(const Type* Ty);
-
// ConstantVector accessors
Constant* getConstantVector(const VectorType* T,
const std::vector<Constant*>& V);
Modified: llvm/trunk/include/llvm/Support/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PatternMatch.h?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/Support/PatternMatch.h Mon Jul 27 15:59:43 2009
@@ -506,7 +506,7 @@
}
private:
bool matchIfNeg(Value *LHS, Value *RHS, LLVMContext &Context) {
- return LHS == Context.getZeroValueForNegation(LHS->getType()) &&
+ return LHS == ConstantFP::getZeroValueForNegation(LHS->getType()) &&
L.match(RHS, Context);
}
};
@@ -535,7 +535,7 @@
}
private:
bool matchIfFNeg(Value *LHS, Value *RHS, LLVMContext &Context) {
- return LHS == Context.getZeroValueForNegation(LHS->getType()) &&
+ return LHS == ConstantFP::getZeroValueForNegation(LHS->getType()) &&
L.match(RHS, Context);
}
};
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Mon Jul 27 15:59:43 2009
@@ -655,9 +655,9 @@
}
if (Ty == Type::FloatTy)
- return Context.getConstantFP(APFloat((float)V));
+ return ConstantFP::get(Context, APFloat((float)V));
if (Ty == Type::DoubleTy)
- return Context.getConstantFP(APFloat(V));
+ return ConstantFP::get(Context, APFloat(V));
llvm_unreachable("Can only constant fold float/double");
return 0; // dummy return to suppress warning
}
@@ -674,9 +674,9 @@
}
if (Ty == Type::FloatTy)
- return Context.getConstantFP(APFloat((float)V));
+ return ConstantFP::get(Context, APFloat((float)V));
if (Ty == Type::DoubleTy)
- return Context.getConstantFP(APFloat(V));
+ return ConstantFP::get(Context, APFloat(V));
llvm_unreachable("Can only constant fold float/double");
return 0; // dummy return to suppress warning
}
@@ -796,10 +796,10 @@
}
} else if (ConstantInt *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
if (Name == "llvm.powi.f32") {
- return Context.getConstantFP(APFloat((float)std::pow((float)Op1V,
+ return ConstantFP::get(Context, APFloat((float)std::pow((float)Op1V,
(int)Op2C->getZExtValue())));
} else if (Name == "llvm.powi.f64") {
- return Context.getConstantFP(APFloat((double)std::pow((double)Op1V,
+ return ConstantFP::get(Context, APFloat((double)std::pow((double)Op1V,
(int)Op2C->getZExtValue())));
}
}
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Jul 27 15:59:43 2009
@@ -2143,7 +2143,7 @@
ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven,
&Ignored);
}
- V = Context.getConstantFP(ID.APFloatVal);
+ V = ConstantFP::get(Context, ID.APFloatVal);
if (V->getType() != Ty)
return Error(ID.Loc, "floating point constant does not have type '" +
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Jul 27 15:59:43 2009
@@ -896,19 +896,19 @@
if (Record.empty())
return Error("Invalid FLOAT record");
if (CurTy == Type::FloatTy)
- V = Context.getConstantFP(APFloat(APInt(32, (uint32_t)Record[0])));
+ V = ConstantFP::get(Context, APFloat(APInt(32, (uint32_t)Record[0])));
else if (CurTy == Type::DoubleTy)
- V = Context.getConstantFP(APFloat(APInt(64, Record[0])));
+ V = ConstantFP::get(Context, APFloat(APInt(64, Record[0])));
else if (CurTy == Type::X86_FP80Ty) {
// Bits are not stored the same way as a normal i80 APInt, compensate.
uint64_t Rearrange[2];
Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
Rearrange[1] = Record[0] >> 48;
- V = Context.getConstantFP(APFloat(APInt(80, 2, Rearrange)));
+ V = ConstantFP::get(Context, APFloat(APInt(80, 2, Rearrange)));
} else if (CurTy == Type::FP128Ty)
- V = Context.getConstantFP(APFloat(APInt(128, 2, &Record[0]), true));
+ V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]), true));
else if (CurTy == Type::PPC_FP128Ty)
- V = Context.getConstantFP(APFloat(APInt(128, 2, &Record[0])));
+ V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0])));
else
V = Context.getUndef(CurTy);
break;
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Mon Jul 27 15:59:43 2009
@@ -916,7 +916,7 @@
SDValue SelectionDAG::getConstantFP(const APFloat& V, MVT VT, bool isTarget) {
- return getConstantFP(*Context->getConstantFP(V), VT, isTarget);
+ return getConstantFP(*ConstantFP::get(*getContext(), V), VT, isTarget);
}
SDValue SelectionDAG::getConstantFP(const ConstantFP& V, MVT VT, bool isTarget){
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Mon Jul 27 15:59:43 2009
@@ -2148,8 +2148,7 @@
const VectorType *DestTy = cast<VectorType>(I.getType());
const Type *ElTy = DestTy->getElementType();
unsigned VL = DestTy->getNumElements();
- std::vector<Constant*> NZ(VL,
- DAG.getContext()->getConstantFPNegativeZero(ElTy));
+ std::vector<Constant*> NZ(VL, ConstantFP::getNegativeZero(ElTy));
Constant *CNZ = DAG.getContext()->getConstantVector(&NZ[0], NZ.size());
if (CV == CNZ) {
SDValue Op2 = getValue(I.getOperand(1));
@@ -2160,8 +2159,7 @@
}
}
if (ConstantFP *CFP = dyn_cast<ConstantFP>(I.getOperand(0)))
- if (CFP->isExactlyValue(
- DAG.getContext()->getConstantFPNegativeZero(Ty)->getValueAPF())) {
+ if (CFP->isExactlyValue(ConstantFP::getNegativeZero(Ty)->getValueAPF())) {
SDValue Op2 = getValue(I.getOperand(1));
setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(),
Op2.getValueType(), Op2));
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Mon Jul 27 15:59:43 2009
@@ -490,15 +490,15 @@
C = ConstantInt::get(F->getContext(), AV.IntVal);
break;
case Type::FloatTyID:
- C = Context.getConstantFP(APFloat(AV.FloatVal));
+ C = ConstantFP::get(F->getContext(), APFloat(AV.FloatVal));
break;
case Type::DoubleTyID:
- C = Context.getConstantFP(APFloat(AV.DoubleVal));
+ C = ConstantFP::get(F->getContext(), APFloat(AV.DoubleVal));
break;
case Type::PPC_FP128TyID:
case Type::X86_FP80TyID:
case Type::FP128TyID:
- C = Context.getConstantFP(APFloat(AV.IntVal));
+ C = ConstantFP::get(F->getContext(), APFloat(AV.IntVal));
break;
case Type::PointerTyID:
void *ArgPtr = GVTOP(AV);
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Mon Jul 27 15:59:43 2009
@@ -4898,9 +4898,9 @@
std::vector<Constant*> CV1;
CV1.push_back(
- Context->getConstantFP(APFloat(APInt(64, 0x4530000000000000ULL))));
+ ConstantFP::get(*Context, APFloat(APInt(64, 0x4530000000000000ULL))));
CV1.push_back(
- Context->getConstantFP(APFloat(APInt(64, 0x4330000000000000ULL))));
+ ConstantFP::get(*Context, APFloat(APInt(64, 0x4330000000000000ULL))));
Constant *C1 = Context->getConstantVector(CV1);
SDValue CPIdx1 = DAG.getConstantPool(C1, getPointerTy(), 16);
@@ -5113,11 +5113,11 @@
EltVT = VT.getVectorElementType();
std::vector<Constant*> CV;
if (EltVT == MVT::f64) {
- Constant *C = Context->getConstantFP(APFloat(APInt(64, ~(1ULL << 63))));
+ Constant *C = ConstantFP::get(*Context, APFloat(APInt(64, ~(1ULL << 63))));
CV.push_back(C);
CV.push_back(C);
} else {
- Constant *C = Context->getConstantFP(APFloat(APInt(32, ~(1U << 31))));
+ Constant *C = ConstantFP::get(*Context, APFloat(APInt(32, ~(1U << 31))));
CV.push_back(C);
CV.push_back(C);
CV.push_back(C);
@@ -5143,11 +5143,11 @@
}
std::vector<Constant*> CV;
if (EltVT == MVT::f64) {
- Constant *C = Context->getConstantFP(APFloat(APInt(64, 1ULL << 63)));
+ Constant *C = ConstantFP::get(*Context, APFloat(APInt(64, 1ULL << 63)));
CV.push_back(C);
CV.push_back(C);
} else {
- Constant *C = Context->getConstantFP(APFloat(APInt(32, 1U << 31)));
+ Constant *C = ConstantFP::get(*Context, APFloat(APInt(32, 1U << 31)));
CV.push_back(C);
CV.push_back(C);
CV.push_back(C);
@@ -5194,13 +5194,13 @@
// First get the sign bit of second operand.
std::vector<Constant*> CV;
if (SrcVT == MVT::f64) {
- CV.push_back(Context->getConstantFP(APFloat(APInt(64, 1ULL << 63))));
- CV.push_back(Context->getConstantFP(APFloat(APInt(64, 0))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, 1ULL << 63))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, 0))));
} else {
- CV.push_back(Context->getConstantFP(APFloat(APInt(32, 1U << 31))));
- CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
- CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
- CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 1U << 31))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
}
Constant *C = Context->getConstantVector(CV);
SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
@@ -5223,13 +5223,13 @@
// Clear first operand sign bit.
CV.clear();
if (VT == MVT::f64) {
- CV.push_back(Context->getConstantFP(APFloat(APInt(64, ~(1ULL << 63)))));
- CV.push_back(Context->getConstantFP(APFloat(APInt(64, 0))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, ~(1ULL << 63)))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, 0))));
} else {
- CV.push_back(Context->getConstantFP(APFloat(APInt(32, ~(1U << 31)))));
- CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
- CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
- CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, ~(1U << 31)))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
+ CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
}
C = Context->getConstantVector(CV);
CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Jul 27 15:59:43 2009
@@ -2354,7 +2354,7 @@
if (Constant *RHSC = dyn_cast<Constant>(RHS)) {
// X + 0 --> X
if (ConstantFP *CFP = dyn_cast<ConstantFP>(RHSC)) {
- if (CFP->isExactlyValue(Context->getConstantFPNegativeZero
+ if (CFP->isExactlyValue(ConstantFP::getNegativeZero
(I.getType())->getValueAPF()))
return ReplaceInstUsesWith(I, LHS);
}
@@ -8779,7 +8779,7 @@
APFloat F = CFP->getValueAPF();
(void)F.convert(Sem, APFloat::rmNearestTiesToEven, &losesInfo);
if (!losesInfo)
- return Context->getConstantFP(F);
+ return ConstantFP::get(*Context, F);
return 0;
}
Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon Jul 27 15:59:43 2009
@@ -2177,8 +2177,6 @@
if (isa<SCEVCouldNotCompute>(BackedgeTakenCount))
return;
- LLVMContext &Context = L->getHeader()->getContext();
-
for (unsigned Stride = 0, e = IU->StrideOrder.size(); Stride != e;
++Stride) {
std::map<const SCEV *, IVUsersOfOneStride *>::iterator SI =
@@ -2240,7 +2238,7 @@
ConstantInt *Init = dyn_cast<ConstantInt>(PH->getIncomingValue(Entry));
if (!Init) continue;
- Constant *NewInit = Context.getConstantFP(DestTy, Init->getZExtValue());
+ Constant *NewInit = ConstantFP::get(DestTy, Init->getZExtValue());
BinaryOperator *Incr =
dyn_cast<BinaryOperator>(PH->getIncomingValue(Latch));
@@ -2264,7 +2262,7 @@
PHINode *NewPH = PHINode::Create(DestTy, "IV.S.", PH);
/* create new increment. '++d' in above example. */
- Constant *CFP = Context.getConstantFP(DestTy, C->getZExtValue());
+ Constant *CFP = ConstantFP::get(DestTy, C->getZExtValue());
BinaryOperator *NewIncr =
BinaryOperator::Create(Incr->getOpcode() == Instruction::Add ?
Instruction::FAdd : Instruction::FSub,
Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Mon Jul 27 15:59:43 2009
@@ -1035,7 +1035,7 @@
if (Op2C == 0) return 0;
if (Op2C->getValueAPF().isZero()) // pow(x, 0.0) -> 1.0
- return Context->getConstantFP(CI->getType(), 1.0);
+ return ConstantFP::get(CI->getType(), 1.0);
if (Op2C->isExactlyValue(0.5)) {
// FIXME: This is not safe for -0.0 and -inf. This can only be done when
@@ -1055,7 +1055,7 @@
if (Op2C->isExactlyValue(2.0)) // pow(x, 2.0) -> x*x
return B.CreateFMul(Op1, Op1, "pow2");
if (Op2C->isExactlyValue(-1.0)) // pow(x, -1.0) -> 1.0/x
- return B.CreateFDiv(Context->getConstantFP(CI->getType(), 1.0),
+ return B.CreateFDiv(ConstantFP::get(CI->getType(), 1.0),
Op1, "powrecip");
return 0;
}
@@ -1094,7 +1094,7 @@
else
Name = "ldexpl";
- Constant *One = Context->getConstantFP(APFloat(1.0f));
+ Constant *One = ConstantFP::get(*Context, APFloat(1.0f));
if (Op->getType() != Type::FloatTy)
One = Context->getConstantExprFPExtend(One, Op->getType());
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Mon Jul 27 15:59:43 2009
@@ -161,7 +161,7 @@
return V;
if (DestTy->isFloatingPoint())
- return Context.getConstantFP(APFloat(CI->getValue(),
+ return ConstantFP::get(Context, APFloat(CI->getValue(),
DestTy != Type::PPC_FP128Ty));
// Otherwise, can't fold this (vector?)
@@ -245,7 +245,7 @@
DestTy == Type::FP128Ty ? APFloat::IEEEquad :
APFloat::Bogus,
APFloat::rmNearestTiesToEven, &ignored);
- return Context.getConstantFP(Val);
+ return ConstantFP::get(Context, Val);
}
return 0; // Can't fold.
case Instruction::FPToUI:
@@ -279,7 +279,7 @@
(void)apf.convertFromAPInt(api,
opc==Instruction::SIToFP,
APFloat::rmNearestTiesToEven);
- return Context.getConstantFP(apf);
+ return ConstantFP::get(Context, apf);
}
return 0;
case Instruction::ZExt:
@@ -795,19 +795,19 @@
break;
case Instruction::FAdd:
(void)C3V.add(C2V, APFloat::rmNearestTiesToEven);
- return Context.getConstantFP(C3V);
+ return ConstantFP::get(Context, C3V);
case Instruction::FSub:
(void)C3V.subtract(C2V, APFloat::rmNearestTiesToEven);
- return Context.getConstantFP(C3V);
+ return ConstantFP::get(Context, C3V);
case Instruction::FMul:
(void)C3V.multiply(C2V, APFloat::rmNearestTiesToEven);
- return Context.getConstantFP(C3V);
+ return ConstantFP::get(Context, C3V);
case Instruction::FDiv:
(void)C3V.divide(C2V, APFloat::rmNearestTiesToEven);
- return Context.getConstantFP(C3V);
+ return ConstantFP::get(Context, C3V);
case Instruction::FRem:
(void)C3V.mod(C2V, APFloat::rmNearestTiesToEven);
- return Context.getConstantFP(C3V);
+ return ConstantFP::get(Context, C3V);
}
}
} else if (const VectorType *VTy = dyn_cast<VectorType>(C1->getType())) {
Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Mon Jul 27 15:59:43 2009
@@ -258,6 +258,87 @@
}
#endif
+/// get() - This returns a constant fp for the specified value in the
+/// specified type. This should only be used for simple constant values like
+/// 2.0/1.0 etc, that are known-valid both as double and as the target format.
+Constant* ConstantFP::get(const Type* Ty, double V) {
+ LLVMContext &Context = Ty->getContext();
+
+ APFloat FV(V);
+ bool ignored;
+ FV.convert(*TypeToFloatSemantics(Ty->getScalarType()),
+ APFloat::rmNearestTiesToEven, &ignored);
+ Constant *C = get(Context, FV);
+
+ // For vectors, broadcast the value.
+ if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
+ return Context.getConstantVector(
+ std::vector<Constant *>(VTy->getNumElements(), C));
+
+ return C;
+}
+
+ConstantFP* ConstantFP::getNegativeZero(const Type* Ty) {
+ LLVMContext &Context = Ty->getContext();
+ APFloat apf = cast <ConstantFP>(Context.getNullValue(Ty))->getValueAPF();
+ apf.changeSign();
+ return get(Context, apf);
+}
+
+
+Constant* ConstantFP::getZeroValueForNegation(const Type* Ty) {
+ LLVMContext &Context = Ty->getContext();
+ if (const VectorType *PTy = dyn_cast<VectorType>(Ty))
+ if (PTy->getElementType()->isFloatingPoint()) {
+ std::vector<Constant*> zeros(PTy->getNumElements(),
+ getNegativeZero(PTy->getElementType()));
+ return Context.getConstantVector(PTy, zeros);
+ }
+
+ if (Ty->isFloatingPoint())
+ return getNegativeZero(Ty);
+
+ return Context.getNullValue(Ty);
+}
+
+
+// ConstantFP accessors.
+ConstantFP* ConstantFP::get(LLVMContext &Context, const APFloat& V) {
+ DenseMapAPFloatKeyInfo::KeyTy Key(V);
+
+ LLVMContextImpl* pImpl = Context.pImpl;
+
+ pImpl->ConstantsLock.reader_acquire();
+ ConstantFP *&Slot = pImpl->FPConstants[Key];
+ pImpl->ConstantsLock.reader_release();
+
+ if (!Slot) {
+ sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
+ ConstantFP *&NewSlot = pImpl->FPConstants[Key];
+ if (!NewSlot) {
+ const Type *Ty;
+ if (&V.getSemantics() == &APFloat::IEEEsingle)
+ Ty = Type::FloatTy;
+ else if (&V.getSemantics() == &APFloat::IEEEdouble)
+ Ty = Type::DoubleTy;
+ else if (&V.getSemantics() == &APFloat::x87DoubleExtended)
+ Ty = Type::X86_FP80Ty;
+ else if (&V.getSemantics() == &APFloat::IEEEquad)
+ Ty = Type::FP128Ty;
+ else {
+ assert(&V.getSemantics() == &APFloat::PPCDoubleDouble &&
+ "Unknown FP format");
+ Ty = Type::PPC_FP128Ty;
+ }
+ NewSlot = new ConstantFP(Ty, V);
+ }
+
+ return NewSlot;
+ }
+
+ return Slot;
+}
+
ConstantFP::ConstantFP(const Type *Ty, const APFloat& V)
: Constant(Ty, ConstantFPVal, 0, 0), Val(V) {
assert(&V.getSemantics() == TypeToFloatSemantics(Ty) &&
Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Mon Jul 27 15:59:43 2009
@@ -388,11 +388,11 @@
bool ignored;
APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven,
&ignored);
- return wrap(getGlobalContext().getConstantFP(APN));
+ return wrap(ConstantFP::get(getGlobalContext(), APN));
}
LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
- return wrap(getGlobalContext().getConstantFP(
+ return wrap(ConstantFP::get(getGlobalContext(),
APFloat(SemanticsForType(unwrap(RealTy)), Text)));
}
Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Mon Jul 27 15:59:43 2009
@@ -1577,7 +1577,7 @@
BinaryOperator *BinaryOperator::CreateNeg(LLVMContext &Context,
Value *Op, const Twine &Name,
Instruction *InsertBefore) {
- Value *zero = Context.getZeroValueForNegation(Op->getType());
+ Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
return new BinaryOperator(Instruction::Sub,
zero, Op,
Op->getType(), Name, InsertBefore);
@@ -1586,7 +1586,7 @@
BinaryOperator *BinaryOperator::CreateNeg(LLVMContext &Context,
Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd) {
- Value *zero = Context.getZeroValueForNegation(Op->getType());
+ Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
return new BinaryOperator(Instruction::Sub,
zero, Op,
Op->getType(), Name, InsertAtEnd);
@@ -1595,7 +1595,7 @@
BinaryOperator *BinaryOperator::CreateFNeg(LLVMContext &Context,
Value *Op, const Twine &Name,
Instruction *InsertBefore) {
- Value *zero = Context.getZeroValueForNegation(Op->getType());
+ Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
return new BinaryOperator(Instruction::FSub,
zero, Op,
Op->getType(), Name, InsertBefore);
@@ -1604,7 +1604,7 @@
BinaryOperator *BinaryOperator::CreateFNeg(LLVMContext &Context,
Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd) {
- Value *zero = Context.getZeroValueForNegation(Op->getType());
+ Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
return new BinaryOperator(Instruction::FSub,
zero, Op,
Op->getType(), Name, InsertAtEnd);
Modified: llvm/trunk/lib/VMCore/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContext.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContext.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContext.cpp Mon Jul 27 15:59:43 2009
@@ -41,15 +41,16 @@
case Type::IntegerTyID:
return ConstantInt::get(Ty, 0);
case Type::FloatTyID:
- return getConstantFP(APFloat(APInt(32, 0)));
+ return ConstantFP::get(Ty->getContext(), APFloat(APInt(32, 0)));
case Type::DoubleTyID:
- return getConstantFP(APFloat(APInt(64, 0)));
+ return ConstantFP::get(Ty->getContext(), APFloat(APInt(64, 0)));
case Type::X86_FP80TyID:
- return getConstantFP(APFloat(APInt(80, 2, zero)));
+ return ConstantFP::get(Ty->getContext(), APFloat(APInt(80, 2, zero)));
case Type::FP128TyID:
- return getConstantFP(APFloat(APInt(128, 2, zero), true));
+ return ConstantFP::get(Ty->getContext(),
+ APFloat(APInt(128, 2, zero), true));
case Type::PPC_FP128TyID:
- return getConstantFP(APFloat(APInt(128, 2, zero)));
+ return ConstantFP::get(Ty->getContext(), APFloat(APInt(128, 2, zero)));
case Type::PointerTyID:
return getConstantPointerNull(cast<PointerType>(Ty));
case Type::StructTyID:
@@ -276,7 +277,7 @@
assert(C->getType()->isIntOrIntVector() &&
"Cannot NEG a nonintegral value!");
return getConstantExpr(Instruction::Sub,
- getZeroValueForNegation(C->getType()),
+ ConstantFP::getZeroValueForNegation(C->getType()),
C);
}
@@ -284,7 +285,7 @@
assert(C->getType()->isFPOrFPVector() &&
"Cannot FNEG a non-floating-point value!");
return getConstantExpr(Instruction::FSub,
- getZeroValueForNegation(C->getType()),
+ ConstantFP::getZeroValueForNegation(C->getType()),
C);
}
@@ -424,65 +425,6 @@
return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
}
-Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
- if (const VectorType *PTy = dyn_cast<VectorType>(Ty))
- if (PTy->getElementType()->isFloatingPoint()) {
- std::vector<Constant*> zeros(PTy->getNumElements(),
- getConstantFPNegativeZero(PTy->getElementType()));
- return getConstantVector(PTy, zeros);
- }
-
- if (Ty->isFloatingPoint())
- return getConstantFPNegativeZero(Ty);
-
- return getNullValue(Ty);
-}
-
-
-// ConstantFP accessors.
-ConstantFP* LLVMContext::getConstantFP(const APFloat& V) {
- return pImpl->getConstantFP(V);
-}
-
-static const fltSemantics *TypeToFloatSemantics(const Type *Ty) {
- if (Ty == Type::FloatTy)
- return &APFloat::IEEEsingle;
- if (Ty == Type::DoubleTy)
- return &APFloat::IEEEdouble;
- if (Ty == Type::X86_FP80Ty)
- return &APFloat::x87DoubleExtended;
- else if (Ty == Type::FP128Ty)
- return &APFloat::IEEEquad;
-
- assert(Ty == Type::PPC_FP128Ty && "Unknown FP format");
- return &APFloat::PPCDoubleDouble;
-}
-
-/// get() - This returns a constant fp for the specified value in the
-/// specified type. This should only be used for simple constant values like
-/// 2.0/1.0 etc, that are known-valid both as double and as the target format.
-Constant* LLVMContext::getConstantFP(const Type* Ty, double V) {
- APFloat FV(V);
- bool ignored;
- FV.convert(*TypeToFloatSemantics(Ty->getScalarType()),
- APFloat::rmNearestTiesToEven, &ignored);
- Constant *C = getConstantFP(FV);
-
- // For vectors, broadcast the value.
- if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
- return
- getConstantVector(std::vector<Constant *>(VTy->getNumElements(), C));
-
- return C;
-}
-
-ConstantFP* LLVMContext::getConstantFPNegativeZero(const Type* Ty) {
- APFloat apf = cast <ConstantFP>(getNullValue(Ty))->getValueAPF();
- apf.changeSign();
- return getConstantFP(apf);
-}
-
-
// ConstantVector accessors.
Constant* LLVMContext::getConstantVector(const VectorType* T,
const std::vector<Constant*>& V) {
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.cpp?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.cpp Mon Jul 27 15:59:43 2009
@@ -49,41 +49,6 @@
LLVMContextImpl::LLVMContextImpl(LLVMContext &C) :
Context(C), TheTrueVal(0), TheFalseVal(0) { }
-
-ConstantFP *LLVMContextImpl::getConstantFP(const APFloat &V) {
- DenseMapAPFloatKeyInfo::KeyTy Key(V);
-
- ConstantsLock.reader_acquire();
- ConstantFP *&Slot = FPConstants[Key];
- ConstantsLock.reader_release();
-
- if (!Slot) {
- sys::SmartScopedWriter<true> Writer(ConstantsLock);
- ConstantFP *&NewSlot = FPConstants[Key];
- if (!NewSlot) {
- const Type *Ty;
- if (&V.getSemantics() == &APFloat::IEEEsingle)
- Ty = Type::FloatTy;
- else if (&V.getSemantics() == &APFloat::IEEEdouble)
- Ty = Type::DoubleTy;
- else if (&V.getSemantics() == &APFloat::x87DoubleExtended)
- Ty = Type::X86_FP80Ty;
- else if (&V.getSemantics() == &APFloat::IEEEquad)
- Ty = Type::FP128Ty;
- else {
- assert(&V.getSemantics() == &APFloat::PPCDoubleDouble &&
- "Unknown FP format");
- Ty = Type::PPC_FP128Ty;
- }
- NewSlot = new ConstantFP(Ty, V);
- }
-
- return NewSlot;
- }
-
- return Slot;
-}
-
MDString *LLVMContextImpl::getMDString(const char *StrBegin,
unsigned StrLength) {
sys::SmartScopedWriter<true> Writer(ConstantsLock);
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=77247&r1=77246&r2=77247&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Mon Jul 27 15:59:43 2009
@@ -457,11 +457,10 @@
LLVMContextImpl(const LLVMContextImpl&);
friend class ConstantInt;
+ friend class ConstantFP;
public:
LLVMContextImpl(LLVMContext &C);
- ConstantFP *getConstantFP(const APFloat &V);
-
MDString *getMDString(const char *StrBegin, unsigned StrLength);
MDNode *getMDNode(Value*const* Vals, unsigned NumVals);
More information about the llvm-commits
mailing list