[llvm] [DirectX] Propagate shader flags mask of callees to callers (PR #118306)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 5 16:21:52 PST 2025
================
@@ -46,21 +49,63 @@ static void updateFunctionFlags(ComputedShaderFlags &CSF,
}
}
-void ModuleShaderFlags::initialize(const Module &M) {
- // Collect shader flags for each of the functions
- for (const auto &F : M.getFunctionList()) {
- if (F.isDeclaration())
- continue;
- ComputedShaderFlags CSF;
- for (const auto &BB : F)
- for (const auto &I : BB)
- updateFunctionFlags(CSF, I);
- // Insert shader flag mask for function F
- FunctionFlags.push_back({&F, CSF});
- // Update combined shader flags mask
- CombinedSFMask.merge(CSF);
+void ModuleShaderFlags::initialize(Module &M) {
+ CallGraph CG(M);
+
+ // Compute Shader Flags Mask for all functions using post-order visit of SCC
+ // of the call graph.
+ for (scc_iterator<CallGraph *> SCCI = scc_begin(&CG); !SCCI.isAtEnd();
+ ++SCCI) {
+ const std::vector<CallGraphNode *> &CurSCC = *SCCI;
+
+ // Union of shader masks of all functions in CurSCC
+ ComputedShaderFlags SCCSF;
+ for (CallGraphNode *CGN : CurSCC) {
+ Function *F = CGN->getFunction();
+ if (!F)
+ continue;
+
+ if (F->isDeclaration())
+ continue;
+
+ ComputedShaderFlags CSF;
+ for (const auto &BB : *F)
+ for (const auto &I : BB)
+ updateFunctionFlags(CSF, I);
+ // Update combined shader flags mask for all functions in this SCC
+ SCCSF.merge(CSF);
+ }
+
+ // Update combined shader flags mask for all functions of the module
+ CombinedSFMask.merge(SCCSF);
+
+ // Shader flags mask of each of the functions in an SCC of the call graph is
+ // the union of all functions in the SCC. Update shader flags masks of
+ // functions in SCC accordingly. This is trivially true if SCC contains one
+ // function.
+ for (CallGraphNode *CGN : CurSCC) {
+ Function *F = CGN->getFunction();
+ if (!F)
+ continue;
----------------
bogner wrote:
We should probably have the exact same checks here as the loop above (ie, skip both external nodes and declarations). It may be arguably more maintainable to just fill a `SmallVector<Function *>` with the functions we handle in the SCC and loop over that instead of looping over CurSCC again and having to repeat the checks.
https://github.com/llvm/llvm-project/pull/118306
More information about the llvm-commits
mailing list