[llvm-commits] [llvm] r165726 - in /llvm/trunk: include/llvm-c/ include/llvm/ include/llvm/Target/ include/llvm/Transforms/Utils/ lib/Analysis/ lib/CodeGen/ lib/CodeGen/AsmPrinter/ lib/CodeGen/SelectionDAG/ lib/ExecutionEngine/ lib/ExecutionEngine/Interpreter/ lib/ExecutionEngine/JIT/ lib/Target/ lib/Target/ARM/ lib/Target/MBlaze/ lib/Target/MSP430/ lib/Target/NVPTX/ lib/Target/PowerPC/ lib/Target/X86/ lib/Transforms/InstCombine/ lib/Transforms/Instrumentation/ lib/Transforms/Scalar/ lib/Transforms/Utils/

Duncan Sands baldrick at free.fr
Thu Oct 11 10:42:49 PDT 2012


Hi Micah,

> Add in the first iteration of support for llvm/clang/lldb to allow variable per address space pointer sizes to be optimized correctly.


> --- llvm/trunk/include/llvm/DataLayout.h (original)
> +++ llvm/trunk/include/llvm/DataLayout.h Thu Oct 11 12:21:41 2012
> @@ -231,9 +231,7 @@
>     }
>
>     /// Layout pointer alignment
> -  /// FIXME: The defaults need to be removed once all of
> -  /// the backends/clients are updated.
> -  unsigned getPointerABIAlignment(unsigned AS = 0)  const {
> +  unsigned getPointerABIAlignment(unsigned AS)  const {

Mysterious number of spaces before "const".

>       DenseMap<unsigned, PointerAlignElem>::const_iterator val = Pointers.find(AS);
>       if (val == Pointers.end()) {
>         val = Pointers.find(0);
> @@ -251,9 +247,7 @@
>       return val->second.PrefAlign;
>     }
>     /// Layout pointer size
> -  /// FIXME: The defaults need to be removed once all of
> -  /// the backends/clients are updated.
> -  unsigned getPointerSize(unsigned AS = 0)          const {
> +  unsigned getPointerSize(unsigned AS)          const {

Even more mysterious!

>       DenseMap<unsigned, PointerAlignElem>::const_iterator val = Pointers.find(AS);
>       if (val == Pointers.end()) {
>         val = Pointers.find(0);
> @@ -261,9 +255,7 @@
>       return val->second.TypeBitWidth;
>     }
>     /// Layout pointer size, in bits
> -  /// FIXME: The defaults need to be removed once all of
> -  /// the backends/clients are updated.
> -  unsigned getPointerSizeInBits(unsigned AS = 0)    const {
> +  unsigned getPointerSizeInBits(unsigned AS)    const {

Likewise.

>       DenseMap<unsigned, PointerAlignElem>::const_iterator val = Pointers.find(AS);
>       if (val == Pointers.end()) {
>         val = Pointers.find(0);
>
> Modified: llvm/trunk/include/llvm/Instructions.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=165726&r1=165725&r2=165726&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Instructions.h (original)
> +++ llvm/trunk/include/llvm/Instructions.h Thu Oct 11 12:21:41 2012
> @@ -350,7 +350,16 @@
>     static unsigned getPointerOperandIndex() { return 1U; }
>
>     unsigned getPointerAddressSpace() const {
> -    return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
> +    if (getPointerOperand()->getType()->isPointerTy())
> +      return cast<PointerType>(getPointerOperand()->getType())
> +        ->getAddressSpace();
> +    if (getPointerOperand()->getType()->isVectorTy()
> +        && cast<VectorType>(getPointerOperand()->getType())->isPointerTy())
> +      return cast<PointerType>(cast<VectorType>(
> +            getPointerOperand()->getType())->getElementType())
> +        ->getAddressSpace();
 > +    llvm_unreachable("Only a vector of pointers or pointers can be used!");
 > +    return 0;

This ugliness could be simplified using getScalarType and local variables
thusly:

    Type *EltTy = 
dyn_cast<PointerType>(getPointerOperand()->getType()->getScalarType());
    assert(EltTy && "Only a vector of pointers or pointers can be used!");
    return EltTy->getAddressSpace();


>     }
>
>     // Methods for support type inquiry through isa, cast, and dyn_cast:
> @@ -3653,7 +3662,15 @@
>
>     /// @brief return the address space of the pointer.
>     unsigned getAddressSpace() const {
> -    return cast<PointerType>(getType())->getAddressSpace();
> +    if (getType()->isPointerTy())
> +      return cast<PointerType>(getType())->getAddressSpace();
> +    if (getType()->isVectorTy() &&
> +        cast<VectorType>(getType())->getElementType()->isPointerTy())
> +      return cast<PointerType>(
> +          cast<VectorType>(getType())->getElementType())
> +        ->getAddressSpace();
> +    llvm_unreachable("Must be a pointer or a vector of pointers.");
> +    return 0;

Likewise.

>     }
>
>     // Methods for support type inquiry through isa, cast, and dyn_cast:
> @@ -3695,7 +3712,16 @@
>
>     /// @brief return the address space of the pointer.
>     unsigned getPointerAddressSpace() const {
> -    return cast<PointerType>(getOperand(0)->getType())->getAddressSpace();
> +    Type *Ty = getOperand(0)->getType();
> +    if (Ty->isPointerTy())
> +      return cast<PointerType>(Ty)->getAddressSpace();
> +    if (Ty->isVectorTy()
> +        && cast<VectorType>(Ty)->getElementType()->isPointerTy())
> +      return cast<PointerType>(
> +          cast<VectorType>(Ty)->getElementType())
> +        ->getAddressSpace();
> +    llvm_unreachable("Must be a pointer or a vector of pointers.");
> +    return 0;

And so on.

>     }
>
>     // Methods for support type inquiry through isa, cast, and dyn_cast:
>

I didn't look at the rest.

Ciao, Duncan.



More information about the llvm-commits mailing list