[llvm] [DirectX] Propagate shader flags mask of callees to callers (PR #118306)

Chris B via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 12:00:39 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);
----------------
llvm-beanz wrote:

How about:
```suggestion
  assert(FunctionFlags.contains(Func) && "Function does not have shader flags.");
  FunctionFlags[Func].merge(SF);
```

Since this can be reduced to a single line of code, it might not actually be worth having a method for it.

What are the conditions where a function might not have shader flags? Can it be considered valid to just treat any function that doesn't have flags as having no flags?

https://github.com/llvm/llvm-project/pull/118306


More information about the llvm-commits mailing list