Add a new Constant::getIntegerValue helper function, and convert a

few places in InstCombine to use it, to fix problems handling pointer
types. This fixes the recent llvm-gcc bootstrap error.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78005 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2009-08-03 22:07:33 +00:00
parent c8bfb7a49d
commit 43ee5f7c08
4 changed files with 111 additions and 8 deletions

View File

@@ -70,6 +70,23 @@ Constant* Constant::getNullValue(const Type* Ty) {
}
}
Constant* Constant::getIntegerValue(const Type* Ty, const APInt &V) {
const Type *ScalarTy = Ty->getScalarType();
// Create the base integer constant.
Constant *C = ConstantInt::get(Ty->getContext(), V);
// Convert an integer to a pointer, if necessary.
if (const PointerType *PTy = dyn_cast<PointerType>(ScalarTy))
C = ConstantExpr::getIntToPtr(C, PTy);
// Broadcast a scalar to a vector, if necessary.
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
C = ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
return C;
}
Constant* Constant::getAllOnesValue(const Type* Ty) {
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
return ConstantInt::get(Ty->getContext(),