mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-04-12 12:33:17 +00:00
Move ConstantFP construction back to the 2.5-ish API.
llvm-svn: 77247
This commit is contained in:
parent
982c2fe893
commit
256c2c250e
@ -159,7 +159,7 @@ we'll do numeric literals:</p>
|
|||||||
<div class="doc_code">
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return getGlobalContext().getConstantFP(APFloat(Val));
|
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
@ -1034,7 +1034,7 @@ static std::map<std::string, Value*> NamedValues;
|
|||||||
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return getGlobalContext().getConstantFP(APFloat(Val));
|
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
|
@ -869,7 +869,7 @@ static FunctionPassManager *TheFPM;
|
|||||||
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return getGlobalContext().getConstantFP(APFloat(Val));
|
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
|
@ -364,7 +364,7 @@ Value *IfExprAST::Codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(CondV,
|
||||||
getGlobalContext().getConstantFP(APFloat(0.0)),
|
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
||||||
"ifcond");
|
"ifcond");
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
@ -796,7 +796,7 @@ references to it will naturally find it in the symbol table.</p>
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// 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");
|
Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar");
|
||||||
@ -815,7 +815,7 @@ will be the value of the loop variable on the next iteration of the loop.</p>
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(EndCond,
|
||||||
getGlobalContext().getConstantFP(APFloat(0.0)),
|
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
||||||
"loopcond");
|
"loopcond");
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
@ -1360,7 +1360,7 @@ static FunctionPassManager *TheFPM;
|
|||||||
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return getGlobalContext().getConstantFP(APFloat(Val));
|
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
@ -1411,7 +1411,7 @@ Value *IfExprAST::Codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(CondV,
|
||||||
getGlobalContext().getConstantFP(APFloat(0.0)),
|
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
||||||
"ifcond");
|
"ifcond");
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
@ -1510,7 +1510,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// 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");
|
Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar");
|
||||||
@ -1521,7 +1521,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(EndCond,
|
||||||
getGlobalContext().getConstantFP(APFloat(0.0)),
|
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
||||||
"loopcond");
|
"loopcond");
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// Create the "after loop" block and insert it.
|
||||||
|
@ -1365,7 +1365,7 @@ static FunctionPassManager *TheFPM;
|
|||||||
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
Value *ErrorV(const char *Str) { Error(Str); return 0; }
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return getGlobalContext().getConstantFP(APFloat(Val));
|
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
@ -1436,7 +1436,7 @@ Value *IfExprAST::Codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(CondV,
|
||||||
getGlobalContext().getConstantFP(APFloat(0.0)),
|
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
||||||
"ifcond");
|
"ifcond");
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
@ -1535,7 +1535,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// 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");
|
Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar");
|
||||||
@ -1546,7 +1546,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(EndCond,
|
||||||
getGlobalContext().getConstantFP(APFloat(0.0)),
|
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
||||||
"loopcond");
|
"loopcond");
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// Create the "after loop" block and insert it.
|
||||||
|
@ -923,7 +923,7 @@ that we replace in OldBindings.</p>
|
|||||||
InitVal = Init->Codegen();
|
InitVal = Init->Codegen();
|
||||||
if (InitVal == 0) return 0;
|
if (InitVal == 0) return 0;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
@ -1623,7 +1623,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
|
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return getGlobalContext().getConstantFP(APFloat(Val));
|
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
@ -1716,7 +1716,7 @@ Value *IfExprAST::Codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(CondV,
|
||||||
getGlobalContext().getConstantFP(APFloat(0.0)),
|
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
||||||
"ifcond");
|
"ifcond");
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
@ -1822,7 +1822,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = getGlobalContext().getConstantFP(APFloat(1.0));
|
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the end condition.
|
// Compute the end condition.
|
||||||
@ -1837,7 +1837,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(EndCond,
|
||||||
getGlobalContext().getConstantFP(APFloat(0.0)),
|
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
||||||
"loopcond");
|
"loopcond");
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// Create the "after loop" block and insert it.
|
||||||
@ -1881,7 +1881,7 @@ Value *VarExprAST::Codegen() {
|
|||||||
InitVal = Init->Codegen();
|
InitVal = Init->Codegen();
|
||||||
if (InitVal == 0) return 0;
|
if (InitVal == 0) return 0;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
|
@ -623,7 +623,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
|
|||||||
|
|
||||||
|
|
||||||
Value *NumberExprAST::Codegen() {
|
Value *NumberExprAST::Codegen() {
|
||||||
return getGlobalContext().getConstantFP(APFloat(Val));
|
return ConstantFP::get(getGlobalContext(), APFloat(Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *VariableExprAST::Codegen() {
|
Value *VariableExprAST::Codegen() {
|
||||||
@ -716,7 +716,7 @@ Value *IfExprAST::Codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
CondV = Builder.CreateFCmpONE(CondV,
|
CondV = Builder.CreateFCmpONE(CondV,
|
||||||
getGlobalContext().getConstantFP(APFloat(0.0)),
|
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
||||||
"ifcond");
|
"ifcond");
|
||||||
|
|
||||||
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
Function *TheFunction = Builder.GetInsertBlock()->getParent();
|
||||||
@ -821,7 +821,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
if (StepVal == 0) return 0;
|
if (StepVal == 0) return 0;
|
||||||
} else {
|
} else {
|
||||||
// If not specified, use 1.0.
|
// If not specified, use 1.0.
|
||||||
StepVal = getGlobalContext().getConstantFP(APFloat(1.0));
|
StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the end condition.
|
// Compute the end condition.
|
||||||
@ -836,7 +836,7 @@ Value *ForExprAST::Codegen() {
|
|||||||
|
|
||||||
// Convert condition to a bool by comparing equal to 0.0.
|
// Convert condition to a bool by comparing equal to 0.0.
|
||||||
EndCond = Builder.CreateFCmpONE(EndCond,
|
EndCond = Builder.CreateFCmpONE(EndCond,
|
||||||
getGlobalContext().getConstantFP(APFloat(0.0)),
|
ConstantFP::get(getGlobalContext(), APFloat(0.0)),
|
||||||
"loopcond");
|
"loopcond");
|
||||||
|
|
||||||
// Create the "after loop" block and insert it.
|
// Create the "after loop" block and insert it.
|
||||||
@ -879,7 +879,7 @@ Value *VarExprAST::Codegen() {
|
|||||||
InitVal = Init->Codegen();
|
InitVal = Init->Codegen();
|
||||||
if (InitVal == 0) return 0;
|
if (InitVal == 0) return 0;
|
||||||
} else { // If not specified, use 0.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);
|
AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName);
|
||||||
|
@ -50,7 +50,6 @@ class ConstantInt : public Constant {
|
|||||||
ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
|
ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
|
||||||
ConstantInt(const IntegerType *Ty, const APInt& V);
|
ConstantInt(const IntegerType *Ty, const APInt& V);
|
||||||
APInt Val;
|
APInt Val;
|
||||||
friend class LLVMContextImpl;
|
|
||||||
protected:
|
protected:
|
||||||
// allocate space for exactly zero operands
|
// allocate space for exactly zero operands
|
||||||
void *operator new(size_t s) {
|
void *operator new(size_t s) {
|
||||||
@ -238,6 +237,19 @@ protected:
|
|||||||
return User::operator new(s, 0);
|
return User::operator new(s, 0);
|
||||||
}
|
}
|
||||||
public:
|
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.
|
/// isValueValidForType - return true if Ty is big enough to represent V.
|
||||||
static bool isValueValidForType(const Type *Ty, const APFloat& V);
|
static bool isValueValidForType(const Type *Ty, const APFloat& V);
|
||||||
inline const APFloat& getValueAPF() const { return Val; }
|
inline const APFloat& getValueAPF() const { return Val; }
|
||||||
|
@ -56,6 +56,7 @@ class LLVMContext {
|
|||||||
LLVMContextImpl* pImpl;
|
LLVMContextImpl* pImpl;
|
||||||
|
|
||||||
friend class ConstantInt;
|
friend class ConstantInt;
|
||||||
|
friend class ConstantFP;
|
||||||
public:
|
public:
|
||||||
LLVMContext();
|
LLVMContext();
|
||||||
~LLVMContext();
|
~LLVMContext();
|
||||||
@ -180,21 +181,6 @@ public:
|
|||||||
///
|
///
|
||||||
Constant* getConstantExprSizeOf(const Type* Ty);
|
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
|
// ConstantVector accessors
|
||||||
Constant* getConstantVector(const VectorType* T,
|
Constant* getConstantVector(const VectorType* T,
|
||||||
const std::vector<Constant*>& V);
|
const std::vector<Constant*>& V);
|
||||||
|
@ -506,7 +506,7 @@ struct neg_match {
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
bool matchIfNeg(Value *LHS, Value *RHS, LLVMContext &Context) {
|
bool matchIfNeg(Value *LHS, Value *RHS, LLVMContext &Context) {
|
||||||
return LHS == Context.getZeroValueForNegation(LHS->getType()) &&
|
return LHS == ConstantFP::getZeroValueForNegation(LHS->getType()) &&
|
||||||
L.match(RHS, Context);
|
L.match(RHS, Context);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -535,7 +535,7 @@ struct fneg_match {
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
bool matchIfFNeg(Value *LHS, Value *RHS, LLVMContext &Context) {
|
bool matchIfFNeg(Value *LHS, Value *RHS, LLVMContext &Context) {
|
||||||
return LHS == Context.getZeroValueForNegation(LHS->getType()) &&
|
return LHS == ConstantFP::getZeroValueForNegation(LHS->getType()) &&
|
||||||
L.match(RHS, Context);
|
L.match(RHS, Context);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -655,9 +655,9 @@ static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Ty == Type::FloatTy)
|
if (Ty == Type::FloatTy)
|
||||||
return Context.getConstantFP(APFloat((float)V));
|
return ConstantFP::get(Context, APFloat((float)V));
|
||||||
if (Ty == Type::DoubleTy)
|
if (Ty == Type::DoubleTy)
|
||||||
return Context.getConstantFP(APFloat(V));
|
return ConstantFP::get(Context, APFloat(V));
|
||||||
llvm_unreachable("Can only constant fold float/double");
|
llvm_unreachable("Can only constant fold float/double");
|
||||||
return 0; // dummy return to suppress warning
|
return 0; // dummy return to suppress warning
|
||||||
}
|
}
|
||||||
@ -674,9 +674,9 @@ static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Ty == Type::FloatTy)
|
if (Ty == Type::FloatTy)
|
||||||
return Context.getConstantFP(APFloat((float)V));
|
return ConstantFP::get(Context, APFloat((float)V));
|
||||||
if (Ty == Type::DoubleTy)
|
if (Ty == Type::DoubleTy)
|
||||||
return Context.getConstantFP(APFloat(V));
|
return ConstantFP::get(Context, APFloat(V));
|
||||||
llvm_unreachable("Can only constant fold float/double");
|
llvm_unreachable("Can only constant fold float/double");
|
||||||
return 0; // dummy return to suppress warning
|
return 0; // dummy return to suppress warning
|
||||||
}
|
}
|
||||||
@ -796,10 +796,10 @@ llvm::ConstantFoldCall(Function *F,
|
|||||||
}
|
}
|
||||||
} else if (ConstantInt *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
|
} else if (ConstantInt *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
|
||||||
if (Name == "llvm.powi.f32") {
|
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())));
|
(int)Op2C->getZExtValue())));
|
||||||
} else if (Name == "llvm.powi.f64") {
|
} 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())));
|
(int)Op2C->getZExtValue())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2143,7 +2143,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
|
|||||||
ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven,
|
ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven,
|
||||||
&Ignored);
|
&Ignored);
|
||||||
}
|
}
|
||||||
V = Context.getConstantFP(ID.APFloatVal);
|
V = ConstantFP::get(Context, ID.APFloatVal);
|
||||||
|
|
||||||
if (V->getType() != Ty)
|
if (V->getType() != Ty)
|
||||||
return Error(ID.Loc, "floating point constant does not have type '" +
|
return Error(ID.Loc, "floating point constant does not have type '" +
|
||||||
|
@ -896,19 +896,19 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
if (Record.empty())
|
if (Record.empty())
|
||||||
return Error("Invalid FLOAT record");
|
return Error("Invalid FLOAT record");
|
||||||
if (CurTy == Type::FloatTy)
|
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)
|
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) {
|
else if (CurTy == Type::X86_FP80Ty) {
|
||||||
// Bits are not stored the same way as a normal i80 APInt, compensate.
|
// Bits are not stored the same way as a normal i80 APInt, compensate.
|
||||||
uint64_t Rearrange[2];
|
uint64_t Rearrange[2];
|
||||||
Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
|
Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
|
||||||
Rearrange[1] = Record[0] >> 48;
|
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)
|
} 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)
|
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
|
else
|
||||||
V = Context.getUndef(CurTy);
|
V = Context.getUndef(CurTy);
|
||||||
break;
|
break;
|
||||||
|
@ -916,7 +916,7 @@ SDValue SelectionDAG::getIntPtrConstant(uint64_t Val, bool isTarget) {
|
|||||||
|
|
||||||
|
|
||||||
SDValue SelectionDAG::getConstantFP(const APFloat& V, MVT VT, bool isTarget) {
|
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){
|
SDValue SelectionDAG::getConstantFP(const ConstantFP& V, MVT VT, bool isTarget){
|
||||||
|
@ -2148,8 +2148,7 @@ void SelectionDAGLowering::visitFSub(User &I) {
|
|||||||
const VectorType *DestTy = cast<VectorType>(I.getType());
|
const VectorType *DestTy = cast<VectorType>(I.getType());
|
||||||
const Type *ElTy = DestTy->getElementType();
|
const Type *ElTy = DestTy->getElementType();
|
||||||
unsigned VL = DestTy->getNumElements();
|
unsigned VL = DestTy->getNumElements();
|
||||||
std::vector<Constant*> NZ(VL,
|
std::vector<Constant*> NZ(VL, ConstantFP::getNegativeZero(ElTy));
|
||||||
DAG.getContext()->getConstantFPNegativeZero(ElTy));
|
|
||||||
Constant *CNZ = DAG.getContext()->getConstantVector(&NZ[0], NZ.size());
|
Constant *CNZ = DAG.getContext()->getConstantVector(&NZ[0], NZ.size());
|
||||||
if (CV == CNZ) {
|
if (CV == CNZ) {
|
||||||
SDValue Op2 = getValue(I.getOperand(1));
|
SDValue Op2 = getValue(I.getOperand(1));
|
||||||
@ -2160,8 +2159,7 @@ void SelectionDAGLowering::visitFSub(User &I) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ConstantFP *CFP = dyn_cast<ConstantFP>(I.getOperand(0)))
|
if (ConstantFP *CFP = dyn_cast<ConstantFP>(I.getOperand(0)))
|
||||||
if (CFP->isExactlyValue(
|
if (CFP->isExactlyValue(ConstantFP::getNegativeZero(Ty)->getValueAPF())) {
|
||||||
DAG.getContext()->getConstantFPNegativeZero(Ty)->getValueAPF())) {
|
|
||||||
SDValue Op2 = getValue(I.getOperand(1));
|
SDValue Op2 = getValue(I.getOperand(1));
|
||||||
setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(),
|
setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(),
|
||||||
Op2.getValueType(), Op2));
|
Op2.getValueType(), Op2));
|
||||||
|
@ -490,15 +490,15 @@ GenericValue JIT::runFunction(Function *F,
|
|||||||
C = ConstantInt::get(F->getContext(), AV.IntVal);
|
C = ConstantInt::get(F->getContext(), AV.IntVal);
|
||||||
break;
|
break;
|
||||||
case Type::FloatTyID:
|
case Type::FloatTyID:
|
||||||
C = Context.getConstantFP(APFloat(AV.FloatVal));
|
C = ConstantFP::get(F->getContext(), APFloat(AV.FloatVal));
|
||||||
break;
|
break;
|
||||||
case Type::DoubleTyID:
|
case Type::DoubleTyID:
|
||||||
C = Context.getConstantFP(APFloat(AV.DoubleVal));
|
C = ConstantFP::get(F->getContext(), APFloat(AV.DoubleVal));
|
||||||
break;
|
break;
|
||||||
case Type::PPC_FP128TyID:
|
case Type::PPC_FP128TyID:
|
||||||
case Type::X86_FP80TyID:
|
case Type::X86_FP80TyID:
|
||||||
case Type::FP128TyID:
|
case Type::FP128TyID:
|
||||||
C = Context.getConstantFP(APFloat(AV.IntVal));
|
C = ConstantFP::get(F->getContext(), APFloat(AV.IntVal));
|
||||||
break;
|
break;
|
||||||
case Type::PointerTyID:
|
case Type::PointerTyID:
|
||||||
void *ArgPtr = GVTOP(AV);
|
void *ArgPtr = GVTOP(AV);
|
||||||
|
@ -4898,9 +4898,9 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) {
|
|||||||
|
|
||||||
std::vector<Constant*> CV1;
|
std::vector<Constant*> CV1;
|
||||||
CV1.push_back(
|
CV1.push_back(
|
||||||
Context->getConstantFP(APFloat(APInt(64, 0x4530000000000000ULL))));
|
ConstantFP::get(*Context, APFloat(APInt(64, 0x4530000000000000ULL))));
|
||||||
CV1.push_back(
|
CV1.push_back(
|
||||||
Context->getConstantFP(APFloat(APInt(64, 0x4330000000000000ULL))));
|
ConstantFP::get(*Context, APFloat(APInt(64, 0x4330000000000000ULL))));
|
||||||
Constant *C1 = Context->getConstantVector(CV1);
|
Constant *C1 = Context->getConstantVector(CV1);
|
||||||
SDValue CPIdx1 = DAG.getConstantPool(C1, getPointerTy(), 16);
|
SDValue CPIdx1 = DAG.getConstantPool(C1, getPointerTy(), 16);
|
||||||
|
|
||||||
@ -5113,11 +5113,11 @@ SDValue X86TargetLowering::LowerFABS(SDValue Op, SelectionDAG &DAG) {
|
|||||||
EltVT = VT.getVectorElementType();
|
EltVT = VT.getVectorElementType();
|
||||||
std::vector<Constant*> CV;
|
std::vector<Constant*> CV;
|
||||||
if (EltVT == MVT::f64) {
|
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);
|
||||||
CV.push_back(C);
|
CV.push_back(C);
|
||||||
} else {
|
} 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);
|
CV.push_back(C);
|
||||||
CV.push_back(C);
|
CV.push_back(C);
|
||||||
@ -5143,11 +5143,11 @@ SDValue X86TargetLowering::LowerFNEG(SDValue Op, SelectionDAG &DAG) {
|
|||||||
}
|
}
|
||||||
std::vector<Constant*> CV;
|
std::vector<Constant*> CV;
|
||||||
if (EltVT == MVT::f64) {
|
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);
|
||||||
CV.push_back(C);
|
CV.push_back(C);
|
||||||
} else {
|
} 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);
|
CV.push_back(C);
|
||||||
CV.push_back(C);
|
CV.push_back(C);
|
||||||
@ -5194,13 +5194,13 @@ SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) {
|
|||||||
// First get the sign bit of second operand.
|
// First get the sign bit of second operand.
|
||||||
std::vector<Constant*> CV;
|
std::vector<Constant*> CV;
|
||||||
if (SrcVT == MVT::f64) {
|
if (SrcVT == MVT::f64) {
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(64, 1ULL << 63))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, 1ULL << 63))));
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(64, 0))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, 0))));
|
||||||
} else {
|
} else {
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(32, 1U << 31))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 1U << 31))));
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
|
||||||
}
|
}
|
||||||
Constant *C = Context->getConstantVector(CV);
|
Constant *C = Context->getConstantVector(CV);
|
||||||
SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
|
SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
|
||||||
@ -5223,13 +5223,13 @@ SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) {
|
|||||||
// Clear first operand sign bit.
|
// Clear first operand sign bit.
|
||||||
CV.clear();
|
CV.clear();
|
||||||
if (VT == MVT::f64) {
|
if (VT == MVT::f64) {
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(64, ~(1ULL << 63)))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, ~(1ULL << 63)))));
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(64, 0))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, 0))));
|
||||||
} else {
|
} else {
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(32, ~(1U << 31)))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, ~(1U << 31)))));
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
|
||||||
CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0))));
|
CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
|
||||||
}
|
}
|
||||||
C = Context->getConstantVector(CV);
|
C = Context->getConstantVector(CV);
|
||||||
CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
|
CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
|
||||||
|
@ -2354,7 +2354,7 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
|
|||||||
if (Constant *RHSC = dyn_cast<Constant>(RHS)) {
|
if (Constant *RHSC = dyn_cast<Constant>(RHS)) {
|
||||||
// X + 0 --> X
|
// X + 0 --> X
|
||||||
if (ConstantFP *CFP = dyn_cast<ConstantFP>(RHSC)) {
|
if (ConstantFP *CFP = dyn_cast<ConstantFP>(RHSC)) {
|
||||||
if (CFP->isExactlyValue(Context->getConstantFPNegativeZero
|
if (CFP->isExactlyValue(ConstantFP::getNegativeZero
|
||||||
(I.getType())->getValueAPF()))
|
(I.getType())->getValueAPF()))
|
||||||
return ReplaceInstUsesWith(I, LHS);
|
return ReplaceInstUsesWith(I, LHS);
|
||||||
}
|
}
|
||||||
@ -8779,7 +8779,7 @@ static Constant *FitsInFPType(ConstantFP *CFP, const fltSemantics &Sem,
|
|||||||
APFloat F = CFP->getValueAPF();
|
APFloat F = CFP->getValueAPF();
|
||||||
(void)F.convert(Sem, APFloat::rmNearestTiesToEven, &losesInfo);
|
(void)F.convert(Sem, APFloat::rmNearestTiesToEven, &losesInfo);
|
||||||
if (!losesInfo)
|
if (!losesInfo)
|
||||||
return Context->getConstantFP(F);
|
return ConstantFP::get(*Context, F);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2177,8 +2177,6 @@ void LoopStrengthReduce::OptimizeShadowIV(Loop *L) {
|
|||||||
if (isa<SCEVCouldNotCompute>(BackedgeTakenCount))
|
if (isa<SCEVCouldNotCompute>(BackedgeTakenCount))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LLVMContext &Context = L->getHeader()->getContext();
|
|
||||||
|
|
||||||
for (unsigned Stride = 0, e = IU->StrideOrder.size(); Stride != e;
|
for (unsigned Stride = 0, e = IU->StrideOrder.size(); Stride != e;
|
||||||
++Stride) {
|
++Stride) {
|
||||||
std::map<const SCEV *, IVUsersOfOneStride *>::iterator SI =
|
std::map<const SCEV *, IVUsersOfOneStride *>::iterator SI =
|
||||||
@ -2240,7 +2238,7 @@ void LoopStrengthReduce::OptimizeShadowIV(Loop *L) {
|
|||||||
|
|
||||||
ConstantInt *Init = dyn_cast<ConstantInt>(PH->getIncomingValue(Entry));
|
ConstantInt *Init = dyn_cast<ConstantInt>(PH->getIncomingValue(Entry));
|
||||||
if (!Init) continue;
|
if (!Init) continue;
|
||||||
Constant *NewInit = Context.getConstantFP(DestTy, Init->getZExtValue());
|
Constant *NewInit = ConstantFP::get(DestTy, Init->getZExtValue());
|
||||||
|
|
||||||
BinaryOperator *Incr =
|
BinaryOperator *Incr =
|
||||||
dyn_cast<BinaryOperator>(PH->getIncomingValue(Latch));
|
dyn_cast<BinaryOperator>(PH->getIncomingValue(Latch));
|
||||||
@ -2264,7 +2262,7 @@ void LoopStrengthReduce::OptimizeShadowIV(Loop *L) {
|
|||||||
PHINode *NewPH = PHINode::Create(DestTy, "IV.S.", PH);
|
PHINode *NewPH = PHINode::Create(DestTy, "IV.S.", PH);
|
||||||
|
|
||||||
/* create new increment. '++d' in above example. */
|
/* create new increment. '++d' in above example. */
|
||||||
Constant *CFP = Context.getConstantFP(DestTy, C->getZExtValue());
|
Constant *CFP = ConstantFP::get(DestTy, C->getZExtValue());
|
||||||
BinaryOperator *NewIncr =
|
BinaryOperator *NewIncr =
|
||||||
BinaryOperator::Create(Incr->getOpcode() == Instruction::Add ?
|
BinaryOperator::Create(Incr->getOpcode() == Instruction::Add ?
|
||||||
Instruction::FAdd : Instruction::FSub,
|
Instruction::FAdd : Instruction::FSub,
|
||||||
|
@ -1035,7 +1035,7 @@ struct VISIBILITY_HIDDEN PowOpt : public LibCallOptimization {
|
|||||||
if (Op2C == 0) return 0;
|
if (Op2C == 0) return 0;
|
||||||
|
|
||||||
if (Op2C->getValueAPF().isZero()) // pow(x, 0.0) -> 1.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)) {
|
if (Op2C->isExactlyValue(0.5)) {
|
||||||
// FIXME: This is not safe for -0.0 and -inf. This can only be done when
|
// FIXME: This is not safe for -0.0 and -inf. This can only be done when
|
||||||
@ -1055,7 +1055,7 @@ struct VISIBILITY_HIDDEN PowOpt : public LibCallOptimization {
|
|||||||
if (Op2C->isExactlyValue(2.0)) // pow(x, 2.0) -> x*x
|
if (Op2C->isExactlyValue(2.0)) // pow(x, 2.0) -> x*x
|
||||||
return B.CreateFMul(Op1, Op1, "pow2");
|
return B.CreateFMul(Op1, Op1, "pow2");
|
||||||
if (Op2C->isExactlyValue(-1.0)) // pow(x, -1.0) -> 1.0/x
|
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");
|
Op1, "powrecip");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1094,7 +1094,7 @@ struct VISIBILITY_HIDDEN Exp2Opt : public LibCallOptimization {
|
|||||||
else
|
else
|
||||||
Name = "ldexpl";
|
Name = "ldexpl";
|
||||||
|
|
||||||
Constant *One = Context->getConstantFP(APFloat(1.0f));
|
Constant *One = ConstantFP::get(*Context, APFloat(1.0f));
|
||||||
if (Op->getType() != Type::FloatTy)
|
if (Op->getType() != Type::FloatTy)
|
||||||
One = Context->getConstantExprFPExtend(One, Op->getType());
|
One = Context->getConstantExprFPExtend(One, Op->getType());
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ static Constant *FoldBitCast(LLVMContext &Context,
|
|||||||
return V;
|
return V;
|
||||||
|
|
||||||
if (DestTy->isFloatingPoint())
|
if (DestTy->isFloatingPoint())
|
||||||
return Context.getConstantFP(APFloat(CI->getValue(),
|
return ConstantFP::get(Context, APFloat(CI->getValue(),
|
||||||
DestTy != Type::PPC_FP128Ty));
|
DestTy != Type::PPC_FP128Ty));
|
||||||
|
|
||||||
// Otherwise, can't fold this (vector?)
|
// Otherwise, can't fold this (vector?)
|
||||||
@ -245,7 +245,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
|
|||||||
DestTy == Type::FP128Ty ? APFloat::IEEEquad :
|
DestTy == Type::FP128Ty ? APFloat::IEEEquad :
|
||||||
APFloat::Bogus,
|
APFloat::Bogus,
|
||||||
APFloat::rmNearestTiesToEven, &ignored);
|
APFloat::rmNearestTiesToEven, &ignored);
|
||||||
return Context.getConstantFP(Val);
|
return ConstantFP::get(Context, Val);
|
||||||
}
|
}
|
||||||
return 0; // Can't fold.
|
return 0; // Can't fold.
|
||||||
case Instruction::FPToUI:
|
case Instruction::FPToUI:
|
||||||
@ -279,7 +279,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
|
|||||||
(void)apf.convertFromAPInt(api,
|
(void)apf.convertFromAPInt(api,
|
||||||
opc==Instruction::SIToFP,
|
opc==Instruction::SIToFP,
|
||||||
APFloat::rmNearestTiesToEven);
|
APFloat::rmNearestTiesToEven);
|
||||||
return Context.getConstantFP(apf);
|
return ConstantFP::get(Context, apf);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
case Instruction::ZExt:
|
case Instruction::ZExt:
|
||||||
@ -795,19 +795,19 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
|
|||||||
break;
|
break;
|
||||||
case Instruction::FAdd:
|
case Instruction::FAdd:
|
||||||
(void)C3V.add(C2V, APFloat::rmNearestTiesToEven);
|
(void)C3V.add(C2V, APFloat::rmNearestTiesToEven);
|
||||||
return Context.getConstantFP(C3V);
|
return ConstantFP::get(Context, C3V);
|
||||||
case Instruction::FSub:
|
case Instruction::FSub:
|
||||||
(void)C3V.subtract(C2V, APFloat::rmNearestTiesToEven);
|
(void)C3V.subtract(C2V, APFloat::rmNearestTiesToEven);
|
||||||
return Context.getConstantFP(C3V);
|
return ConstantFP::get(Context, C3V);
|
||||||
case Instruction::FMul:
|
case Instruction::FMul:
|
||||||
(void)C3V.multiply(C2V, APFloat::rmNearestTiesToEven);
|
(void)C3V.multiply(C2V, APFloat::rmNearestTiesToEven);
|
||||||
return Context.getConstantFP(C3V);
|
return ConstantFP::get(Context, C3V);
|
||||||
case Instruction::FDiv:
|
case Instruction::FDiv:
|
||||||
(void)C3V.divide(C2V, APFloat::rmNearestTiesToEven);
|
(void)C3V.divide(C2V, APFloat::rmNearestTiesToEven);
|
||||||
return Context.getConstantFP(C3V);
|
return ConstantFP::get(Context, C3V);
|
||||||
case Instruction::FRem:
|
case Instruction::FRem:
|
||||||
(void)C3V.mod(C2V, APFloat::rmNearestTiesToEven);
|
(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())) {
|
} else if (const VectorType *VTy = dyn_cast<VectorType>(C1->getType())) {
|
||||||
|
@ -258,6 +258,87 @@ static const fltSemantics *TypeToFloatSemantics(const Type *Ty) {
|
|||||||
}
|
}
|
||||||
#endif
|
#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)
|
ConstantFP::ConstantFP(const Type *Ty, const APFloat& V)
|
||||||
: Constant(Ty, ConstantFPVal, 0, 0), Val(V) {
|
: Constant(Ty, ConstantFPVal, 0, 0), Val(V) {
|
||||||
assert(&V.getSemantics() == TypeToFloatSemantics(Ty) &&
|
assert(&V.getSemantics() == TypeToFloatSemantics(Ty) &&
|
||||||
|
@ -388,11 +388,11 @@ LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
|
|||||||
bool ignored;
|
bool ignored;
|
||||||
APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven,
|
APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven,
|
||||||
&ignored);
|
&ignored);
|
||||||
return wrap(getGlobalContext().getConstantFP(APN));
|
return wrap(ConstantFP::get(getGlobalContext(), APN));
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
|
LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
|
||||||
return wrap(getGlobalContext().getConstantFP(
|
return wrap(ConstantFP::get(getGlobalContext(),
|
||||||
APFloat(SemanticsForType(unwrap(RealTy)), Text)));
|
APFloat(SemanticsForType(unwrap(RealTy)), Text)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1577,7 +1577,7 @@ BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
|
|||||||
BinaryOperator *BinaryOperator::CreateNeg(LLVMContext &Context,
|
BinaryOperator *BinaryOperator::CreateNeg(LLVMContext &Context,
|
||||||
Value *Op, const Twine &Name,
|
Value *Op, const Twine &Name,
|
||||||
Instruction *InsertBefore) {
|
Instruction *InsertBefore) {
|
||||||
Value *zero = Context.getZeroValueForNegation(Op->getType());
|
Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
|
||||||
return new BinaryOperator(Instruction::Sub,
|
return new BinaryOperator(Instruction::Sub,
|
||||||
zero, Op,
|
zero, Op,
|
||||||
Op->getType(), Name, InsertBefore);
|
Op->getType(), Name, InsertBefore);
|
||||||
@ -1586,7 +1586,7 @@ BinaryOperator *BinaryOperator::CreateNeg(LLVMContext &Context,
|
|||||||
BinaryOperator *BinaryOperator::CreateNeg(LLVMContext &Context,
|
BinaryOperator *BinaryOperator::CreateNeg(LLVMContext &Context,
|
||||||
Value *Op, const Twine &Name,
|
Value *Op, const Twine &Name,
|
||||||
BasicBlock *InsertAtEnd) {
|
BasicBlock *InsertAtEnd) {
|
||||||
Value *zero = Context.getZeroValueForNegation(Op->getType());
|
Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
|
||||||
return new BinaryOperator(Instruction::Sub,
|
return new BinaryOperator(Instruction::Sub,
|
||||||
zero, Op,
|
zero, Op,
|
||||||
Op->getType(), Name, InsertAtEnd);
|
Op->getType(), Name, InsertAtEnd);
|
||||||
@ -1595,7 +1595,7 @@ BinaryOperator *BinaryOperator::CreateNeg(LLVMContext &Context,
|
|||||||
BinaryOperator *BinaryOperator::CreateFNeg(LLVMContext &Context,
|
BinaryOperator *BinaryOperator::CreateFNeg(LLVMContext &Context,
|
||||||
Value *Op, const Twine &Name,
|
Value *Op, const Twine &Name,
|
||||||
Instruction *InsertBefore) {
|
Instruction *InsertBefore) {
|
||||||
Value *zero = Context.getZeroValueForNegation(Op->getType());
|
Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
|
||||||
return new BinaryOperator(Instruction::FSub,
|
return new BinaryOperator(Instruction::FSub,
|
||||||
zero, Op,
|
zero, Op,
|
||||||
Op->getType(), Name, InsertBefore);
|
Op->getType(), Name, InsertBefore);
|
||||||
@ -1604,7 +1604,7 @@ BinaryOperator *BinaryOperator::CreateFNeg(LLVMContext &Context,
|
|||||||
BinaryOperator *BinaryOperator::CreateFNeg(LLVMContext &Context,
|
BinaryOperator *BinaryOperator::CreateFNeg(LLVMContext &Context,
|
||||||
Value *Op, const Twine &Name,
|
Value *Op, const Twine &Name,
|
||||||
BasicBlock *InsertAtEnd) {
|
BasicBlock *InsertAtEnd) {
|
||||||
Value *zero = Context.getZeroValueForNegation(Op->getType());
|
Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
|
||||||
return new BinaryOperator(Instruction::FSub,
|
return new BinaryOperator(Instruction::FSub,
|
||||||
zero, Op,
|
zero, Op,
|
||||||
Op->getType(), Name, InsertAtEnd);
|
Op->getType(), Name, InsertAtEnd);
|
||||||
|
@ -41,15 +41,16 @@ Constant* LLVMContext::getNullValue(const Type* Ty) {
|
|||||||
case Type::IntegerTyID:
|
case Type::IntegerTyID:
|
||||||
return ConstantInt::get(Ty, 0);
|
return ConstantInt::get(Ty, 0);
|
||||||
case Type::FloatTyID:
|
case Type::FloatTyID:
|
||||||
return getConstantFP(APFloat(APInt(32, 0)));
|
return ConstantFP::get(Ty->getContext(), APFloat(APInt(32, 0)));
|
||||||
case Type::DoubleTyID:
|
case Type::DoubleTyID:
|
||||||
return getConstantFP(APFloat(APInt(64, 0)));
|
return ConstantFP::get(Ty->getContext(), APFloat(APInt(64, 0)));
|
||||||
case Type::X86_FP80TyID:
|
case Type::X86_FP80TyID:
|
||||||
return getConstantFP(APFloat(APInt(80, 2, zero)));
|
return ConstantFP::get(Ty->getContext(), APFloat(APInt(80, 2, zero)));
|
||||||
case Type::FP128TyID:
|
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:
|
case Type::PPC_FP128TyID:
|
||||||
return getConstantFP(APFloat(APInt(128, 2, zero)));
|
return ConstantFP::get(Ty->getContext(), APFloat(APInt(128, 2, zero)));
|
||||||
case Type::PointerTyID:
|
case Type::PointerTyID:
|
||||||
return getConstantPointerNull(cast<PointerType>(Ty));
|
return getConstantPointerNull(cast<PointerType>(Ty));
|
||||||
case Type::StructTyID:
|
case Type::StructTyID:
|
||||||
@ -276,7 +277,7 @@ Constant* LLVMContext::getConstantExprNeg(Constant* C) {
|
|||||||
assert(C->getType()->isIntOrIntVector() &&
|
assert(C->getType()->isIntOrIntVector() &&
|
||||||
"Cannot NEG a nonintegral value!");
|
"Cannot NEG a nonintegral value!");
|
||||||
return getConstantExpr(Instruction::Sub,
|
return getConstantExpr(Instruction::Sub,
|
||||||
getZeroValueForNegation(C->getType()),
|
ConstantFP::getZeroValueForNegation(C->getType()),
|
||||||
C);
|
C);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +285,7 @@ Constant* LLVMContext::getConstantExprFNeg(Constant* C) {
|
|||||||
assert(C->getType()->isFPOrFPVector() &&
|
assert(C->getType()->isFPOrFPVector() &&
|
||||||
"Cannot FNEG a non-floating-point value!");
|
"Cannot FNEG a non-floating-point value!");
|
||||||
return getConstantExpr(Instruction::FSub,
|
return getConstantExpr(Instruction::FSub,
|
||||||
getZeroValueForNegation(C->getType()),
|
ConstantFP::getZeroValueForNegation(C->getType()),
|
||||||
C);
|
C);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,65 +425,6 @@ Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) {
|
|||||||
return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
|
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.
|
// ConstantVector accessors.
|
||||||
Constant* LLVMContext::getConstantVector(const VectorType* T,
|
Constant* LLVMContext::getConstantVector(const VectorType* T,
|
||||||
const std::vector<Constant*>& V) {
|
const std::vector<Constant*>& V) {
|
||||||
|
@ -49,41 +49,6 @@ static std::vector<Constant*> getValType(ConstantVector *CP) {
|
|||||||
LLVMContextImpl::LLVMContextImpl(LLVMContext &C) :
|
LLVMContextImpl::LLVMContextImpl(LLVMContext &C) :
|
||||||
Context(C), TheTrueVal(0), TheFalseVal(0) { }
|
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,
|
MDString *LLVMContextImpl::getMDString(const char *StrBegin,
|
||||||
unsigned StrLength) {
|
unsigned StrLength) {
|
||||||
sys::SmartScopedWriter<true> Writer(ConstantsLock);
|
sys::SmartScopedWriter<true> Writer(ConstantsLock);
|
||||||
|
@ -457,11 +457,10 @@ class LLVMContextImpl {
|
|||||||
LLVMContextImpl(const LLVMContextImpl&);
|
LLVMContextImpl(const LLVMContextImpl&);
|
||||||
|
|
||||||
friend class ConstantInt;
|
friend class ConstantInt;
|
||||||
|
friend class ConstantFP;
|
||||||
public:
|
public:
|
||||||
LLVMContextImpl(LLVMContext &C);
|
LLVMContextImpl(LLVMContext &C);
|
||||||
|
|
||||||
ConstantFP *getConstantFP(const APFloat &V);
|
|
||||||
|
|
||||||
MDString *getMDString(const char *StrBegin, unsigned StrLength);
|
MDString *getMDString(const char *StrBegin, unsigned StrLength);
|
||||||
|
|
||||||
MDNode *getMDNode(Value*const* Vals, unsigned NumVals);
|
MDNode *getMDNode(Value*const* Vals, unsigned NumVals);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user