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

Damyan Pepper via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 11:30:56 PDT 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;
+}
+
+SmallVector<std::pair<Function const *, ComputedShaderFlags>>
+DXILModuleShaderFlagsInfo::getFunctionFlags() const {
+  return FunctionFlags;
----------------
damyanp wrote:

This is returning a copy of `FunctionFlags`.  Is that really the intent here?  I'd expect it to return a const-reference to `FunctionFlags` to avoid unnecessary copies being made.

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


More information about the llvm-commits mailing list