eliminate a bunch of pointless LLVMContext arguments.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95001 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-02-01 20:48:08 +00:00
parent a419b56d89
commit b29d596072
5 changed files with 150 additions and 206 deletions

View File

@ -104,8 +104,7 @@ public:
/// type, returns the elements of the vector in the specified smallvector.
/// This handles breaking down a vector undef into undef elements, etc. For
/// constant exprs and other cases we can't handle, we return an empty vector.
void getVectorElements(LLVMContext &Context,
SmallVectorImpl<Constant*> &Elts) const;
void getVectorElements(SmallVectorImpl<Constant*> &Elts) const;
/// destroyConstant - Called if some element of this constant is no longer
/// valid. At this point only other constants may be on the use_list for this

View File

@ -2317,8 +2317,7 @@ void SelectionDAGBuilder::visitShuffleVector(User &I) {
// Convert the ConstantVector mask operand into an array of ints, with -1
// representing undef values.
SmallVector<Constant*, 8> MaskElts;
cast<Constant>(I.getOperand(2))->getVectorElements(*DAG.getContext(),
MaskElts);
cast<Constant>(I.getOperand(2))->getVectorElements(MaskElts);
unsigned MaskNumElts = MaskElts.size();
for (unsigned i = 0; i != MaskNumElts; ++i) {
if (isa<UndefValue>(MaskElts[i]))

View File

@ -24,7 +24,6 @@
#include "llvm/Function.h"
#include "llvm/GlobalAlias.h"
#include "llvm/GlobalVariable.h"
#include "llvm/LLVMContext.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
@ -41,7 +40,7 @@ using namespace llvm;
/// BitCastConstantVector - Convert the specified ConstantVector node to the
/// specified vector type. At this point, we know that the elements of the
/// input vector constant are all simple integer or FP values.
static Constant *BitCastConstantVector(LLVMContext &Context, ConstantVector *CV,
static Constant *BitCastConstantVector(ConstantVector *CV,
const VectorType *DstTy) {
// If this cast changes element count then we can't handle it here:
// doing so requires endianness information. This should be handled by
@ -91,8 +90,7 @@ foldConstantCastPair(
Type::getInt64Ty(DstTy->getContext()));
}
static Constant *FoldBitCast(LLVMContext &Context,
Constant *V, const Type *DestTy) {
static Constant *FoldBitCast(Constant *V, const Type *DestTy) {
const Type *SrcTy = V->getType();
if (SrcTy == DestTy)
return V; // no-op cast
@ -103,7 +101,8 @@ static Constant *FoldBitCast(LLVMContext &Context,
if (const PointerType *DPTy = dyn_cast<PointerType>(DestTy))
if (PTy->getAddressSpace() == DPTy->getAddressSpace()) {
SmallVector<Value*, 8> IdxList;
Value *Zero = Constant::getNullValue(Type::getInt32Ty(Context));
Value *Zero =
Constant::getNullValue(Type::getInt32Ty(DPTy->getContext()));
IdxList.push_back(Zero);
const Type *ElTy = PTy->getElementType();
while (ElTy != DPTy->getElementType()) {
@ -139,15 +138,14 @@ static Constant *FoldBitCast(LLVMContext &Context,
return Constant::getNullValue(DestTy);
if (ConstantVector *CV = dyn_cast<ConstantVector>(V))
return BitCastConstantVector(Context, CV, DestPTy);
return BitCastConstantVector(CV, DestPTy);
}
// Canonicalize scalar-to-vector bitcasts into vector-to-vector bitcasts
// This allows for other simplifications (although some of them
// can only be handled by Analysis/ConstantFolding.cpp).
if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
return ConstantExpr::getBitCast(
ConstantVector::get(&V, 1), DestPTy);
return ConstantExpr::getBitCast(ConstantVector::get(&V, 1), DestPTy);
}
// Finally, implement bitcast folding now. The code below doesn't handle
@ -163,17 +161,18 @@ static Constant *FoldBitCast(LLVMContext &Context,
return V;
if (DestTy->isFloatingPoint())
return ConstantFP::get(Context, APFloat(CI->getValue(),
DestTy != Type::getPPC_FP128Ty(Context)));
return ConstantFP::get(DestTy->getContext(),
APFloat(CI->getValue(),
!DestTy->isPPC_FP128Ty()));
// Otherwise, can't fold this (vector?)
return 0;
}
// Handle ConstantFP input.
// Handle ConstantFP input: FP -> Integral.
if (ConstantFP *FP = dyn_cast<ConstantFP>(V))
// FP -> Integral.
return ConstantInt::get(Context, FP->getValueAPF().bitcastToAPInt());
return ConstantInt::get(FP->getContext(),
FP->getValueAPF().bitcastToAPInt());
return 0;
}
@ -434,8 +433,7 @@ static Constant *getFoldedOffsetOf(const Type *Ty, Constant *FieldNo,
return C;
}
Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
unsigned opc, Constant *V,
Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
const Type *DestTy) {
if (isa<UndefValue>(V)) {
// zext(undef) = 0, because the top bits will be zero.
@ -504,7 +502,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
DestTy->isFP128Ty() ? APFloat::IEEEquad :
APFloat::Bogus,
APFloat::rmNearestTiesToEven, &ignored);
return ConstantFP::get(Context, Val);
return ConstantFP::get(V->getContext(), Val);
}
return 0; // Can't fold.
case Instruction::FPToUI:
@ -517,7 +515,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
(void) V.convertToInteger(x, DestBitWidth, opc==Instruction::FPToSI,
APFloat::rmTowardZero, &ignored);
APInt Val(DestBitWidth, 2, x);
return ConstantInt::get(Context, Val);
return ConstantInt::get(FPC->getContext(), Val);
}
return 0; // Can't fold.
case Instruction::IntToPtr: //always treated as unsigned
@ -593,7 +591,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
(void)apf.convertFromAPInt(api,
opc==Instruction::SIToFP,
APFloat::rmNearestTiesToEven);
return ConstantFP::get(Context, apf);
return ConstantFP::get(V->getContext(), apf);
}
return 0;
case Instruction::ZExt:
@ -601,7 +599,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
APInt Result(CI->getValue());
Result.zext(BitWidth);
return ConstantInt::get(Context, Result);
return ConstantInt::get(V->getContext(), Result);
}
return 0;
case Instruction::SExt:
@ -609,7 +607,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
APInt Result(CI->getValue());
Result.sext(BitWidth);
return ConstantInt::get(Context, Result);
return ConstantInt::get(V->getContext(), Result);
}
return 0;
case Instruction::Trunc: {
@ -617,7 +615,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
APInt Result(CI->getValue());
Result.trunc(DestBitWidth);
return ConstantInt::get(Context, Result);
return ConstantInt::get(V->getContext(), Result);
}
// The input must be a constantexpr. See if we can simplify this based on
@ -631,12 +629,11 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
return 0;
}
case Instruction::BitCast:
return FoldBitCast(Context, V, DestTy);
return FoldBitCast(V, DestTy);
}
}
Constant *llvm::ConstantFoldSelectInstruction(LLVMContext&,
Constant *Cond,
Constant *llvm::ConstantFoldSelectInstruction(Constant *Cond,
Constant *V1, Constant *V2) {
if (ConstantInt *CB = dyn_cast<ConstantInt>(Cond))
return CB->getZExtValue() ? V1 : V2;
@ -648,8 +645,7 @@ Constant *llvm::ConstantFoldSelectInstruction(LLVMContext&,
return 0;
}
Constant *llvm::ConstantFoldExtractElementInstruction(LLVMContext &Context,
Constant *Val,
Constant *llvm::ConstantFoldExtractElementInstruction(Constant *Val,
Constant *Idx) {
if (isa<UndefValue>(Val)) // ee(undef, x) -> undef
return UndefValue::get(cast<VectorType>(Val->getType())->getElementType());
@ -668,8 +664,7 @@ Constant *llvm::ConstantFoldExtractElementInstruction(LLVMContext &Context,
return 0;
}
Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context,
Constant *Val,
Constant *llvm::ConstantFoldInsertElementInstruction(Constant *Val,
Constant *Elt,
Constant *Idx) {
ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx);
@ -728,8 +723,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context,
/// GetVectorElement - If C is a ConstantVector, ConstantAggregateZero or Undef
/// return the specified element value. Otherwise return null.
static Constant *GetVectorElement(LLVMContext &Context, Constant *C,
unsigned EltNo) {
static Constant *GetVectorElement(Constant *C, unsigned EltNo) {
if (ConstantVector *CV = dyn_cast<ConstantVector>(C))
return CV->getOperand(EltNo);
@ -741,8 +735,7 @@ static Constant *GetVectorElement(LLVMContext &Context, Constant *C,
return 0;
}
Constant *llvm::ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
Constant *V1,
Constant *llvm::ConstantFoldShuffleVectorInstruction(Constant *V1,
Constant *V2,
Constant *Mask) {
// Undefined shuffle mask -> undefined value.
@ -755,7 +748,7 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
// Loop over the shuffle mask, evaluating each element.
SmallVector<Constant*, 32> Result;
for (unsigned i = 0; i != MaskNumElts; ++i) {
Constant *InElt = GetVectorElement(Context, Mask, i);
Constant *InElt = GetVectorElement(Mask, i);
if (InElt == 0) return 0;
if (isa<UndefValue>(InElt))
@ -765,9 +758,9 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
if (Elt >= SrcNumElts*2)
InElt = UndefValue::get(EltTy);
else if (Elt >= SrcNumElts)
InElt = GetVectorElement(Context, V2, Elt - SrcNumElts);
InElt = GetVectorElement(V2, Elt - SrcNumElts);
else
InElt = GetVectorElement(Context, V1, Elt);
InElt = GetVectorElement(V1, Elt);
if (InElt == 0) return 0;
} else {
// Unknown value.
@ -779,8 +772,7 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
return ConstantVector::get(&Result[0], Result.size());
}
Constant *llvm::ConstantFoldExtractValueInstruction(LLVMContext &Context,
Constant *Agg,
Constant *llvm::ConstantFoldExtractValueInstruction(Constant *Agg,
const unsigned *Idxs,
unsigned NumIdx) {
// Base case: no indices, so return the entire value.
@ -800,19 +792,18 @@ Constant *llvm::ConstantFoldExtractValueInstruction(LLVMContext &Context,
// Otherwise recurse.
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Agg))
return ConstantFoldExtractValueInstruction(Context, CS->getOperand(*Idxs),
return ConstantFoldExtractValueInstruction(CS->getOperand(*Idxs),
Idxs+1, NumIdx-1);
if (ConstantArray *CA = dyn_cast<ConstantArray>(Agg))
return ConstantFoldExtractValueInstruction(Context, CA->getOperand(*Idxs),
return ConstantFoldExtractValueInstruction(CA->getOperand(*Idxs),
Idxs+1, NumIdx-1);
ConstantVector *CV = cast<ConstantVector>(Agg);
return ConstantFoldExtractValueInstruction(Context, CV->getOperand(*Idxs),
return ConstantFoldExtractValueInstruction(CV->getOperand(*Idxs),
Idxs+1, NumIdx-1);
}
Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
Constant *Agg,
Constant *llvm::ConstantFoldInsertValueInstruction(Constant *Agg,
Constant *Val,
const unsigned *Idxs,
unsigned NumIdx) {
@ -840,14 +831,14 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
const Type *MemberTy = AggTy->getTypeAtIndex(i);
Constant *Op =
(*Idxs == i) ?
ConstantFoldInsertValueInstruction(Context, UndefValue::get(MemberTy),
ConstantFoldInsertValueInstruction(UndefValue::get(MemberTy),
Val, Idxs+1, NumIdx-1) :
UndefValue::get(MemberTy);
Ops[i] = Op;
}
if (const StructType* ST = dyn_cast<StructType>(AggTy))
return ConstantStruct::get(Context, Ops, ST->isPacked());
return ConstantStruct::get(ST->getContext(), Ops, ST->isPacked());
return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
}
@ -871,15 +862,14 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
const Type *MemberTy = AggTy->getTypeAtIndex(i);
Constant *Op =
(*Idxs == i) ?
ConstantFoldInsertValueInstruction(Context,
Constant::getNullValue(MemberTy),
ConstantFoldInsertValueInstruction(Constant::getNullValue(MemberTy),
Val, Idxs+1, NumIdx-1) :
Constant::getNullValue(MemberTy);
Ops[i] = Op;
}
if (const StructType* ST = dyn_cast<StructType>(AggTy))
return ConstantStruct::get(Context, Ops, ST->isPacked());
if (const StructType *ST = dyn_cast<StructType>(AggTy))
return ConstantStruct::get(ST->getContext(), Ops, ST->isPacked());
return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
}
@ -889,13 +879,12 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
for (unsigned i = 0; i < Agg->getNumOperands(); ++i) {
Constant *Op = cast<Constant>(Agg->getOperand(i));
if (*Idxs == i)
Op = ConstantFoldInsertValueInstruction(Context, Op,
Val, Idxs+1, NumIdx-1);
Op = ConstantFoldInsertValueInstruction(Op, Val, Idxs+1, NumIdx-1);
Ops[i] = Op;
}
if (const StructType* ST = dyn_cast<StructType>(Agg->getType()))
return ConstantStruct::get(Context, Ops, ST->isPacked());
return ConstantStruct::get(ST->getContext(), Ops, ST->isPacked());
return ConstantArray::get(cast<ArrayType>(Agg->getType()), Ops);
}
@ -903,8 +892,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
}
Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
unsigned Opcode,
Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
Constant *C1, Constant *C2) {
// No compile-time operations on this type yet.
if (C1->getType()->isPPC_FP128Ty())
@ -1061,51 +1049,51 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
default:
break;
case Instruction::Add:
return ConstantInt::get(Context, C1V + C2V);
return ConstantInt::get(CI1->getContext(), C1V + C2V);
case Instruction::Sub:
return ConstantInt::get(Context, C1V - C2V);
return ConstantInt::get(CI1->getContext(), C1V - C2V);
case Instruction::Mul:
return ConstantInt::get(Context, C1V * C2V);
return ConstantInt::get(CI1->getContext(), C1V * C2V);
case Instruction::UDiv:
assert(!CI2->isNullValue() && "Div by zero handled above");
return ConstantInt::get(Context, C1V.udiv(C2V));
return ConstantInt::get(CI1->getContext(), C1V.udiv(C2V));
case Instruction::SDiv:
assert(!CI2->isNullValue() && "Div by zero handled above");
if (C2V.isAllOnesValue() && C1V.isMinSignedValue())
return UndefValue::get(CI1->getType()); // MIN_INT / -1 -> undef
return ConstantInt::get(Context, C1V.sdiv(C2V));
return ConstantInt::get(CI1->getContext(), C1V.sdiv(C2V));
case Instruction::URem:
assert(!CI2->isNullValue() && "Div by zero handled above");
return ConstantInt::get(Context, C1V.urem(C2V));
return ConstantInt::get(CI1->getContext(), C1V.urem(C2V));
case Instruction::SRem:
assert(!CI2->isNullValue() && "Div by zero handled above");
if (C2V.isAllOnesValue() && C1V.isMinSignedValue())
return UndefValue::get(CI1->getType()); // MIN_INT % -1 -> undef
return ConstantInt::get(Context, C1V.srem(C2V));
return ConstantInt::get(CI1->getContext(), C1V.srem(C2V));
case Instruction::And:
return ConstantInt::get(Context, C1V & C2V);
return ConstantInt::get(CI1->getContext(), C1V & C2V);
case Instruction::Or:
return ConstantInt::get(Context, C1V | C2V);
return ConstantInt::get(CI1->getContext(), C1V | C2V);
case Instruction::Xor:
return ConstantInt::get(Context, C1V ^ C2V);
return ConstantInt::get(CI1->getContext(), C1V ^ C2V);
case Instruction::Shl: {
uint32_t shiftAmt = C2V.getZExtValue();
if (shiftAmt < C1V.getBitWidth())
return ConstantInt::get(Context, C1V.shl(shiftAmt));
return ConstantInt::get(CI1->getContext(), C1V.shl(shiftAmt));
else
return UndefValue::get(C1->getType()); // too big shift is undef
}
case Instruction::LShr: {
uint32_t shiftAmt = C2V.getZExtValue();
if (shiftAmt < C1V.getBitWidth())
return ConstantInt::get(Context, C1V.lshr(shiftAmt));
return ConstantInt::get(CI1->getContext(), C1V.lshr(shiftAmt));
else
return UndefValue::get(C1->getType()); // too big shift is undef
}
case Instruction::AShr: {
uint32_t shiftAmt = C2V.getZExtValue();
if (shiftAmt < C1V.getBitWidth())
return ConstantInt::get(Context, C1V.ashr(shiftAmt));
return ConstantInt::get(CI1->getContext(), C1V.ashr(shiftAmt));
else
return UndefValue::get(C1->getType()); // too big shift is undef
}
@ -1135,19 +1123,19 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
break;
case Instruction::FAdd:
(void)C3V.add(C2V, APFloat::rmNearestTiesToEven);
return ConstantFP::get(Context, C3V);
return ConstantFP::get(C1->getContext(), C3V);
case Instruction::FSub:
(void)C3V.subtract(C2V, APFloat::rmNearestTiesToEven);
return ConstantFP::get(Context, C3V);
return ConstantFP::get(C1->getContext(), C3V);
case Instruction::FMul:
(void)C3V.multiply(C2V, APFloat::rmNearestTiesToEven);
return ConstantFP::get(Context, C3V);
return ConstantFP::get(C1->getContext(), C3V);
case Instruction::FDiv:
(void)C3V.divide(C2V, APFloat::rmNearestTiesToEven);
return ConstantFP::get(Context, C3V);
return ConstantFP::get(C1->getContext(), C3V);
case Instruction::FRem:
(void)C3V.mod(C2V, APFloat::rmNearestTiesToEven);
return ConstantFP::get(Context, C3V);
return ConstantFP::get(C1->getContext(), C3V);
}
}
} else if (const VectorType *VTy = dyn_cast<VectorType>(C1->getType())) {
@ -1317,7 +1305,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
case Instruction::Or:
case Instruction::Xor:
// No change of opcode required.
return ConstantFoldBinaryInstruction(Context, Opcode, C2, C1);
return ConstantFoldBinaryInstruction(Opcode, C2, C1);
case Instruction::Shl:
case Instruction::LShr:
@ -1358,7 +1346,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
case Instruction::SRem:
// We can assume that C2 == 1. If it were zero the result would be
// undefined through division by zero.
return ConstantInt::getFalse(Context);
return ConstantInt::getFalse(C1->getContext());
default:
break;
}
@ -1392,8 +1380,7 @@ static bool isMaybeZeroSizedType(const Type *Ty) {
/// first is less than the second, return -1, if the second is less than the
/// first, return 1. If the constants are not integral, return -2.
///
static int IdxCompare(LLVMContext &Context, Constant *C1, Constant *C2,
const Type *ElTy) {
static int IdxCompare(Constant *C1, Constant *C2, const Type *ElTy) {
if (C1 == C2) return 0;
// Ok, we found a different index. If they are not ConstantInt, we can't do
@ -1404,10 +1391,10 @@ static int IdxCompare(LLVMContext &Context, Constant *C1, Constant *C2,
// Ok, we have two differing integer indices. Sign extend them to be the same
// type. Long is always big enough, so we use it.
if (!C1->getType()->isInteger(64))
C1 = ConstantExpr::getSExt(C1, Type::getInt64Ty(Context));
C1 = ConstantExpr::getSExt(C1, Type::getInt64Ty(C1->getContext()));
if (!C2->getType()->isInteger(64))
C2 = ConstantExpr::getSExt(C2, Type::getInt64Ty(Context));
C2 = ConstantExpr::getSExt(C2, Type::getInt64Ty(C1->getContext()));
if (C1 == C2) return 0; // They are equal
@ -1436,8 +1423,7 @@ static int IdxCompare(LLVMContext &Context, Constant *C1, Constant *C2,
/// To simplify this code we canonicalize the relation so that the first
/// operand is always the most "complex" of the two. We consider ConstantFP
/// to be the simplest, and ConstantExprs to be the most complex.
static FCmpInst::Predicate evaluateFCmpRelation(LLVMContext &Context,
Constant *V1, Constant *V2) {
static FCmpInst::Predicate evaluateFCmpRelation(Constant *V1, Constant *V2) {
assert(V1->getType() == V2->getType() &&
"Cannot compare values of different types!");
@ -1470,7 +1456,7 @@ static FCmpInst::Predicate evaluateFCmpRelation(LLVMContext &Context,
}
// If the first operand is simple and second is ConstantExpr, swap operands.
FCmpInst::Predicate SwappedRelation = evaluateFCmpRelation(Context, V2, V1);
FCmpInst::Predicate SwappedRelation = evaluateFCmpRelation(V2, V1);
if (SwappedRelation != FCmpInst::BAD_FCMP_PREDICATE)
return FCmpInst::getSwappedPredicate(SwappedRelation);
} else {
@ -1505,8 +1491,7 @@ static FCmpInst::Predicate evaluateFCmpRelation(LLVMContext &Context,
/// constants (like ConstantInt) to be the simplest, followed by
/// GlobalValues, followed by ConstantExpr's (the most complex).
///
static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context,
Constant *V1, Constant *V2,
static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2,
bool isSigned) {
assert(V1->getType() == V2->getType() &&
"Cannot compare different types of values!");
@ -1538,14 +1523,14 @@ static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context,
// If the first operand is simple, swap operands.
ICmpInst::Predicate SwappedRelation =
evaluateICmpRelation(Context, V2, V1, isSigned);
evaluateICmpRelation(V2, V1, isSigned);
if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE)
return ICmpInst::getSwappedPredicate(SwappedRelation);
} else if (const GlobalValue *GV = dyn_cast<GlobalValue>(V1)) {
if (isa<ConstantExpr>(V2)) { // Swap as necessary.
ICmpInst::Predicate SwappedRelation =
evaluateICmpRelation(Context, V2, V1, isSigned);
evaluateICmpRelation(V2, V1, isSigned);
if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE)
return ICmpInst::getSwappedPredicate(SwappedRelation);
return ICmpInst::BAD_ICMP_PREDICATE;
@ -1571,7 +1556,7 @@ static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context,
} else if (const BlockAddress *BA = dyn_cast<BlockAddress>(V1)) {
if (isa<ConstantExpr>(V2)) { // Swap as necessary.
ICmpInst::Predicate SwappedRelation =
evaluateICmpRelation(Context, V2, V1, isSigned);
evaluateICmpRelation(V2, V1, isSigned);
if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE)
return ICmpInst::getSwappedPredicate(SwappedRelation);
return ICmpInst::BAD_ICMP_PREDICATE;
@ -1617,7 +1602,7 @@ static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context,
(isa<PointerType>(CE1->getType()) || CE1->getType()->isInteger())) {
if (CE1->getOpcode() == Instruction::ZExt) isSigned = false;
if (CE1->getOpcode() == Instruction::SExt) isSigned = true;
return evaluateICmpRelation(Context, CE1Op0,
return evaluateICmpRelation(CE1Op0,
Constant::getNullValue(CE1Op0->getType()),
isSigned);
}
@ -1706,7 +1691,7 @@ static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context,
gep_type_iterator GTI = gep_type_begin(CE1);
for (;i != CE1->getNumOperands() && i != CE2->getNumOperands();
++i, ++GTI)
switch (IdxCompare(Context, CE1->getOperand(i),
switch (IdxCompare(CE1->getOperand(i),
CE2->getOperand(i), GTI.getIndexedType())) {
case -1: return isSigned ? ICmpInst::ICMP_SLT:ICmpInst::ICMP_ULT;
case 1: return isSigned ? ICmpInst::ICMP_SGT:ICmpInst::ICMP_UGT;
@ -1742,14 +1727,14 @@ static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context,
return ICmpInst::BAD_ICMP_PREDICATE;
}
Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
unsigned short pred,
Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
Constant *C1, Constant *C2) {
const Type *ResultTy;
if (const VectorType *VT = dyn_cast<VectorType>(C1->getType()))
ResultTy = VectorType::get(Type::getInt1Ty(Context), VT->getNumElements());
ResultTy = VectorType::get(Type::getInt1Ty(C1->getContext()),
VT->getNumElements());
else
ResultTy = Type::getInt1Ty(Context);
ResultTy = Type::getInt1Ty(C1->getContext());
// Fold FCMP_FALSE/FCMP_TRUE unconditionally.
if (pred == FCmpInst::FCMP_FALSE)
@ -1772,9 +1757,9 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
// Don't try to evaluate aliases. External weak GV can be null.
if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) {
if (pred == ICmpInst::ICMP_EQ)
return ConstantInt::getFalse(Context);
return ConstantInt::getFalse(C1->getContext());
else if (pred == ICmpInst::ICMP_NE)
return ConstantInt::getTrue(Context);
return ConstantInt::getTrue(C1->getContext());
}
// icmp eq/ne(GV,null) -> false/true
} else if (C2->isNullValue()) {
@ -1782,9 +1767,9 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
// Don't try to evaluate aliases. External weak GV can be null.
if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) {
if (pred == ICmpInst::ICMP_EQ)
return ConstantInt::getFalse(Context);
return ConstantInt::getFalse(C1->getContext());
else if (pred == ICmpInst::ICMP_NE)
return ConstantInt::getTrue(Context);
return ConstantInt::getTrue(C1->getContext());
}
}
@ -1807,26 +1792,16 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
APInt V2 = cast<ConstantInt>(C2)->getValue();
switch (pred) {
default: llvm_unreachable("Invalid ICmp Predicate"); return 0;
case ICmpInst::ICMP_EQ:
return ConstantInt::get(Type::getInt1Ty(Context), V1 == V2);
case ICmpInst::ICMP_NE:
return ConstantInt::get(Type::getInt1Ty(Context), V1 != V2);
case ICmpInst::ICMP_SLT:
return ConstantInt::get(Type::getInt1Ty(Context), V1.slt(V2));
case ICmpInst::ICMP_SGT:
return ConstantInt::get(Type::getInt1Ty(Context), V1.sgt(V2));
case ICmpInst::ICMP_SLE:
return ConstantInt::get(Type::getInt1Ty(Context), V1.sle(V2));
case ICmpInst::ICMP_SGE:
return ConstantInt::get(Type::getInt1Ty(Context), V1.sge(V2));
case ICmpInst::ICMP_ULT:
return ConstantInt::get(Type::getInt1Ty(Context), V1.ult(V2));
case ICmpInst::ICMP_UGT:
return ConstantInt::get(Type::getInt1Ty(Context), V1.ugt(V2));
case ICmpInst::ICMP_ULE:
return ConstantInt::get(Type::getInt1Ty(Context), V1.ule(V2));
case ICmpInst::ICMP_UGE:
return ConstantInt::get(Type::getInt1Ty(Context), V1.uge(V2));
case ICmpInst::ICMP_EQ: return ConstantInt::get(ResultTy, V1 == V2);
case ICmpInst::ICMP_NE: return ConstantInt::get(ResultTy, V1 != V2);
case ICmpInst::ICMP_SLT: return ConstantInt::get(ResultTy, V1.slt(V2));
case ICmpInst::ICMP_SGT: return ConstantInt::get(ResultTy, V1.sgt(V2));
case ICmpInst::ICMP_SLE: return ConstantInt::get(ResultTy, V1.sle(V2));
case ICmpInst::ICMP_SGE: return ConstantInt::get(ResultTy, V1.sge(V2));
case ICmpInst::ICMP_ULT: return ConstantInt::get(ResultTy, V1.ult(V2));
case ICmpInst::ICMP_UGT: return ConstantInt::get(ResultTy, V1.ugt(V2));
case ICmpInst::ICMP_ULE: return ConstantInt::get(ResultTy, V1.ule(V2));
case ICmpInst::ICMP_UGE: return ConstantInt::get(ResultTy, V1.uge(V2));
}
} else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
APFloat C1V = cast<ConstantFP>(C1)->getValueAPF();
@ -1834,47 +1809,47 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
APFloat::cmpResult R = C1V.compare(C2V);
switch (pred) {
default: llvm_unreachable("Invalid FCmp Predicate"); return 0;
case FCmpInst::FCMP_FALSE: return ConstantInt::getFalse(Context);
case FCmpInst::FCMP_TRUE: return ConstantInt::getTrue(Context);
case FCmpInst::FCMP_FALSE: return Constant::getNullValue(ResultTy);
case FCmpInst::FCMP_TRUE: return Constant::getAllOnesValue(ResultTy);
case FCmpInst::FCMP_UNO:
return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered);
return ConstantInt::get(ResultTy, R==APFloat::cmpUnordered);
case FCmpInst::FCMP_ORD:
return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpUnordered);
return ConstantInt::get(ResultTy, R!=APFloat::cmpUnordered);
case FCmpInst::FCMP_UEQ:
return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered ||
R==APFloat::cmpEqual);
return ConstantInt::get(ResultTy, R==APFloat::cmpUnordered ||
R==APFloat::cmpEqual);
case FCmpInst::FCMP_OEQ:
return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpEqual);
return ConstantInt::get(ResultTy, R==APFloat::cmpEqual);
case FCmpInst::FCMP_UNE:
return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpEqual);
return ConstantInt::get(ResultTy, R!=APFloat::cmpEqual);
case FCmpInst::FCMP_ONE:
return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpLessThan ||
R==APFloat::cmpGreaterThan);
return ConstantInt::get(ResultTy, R==APFloat::cmpLessThan ||
R==APFloat::cmpGreaterThan);
case FCmpInst::FCMP_ULT:
return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered ||
R==APFloat::cmpLessThan);
return ConstantInt::get(ResultTy, R==APFloat::cmpUnordered ||
R==APFloat::cmpLessThan);
case FCmpInst::FCMP_OLT:
return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpLessThan);
return ConstantInt::get(ResultTy, R==APFloat::cmpLessThan);
case FCmpInst::FCMP_UGT:
return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered ||
R==APFloat::cmpGreaterThan);
return ConstantInt::get(ResultTy, R==APFloat::cmpUnordered ||
R==APFloat::cmpGreaterThan);
case FCmpInst::FCMP_OGT:
return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpGreaterThan);
return ConstantInt::get(ResultTy, R==APFloat::cmpGreaterThan);
case FCmpInst::FCMP_ULE:
return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpGreaterThan);
return ConstantInt::get(ResultTy, R!=APFloat::cmpGreaterThan);
case FCmpInst::FCMP_OLE:
return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpLessThan ||
R==APFloat::cmpEqual);
return ConstantInt::get(ResultTy, R==APFloat::cmpLessThan ||
R==APFloat::cmpEqual);
case FCmpInst::FCMP_UGE:
return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpLessThan);
return ConstantInt::get(ResultTy, R!=APFloat::cmpLessThan);
case FCmpInst::FCMP_OGE:
return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpGreaterThan ||
R==APFloat::cmpEqual);
return ConstantInt::get(ResultTy, R==APFloat::cmpGreaterThan ||
R==APFloat::cmpEqual);
}
} else if (isa<VectorType>(C1->getType())) {
SmallVector<Constant*, 16> C1Elts, C2Elts;
C1->getVectorElements(Context, C1Elts);
C2->getVectorElements(Context, C2Elts);
C1->getVectorElements(C1Elts);
C2->getVectorElements(C2Elts);
if (C1Elts.empty() || C2Elts.empty())
return 0;
@ -1890,7 +1865,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
if (C1->getType()->isFloatingPoint()) {
int Result = -1; // -1 = unknown, 0 = known false, 1 = known true.
switch (evaluateFCmpRelation(Context, C1, C2)) {
switch (evaluateFCmpRelation(C1, C2)) {
default: llvm_unreachable("Unknown relation!");
case FCmpInst::FCMP_UNO:
case FCmpInst::FCMP_ORD:
@ -1944,12 +1919,12 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
// If we evaluated the result, return it now.
if (Result != -1)
return ConstantInt::get(Type::getInt1Ty(Context), Result);
return ConstantInt::get(ResultTy, Result);
} else {
// Evaluate the relation between the two constants, per the predicate.
int Result = -1; // -1 = unknown, 0 = known false, 1 = known true.
switch (evaluateICmpRelation(Context, C1, C2, CmpInst::isSigned(pred))) {
switch (evaluateICmpRelation(C1, C2, CmpInst::isSigned(pred))) {
default: llvm_unreachable("Unknown relational!");
case ICmpInst::BAD_ICMP_PREDICATE:
break; // Couldn't determine anything about these constants.
@ -2014,7 +1989,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
// If we evaluated the result, return it now.
if (Result != -1)
return ConstantInt::get(Type::getInt1Ty(Context), Result);
return ConstantInt::get(ResultTy, Result);
// If the right hand side is a bitcast, try using its inverse to simplify
// it by moving it to the left hand side. We can't do this if it would turn
@ -2094,8 +2069,7 @@ static bool isInBoundsIndices(Constant *const *Idxs, size_t NumIdx) {
return true;
}
Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
Constant *C,
Constant *llvm::ConstantFoldGetElementPtr(Constant *C,
bool inBounds,
Constant* const *Idxs,
unsigned NumIdx) {
@ -2155,10 +2129,9 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
if (!Idx0->isNullValue()) {
const Type *IdxTy = Combined->getType();
if (IdxTy != Idx0->getType()) {
Constant *C1 =
ConstantExpr::getSExtOrBitCast(Idx0, Type::getInt64Ty(Context));
Constant *C2 = ConstantExpr::getSExtOrBitCast(Combined,
Type::getInt64Ty(Context));
const Type *Int64Ty = Type::getInt64Ty(IdxTy->getContext());
Constant *C1 = ConstantExpr::getSExtOrBitCast(Idx0, Int64Ty);
Constant *C2 = ConstantExpr::getSExtOrBitCast(Combined, Int64Ty);
Combined = ConstantExpr::get(Instruction::Add, C1, C2);
} else {
Combined =
@ -2227,10 +2200,10 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
// overflow trouble.
if (!PrevIdx->getType()->isInteger(64))
PrevIdx = ConstantExpr::getSExt(PrevIdx,
Type::getInt64Ty(Context));
Type::getInt64Ty(Div->getContext()));
if (!Div->getType()->isInteger(64))
Div = ConstantExpr::getSExt(Div,
Type::getInt64Ty(Context));
Type::getInt64Ty(Div->getContext()));
NewIdxs[i-1] = ConstantExpr::getAdd(PrevIdx, Div);
} else {

View File

@ -23,46 +23,31 @@ namespace llvm {
class Value;
class Constant;
class Type;
class LLVMContext;
// Constant fold various types of instruction...
Constant *ConstantFoldCastInstruction(
LLVMContext &Context,
unsigned opcode, ///< The opcode of the cast
Constant *V, ///< The source constant
const Type *DestTy ///< The destination type
);
Constant *ConstantFoldSelectInstruction(LLVMContext &Context,
Constant *Cond,
Constant *ConstantFoldSelectInstruction(Constant *Cond,
Constant *V1, Constant *V2);
Constant *ConstantFoldExtractElementInstruction(LLVMContext &Context,
Constant *Val,
Constant *Idx);
Constant *ConstantFoldInsertElementInstruction(LLVMContext &Context,
Constant *Val,
Constant *Elt,
Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx);
Constant *ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt,
Constant *Idx);
Constant *ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
Constant *V1,
Constant *V2,
Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
Constant *Mask);
Constant *ConstantFoldExtractValueInstruction(LLVMContext &Context,
Constant *Agg,
Constant *ConstantFoldExtractValueInstruction(Constant *Agg,
const unsigned *Idxs,
unsigned NumIdx);
Constant *ConstantFoldInsertValueInstruction(LLVMContext &Context,
Constant *Agg,
Constant *Val,
Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
const unsigned *Idxs,
unsigned NumIdx);
Constant *ConstantFoldBinaryInstruction(LLVMContext &Context,
unsigned Opcode, Constant *V1,
Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1,
Constant *V2);
Constant *ConstantFoldCompareInstruction(LLVMContext &Context,
unsigned short predicate,
Constant *ConstantFoldCompareInstruction(unsigned short predicate,
Constant *C1, Constant *C2);
Constant *ConstantFoldGetElementPtr(LLVMContext &Context, Constant *C,
bool inBounds,
Constant *ConstantFoldGetElementPtr(Constant *C, bool inBounds,
Constant* const *Idxs, unsigned NumIdx);
} // End llvm namespace

View File

@ -228,8 +228,7 @@ Constant::PossibleRelocationsTy Constant::getRelocationInfo() const {
/// type, returns the elements of the vector in the specified smallvector.
/// This handles breaking down a vector undef into undef elements, etc. For
/// constant exprs and other cases we can't handle, we return an empty vector.
void Constant::getVectorElements(LLVMContext &Context,
SmallVectorImpl<Constant*> &Elts) const {
void Constant::getVectorElements(SmallVectorImpl<Constant*> &Elts) const {
assert(isa<VectorType>(getType()) && "Not a vector constant!");
if (const ConstantVector *CV = dyn_cast<ConstantVector>(this)) {
@ -1139,7 +1138,7 @@ static inline Constant *getFoldedCast(
Instruction::CastOps opc, Constant *C, const Type *Ty) {
assert(Ty->isFirstClassType() && "Cannot cast to an aggregate type!");
// Fold a few common cases
if (Constant *FC = ConstantFoldCastInstruction(Ty->getContext(), opc, C, Ty))
if (Constant *FC = ConstantFoldCastInstruction(opc, C, Ty))
return FC;
LLVMContextImpl *pImpl = Ty->getContext().pImpl;
@ -1373,8 +1372,7 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
"Operand types in binary constant expression should match");
if (ReqTy == C1->getType() || ReqTy == Type::getInt1Ty(ReqTy->getContext()))
if (Constant *FC = ConstantFoldBinaryInstruction(ReqTy->getContext(),
Opcode, C1, C2))
if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
return FC; // Fold a few common cases...
std::vector<Constant*> argVec(1, C1); argVec.push_back(C2);
@ -1526,8 +1524,7 @@ Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
assert(!SelectInst::areInvalidOperands(C, V1, V2)&&"Invalid select operands");
if (ReqTy == V1->getType())
if (Constant *SC = ConstantFoldSelectInstruction(
ReqTy->getContext(), C, V1, V2))
if (Constant *SC = ConstantFoldSelectInstruction(C, V1, V2))
return SC; // Fold common cases
std::vector<Constant*> argVec(3, C);
@ -1547,9 +1544,8 @@ Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
cast<PointerType>(ReqTy)->getElementType() &&
"GEP indices invalid!");
if (Constant *FC = ConstantFoldGetElementPtr(
ReqTy->getContext(), C, /*inBounds=*/false,
(Constant**)Idxs, NumIdx))
if (Constant *FC = ConstantFoldGetElementPtr(C, /*inBounds=*/false,
(Constant**)Idxs, NumIdx))
return FC; // Fold a few common cases...
assert(isa<PointerType>(C->getType()) &&
@ -1575,9 +1571,8 @@ Constant *ConstantExpr::getInBoundsGetElementPtrTy(const Type *ReqTy,
cast<PointerType>(ReqTy)->getElementType() &&
"GEP indices invalid!");
if (Constant *FC = ConstantFoldGetElementPtr(
ReqTy->getContext(), C, /*inBounds=*/true,
(Constant**)Idxs, NumIdx))
if (Constant *FC = ConstantFoldGetElementPtr(C, /*inBounds=*/true,
(Constant**)Idxs, NumIdx))
return FC; // Fold a few common cases...
assert(isa<PointerType>(C->getType()) &&
@ -1633,8 +1628,7 @@ ConstantExpr::getICmp(unsigned short pred, Constant *LHS, Constant *RHS) {
assert(pred >= ICmpInst::FIRST_ICMP_PREDICATE &&
pred <= ICmpInst::LAST_ICMP_PREDICATE && "Invalid ICmp Predicate");
if (Constant *FC = ConstantFoldCompareInstruction(
LHS->getContext(), pred, LHS, RHS))
if (Constant *FC = ConstantFoldCompareInstruction(pred, LHS, RHS))
return FC; // Fold a few common cases...
// Look up the constant in the table first to ensure uniqueness
@ -1657,8 +1651,7 @@ ConstantExpr::getFCmp(unsigned short pred, Constant *LHS, Constant *RHS) {
assert(LHS->getType() == RHS->getType());
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && "Invalid FCmp Predicate");
if (Constant *FC = ConstantFoldCompareInstruction(
LHS->getContext(), pred, LHS, RHS))
if (Constant *FC = ConstantFoldCompareInstruction(pred, LHS, RHS))
return FC; // Fold a few common cases...
// Look up the constant in the table first to ensure uniqueness
@ -1678,8 +1671,7 @@ ConstantExpr::getFCmp(unsigned short pred, Constant *LHS, Constant *RHS) {
Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
Constant *Idx) {
if (Constant *FC = ConstantFoldExtractElementInstruction(
ReqTy->getContext(), Val, Idx))
if (Constant *FC = ConstantFoldExtractElementInstruction(Val, Idx))
return FC; // Fold a few common cases.
// Look up the constant in the table first to ensure uniqueness
std::vector<Constant*> ArgVec(1, Val);
@ -1701,8 +1693,7 @@ Constant *ConstantExpr::getExtractElement(Constant *Val, Constant *Idx) {
Constant *ConstantExpr::getInsertElementTy(const Type *ReqTy, Constant *Val,
Constant *Elt, Constant *Idx) {
if (Constant *FC = ConstantFoldInsertElementInstruction(
ReqTy->getContext(), Val, Elt, Idx))
if (Constant *FC = ConstantFoldInsertElementInstruction(Val, Elt, Idx))
return FC; // Fold a few common cases.
// Look up the constant in the table first to ensure uniqueness
std::vector<Constant*> ArgVec(1, Val);
@ -1727,8 +1718,7 @@ Constant *ConstantExpr::getInsertElement(Constant *Val, Constant *Elt,
Constant *ConstantExpr::getShuffleVectorTy(const Type *ReqTy, Constant *V1,
Constant *V2, Constant *Mask) {
if (Constant *FC = ConstantFoldShuffleVectorInstruction(
ReqTy->getContext(), V1, V2, Mask))
if (Constant *FC = ConstantFoldShuffleVectorInstruction(V1, V2, Mask))
return FC; // Fold a few common cases...
// Look up the constant in the table first to ensure uniqueness
std::vector<Constant*> ArgVec(1, V1);
@ -1761,8 +1751,7 @@ Constant *ConstantExpr::getInsertValueTy(const Type *ReqTy, Constant *Agg,
"insertvalue type invalid!");
assert(Agg->getType()->isFirstClassType() &&
"Non-first-class type for constant InsertValue expression");
Constant *FC = ConstantFoldInsertValueInstruction(
ReqTy->getContext(), Agg, Val, Idxs, NumIdx);
Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs, NumIdx);
assert(FC && "InsertValue constant expr couldn't be folded!");
return FC;
}
@ -1788,8 +1777,7 @@ Constant *ConstantExpr::getExtractValueTy(const Type *ReqTy, Constant *Agg,
"extractvalue indices invalid!");
assert(Agg->getType()->isFirstClassType() &&
"Non-first-class type for constant extractvalue expression");
Constant *FC = ConstantFoldExtractValueInstruction(
ReqTy->getContext(), Agg, Idxs, NumIdx);
Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs, NumIdx);
assert(FC && "ExtractValue constant expr couldn't be folded!");
return FC;
}