[llvm] [DirectX] Propagate shader flags mask of callees to callers (PR #118306)
S. Bharadwaj Yadavalli via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 3 12:08:46 PST 2024
================
@@ -81,16 +101,31 @@ void ComputedShaderFlags::print(raw_ostream &OS) const {
OS << ";\n";
}
-/// Return the shader flags mask of the specified function Func.
-const ComputedShaderFlags &
-ModuleShaderFlags::getFunctionFlags(const Function *Func) const {
+auto ModuleShaderFlags::getFunctionShaderFlagInfo(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); });
assert((Iter != FunctionFlags.end() && Iter->first == Func) &&
"No Shader Flags Mask exists for function");
- return Iter->second;
+ return Iter;
+}
+
+/// Merge mask NewSF to that of Func, if different.
+/// Return true if mask of Func is changed, else false.
+bool ModuleShaderFlags::mergeFunctionShaderFlags(
+ const Function *Func, const ComputedShaderFlags NewSF) {
+ const auto FuncSFInfo = getFunctionShaderFlagInfo(Func);
----------------
bharadwajy wrote:
> As written, this is probably a `const` local variable (copy)... which you then `const_cast` below. This is a prime example of why `auto` should be used judiciously.
Yeah, the root cause for the use of `const_cast` and `auto` return type stems from the desire to define the functionality to search through the `FunctionFlags` in a single place. The idea is to use the same function (which is `getFunctionShaderFlagsinfo()`) to (a) query for the shader flags of a `Function *` and (b) to locate the `std::pair<>` for merge/update the shader flags of a given `Function *`.
Will try out a different refactoring while keeping that goal intact.
https://github.com/llvm/llvm-project/pull/118306
More information about the llvm-commits
mailing list