Why no setAddressSpace method?

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); }

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