[llvm] r189000 - Add a new helper method to Value to strip in-bounds constant offsets of

Duncan Sands duncan.sands at gmail.com
Mon Sep 16 05:07:02 PDT 2013


Hi Chandler,

On 22/08/13 13:25, Chandler Carruth wrote:
> Author: chandlerc
> Date: Thu Aug 22 06:25:11 2013
> New Revision: 189000
>
> URL: http://llvm.org/viewvc/llvm-project?rev=189000&view=rev
> Log:
> Add a new helper method to Value to strip in-bounds constant offsets of
> pointers, but accumulate the offset into an APInt in the process of
> stripping it.
>
> This is a pretty handy thing to have, such as when trying to determine
> if two pointers are at some constant relative offset. I'll be committing
> a patch shortly to use it for exactly that purpose.
>
> Modified:
>      llvm/trunk/include/llvm/IR/Value.h
>      llvm/trunk/lib/IR/Value.cpp
>


> --- llvm/trunk/lib/IR/Value.cpp (original)
> +++ llvm/trunk/lib/IR/Value.cpp Thu Aug 22 06:25:11 2013
> @@ -393,6 +393,40 @@ Value *Value::stripInBoundsConstantOffse
>     return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(this);
>   }
>
> +Value *Value::stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,
> +                                                        APInt &Offset) {
> +  if (!getType()->isPointerTy())
> +    return this;
> +
> +  assert(Offset.getBitWidth() == DL.getPointerSizeInBits(cast<PointerType>(
> +                                     getType())->getAddressSpace()) &&
> +         "The offset must have exactly as many bits as our pointer.");

Is there really no neater way of getting the pointer size in bits?  If not,
maybe add a helper for that?

Ciao, Duncan.



More information about the llvm-commits mailing list