Skip to content

[BOLT][DWARF][NFC] Remove unnecessary SectionOffset #97841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

sayhaan
Copy link
Member

@sayhaan sayhaan commented Jul 5, 2024

Removes unnecessary SectionOffset variable from DebugData.

Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: https://phabricator.intern.facebook.com/D59175270
@sayhaan sayhaan marked this pull request as ready for review July 5, 2024 17:49
Comment on lines 179 to 181
void DebugRangesSectionWriter::appendToRangeBuffer(
const DebugBufferVector &CUBuffer) {
*RangesStream << CUBuffer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks duplicated and the function below still sets SectionOffset - can you please check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, was an error when rebasing and the old definition was included.

@llvmbot llvmbot added the BOLT label Jul 5, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 5, 2024

@llvm/pr-subscribers-bolt

Author: Sayhaan Siddiqui (sayhaan)

Changes

Removes unnecessary SectionOffset variable from DebugData.


Full diff: https://github.com/llvm/llvm-project/pull/97841.diff

2 Files Affected:

  • (modified) bolt/include/bolt/Core/DebugData.h (-4)
  • (modified) bolt/lib/Core/DebugData.cpp (+4-7)
diff --git a/bolt/include/bolt/Core/DebugData.h b/bolt/include/bolt/Core/DebugData.h
index 144433ac78a37..cdcc8cd61f4fa 100644
--- a/bolt/include/bolt/Core/DebugData.h
+++ b/bolt/include/bolt/Core/DebugData.h
@@ -233,10 +233,6 @@ class DebugRangesSectionWriter {
 
   std::mutex WriterMutex;
 
-  /// Current offset in the section (updated as new entries are written).
-  /// Starts with 16 since the first 16 bytes are reserved for an empty range.
-  uint32_t SectionOffset{0};
-
   /// Offset of an empty address ranges list.
   static constexpr uint64_t EmptyRangesOffset{0};
 
diff --git a/bolt/lib/Core/DebugData.cpp b/bolt/lib/Core/DebugData.cpp
index 08d4c45aac791..579af3bce4eb8 100644
--- a/bolt/lib/Core/DebugData.cpp
+++ b/bolt/lib/Core/DebugData.cpp
@@ -138,8 +138,7 @@ DebugRangesSectionWriter::DebugRangesSectionWriter() {
   RangesStream = std::make_unique<raw_svector_ostream>(*RangesBuffer);
 
   // Add an empty range as the first entry;
-  SectionOffset +=
-      writeAddressRanges(*RangesStream.get(), DebugAddressRangesVector{});
+  writeAddressRanges(*RangesStream.get(), DebugAddressRangesVector{});
   Kind = RangesWriterKind::DebugRangesWriter;
 }
 
@@ -166,21 +165,20 @@ uint64_t DebugRangesSectionWriter::addRanges(DebugAddressRangesVector &Ranges) {
   // Reading the SectionOffset and updating it should be atomic to guarantee
   // unique and correct offsets in patches.
   std::lock_guard<std::mutex> Lock(WriterMutex);
-  const uint32_t EntryOffset = SectionOffset;
-  SectionOffset += writeAddressRanges(*RangesStream.get(), Ranges);
+  const uint32_t EntryOffset = RangesBuffer->size();
+  writeAddressRanges(*RangesStream.get(), Ranges);
 
   return EntryOffset;
 }
 
 uint64_t DebugRangesSectionWriter::getSectionOffset() {
   std::lock_guard<std::mutex> Lock(WriterMutex);
-  return SectionOffset;
+  return RangesBuffer->size();
 }
 
 void DebugRangesSectionWriter::appendToRangeBuffer(
     const DebugBufferVector &CUBuffer) {
   *RangesStream << CUBuffer;
-  SectionOffset = RangesBuffer->size();
 }
 
 DebugAddrWriter *DebugRangeListsSectionWriter::AddrWriter = nullptr;
@@ -327,7 +325,6 @@ void DebugRangeListsSectionWriter::finalizeSection() {
   *RangesStream << *Header;
   *RangesStream << *CUArrayBuffer;
   *RangesStream << *CUBodyBuffer;
-  SectionOffset = RangesBuffer->size();
 }
 
 void DebugRangeListsSectionWriter::initSection(DWARFUnit &Unit) {

@sayhaan sayhaan merged commit f137be3 into llvm:main Jul 9, 2024
6 checks passed
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
Removes unnecessary SectionOffset variable from DebugData.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants