[llvm-branch-commits] [llvm] [HLSL] Refactor Offset calculation while writing Root Signatures. (PR #128577)

Damyan Pepper via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 25 12:39:26 PST 2025


================
@@ -12,44 +12,59 @@
 using namespace llvm;
 using namespace llvm::mcdxbc;
 
+void setRewrite(raw_ostream &Stream, uint32_t &Offset) {
+  const uint32_t DummyValue = std::numeric_limits<uint32_t>::max();
+  Offset = Stream.tell();
+  support::endian::write(Stream, DummyValue, llvm::endianness::little);
+}
+
+void rewriteOffset(buffer_ostream &Stream, uint32_t Offset) {
+  uint32_t Value = Stream.tell();
+  auto *InsertPoint = &Stream.buffer()[Offset];
+  support::endian::write(InsertPoint, Value, llvm::endianness::little);
+}
----------------
damyanp wrote:

`Stream.pwrite` can help you avoid messing around with buffers and pointers.

```suggestion
void rewriteOffset(buffer_ostream &Stream, uint32_t Offset) {
  uint32_t Value =
      support::endian::byte_swap<uint32_t, llvm::endianness::little>(
          Stream.tell());
  
  Stream.pwrite(reinterpret_cast<const char *>(&Value), sizeof(Value), Offset);
}```

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


More information about the llvm-branch-commits mailing list