[llvm] [DirectX] Infrastructure to collect shader flags for each function (PR #112967)

S. Bharadwaj Yadavalli via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 09:37:23 PST 2024


================
@@ -63,17 +118,78 @@ void ComputedShaderFlags::print(raw_ostream &OS) const {
   OS << ";\n";
 }
 
+void DXILModuleShaderFlagsInfo::clear() {
+  ModuleFlags = ComputedShaderFlags{};
+  FunctionFlags.clear();
+}
+
+/// Insert the pair <Func, FlagMask> into the sorted vector
+/// FunctionFlags. The insertion is expected to be in-order and hence
+/// is done at the end of the already sorted list.
+[[nodiscard]] bool DXILModuleShaderFlagsInfo::insertInorderFunctionFlags(
+    const Function *Func, ComputedShaderFlags FlagMask) {
+  std::pair<Function const *, ComputedShaderFlags> V{Func, {}};
+  auto Iter = llvm::lower_bound(FunctionFlags, V);
+  if (Iter != FunctionFlags.end())
+    return false;
+
+  FunctionFlags.push_back({Func, FlagMask});
+  return true;
+}
----------------
bharadwajy wrote:

> This all seems overly complicated. Why isn't it sufficient just to do a push_back from within `computeFlags`?
> 
> The only way I think this could go wrong would be if something the call to `llvm::sort(FuncList)` somehow didn't sort the list. But as some point I think we have to trust that that code works.

Deleted the potentially redundant checks. This access function is called in `computeFlags()` - a static function - to "push back" `<function, flags>` pair to `FunctionFlags` - a private member.

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


More information about the llvm-commits mailing list