[llvm-commits] [llvm] r123381 - in /llvm/trunk: lib/Transforms/Scalar/ScalarReplAggregates.cpp test/Transforms/ScalarRepl/copy-aggregate.ll

Frits van Bommel fvbommel at gmail.com
Thu Jan 13 10:18:47 PST 2011


On Thu, Jan 13, 2011 at 6:45 PM, Bob Wilson <bob.wilson at apple.com> wrote:
> +/// isHomogeneousAggregate - Check if type T is a struct or array containing
> +/// elements of the same type (which is always true for arrays).  If so,
> +/// return true with NumElts and EltTy set to the number of elements and the
> +/// element type, respectively.
> +static bool isHomogeneousAggregate(const Type *T, unsigned &NumElts,
> +                                   const Type *&EltTy) {
> +  if (const ArrayType *AT = dyn_cast<ArrayType>(T)) {
> +    NumElts = AT->getNumElements();
> +    EltTy = AT->getElementType();
> +    return true;
> +  }
> +  if (const StructType *ST = dyn_cast<StructType>(T)) {
> +    NumElts = ST->getNumContainedTypes();
> +    EltTy = ST->getContainedType(0);

I don't think that works for empty structs...

> +    for (unsigned n = 1; n < NumElts; ++n) {
> +      if (ST->getContainedType(n) != EltTy)
> +        return false;
> +    }
> +    return true;
> +  }
> +  return false;
> +}




More information about the llvm-commits mailing list