Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
0c8f5c4
Initial working data-flow-based dynamic-dispatch pass
saipraveenb25 Jul 17, 2025
41c998c
Expand implementation to also handle inter-procedural edges
saipraveenb25 Jul 20, 2025
e7ecb75
More tests + fixes (generic interfaces & dependent associated types s…
saipraveenb25 Jul 23, 2025
feaa2fa
Make test files work with slang-test add CHECK statements
saipraveenb25 Jul 23, 2025
d13f3d7
Simplify the inst states
saipraveenb25 Jul 23, 2025
2543391
Bottleneck info updates through a single func
saipraveenb25 Jul 23, 2025
3e38e82
Use more granular work items (inst-level) + add support for `createDy…
saipraveenb25 Jul 23, 2025
de04cd8
Further simplify: Use IR insts instead of hash-sets to avoid repeated…
saipraveenb25 Jul 24, 2025
ca8886b
Integrate into specialization pass + add initial support for propagat…
saipraveenb25 Jul 24, 2025
47f7786
Make propagation map use insts-with-context
saipraveenb25 Jul 24, 2025
f07726f
Improve context-sensitive analysis. Concrete specialization of dynami…
saipraveenb25 Jul 25, 2025
0f81310
Add lowering of specialization contexts by specializing generic param…
saipraveenb25 Jul 28, 2025
9c53d1f
Update slang-emit.cpp
saipraveenb25 Jul 28, 2025
c3f57df
Support data-flow and lowering for inout/out function parameters
saipraveenb25 Jul 29, 2025
1b50349
Delete slang-vscode.natvis
saipraveenb25 Jul 29, 2025
a2923fd
Delete sample.slang
saipraveenb25 Jul 29, 2025
2ae4b83
Minor fixes
saipraveenb25 Jul 29, 2025
b58f2e8
Use IR ops instead of a custom struct to track type flow data.
saipraveenb25 Jul 29, 2025
7cd7d71
Halfway through refactoring the code to split analysis and lowering
saipraveenb25 Jul 31, 2025
015e93b
Dispatch tests passing with overhauled approach
saipraveenb25 Aug 4, 2025
a716f4d
Delete commented-out lines
saipraveenb25 Aug 4, 2025
89794ff
More fixes to get dynamic dispatch tests passing
saipraveenb25 Aug 5, 2025
10b8118
Fix up to get all dynamic-dispatch tests to pass
saipraveenb25 Aug 5, 2025
2f85889
Multiple fixes to auto-diff and specialization pass. All dynamic-disp…
saipraveenb25 Aug 7, 2025
1d99777
More test fixes (COM interfaces are properly left alone now)
saipraveenb25 Aug 8, 2025
b579ea2
Fix up for one more test
saipraveenb25 Aug 11, 2025
11a1fee
Remove commented out code.
saipraveenb25 Aug 11, 2025
8f1c28b
Remove unused function
saipraveenb25 Aug 11, 2025
e3081fe
Fix formatting and warnings
saipraveenb25 Aug 11, 2025
5f3b841
Update slang-ir-witness-table-wrapper.cpp
saipraveenb25 Aug 11, 2025
b313c0a
Update slang-ir-specialize.cpp
saipraveenb25 Aug 11, 2025
aeaa4b4
Clean up, fix warnings and add a new inst for a cleaner way to handle…
saipraveenb25 Aug 11, 2025
f554ff7
Clean up implementation of interface -> tagged-union casts
saipraveenb25 Aug 11, 2025
d7ef2a2
Some more fixups
saipraveenb25 Aug 11, 2025
209031e
More fixes to get all tests passing
saipraveenb25 Aug 12, 2025
9347b4f
Update slang-ir-lower-dynamic-insts.cpp
saipraveenb25 Aug 12, 2025
1a4021c
Fix the last two tests
saipraveenb25 Aug 12, 2025
dbd7402
Fixup minor bug
saipraveenb25 Aug 13, 2025
79773d3
Fix unused var
saipraveenb25 Aug 13, 2025
7efc97c
More fixes for specialization
saipraveenb25 Aug 13, 2025
a5cf6b2
More fixes for Falcor
saipraveenb25 Aug 14, 2025
95c38f2
Fix insts getting inserted into the middle of the param list
saipraveenb25 Aug 15, 2025
76b39ef
Make the default conformance be the last one instead of the first one
saipraveenb25 Aug 19, 2025
e1485c0
Delete 2.hlsl
saipraveenb25 Aug 20, 2025
0c9fa6b
Split files into 3 (collection utilities, specialization and lowering)
saipraveenb25 Aug 20, 2025
f9e4d71
Update slang-ir.h
saipraveenb25 Aug 20, 2025
0e1ba02
Fix formatting
saipraveenb25 Aug 20, 2025
70d1899
Update switch-case.slang
saipraveenb25 Aug 20, 2025
cfb8469
Fix default value selection
saipraveenb25 Aug 21, 2025
7b277a9
Merge branch 'master' into type-flow
saipraveenb25 Aug 21, 2025
704d381
Update slang-ir-insts-stable-names.lua
saipraveenb25 Aug 21, 2025
c303878
Add `GetTagForSpecializedCollection` to represent the dynamic result …
saipraveenb25 Sep 2, 2025
e127fdc
Merge branch 'master' into type-flow
saipraveenb25 Sep 2, 2025
40239f0
Update direction info to include address space.
saipraveenb25 Sep 2, 2025
01a1869
Update specialization pass to cache its specialization entries at the…
saipraveenb25 Sep 2, 2025
0fe0f8e
Make type flow insts easier to use + fix specialization pass
saipraveenb25 Sep 2, 2025
f77750d
Merge branch 'master' into type-flow
saipraveenb25 Sep 3, 2025
a0e2f3e
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Oct 7, 2025
c5f0a5f
Merge with ToT, add some comments for inst, make specialization dicti…
saipraveenb25 Oct 7, 2025
18c1257
Merge branch 'type-flow' of github.com:saipraveenb25/slang into type-…
saipraveenb25 Oct 7, 2025
bf29b0b
Cleanup + add details comments
saipraveenb25 Oct 9, 2025
af27e08
Add comments for typeflow inst lowering pass.
saipraveenb25 Oct 9, 2025
625d521
More comment fixes
saipraveenb25 Oct 9, 2025
6a6cab5
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Oct 9, 2025
e50190a
More documentation
saipraveenb25 Oct 10, 2025
ad663cb
More comments + minor changes
saipraveenb25 Oct 10, 2025
5e9c925
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Oct 10, 2025
9dc2b97
Remove commented code
saipraveenb25 Oct 10, 2025
e40d50f
Fix some comments
saipraveenb25 Oct 10, 2025
eb71d2e
Merge branch 'master' into type-flow
saipraveenb25 Oct 10, 2025
049a09a
Merge branch 'master' into type-flow
saipraveenb25 Oct 10, 2025
ad2e321
Update slang-ir-typeflow-collection.h
saipraveenb25 Oct 10, 2025
a7b4ae0
Merge branch 'type-flow' of github.com:saipraveenb25/slang into type-…
saipraveenb25 Oct 10, 2025
f09ce0c
Put the speciliazation dictionary checks for `Undefined` into a separ…
saipraveenb25 Oct 14, 2025
397bbf9
Merge branch 'master' into type-flow
saipraveenb25 Oct 14, 2025
9f97686
Add support for specializing optional existential types.
saipraveenb25 Oct 14, 2025
3b3f58f
Merge branch 'type-flow' of github.com:saipraveenb25/slang into type-…
saipraveenb25 Oct 14, 2025
80f2193
Update slang-ir-typeflow-specialize.cpp
saipraveenb25 Oct 14, 2025
c9b3965
More fixes for optional existential types
saipraveenb25 Oct 14, 2025
43a84f3
More fixes for existential IFoo (add another test)
saipraveenb25 Oct 15, 2025
091139e
Fix VM emit for unreachable blocks.
saipraveenb25 Oct 15, 2025
b022534
Update slang-ir-specialize.cpp
saipraveenb25 Oct 15, 2025
2d58035
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Oct 15, 2025
589e0dc
Overhaul semantics of the propagation info insts + several fixes and …
saipraveenb25 Oct 21, 2025
44b0108
Some more testing. Change tags to use global unique IDs instead of lo…
saipraveenb25 Oct 21, 2025
9eb827d
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Oct 22, 2025
bba9b1a
Fix unused vars
saipraveenb25 Oct 22, 2025
924e332
Update slang-ir-typeflow-specialize.cpp
saipraveenb25 Oct 22, 2025
84395e9
Move set builder logic into IRBuilder
saipraveenb25 Oct 22, 2025
ea362d6
Bulk rename collection instructions
saipraveenb25 Oct 22, 2025
7167849
Remove `TypeFlowData` base inst.
saipraveenb25 Oct 22, 2025
f7a8722
Update slang-ir-typeflow-specialize.cpp
saipraveenb25 Oct 22, 2025
a4f538a
Update slang-ir-typeflow-specialize.cpp
saipraveenb25 Oct 22, 2025
17e38e2
More CI fixes
saipraveenb25 Oct 22, 2025
5b0263a
Fix up documentation
saipraveenb25 Oct 22, 2025
8d38634
Update comments for op-codes
saipraveenb25 Oct 23, 2025
640d6a0
Update slang-ir-typeflow-specialize.cpp
saipraveenb25 Oct 23, 2025
cd1c74d
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Oct 23, 2025
98de01e
Disable old generics pass completely. Get tests passing.
saipraveenb25 Oct 30, 2025
c92ed7e
Remove the old generics pass completely
saipraveenb25 Oct 30, 2025
85dce7c
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Oct 30, 2025
150e097
Fix-up
saipraveenb25 Oct 30, 2025
d386b06
Fix lowering of bound interface types
saipraveenb25 Oct 30, 2025
74a55d4
Fix detection of COM objects during lowering
saipraveenb25 Oct 31, 2025
74711f6
Fix-up uninitialized vars
saipraveenb25 Oct 31, 2025
31f1e21
Move some set utilities into `IRSetBase`, use memory pools for lists …
saipraveenb25 Oct 31, 2025
ba249f3
Add uninitialized object diagnostic + test
saipraveenb25 Oct 31, 2025
6712825
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Oct 31, 2025
8694750
Fix for Falcor test.
saipraveenb25 Nov 3, 2025
778b654
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Nov 3, 2025
9640dc9
Fix CI
saipraveenb25 Nov 3, 2025
1ad3745
Add comments, rename some files to better reflect their contents, upd…
saipraveenb25 Nov 3, 2025
9b9927b
More documentation tweaks. Remove unused ops. Re-order sets during in…
saipraveenb25 Nov 4, 2025
1e833df
Remove op-less set building logic. Fix warnings. More doc tweaks
saipraveenb25 Nov 4, 2025
ab25721
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Nov 4, 2025
562c751
Fix CI warning
saipraveenb25 Nov 4, 2025
dbb2972
Copy decorations when specializing; Add name hints for dispatchers
saipraveenb25 Nov 4, 2025
e12dcba
Update func-type in the debug-func-decoration when legalizing
saipraveenb25 Nov 4, 2025
4011762
Update switch-case.slang
saipraveenb25 Nov 4, 2025
3857285
Update slang-ir-specialize.cpp
saipraveenb25 Nov 4, 2025
e74fde9
Merge branch 'master' into type-flow
saipraveenb25 Nov 5, 2025
fb07bfd
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Nov 12, 2025
2633783
Merge branch 'type-flow' of github.com:saipraveenb25/slang into type-…
saipraveenb25 Nov 12, 2025
3e3bcec
Merge branch 'master' into type-flow
saipraveenb25 Nov 13, 2025
87b00e9
Merge branch 'master' into type-flow
saipraveenb25 Nov 13, 2025
8910e0b
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Nov 25, 2025
67bb72b
Fix debug info test to reflect emitted function signatures
saipraveenb25 Nov 25, 2025
355ca76
Revert debug function change for now..
saipraveenb25 Nov 25, 2025
8aab1f6
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Dec 2, 2025
c9ddbaa
Wrap passes with the new tracking tool
saipraveenb25 Dec 2, 2025
7d02c4b
Update slang-ir-specialize.cpp
saipraveenb25 Dec 2, 2025
486ec44
Merge remote-tracking branch 'upstream' into type-flow
saipraveenb25 Dec 3, 2025
f032141
Merge branch 'master' into type-flow
saipraveenb25 Dec 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/slang/slang-diagnostic-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,11 @@ DIAGNOSTIC(
noTypeConformancesFoundForInterface,
"No type conformances are found for interface '$0'. Code generation for current target "
"requires at least one implementation type present in the linkage.")
DIAGNOSTIC(
50101,
Error,
dynamicDispatchOnPotentiallyUninitializedExistential,
"Cannot dynamically dispatch on potentially uninitialized interface object '$0'.")

DIAGNOSTIC(
52000,
Expand Down
8 changes: 8 additions & 0 deletions source/slang/slang-emit-vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,11 @@ class ByteCodeEmitter
}
}

bool isUnreachableBlock(IRBlock* block)
{
return as<IRUnreachable>(block->getTerminator()) != nullptr;
}

void emitFunction(IRFunc* func)
{
VMByteCodeFunctionBuilder funcBuilder;
Expand All @@ -1100,6 +1105,9 @@ class ByteCodeEmitter

for (auto block : func->getBlocks())
{
if (isUnreachableBlock(block))
continue;

mapBlockToByteOffset[block] = funcBuilder.code.getCount();

for (auto inst : block->getChildren())
Expand Down
50 changes: 32 additions & 18 deletions source/slang/slang-emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "slang-emit-vm.h"
#include "slang-emit-wgsl.h"
#include "slang-ir-any-value-inference.h"
#include "slang-ir-any-value-marshalling.h"
#include "slang-ir-autodiff.h"
#include "slang-ir-bind-existentials.h"
#include "slang-ir-byte-address-legalize.h"
Expand Down Expand Up @@ -77,9 +78,9 @@
#include "slang-ir-lower-buffer-element-type.h"
#include "slang-ir-lower-combined-texture-sampler.h"
#include "slang-ir-lower-coopvec.h"
#include "slang-ir-lower-dynamic-dispatch-insts.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"
#include "slang-ir-lower-optional-type.h"
Expand Down Expand Up @@ -114,6 +115,7 @@
#include "slang-ir-synthesize-active-mask.h"
#include "slang-ir-transform-params-to-constref.h"
#include "slang-ir-translate-global-varying-var.h"
#include "slang-ir-typeflow-specialize.h"
#include "slang-ir-undo-param-copy.h"
#include "slang-ir-uniformity.h"
#include "slang-ir-user-type-hint.h"
Expand Down Expand Up @@ -862,6 +864,12 @@ Result linkAndOptimizeIR(
// Lower all the LValue implict casts (used for out/inout/ref scenarios)
SLANG_PASS(lowerLValueCast, targetProgram);

// Lower enum types early since enums and enum casts may appear in
// specialization & not resolving them here would block specialization.
//
if (requiredLoweringPassSet.enumType)
SLANG_PASS(lowerEnumType, sink);

IRSimplificationOptions defaultIRSimplificationOptions =
IRSimplificationOptions::getDefault(targetProgram);
IRSimplificationOptions fastIRSimplificationOptions =
Expand Down Expand Up @@ -1111,21 +1119,14 @@ Result linkAndOptimizeIR(
SLANG_RETURN_ON_FAIL(SLANG_PASS(performTypeInlining, targetProgram, sink));
}

if (requiredLoweringPassSet.reinterpret)
SLANG_PASS(lowerReinterpret, targetProgram, sink);

if (sink->getErrorCount() != 0)
return SLANG_FAIL;

validateIRModuleIfEnabled(codeGenContext, irModule);

SLANG_PASS(inferAnyValueSizeWhereNecessary, targetProgram);
SLANG_PASS(inferAnyValueSizeWhereNecessary, targetProgram, sink);

// If we have any witness tables that are marked as `KeepAlive`,
// but are not used for dynamic dispatch, unpin them so we don't
// do unnecessary work to lower them.
SLANG_PASS(unpinWitnessTables);

if (!fastIRSimplificationOptions.minimalOptimization)
{
SLANG_PASS(simplifyIR, targetProgram, fastIRSimplificationOptions, sink);
Expand All @@ -1135,6 +1136,26 @@ Result linkAndOptimizeIR(
SLANG_PASS(eliminateDeadCode, fastIRSimplificationOptions.deadCodeElimOptions);
}

// Tagged union type lowering typically generates more reinterpret instructions.
if (SLANG_PASS(lowerTaggedUnionTypes, sink))
requiredLoweringPassSet.reinterpret = true;

SLANG_PASS(lowerUntaggedUnionTypes, targetProgram, sink);

if (requiredLoweringPassSet.reinterpret)
SLANG_PASS(lowerReinterpret, targetProgram, sink);

SLANG_PASS(lowerSequentialIDTagCasts, codeGenContext->getLinkage(), sink);
SLANG_PASS(lowerTagInsts, sink);
SLANG_PASS(lowerTagTypes);

SLANG_PASS(eliminateDeadCode, fastIRSimplificationOptions.deadCodeElimOptions);

SLANG_PASS(lowerExistentials, targetProgram, sink);

if (sink->getErrorCount() != 0)
return SLANG_FAIL;

if (!ArtifactDescUtil::isCpuLikeTarget(artifactDesc) &&
targetProgram->getOptionSet().shouldRunNonEssentialValidation())
{
Expand All @@ -1143,16 +1164,9 @@ Result linkAndOptimizeIR(
SLANG_RETURN_ON_FAIL(SLANG_PASS(checkGetStringHashInsts, sink));
}

// For targets that supports dynamic dispatch, we need to lower the
// generics / interface types to ordinary functions and types using
// function pointers.
if (requiredLoweringPassSet.generics)
SLANG_PASS(lowerGenerics, targetProgram, sink);
else
SLANG_PASS(cleanupGenerics, targetProgram, sink);
SLANG_PASS(lowerTuples, sink);

if (requiredLoweringPassSet.enumType)
SLANG_PASS(lowerEnumType, sink);
SLANG_PASS(generateAnyValueMarshallingFunctions);

// Don't need to run any further target-dependent passes if we are generating code
// for host vm.
Expand Down
32 changes: 28 additions & 4 deletions source/slang/slang-ir-any-value-inference.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "slang-ir-any-value-inference.h"

#include "../core/slang-func-ptr.h"
#include "slang-ir-generics-lowering-context.h"
#include "slang-ir-insts.h"
#include "slang-ir-layout.h"
#include "slang-ir-util.h"
Expand Down Expand Up @@ -90,7 +89,10 @@ List<IRInterfaceType*> sortTopologically(
return sortedInterfaceTypes;
}

void inferAnyValueSizeWhereNecessary(IRModule* module, TargetProgram* targetProgram)
void inferAnyValueSizeWhereNecessary(
IRModule* module,
TargetProgram* targetProgram,
DiagnosticSink* sink)
{
// Go through the global insts and collect all interface types.
// For each interface type, infer its any-value-size, by looking up
Expand Down Expand Up @@ -130,9 +132,10 @@ void inferAnyValueSizeWhereNecessary(IRModule* module, TargetProgram* targetProg
if (interfaceType->findDecoration<IRBuiltinDecoration>())
continue;

// If the interface already has an explicit any-value-size, don't infer anything.
/* If the interface already has an explicit any-value-size, don't infer anything.
if (interfaceType->findDecoration<IRAnyValueSizeDecoration>())
continue;
*/

// Skip interfaces that are not implemented by any type.
if (!implementedInterfaces.contains(interfaceType))
Expand Down Expand Up @@ -213,6 +216,12 @@ void inferAnyValueSizeWhereNecessary(IRModule* module, TargetProgram* targetProg

for (auto interfaceType : sortedInterfaceTypes)
{
IRIntegerValue existingMaxSize = (IRIntegerValue)kMaxInt; // Default to max int.
if (auto existingAnyValueDecor = interfaceType->findDecoration<IRAnyValueSizeDecoration>())
{
existingMaxSize = existingAnyValueDecor->getSize();
}

IRIntegerValue maxAnyValueSize = -1;
for (auto implType : mapInterfaceToImplementations[interfaceType])
{
Expand All @@ -223,6 +232,18 @@ void inferAnyValueSizeWhereNecessary(IRModule* module, TargetProgram* targetProg
&sizeAndAlignment);

maxAnyValueSize = Math::Max(maxAnyValueSize, sizeAndAlignment.size);

// Diagnose if the existing any-value-size is smaller than the inferred size.
if (existingMaxSize < sizeAndAlignment.size)
{
sink->diagnose(implType, Diagnostics::typeDoesNotFitAnyValueSize, implType);
sink->diagnoseWithoutSourceView(
implType,
Diagnostics::typeAndLimit,
implType,
sizeAndAlignment.size,
existingMaxSize);
}
}

// Should not encounter interface types without any conforming implementations.
Expand All @@ -232,7 +253,10 @@ void inferAnyValueSizeWhereNecessary(IRModule* module, TargetProgram* targetProg
if (maxAnyValueSize >= 0)
{
IRBuilder builder(module);
builder.addAnyValueSizeDecoration(interfaceType, maxAnyValueSize);
if (!interfaceType->findDecoration<IRAnyValueSizeDecoration>())
{
builder.addAnyValueSizeDecoration(interfaceType, maxAnyValueSize);
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion source/slang/slang-ir-any-value-inference.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@

namespace Slang
{
void inferAnyValueSizeWhereNecessary(IRModule* module, TargetProgram* targetProgram);
void inferAnyValueSizeWhereNecessary(
IRModule* module,
TargetProgram* targetProgram,
DiagnosticSink* sink);
}
Loading
Loading