[PATCH] D26196: AMDGPU: Translate null pointers in private and local addr space

John McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 2 16:41:43 PDT 2016


rjmccall added a comment.

I think there are a number of conceptual questions here, chiefly among them whether an llvm::ConstantPointerNull in an address-space type should have the correct representation for the target.  If the decision for that is "no", then ok, we can produce an explicit representation in IRGen; however, we will need to update quite a bit of code in order to do so correctly.

In general, frontend address spaces don't necessarily correspond to IR address spaces.  All of your address-space operations need to be parameterized with a frontend address space (or both a source and dest address space for conversions).  The question you should be keeping in mind when designing these APIs is "what if there were an address space defined to be exactly the generic address space, only with a different null value?"

IRGen has primitive knowledge about null pointer representations that are encoded in a bunch of places.  Among them are:

- Emitting zero-initialization.  Fortunately, we already have this well-abstracted because of C++; search for isZeroInitializable.
- Converting from a literal 0, nullptr_t etc. to a given pointer type; this is CK_NullToPointer.
- Source-level conversions of a pointer type to boolean; this is CK_PointerToBoolean.
- Inherent null-checks of pointer values; you'll need to search for CK_DerivedToBase and CK_BaseToDerived.

You will also need to verify that the AST-level constant evaluator correctly distinguishes between CK_NullToPointer and CK_IntegerToPointer.

I think you need to provide three basic operations on CodeGenTargetInfo:

- Get a null pointer value in a given address space as an llvm::Constant.
- Test whether a value in a given address space is a null value.
- Convert a value from one address space to another.  You'll need to make sure that everything in IRGen that does an address space conversion goes through this, and the default implementation should be the only thing that ever creates an LLVM addrspace cast.


https://reviews.llvm.org/D26196





More information about the cfe-commits mailing list