summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Constants.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-08-03 22:07:33 +0000
committerDan Gohman <gohman@apple.com>2009-08-03 22:07:33 +0000
commitf011f5a8a20dc04cd87eb9ce8ae857299ea91c6b (patch)
tree45837b51f5056ef4e8d3508ed4d0405ee6d90e06 /llvm/lib/VMCore/Constants.cpp
parentfeb01a100b305be28d698742d50dce1784985cfb (diff)
downloadbcm5719-llvm-f011f5a8a20dc04cd87eb9ce8ae857299ea91c6b.tar.gz
bcm5719-llvm-f011f5a8a20dc04cd87eb9ce8ae857299ea91c6b.zip
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. llvm-svn: 78005
Diffstat (limited to 'llvm/lib/VMCore/Constants.cpp')
-rw-r--r--llvm/lib/VMCore/Constants.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 7482154d839..e02e28a87ee 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -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(),
OpenPOWER on IntegriCloud