[LLVMdev] Why no setAddressSpace method?

Benjamin Kramer benny.kra at googlemail.com
Sun Jun 10 03:18:48 PDT 2012


On 10.06.2012, at 02:25, Dmitry N. Mikushin wrote:

> Dear LLVM,
> 
> A minor thing.
> 
> During opt passes it is sometimes needed to adjust the pointer address space. However, I've noticed PointerType in LLVM has only get accessor, and clang has its initial setter. Maybe better to
> 
> --- DerivedTypes.h    (revision 156703)
> +++ DerivedTypes.h    (working copy)
> @@ -450,6 +450,9 @@
>    /// @brief Return the address space of the Pointer type.
>    inline unsigned getAddressSpace() const { return getSubclassData(); }
>  
> +  /// @brief Set the address space of the Pointer type.
> +  inline void setAddressSpace(unsigned addrspace) { setSubclassData(addrspace); }
> +
>    // Implement support type inquiry through isa, cast, and dyn_cast.
>    static inline bool classof(const PointerType *) { return true; }
>    static inline bool classof(const Type *T) {
> 
> - is it wrong or undesired by some reason? This way it would be exposed to all frontends and opt passes.

The idea is that types are uniqued by the LLVMContext and immutable afterwards. If you mutate a type you'll change all instances of the type used in the context and it may confuse the uniquing logic.

If you want to change the address space you have to create a new type

PointerType::get(OldType->getElementType(), NewAddressSpace)

and recreate the affected instructions.

- Ben





More information about the llvm-dev mailing list