Skip to content

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

Open
hekota wants to merge 4 commits intomicrosoft:mainfrom
hekota:linalg-matrix-metadata-cleanup
Open

Remove unused target types from !dx.targetTypes metadata#8202
hekota wants to merge 4 commits intomicrosoft:mainfrom
hekota:linalg-matrix-metadata-cleanup

Conversation

@hekota
Copy link
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
Contributor

github-actions bot commented Feb 25, 2026

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

Copy link
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.

@github-project-automation github-project-automation bot moved this from New to In progress in HLSL Roadmap Feb 27, 2026
@hekota
Copy link
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
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
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.

static const char *m_NamePrefix;
static const char *m_TypePrefix;
static const char *m_MatrixTypePrefix;
static const char *m_LinAlgNamePrefix;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The dx.types version of this was put into DxilUtil in this PR https://github.com/microsoft/DirectXShaderCompiler/pull/8186/changes

Might make sense to have them next to each other?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

LinAlgMatrix metadata cleanup

4 participants