[llvm] [DirectX] Propagate shader flags mask of callees to callers (PR #118306)
S. Bharadwaj Yadavalli via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 5 15:05:40 PST 2024
================
@@ -84,15 +145,22 @@ void ComputedShaderFlags::print(raw_ostream &OS) const {
/// Return the shader flags mask of the specified function Func.
const ComputedShaderFlags &
ModuleShaderFlags::getFunctionFlags(const Function *Func) const {
- const auto Iter = llvm::lower_bound(
- FunctionFlags, Func,
- [](const std::pair<const Function *, ComputedShaderFlags> FSM,
- const Function *FindFunc) { return (FSM.first < FindFunc); });
+ auto Iter = FunctionFlags.find(Func);
assert((Iter != FunctionFlags.end() && Iter->first == Func) &&
- "No Shader Flags Mask exists for function");
+ "Get Shader Flags : No Shader Flags Mask exists for function");
return Iter->second;
}
+/// Merge specified shader flags mask SF with current mask of the specified
+/// function Func.
+void ModuleShaderFlags::mergeFunctionShaderFlags(const Function *Func,
+ ComputedShaderFlags SF) {
+ auto Iter = FunctionFlags.find(Func);
+ assert((Iter != FunctionFlags.end() && Iter->first == Func) &&
+ "Merge Shader Flags : No Shader Flags Mask exists for function");
+ Iter->second.merge(SF);
----------------
bharadwajy wrote:
> What are the conditions where a function might not have shader flags?
AFAIK, in a well-formed module, a function that is not a declaration, has an implementation associated. As a result, it must have a shader flags mask (with zero or a non-zero value) associated with it. Hence, a function that has no shader flags associated with it is not in the module. Such situation is considered a bug in the analysis pass or in the transformation pass that queries for shader flags of such (an unknown) function. Hence the `assert`s in `mergeDunctionShaderFlags()` and `getFunctionFlags()` where, in addition, `[]` is not used since it inserts a default initialized shader flag mask.
> Can it be considered valid to just treat any function that doesn't have flags as having no flags?
By treating a function with non-existent shader flags in the shader flags map as having no flags (and not asserting), it appears that consistency between other passes and information collected by shader flag analysis pass would be broken - at a minimum. In other words, shader flag analysis information is providing incorrect information about a function whose existence it has no information about.
Let me know if I missed something in any of my assumptions about module functions.
https://github.com/llvm/llvm-project/pull/118306
More information about the llvm-commits
mailing list