Clean ExprConstant/CGExprConstant up a bit. NFC.

llvm-svn: 255314
This commit is contained in:
George Burgess IV 2015-12-11 00:23:35 +00:00
parent 2d4803e81b
commit 533ff009ff
2 changed files with 16 additions and 14 deletions

View File

@ -1180,7 +1180,7 @@ static bool EvaluatePointer(const Expr *E, LValue &Result, EvalInfo &Info);
static bool EvaluateMemberPointer(const Expr *E, MemberPtr &Result,
EvalInfo &Info);
static bool EvaluateTemporary(const Expr *E, LValue &Result, EvalInfo &Info);
static bool EvaluateInteger(const Expr *E, APSInt &Result, EvalInfo &Info);
static bool EvaluateInteger(const Expr *E, APSInt &Result, EvalInfo &Info);
static bool EvaluateIntegerOrLValue(const Expr *E, APValue &Result,
EvalInfo &Info);
static bool EvaluateFloat(const Expr *E, APFloat &Result, EvalInfo &Info);
@ -1607,7 +1607,7 @@ static bool HandleFloatToFloatCast(EvalInfo &Info, const Expr *E,
static APSInt HandleIntToIntCast(EvalInfo &Info, const Expr *E,
QualType DestType, QualType SrcType,
APSInt &Value) {
const APSInt &Value) {
unsigned DestWidth = Info.Ctx.getIntWidth(DestType);
APSInt Result = Value;
// Figure out if this is a truncate, extend or noop cast.
@ -5655,7 +5655,7 @@ static bool EvaluateVector(const Expr* E, APValue& Result, EvalInfo &Info) {
return VectorExprEvaluator(Info, Result).Visit(E);
}
bool VectorExprEvaluator::VisitCastExpr(const CastExpr* E) {
bool VectorExprEvaluator::VisitCastExpr(const CastExpr *E) {
const VectorType *VTy = E->getType()->castAs<VectorType>();
unsigned NElts = VTy->getNumElements();
@ -5668,13 +5668,13 @@ bool VectorExprEvaluator::VisitCastExpr(const CastExpr* E) {
if (SETy->isIntegerType()) {
APSInt IntResult;
if (!EvaluateInteger(SE, IntResult, Info))
return false;
Val = APValue(IntResult);
return false;
Val = APValue(std::move(IntResult));
} else if (SETy->isRealFloatingType()) {
APFloat F(0.0);
if (!EvaluateFloat(SE, F, Info))
return false;
Val = APValue(F);
APFloat FloatResult(0.0);
if (!EvaluateFloat(SE, FloatResult, Info))
return false;
Val = APValue(std::move(FloatResult));
} else {
return Error(E);
}

View File

@ -1350,15 +1350,17 @@ llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value,
return llvm::ConstantStruct::get(STy, Complex);
}
case APValue::Vector: {
SmallVector<llvm::Constant *, 4> Inits;
unsigned NumElts = Value.getVectorLength();
SmallVector<llvm::Constant *, 4> Inits(NumElts);
for (unsigned i = 0; i != NumElts; ++i) {
const APValue &Elt = Value.getVectorElt(i);
for (unsigned I = 0; I != NumElts; ++I) {
const APValue &Elt = Value.getVectorElt(I);
if (Elt.isInt())
Inits.push_back(llvm::ConstantInt::get(VMContext, Elt.getInt()));
Inits[I] = llvm::ConstantInt::get(VMContext, Elt.getInt());
else if (Elt.isFloat())
Inits[I] = llvm::ConstantFP::get(VMContext, Elt.getFloat());
else
Inits.push_back(llvm::ConstantFP::get(VMContext, Elt.getFloat()));
llvm_unreachable("unsupported vector element type");
}
return llvm::ConstantVector::get(Inits);
}