Skip to content

[BOLT][DWARF][NFC] Move initialization of DWOName outside of lambda #99728

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 3 commits into from
Jul 24, 2024

Conversation

sayhaan
Copy link
Member

@sayhaan sayhaan commented Jul 20, 2024

Followup to the splitting of processUnitDIE, moves code that accesses common resource to be outside of the function that will be parallelized.

Followup to #99957

@sayhaan sayhaan force-pushed the T187681160-1-followup branch from dfe7807 to c9bac7e Compare July 20, 2024 01:07
Summary: 

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D59997905
@sayhaan sayhaan force-pushed the T187681160-1-followup branch from c9bac7e to 0c66a79 Compare July 23, 2024 20:01
@sayhaan sayhaan marked this pull request as ready for review July 23, 2024 20:22
@llvmbot llvmbot added the BOLT label Jul 23, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 23, 2024

@llvm/pr-subscribers-bolt

Author: Sayhaan Siddiqui (sayhaan)

Changes

Followup to the splitting of processUnitDIE, moves code that accesses common resource to be outside of the function that will be parallelized.


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

1 Files Affected:

  • (modified) bolt/lib/Rewrite/DWARFRewriter.cpp (+12-12)
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index f0dd7baf82879..66520ebab47e1 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -668,20 +668,12 @@ void DWARFRewriter::updateDebugInfo() {
   auto processSplitCU = [&](DWARFUnit &Unit, DWARFUnit &SplitCU,
                             DIEBuilder &DIEBlder,
                             DebugRangesSectionWriter &TempRangesSectionWriter,
-                            DebugAddrWriter &AddressWriter) {
+                            DebugAddrWriter &AddressWriter,
+                            std::string &DWOName,
+                            std::optional<std::string> &DwarfOutputPath) {
     DIEBuilder DWODIEBuilder(BC, &(SplitCU).getContext(), DebugNamesTable,
                              &Unit);
     DWODIEBuilder.buildDWOUnit(SplitCU);
-    std::string DWOName = "";
-    std::optional<std::string> DwarfOutputPath =
-        opts::DwarfOutputPath.empty()
-            ? std::nullopt
-            : std::optional<std::string>(opts::DwarfOutputPath.c_str());
-    {
-      std::lock_guard<std::mutex> Lock(AccessMutex);
-      DWOName = DIEBlder.updateDWONameCompDir(
-          *StrOffstsWriter, *StrWriter, Unit, DwarfOutputPath, std::nullopt);
-    }
     DebugStrOffsetsWriter DWOStrOffstsWriter(BC);
     DebugStrWriter DWOStrWriter((SplitCU).getContext(), true);
     DWODIEBuilder.updateDWONameCompDirForTypes(
@@ -759,8 +751,16 @@ void DWARFRewriter::updateDebugInfo() {
       DebugRangesSectionWriter *TempRangesSectionWriter =
           CU->getVersion() >= 5 ? RangeListsWritersByCU[*DWOId].get()
                                 : LegacyRangesWritersByCU[*DWOId].get();
+      std::string DWOName = "";
+      std::optional<std::string> DwarfOutputPath =
+          opts::DwarfOutputPath.empty()
+              ? std::nullopt
+              : std::optional<std::string>(opts::DwarfOutputPath.c_str());
+      std::lock_guard<std::mutex> Lock(AccessMutex);
+      DWOName = DIEBlder.updateDWONameCompDir(*StrOffstsWriter, *StrWriter, *CU,
+                                              DwarfOutputPath, std::nullopt);
       processSplitCU(*CU, **SplitCU, DIEBlder, *TempRangesSectionWriter,
-                     AddressWriter);
+                     AddressWriter, DWOName, DwarfOutputPath);
     }
     for (DWARFUnit *CU : DIEBlder.getProcessedCUs())
       processMainBinaryCU(*CU, DIEBlder);

Copy link

github-actions bot commented Jul 23, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

opts::DwarfOutputPath.empty()
? std::nullopt
: std::optional<std::string>(opts::DwarfOutputPath.c_str());
std::string DWOName = DIEBlder.updateDWONameCompDir(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does hoisting this out of the lambda mean you don't need the lock anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

The lock was previously part of the old multithreading implementation which we weren't using. Previously the plan was to remove it in a followup PR but since we're moving it out of the lambda here it doesn't make sense to have the lock at all since DWOName is processed sequentially.

@sayhaan sayhaan requested a review from ayermolo July 23, 2024 21:32
@ayermolo
Copy link
Contributor

NIt. Change title to be more clear what you moved.
refer to other PR directly by URL.

@sayhaan sayhaan changed the title [BOLT][DWARF][NFC] Move common access outside of parallel function [BOLT][DWARF][NFC] Move initialization of DWOName outside of parallel function Jul 23, 2024
@sayhaan sayhaan changed the title [BOLT][DWARF][NFC] Move initialization of DWOName outside of parallel function [BOLT][DWARF][NFC] Move initialization of DWOName outside of lambda Jul 23, 2024
@sayhaan sayhaan merged commit ea4a348 into llvm:main Jul 24, 2024
6 checks passed
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
…99728)

Summary:
Followup to the splitting of processUnitDIE, moves code that accesses
common resource to be outside of the function that will be parallelized.

Followup to #99957

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250695
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