[llvm] [DXIL][Analysis] Collect Function properties in Metadata Analysis (PR #105728)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 30 12:31:43 PDT 2024
================
@@ -33,15 +38,54 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
MMDAI.ValidatorVersion =
VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue());
}
+
+ // For all HLSL Shader functions
+ for (auto &F : M.functions()) {
+ if (!F.hasFnAttribute("hlsl.shader"))
+ continue;
+
+ EntryProperties EFP{};
+ // Get "hlsl.shader" attribute
+ Attribute EntryAttr = F.getFnAttribute("hlsl.shader");
+ assert(EntryAttr.isValid() &&
+ "Invalid value specified for HLSL function attribute hlsl.shader");
+ StringRef EntryProfile = EntryAttr.getValueAsString();
+ Triple T("", "", "", EntryProfile);
+ EFP.ShaderStage = T.getEnvironment();
+ // Get numthreads attribute value, if one exists
+ StringRef NumThreadsStr =
+ F.getFnAttribute("hlsl.numthreads").getValueAsString();
+ if (!NumThreadsStr.empty()) {
+ SmallVector<StringRef> NumThreadsVec;
+ NumThreadsStr.split(NumThreadsVec, ',');
+ assert(NumThreadsVec.size() == 3 && "Invalid numthreads specified");
+ // Read in the three component values of numthreads
+ if (!llvm::to_integer(NumThreadsVec[0], EFP.NumThreadsX, 10))
+ assert(false && "Failed to parse X component of numthreads");
----------------
bogner wrote:
`if (x) assert(false)` is generally discouraged. It doesn't make much difference, but it's probably better
```c++
[[maybe_unused]] bool Success =
llvm::to_integer(NumThreadsVec[0], EFP.NumThreadsX, 10);
assert(Success&& "Failed to parse X component of numthreads");
```
https://github.com/llvm/llvm-project/pull/105728
More information about the llvm-commits
mailing list