+Constant *ConstantExpr::getInsertValueTy(const Type *ReqTy, Constant *Agg,
+ Constant *Val,
+ const unsigned *Idxs, unsigned NumIdx) {
+ assert(ExtractValueInst::getIndexedType(Agg->getType(), Idxs,
+ Idxs+NumIdx) == Val->getType() &&
+ "insertvalue indices invalid!");
+ assert(Agg->getType() == ReqTy &&
+ "insertvalue type invalid!");
+ assert(Agg->getType()->isFirstClassType() &&
+ "Non-first-class type for constant InsertValue expression");
+ if (Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs, NumIdx))
+ return FC; // Fold a few common cases...
+ // Look up the constant in the table first to ensure uniqueness
+ std::vector<Constant*> ArgVec;
+ ArgVec.push_back(Agg);
+ ArgVec.push_back(Val);
+ SmallVector<unsigned, 4> Indices(Idxs, Idxs + NumIdx);
+ const ExprMapKeyType Key(Instruction::InsertValue, ArgVec, 0, Indices);
+ return ExprConstants->getOrCreate(ReqTy, Key);
+}
+
+Constant *ConstantExpr::getInsertValue(Constant *Agg, Constant *Val,
+ const unsigned *IdxList, unsigned NumIdx) {
+ assert(Agg->getType()->isFirstClassType() &&
+ "Tried to create insertelement operation on non-first-class type!");
+
+ const Type *ReqTy = Agg->getType();
+ const Type *ValTy =
+ ExtractValueInst::getIndexedType(Agg->getType(), IdxList, IdxList+NumIdx);
+ assert(ValTy == Val->getType() && "insertvalue indices invalid!");
+ return getInsertValueTy(ReqTy, Agg, Val, IdxList, NumIdx);
+}
+
+Constant *ConstantExpr::getExtractValueTy(const Type *ReqTy, Constant *Agg,
+ const unsigned *Idxs, unsigned NumIdx) {
+ assert(ExtractValueInst::getIndexedType(Agg->getType(), Idxs,
+ Idxs+NumIdx) == ReqTy &&
+ "extractvalue indices invalid!");
+ assert(Agg->getType()->isFirstClassType() &&
+ "Non-first-class type for constant extractvalue expression");
+ if (Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs, NumIdx))
+ return FC; // Fold a few common cases...
+ // Look up the constant in the table first to ensure uniqueness
+ std::vector<Constant*> ArgVec;
+ ArgVec.push_back(Agg);
+ SmallVector<unsigned, 4> Indices(Idxs, Idxs + NumIdx);
+ const ExprMapKeyType Key(Instruction::ExtractValue, ArgVec, 0, Indices);
+ return ExprConstants->getOrCreate(ReqTy, Key);
+}
+
+Constant *ConstantExpr::getExtractValue(Constant *Agg,
+ const unsigned *IdxList, unsigned NumIdx) {
+ assert(Agg->getType()->isFirstClassType() &&
+ "Tried to create extractelement operation on non-first-class type!");
+
+ const Type *ReqTy =
+ ExtractValueInst::getIndexedType(Agg->getType(), IdxList, IdxList+NumIdx);
+ assert(ReqTy && "extractvalue indices invalid!");
+ return getExtractValueTy(ReqTy, Agg, IdxList, NumIdx);
+}
+
+Constant *ConstantExpr::getZeroValueForNegationExpr(const Type *Ty) {
+ if (const VectorType *PTy = dyn_cast<VectorType>(Ty))
+ if (PTy->getElementType()->isFloatingPoint()) {
+ std::vector<Constant*> zeros(PTy->getNumElements(),
+ ConstantFP::getNegativeZero(PTy->getElementType()));
+ return ConstantVector::get(PTy, zeros);
+ }
+
+ if (Ty->isFloatingPoint())
+ return ConstantFP::getNegativeZero(Ty);
+
+ return Constant::getNullValue(Ty);
+}
+