Skip to content

Remove unused target types from !dx.targetTypes metadata#8202

Merged
hekota merged 5 commits intomicrosoft:mainfrom
hekota:linalg-matrix-metadata-cleanup
Mar 9, 2026
Merged

Remove unused target types from !dx.targetTypes metadata#8202
hekota merged 5 commits intomicrosoft:mainfrom
hekota:linalg-matrix-metadata-cleanup

Conversation

@hekota
Copy link
Copy Markdown
Member

@hekota hekota commented Feb 25, 2026

Make sure !dx.targetTypes metadata node in the final module only contains types that are actually used module. Introduces a new pass DxilTrimTargetTypes that runs towards the end of the pipeline and re-creates the !dx.targetTypes metadata node with only the target types used in the module. This pass runs during single shader compilation and also when multiple lib_6_x modules are linked together for SM 6.10.

Fixes #8133

…ntains types that are actually used module.

Introduces a new pass `DxilTrimTargetTypes` that runs towards the end of the pipeline and re-creates the `!dx.targetTypes` metadata node with only the target types used in the module. This pass runs during single shader compilation and also when multiple lib_6_x modules are linked together for SM 6.10.

Fixes microsoft#8133
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 25, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Copy Markdown
Member

@damyanp damyanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I mostly reviewed for style type things. Mostly typos, but there's enough that we should probably try and fix them.

Comment thread lib/DXIL/DxilOperations.cpp Outdated
Comment thread include/dxc/DXIL/DxilOperations.h Outdated
Comment thread lib/DXIL/DxilUtil.cpp Outdated
Comment thread lib/HLSL/DxilPreparePasses.cpp Outdated
Comment thread lib/HLSL/DxilPreparePasses.cpp Outdated
Comment thread lib/HLSL/DxilPreparePasses.cpp Outdated
Comment thread lib/HLSL/DxilPreparePasses.cpp Outdated
@github-project-automation github-project-automation Bot moved this from New to In progress in HLSL Roadmap Feb 27, 2026
@hekota
Copy link
Copy Markdown
Member Author

hekota commented Feb 27, 2026

LGTM, but I mostly reviewed for style type things. Mostly typos, but there's enough that we should probably try and fix them.

Oops :)


// Map of target type to its metadata node and usage flag.
using TargetTypesUsageMap =
SmallDenseMap<llvm::Type *, std::pair<MDTuple *, bool>, 16>;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: do we actually need to track whether or not types are used, or should we just collect the list of types that are and replace the metadata?

It seems to me that re-computing the set of used types is probably faster than looking at the existing set and determining if it is correct.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we just collect the list of types that are used, we will need to parse the type name to reconstruct the metadata constants. I was under the impression that that's what we want to avoid.

Comment thread include/dxc/DXIL/DxilOperations.h
// mat1 = Matrix::Splat(5);
__builtin_LinAlg_FillMatrix(mat1, 5);

// Matrix<ComponentType::I32, 4, 5, MatrixUse::A, MatrixScope::Thread> m;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Looks like this comment is out of sync

@hekota hekota enabled auto-merge (squash) March 9, 2026 19:07
@hekota hekota merged commit 8da9786 into microsoft:main Mar 9, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in HLSL Roadmap Mar 9, 2026
V-FEXrt added a commit that referenced this pull request Mar 10, 2026
#8202 and
#8233 collided
post merge to reveal a long standing bug with `-lib_6_x` that is
currently breaking CI on main.

This change fixes that bug by skipping reachable call diagnostics in the
case that they are allowed to be transiently invalid. The comment in the
PR is a bit more verbose on the details and I'll avoid reposting it
here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

LinAlgMatrix metadata cleanup

4 participants