[PATCH] D135202: [IR] Add an opaque type to LLVM.
Joshua Cranmer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 14 11:30:10 PDT 2022
jcranmer-intel added a comment.
In D135202#3855371 <https://reviews.llvm.org/D135202#3855371>, @nhaehnle wrote:
> Here's a random thought: what if the types are parameterized using metadata instead of ints?
My original thought was using `ConstantInt`, actually, and that should in principle be relatively easy to parse. Getting the integer value out of metadata is a pretty circuitous route, and if you want arbitrary-sized integers, `ConstantInt` or an `APInt` are much simpler routes.
One downside with `ConstantInt` is that it implies the *size* of the integer matters for distinguishing types (e.g., `ext("a", i32 10)` is not the same as `ext("a", i64 10)`). That makes `APInt` seem a better solution to me than `ConstantInt`, but I'm not entirely certain the extra flexibility over a bare `unsigned` is necessary--if it does turn out to be the case, upgrading `unsigned` to `APInt` could still be done without substantial changes to syntax or API.
================
Comment at: llvm/lib/IR/Constants.cpp:1092
+ if (isa<OpaqueType>(Ty))
+ return ElementCount::getNull();
return ElementCount::getFixed(Ty->getStructNumElements());
----------------
nhaehnle wrote:
> jcranmer-intel wrote:
> > nikic wrote:
> > > This looks pretty dubious. We probably shouldn't be modelling opaque types using ConstantAggregateZero, as it is not an aggregate type.
> > >
> > > Is zeroinitializer support actually required?
> > Yes, for at least some of the types. (https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpConstantNull lists the opaque types for which something like null exists).
> >
> > I agree that `ConstantAggregateZero` is somewhat dubious as a class, but it seemed more fitting than any other class, not least of which being the fact that it causes `zeroinitializer` to work without any extra effort.
> >
> > I'm open to suggestions as to what to name a new zeroinitializer class for opaque pointers--I don't have any great names off my head.
> Would an intrinsic that returns the null value work? Or are null initializers also allowed in global variables?
Global variable null initializers are I believe necessary.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D135202/new/
https://reviews.llvm.org/D135202
More information about the llvm-commits
mailing list