diff options
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/Constants.h | 4 | ||||
| -rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 11 |
2 files changed, 15 insertions, 0 deletions
diff --git a/llvm/include/llvm/Constants.h b/llvm/include/llvm/Constants.h index 4c497b6f58b..c8552395313 100644 --- a/llvm/include/llvm/Constants.h +++ b/llvm/include/llvm/Constants.h @@ -438,6 +438,10 @@ public: /// @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); diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index 350a306d797..9c1377dbd7b 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -1286,6 +1286,17 @@ bool ConstantVector::isAllOnesValue() const { 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... // |

