[llvm] [HLSL][DirectX] Extract HLSLBinding out of DXILResource. NFC (PR #150633)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 30 14:50:26 PDT 2025


================
@@ -0,0 +1,141 @@
+//===- HLSLBinding.cpp - Representation for resource bindings in HLSL -----===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Frontend/HLSL/HLSLBinding.h"
+#include "llvm/ADT/STLExtras.h"
+
+using namespace llvm;
+using namespace hlsl;
+
+std::optional<uint32_t>
+BindingInfo::findAvailableBinding(dxil::ResourceClass RC, uint32_t Space,
+                                  int32_t Size) {
+  BindingSpaces &BS = getBindingSpaces(RC);
+  RegisterSpace &RS = BS.getOrInsertSpace(Space);
+  return RS.findAvailableBinding(Size);
+}
+
+BindingInfo::RegisterSpace &
+BindingInfo::BindingSpaces::getOrInsertSpace(uint32_t Space) {
+  for (auto *I = Spaces.begin(); I != Spaces.end(); ++I) {
----------------
bogner wrote:

Done. I also renamed the iterator to `It` and dropped the pointer type to make it clearer we're using an iterator interface here - there's no need to leak the information that `SmallVector<T>::iterator` is `T *` to the caller like this.

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


More information about the llvm-commits mailing list