From 6f6103c4dbc77d5bceae7c8e766ec3cabc293364 Mon Sep 17 00:00:00 2001 From: Julius Ikkala Date: Sat, 3 May 2025 23:27:03 +0300 Subject: Add IREnumType to distinguish enums from ints and each other (#6973) * Add IREnumType to distinguish enums from ints and each other * Add issue example as test * format code * Add expected test output * Fix peephole optimization hanging No idea why this PR triggered this, but there seems to have been a clear bug here anyway, so may just as well fix it now. * Move enum lowering later * Add linkage decoration to enum type * Use filecheck-buffer instead of expected.txt * Fix comment * Make enum casts actually use IR enum casts They were all BuiltinCasts by accident * Lower enum type before VM * Deal with rate-qualified types in enum cast * Allow any value marshalling for enum types * Handle new enum instructions in a couple more switches * Fix formatting --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-emit.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source/slang/slang-emit.cpp') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index aa7387e22..ac6336e9c 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -72,6 +72,7 @@ #include "slang-ir-lower-combined-texture-sampler.h" #include "slang-ir-lower-coopvec.h" #include "slang-ir-lower-dynamic-resource-heap.h" +#include "slang-ir-lower-enum-type.h" #include "slang-ir-lower-generics.h" #include "slang-ir-lower-glsl-ssbo-types.h" #include "slang-ir-lower-l-value-cast.h" @@ -312,6 +313,7 @@ struct RequiredLoweringPassSet bool debugInfo; bool resultType; bool optionalType; + bool enumType; bool combinedTextureSamplers; bool reinterpret; bool generics; @@ -356,6 +358,9 @@ void calcRequiredLoweringPassSet( case kIROp_OptionalType: result.optionalType = true; break; + case kIROp_EnumType: + result.enumType = true; + break; case kIROp_TextureType: if (!isKhronosTarget(codeGenContext->getTargetReq())) { @@ -1159,6 +1164,9 @@ Result linkAndOptimizeIR( cleanupGenerics(targetProgram, irModule, sink); dumpIRIfEnabled(codeGenContext, irModule, "AFTER-LOWER-GENERICS"); + if (requiredLoweringPassSet.enumType) + lowerEnumType(irModule, sink); + // Don't need to run any further target-dependent passes if we are generating code // for host vm. if (target == CodeGenTarget::HostVM) -- cgit v1.2.3