Request explanation about non-integral pointer type

Hi all,

Can you please explain to me Non-integral pointer type in simple terms with an example. The documentation which explains it is not unclear to me.

Thank you,
Kavindu

Some HW may have pointers that contains more than the memory address as an integer. In such a model the pointer value is “opaque” the pointer in itself can’t be just manipulated as an integer like you’d think you can do with a “naive C mental model”.
This may help to understand: https://llvm.org/devmtg/2015-02/slides/chisnall-pointers-not-int.pdf

1 Like

Another example is a relocating (aka “copying”) garbage collector.

A copying GC is free to move an object around in the heap as long as it updates all pointers pointing to said object. This means while a pointer always points to a specific object (and you can perform usual memory optimizations like CSEing loads), the actual bitwise value of the pointer may change arbitrarily.

1 Like

@mehdi_amini and @sanjoy_das_google Thank you. Did understood the basic concept of the non-integral pointer type.

In LLVM, why do we use specific address space for non-integral pointer types (ni in datalayout string)?
Is this related to LLVM compiler front end?

I suspect the use of separate address space helped by isolating this non-usual feature as more of an “opt-in”. That way LLVM optimizers can assume that pointers in the default namespace are “regular” and only needs to be conservative for the cases where they are present.

1 Like

I have another question. Highly appreciate your input on this.

If I specify a non-default address space in LLVM IR (Let’s say we use address space 1 for GC statepoint-example as shown here), can we remove that address space at some point in the LLVM pipeline?

Because I have seen in Julia and gollvm, there are passes to remove address spaces and address space casts. As far as I understood this pass are run after optimization phases.

@mehdi_amini and @sanjoy_das_google, can you please check the above problem?

Address space may be fairly backend specific, I’m not sure.

1 Like