Make SpirvValue
(Kind
) representation and operations more orthogonal and robust (lossless).
#348
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SpirvValue
, and especiallySpirvValueKind
, have been serving several purposes so far:struct SpirvValue { kind: SpirvValueKind, ty: ... }
before this PR)SpirvConst
s (already have some of that done for later PRs)SpirvValueKind::IllegalConst
, aSpan
isn't known initially at all(so there's a need to defer until the time of
SpirvValue::def
, which may bring aSpan
)SpirvValue::strip_ptrcasts
undo pointer castsSpirvValueKind::LogicalPtrCast
contains the value and type IDs for aSpirvValue
(
SpirvValue { kind: SpirvValueKind::Def(original_ptr), ty: original_ptr_ty }
)That has grown ad-hoc, and it can be a nightmare to extend any part of it, hence this work.
More specifically, this PR:
Span
at mostbool
field (zombie_waiting_for_span
) replacesSpirvValueKind::IllegalConst
SpirvValue::def
(which is called everywhere to obtain a SPIR-V ID)only has to check a
bool
(for registering theSpan
), no more string formattingto generate the string message themselves, but it's unclear if that was ever skipped
(and I wasn't able to observe any change in build times, tho more testing is welcome)
SpirvValueKind::LogicalPtrCast
with an equivalentOption
inSpirvValueKind::Def
SpirvValue
generic and reusing it,SpirvValue::strip_ptrcasts
becomessimpler and combining it with
pointercast
is now lossless (wrt other details)SpirvValue
that is simultaneously like the oldSpirvValueKind::IllegalConst
andSpirvValueKind::LogicalPtrCast
at the same time(arguably the main motivation for this PR, specifically as a
const_bitcast
result)SpirvValue
s in theSpirvConst
<->SPIR-V ID "const interning" mapsSpirvValue
's new generic param),this removes all duplicated logic around "deriving
SpirvValue
for a constant"(i.e. what used to decide whether
SpirvValueKind::IllegalConst
should be used)SpirvValue::const_fold_load
becomes trivial, but even more important, lossless(returning the same exact
SpirvValue
as the originalSpirvConst
did)