Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C,
ArrayRef<Value *> Idxs, bool InBounds,
Type *OnlyIfReducedTy) {
- if (Constant *FC = ConstantFoldGetElementPtr(C, InBounds, Idxs))
- return FC; // Fold a few common cases.
-
if (!Ty)
Ty = cast<PointerType>(C->getType()->getScalarType())->getElementType();
else
- assert(Ty ==
- cast<PointerType>(C->getType()->getScalarType())->getElementType());
+ assert(
+ Ty ==
+ cast<PointerType>(C->getType()->getScalarType())->getContainedType(0u));
+
+ if (Constant *FC = ConstantFoldGetElementPtr(Ty, C, InBounds, Idxs))
+ return FC; // Fold a few common cases.
+
// Get the result type of the getelementptr!
Type *DestTy = GetElementPtrInst::getIndexedType(Ty, Idxs);
assert(DestTy && "GEP indices invalid!");
ArgVec.push_back(cast<Constant>(Idxs[i]));
}
const ConstantExprKeyType Key(Instruction::GetElementPtr, ArgVec, 0,
- InBounds ? GEPOperator::IsInBounds : 0);
+ InBounds ? GEPOperator::IsInBounds : 0, None,
+ Ty);
LLVMContextImpl *pImpl = C->getContext().pImpl;
return pImpl->ExprConstants.getOrCreate(ReqTy, Key);
return Instruction::getOpcodeName(getOpcode());
}
-
-
-GetElementPtrConstantExpr::
-GetElementPtrConstantExpr(Constant *C, ArrayRef<Constant*> IdxList,
- Type *DestTy)
- : ConstantExpr(DestTy, Instruction::GetElementPtr,
- OperandTraits<GetElementPtrConstantExpr>::op_end(this)
- - (IdxList.size()+1), IdxList.size()+1) {
- OperandList[0] = C;
+GetElementPtrConstantExpr::GetElementPtrConstantExpr(
+ Type *SrcElementTy, Constant *C, ArrayRef<Constant *> IdxList, Type *DestTy)
+ : ConstantExpr(DestTy, Instruction::GetElementPtr,
+ OperandTraits<GetElementPtrConstantExpr>::op_end(this) -
+ (IdxList.size() + 1),
+ IdxList.size() + 1),
+ SrcElementTy(SrcElementTy) {
+ Op<0>() = C;
for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
OperandList[i+1] = IdxList[i];
}
+Type *GetElementPtrConstantExpr::getSourceElementType() const {
+ return SrcElementTy;
+}
+
//===----------------------------------------------------------------------===//
// ConstantData* implementations