[llvm] [LLVM][DWARF] Create thread safe context for DWP DWARFContext (PR #68262)
Alexander Yermolovich via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 9 16:22:42 PDT 2023
https://github.com/ayermolo updated https://github.com/llvm/llvm-project/pull/68262
>From f8f99ff1b6885706f395756c0e61ef78de9e82a7 Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich <ayermolo at meta.com>
Date: Wed, 4 Oct 2023 14:39:41 -0700
Subject: [PATCH 1/6] [LLVM][DWARF] Create thread safe context for DWP
DWARFContext
Right now DWARFContext is created is the same when input is DWO or DWP file.
Changed so that for DWP it creates a thread safe context.
---
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 1e1ab814673f423..0648ccca16cf2ae 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -575,8 +575,12 @@ class ThreadUnsafeDWARFContextState : public DWARFContext::DWARFContextState {
auto S = std::make_shared<DWOFile>();
S->File = std::move(Obj.get());
- S->Context = DWARFContext::create(*S->File.getBinary(),
- DWARFContext::ProcessDebugRelocations::Ignore);
+ StringRef FileName = S->File.getBinary()->getFileName();
+ S->Context = DWARFContext::create(
+ *S->File.getBinary(), DWARFContext::ProcessDebugRelocations::Ignore,
+ nullptr, "", WithColor::defaultErrorHandler,
+ WithColor::defaultWarningHandler,
+ FileName.find(".dwp") != StringRef::npos);
*Entry = S;
auto *Ctxt = S->Context.get();
return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
>From 4f28df98ffec2291ec0b79a8264217b65ef861f3 Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich <ayermolo at meta.com>
Date: Mon, 9 Oct 2023 10:42:50 -0700
Subject: [PATCH 2/6] fixup! [LLVM][DWARF] Create thread safe context for DWP
DWARFContext
---
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 0648ccca16cf2ae..1284a661087b5bd 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -576,11 +576,13 @@ class ThreadUnsafeDWARFContextState : public DWARFContext::DWARFContextState {
auto S = std::make_shared<DWOFile>();
S->File = std::move(Obj.get());
StringRef FileName = S->File.getBinary()->getFileName();
+ // Allow multi-threaded access if there is a .dwp file as the CU index and TU index might be accessed from multiple threads.
+ bool ThreadSafe = FileName.find(".dwp") != StringRef::npos;
S->Context = DWARFContext::create(
*S->File.getBinary(), DWARFContext::ProcessDebugRelocations::Ignore,
nullptr, "", WithColor::defaultErrorHandler,
WithColor::defaultWarningHandler,
- FileName.find(".dwp") != StringRef::npos);
+ ThreadSafe);
*Entry = S;
auto *Ctxt = S->Context.get();
return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
>From 1e25bb6faf64822295bf253de66a8c1f6a61872c Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich <ayermolo at meta.com>
Date: Mon, 9 Oct 2023 10:43:23 -0700
Subject: [PATCH 3/6] fixup! [LLVM][DWARF] Create thread safe context for DWP
DWARFContext
---
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 1284a661087b5bd..631aa6fd00a2178 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -576,13 +576,13 @@ class ThreadUnsafeDWARFContextState : public DWARFContext::DWARFContextState {
auto S = std::make_shared<DWOFile>();
S->File = std::move(Obj.get());
StringRef FileName = S->File.getBinary()->getFileName();
- // Allow multi-threaded access if there is a .dwp file as the CU index and TU index might be accessed from multiple threads.
+ // Allow multi-threaded access if there is a .dwp file as the CU index and
+ // TU index might be accessed from multiple threads.
bool ThreadSafe = FileName.find(".dwp") != StringRef::npos;
S->Context = DWARFContext::create(
*S->File.getBinary(), DWARFContext::ProcessDebugRelocations::Ignore,
nullptr, "", WithColor::defaultErrorHandler,
- WithColor::defaultWarningHandler,
- ThreadSafe);
+ WithColor::defaultWarningHandler, ThreadSafe);
*Entry = S;
auto *Ctxt = S->Context.get();
return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
>From 7b581b62f1a9e7e94029872f8eab775905930ae7 Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich <ayermolo at meta.com>
Date: Mon, 9 Oct 2023 15:52:57 -0700
Subject: [PATCH 4/6] fixup! [LLVM][DWARF] Create thread safe context for DWP
DWARFContext
---
llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h | 1 +
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 9 ++++++---
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
index 4bd8394e6b4ec82..d5dbc311d8db3eb 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -97,6 +97,7 @@ class DWARFContext : public DIContext {
getDWOContext(StringRef AbsolutePath) = 0;
virtual const DenseMap<uint64_t, DWARFTypeUnit *> &
getTypeUnitMap(bool IsDWO) = 0;
+ virtual bool isThreadSafe() = 0;
/// Parse a macro[.dwo] or macinfo[.dwo] section.
std::unique_ptr<DWARFDebugMacro>
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 631aa6fd00a2178..175c072d9beaf3a 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -574,11 +574,9 @@ class ThreadUnsafeDWARFContextState : public DWARFContext::DWARFContextState {
}
auto S = std::make_shared<DWOFile>();
- S->File = std::move(Obj.get());
- StringRef FileName = S->File.getBinary()->getFileName();
// Allow multi-threaded access if there is a .dwp file as the CU index and
// TU index might be accessed from multiple threads.
- bool ThreadSafe = FileName.find(".dwp") != StringRef::npos;
+ bool ThreadSafe = isThreadSafe();
S->Context = DWARFContext::create(
*S->File.getBinary(), DWARFContext::ProcessDebugRelocations::Ignore,
nullptr, "", WithColor::defaultErrorHandler,
@@ -588,6 +586,8 @@ class ThreadUnsafeDWARFContextState : public DWARFContext::DWARFContextState {
return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
}
+ bool isThreadSafe() override { return false; }
+
const DenseMap<uint64_t, DWARFTypeUnit *> &getNormalTypeUnitMap() {
if (!NormalTypeUnits) {
NormalTypeUnits.emplace();
@@ -723,6 +723,9 @@ class ThreadSafeState : public ThreadUnsafeDWARFContextState {
std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
return ThreadUnsafeDWARFContextState::getDWOContext(AbsolutePath);
}
+
+ bool isThreadSafe() override { return true; }
+
const DenseMap<uint64_t, DWARFTypeUnit *> &
getTypeUnitMap(bool IsDWO) override {
std::unique_lock<std::recursive_mutex> LockGuard(Mutex);
>From 520f8ee02fb1e999e5d83a6a2dffd786c4874426 Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich <ayermolo at meta.com>
Date: Mon, 9 Oct 2023 16:00:08 -0700
Subject: [PATCH 5/6] fixup! [LLVM][DWARF] Create thread safe context for DWP
DWARFContext
---
llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h | 2 +-
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
index d5dbc311d8db3eb..fa98cbcfc4d997f 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -97,7 +97,7 @@ class DWARFContext : public DIContext {
getDWOContext(StringRef AbsolutePath) = 0;
virtual const DenseMap<uint64_t, DWARFTypeUnit *> &
getTypeUnitMap(bool IsDWO) = 0;
- virtual bool isThreadSafe() = 0;
+ virtual bool isThreadSafe() const = 0;
/// Parse a macro[.dwo] or macinfo[.dwo] section.
std::unique_ptr<DWARFDebugMacro>
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 175c072d9beaf3a..9a2327322ab5674 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -586,7 +586,7 @@ class ThreadUnsafeDWARFContextState : public DWARFContext::DWARFContextState {
return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
}
- bool isThreadSafe() override { return false; }
+ bool isThreadSafe() const override { return false; }
const DenseMap<uint64_t, DWARFTypeUnit *> &getNormalTypeUnitMap() {
if (!NormalTypeUnits) {
@@ -724,7 +724,7 @@ class ThreadSafeState : public ThreadUnsafeDWARFContextState {
return ThreadUnsafeDWARFContextState::getDWOContext(AbsolutePath);
}
- bool isThreadSafe() override { return true; }
+ bool isThreadSafe() const override { return true; }
const DenseMap<uint64_t, DWARFTypeUnit *> &
getTypeUnitMap(bool IsDWO) override {
>From 95ad79edd728fa5821efd0c1334aab315c98cb5a Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich <ayermolo at meta.com>
Date: Mon, 9 Oct 2023 16:22:21 -0700
Subject: [PATCH 6/6] fixup! [LLVM][DWARF] Create thread safe context for DWP
DWARFContext
---
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 9a2327322ab5674..fe7e9da7b1ab08d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -574,6 +574,7 @@ class ThreadUnsafeDWARFContextState : public DWARFContext::DWARFContextState {
}
auto S = std::make_shared<DWOFile>();
+ S->File = std::move(Obj.get());
// Allow multi-threaded access if there is a .dwp file as the CU index and
// TU index might be accessed from multiple threads.
bool ThreadSafe = isThreadSafe();
More information about the llvm-commits
mailing list