This is an archive of the discontinued LLVM Phabricator instance.

Make typed pointers to be yet again recognized as pointers
ClosedPublic

Authored by sidorovd on Oct 26 2022, 7:45 AM.

Diff Detail

Event Timeline

sidorovd created this revision.Oct 26 2022, 7:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 26 2022, 7:45 AM
sidorovd requested review of this revision.Oct 26 2022, 7:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 26 2022, 7:45 AM
nikic requested changes to this revision.Oct 26 2022, 7:59 AM

Why do you need this? Typed pointers have very limited use as a representational convenience. They should not be recognized or handled like normal pointers.

This revision now requires changes to proceed.Oct 26 2022, 7:59 AM
sidorovd added a comment.EditedOct 26 2022, 8:07 AM

Why do you need this? Typed pointers have very limited use as a representational convenience. They should not be recognized or handled like normal pointers.

I'm trying to construct a vector of pointers in the patch in the related project that does a translation of LLVM IR to SPIR-V (if you are interested here it is: https://github.com/KhronosGroup/SPIRV-LLVM-Translator/pull/1669 ). As for now SPIR-V doesn't have opaque pointers and hence this vector needs to be created with typed pointers. Like this I'm getting an assert "Element type of a VectorType must be an integer, floating point, or pointer type.", which is a bit weird from my perspective. Probably this fix is not the best (or may be just wrong), but I don't see any reasons to not allow creating of a typed pointer vector. So I'm keen to hear your opinion.

I'm similarly skeptical that this is the best way to go about the problem. Making typed pointers qualify under isPointerTy() potentially breaks a lot of code that assumes isPointerTy() means that it is indeed a PointerType, although this is ameliorated to some degree by the hard prohibition llvm::Value has on construction types with TypedPointerType.

If the problem is that vector types cannot be constructed with typed pointer types as element types, then the best fix is probably to adjust VectorType::isValidElementType to allow typed pointer types as well (and adjust the checkType assertion for Value to check !isa<TypedPointerType>(Ty->getScalarType()) to ensure that vectors-of-typed-pointer-types don't leak into IR).

sidorovd updated this revision to Diff 471128.Oct 27 2022, 4:57 AM
sidorovd added a comment.EditedOct 27 2022, 4:57 AM

@nikic hi, would the current revision be more acceptable?

nikic accepted this revision.Oct 27 2022, 7:08 AM

This looks okay, but it would be good for @jcranmer-intel to confirm that this is strictly required.

This revision is now accepted and ready to land.Oct 27 2022, 7:08 AM
jcranmer-intel accepted this revision.Oct 27 2022, 8:33 AM

Thanks! Probably the name of the commit should be not "Make typed pointers to be yet again recognized as pointers" but "Allow typed pointers to be base of VectorType". I don't have merge rights in llvm.org, so it would be nice if someone helps with merging.

This revision was automatically updated to reflect the committed changes.