aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Instructions.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-04-14 00:12:57 +0000
committerChris Lattner <sabre@nondot.org>2007-04-14 00:12:57 +0000
commit6f771d435111cd943414ab570e9aec0c7a6c2954 (patch)
tree4a331f0ec578b15450e28e2f0144047bf81280c5 /lib/VMCore/Instructions.cpp
parent0468ab302537912264f61066fe8b780e52c7f5ef (diff)
downloadexternal_llvm-6f771d435111cd943414ab570e9aec0c7a6c2954.zip
external_llvm-6f771d435111cd943414ab570e9aec0c7a6c2954.tar.gz
external_llvm-6f771d435111cd943414ab570e9aec0c7a6c2954.tar.bz2
add GetElementPtrInst::hasAllZeroIndices, a long-overdue helper method.
Writing it twice in the same day was too much for me. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35978 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Instructions.cpp')
-rw-r--r--lib/VMCore/Instructions.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index f6abd85..bfda46d 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -966,6 +966,22 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
return PTy->getElementType();
}
+
+/// hasAllZeroIndices - Return true if all of the indices of this GEP are
+/// zeros. If so, the result pointer and the first operand have the same
+/// value, just potentially different types.
+bool GetElementPtrInst::hasAllZeroIndices() const {
+ for (unsigned i = 1, e = getNumOperands(); i != e; ++i) {
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(i))) {
+ if (!CI->isZero()) return false;
+ } else {
+ return false;
+ }
+ }
+ return true;
+}
+
+
//===----------------------------------------------------------------------===//
// ExtractElementInst Implementation
//===----------------------------------------------------------------------===//