[llvm-commits] [llvm] r43076 - in /llvm/trunk: include/llvm/Constants.h lib/VMCore/Constants.cpp
Dan Gohman
djg at cray.com
Wed Oct 17 10:51:31 PDT 2007
Author: djg
Date: Wed Oct 17 12:51:30 2007
New Revision: 43076
URL: http://llvm.org/viewvc/llvm-project?rev=43076&view=rev
Log:
Define a helper function ConstantVector::getSplatValue for testing for
and working with broadcasted constants.
Modified:
llvm/trunk/include/llvm/Constants.h
llvm/trunk/lib/VMCore/Constants.cpp
Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=43076&r1=43075&r2=43076&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Wed Oct 17 12:51:30 2007
@@ -438,6 +438,10 @@
/// @brief Determine if the value is all ones.
bool isAllOnesValue() const;
+ /// getSplatValue - If this is a splat constant, meaning that all of the
+ /// elements have the same value, return that value. Otherwise return NULL.
+ Constant *getSplatValue();
+
virtual void destroyConstant();
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=43076&r1=43075&r2=43076&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Wed Oct 17 12:51:30 2007
@@ -1286,6 +1286,17 @@
return true;
}
+/// getSplatValue - If this is a splat constant, where all of the
+/// elements have the same value, return that value. Otherwise return null.
+Constant *ConstantVector::getSplatValue() {
+ // Check out first element.
+ Constant *Elt = getOperand(0);
+ // Then make sure all remaining elements point to the same value.
+ for (unsigned I = 1, E = getNumOperands(); I < E; ++I)
+ if (getOperand(I) != Elt) return 0;
+ return Elt;
+}
+
//---- ConstantPointerNull::get() implementation...
//
More information about the llvm-commits
mailing list