summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-specialize.cpp
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2024-04-19 16:43:21 -0700
committerGitHub <noreply@github.com>2024-04-19 16:43:21 -0700
commit2da28c50d9c3699692eccde4b86d0b8d2323e55c (patch)
tree6c12a4673210f833c38c147e7b937f1a14dec519 /source/slang/slang-ir-specialize.cpp
parente0aa53fb01aa550219c6f71644e6e7a1202b90b3 (diff)
Support arithmetics on generic arguments (#3968)
Resovles an issue #3935 Slang had to fold the generic arguments after specialization.
Diffstat (limited to 'source/slang/slang-ir-specialize.cpp')
-rw-r--r--source/slang/slang-ir-specialize.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/source/slang/slang-ir-specialize.cpp b/source/slang/slang-ir-specialize.cpp
index a4985eee4..72e39590b 100644
--- a/source/slang/slang-ir-specialize.cpp
+++ b/source/slang/slang-ir-specialize.cpp
@@ -7,6 +7,7 @@
#include "slang-ir-ssa-simplification.h"
#include "slang-ir-lower-witness-lookup.h"
#include "slang-ir-dce.h"
+#include "slang-ir-sccp.h"
#include "../core/slang-performance-profiler.h"
namespace Slang
@@ -211,7 +212,29 @@ struct SpecializationContext
IRGeneric* genericVal,
IRSpecialize* specializeInst)
{
- // First, we want to see if an existing specialization
+ // We need to fold the generic arguments here in order to uniquely identify
+ // which specializations need to be generated.
+ // The folding of the generic-arguments are deferred until the specialization
+ // step here, because the exact value of the generic-arguments can be unknown
+ // until the specialization. The exact values of the generic-arguments may come
+ // from the other modules, and they will be unknown until linking the modules.
+ //
+ UInt argCount = specializeInst->getArgCount();
+ {
+ IRBuilder builder(module);
+ for (UInt ii = 0; ii < argCount; ++ii)
+ {
+ IRUse* argUse = specializeInst->getArgOperand(ii);
+ auto originalArg = argUse->get();
+ IRInst* foldedArg = tryConstantFoldInst(module, originalArg);
+ if (foldedArg == originalArg)
+ continue;
+
+ specializeInst = as<IRSpecialize>(builder.replaceOperand(argUse, foldedArg));
+ }
+ }
+
+ // We want to see if an existing specialization
// has already been made. To do that we will construct a key
// for lookup in the generic specialization context.
//
@@ -223,7 +246,6 @@ struct SpecializationContext
//
Key key;
key.vals.add(specializeInst->getBase());
- UInt argCount = specializeInst->getArgCount();
for (UInt ii = 0; ii < argCount; ++ii)
{
key.vals.add(specializeInst->getArg(ii));