diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h index ccef4cbeabd..c93c514da6a 100644 --- a/include/llvm/DerivedTypes.h +++ b/include/llvm/DerivedTypes.h @@ -101,6 +101,12 @@ public: /// @brief Get the number of bits in this IntegerType unsigned getBitWidth() const { return getSubclassData(); } + /// This method determines if the width of this IntegerType is a power-of-2 + /// in terms of 8 bit bytes. + /// @returns true if this is a power-of-2 byte width. + /// @brief Is this a power-of-2 byte-width IntegerType ? + bool isPowerOf2ByteWidth() const; + // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const IntegerType *T) { return true; } static inline bool classof(const Type *T) { diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index 00e97520b7f..b41d1a0414e 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -975,6 +975,11 @@ const IntegerType *IntegerType::get(unsigned NumBits) { return ITy; } +bool IntegerType::isPowerOf2ByteWidth() const { + unsigned BitWidth = getBitWidth(); + return (BitWidth > 7 && Log2_32(BitWidth) == Log2_32_Ceil(BitWidth)); +} + // FunctionValType - Define a class to hold the key that goes into the TypeMap // namespace llvm {