-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[ADT][DWARFLinker] Template AddressRangesMap on the value type #160013
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
base: main
Are you sure you want to change the base?
Conversation
Currently it hard-codes int64_t as the value type, but other types may be desired.
|
@llvm/pr-subscribers-llvm-support Author: Jessica Clarke (jrtc27) ChangesCurrently it hard-codes int64_t as the value type, but other types may Full diff: https://github.com/llvm/llvm-project/pull/160013.diff 7 Files Affected:
diff --git a/llvm/include/llvm/ADT/AddressRanges.h b/llvm/include/llvm/ADT/AddressRanges.h
index 79ba5d5a3eddb..f26a2ebfc7700 100644
--- a/llvm/include/llvm/ADT/AddressRanges.h
+++ b/llvm/include/llvm/ADT/AddressRanges.h
@@ -140,16 +140,17 @@ class AddressRanges : public AddressRangesBase<AddressRange> {
}
};
-class AddressRangeValuePair {
+template <typename T> class AddressRangeValuePair {
public:
explicit operator AddressRange() const { return Range; }
AddressRange Range;
- int64_t Value = 0;
+ T Value = T();
};
-inline bool operator==(const AddressRangeValuePair &LHS,
- const AddressRangeValuePair &RHS) {
+template <typename T>
+inline bool operator==(const AddressRangeValuePair<T> &LHS,
+ const AddressRangeValuePair<T> &RHS) {
return LHS.Range == RHS.Range && LHS.Value == RHS.Value;
}
@@ -160,15 +161,18 @@ inline bool operator==(const AddressRangeValuePair &LHS,
/// Intersecting([100,200), [150,300)) ranges splitted into non-conflicting
/// parts([100,200), [200,300)). Adjacent([100,200), [200,300)) address
/// ranges are not combined during insertion.
-class AddressRangesMap : public AddressRangesBase<AddressRangeValuePair> {
+template <typename T>
+class AddressRangesMap : public AddressRangesBase<AddressRangeValuePair<T>> {
+ using AddressRangesBase<AddressRangeValuePair<T>>::Ranges;
+
public:
- void insert(AddressRange Range, int64_t Value) {
+ void insert(AddressRange Range, T Value) {
if (Range.empty())
return;
// Search for range which is less than or equal incoming Range.
auto It =
- llvm::partition_point(Ranges, [=](const AddressRangeValuePair &R) {
+ llvm::partition_point(Ranges, [=](const AddressRangeValuePair<T> &R) {
return R.Range.start() <= Range.start();
});
diff --git a/llvm/include/llvm/DWARFLinker/AddressesMap.h b/llvm/include/llvm/DWARFLinker/AddressesMap.h
index e2215c70dc34e..c708c9c2a2d6c 100644
--- a/llvm/include/llvm/DWARFLinker/AddressesMap.h
+++ b/llvm/include/llvm/DWARFLinker/AddressesMap.h
@@ -21,7 +21,7 @@ namespace dwarf_linker {
/// Mapped value in the address map is the offset to apply to the
/// linked address.
-using RangesTy = AddressRangesMap;
+using RangesTy = AddressRangesMap<int64_t>;
/// AddressesMap represents information about valid addresses used
/// by debug information. Valid addresses are those which points to
diff --git a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h
index 714badfabf89c..0cd34d5be966a 100644
--- a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h
+++ b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h
@@ -24,7 +24,7 @@ class DeclContext;
/// Mapped value in the address map is the offset to apply to the
/// linked address.
-using RangesTy = AddressRangesMap;
+using RangesTy = AddressRangesMap<int64_t>;
// This structure keeps patch for the attribute and, optionally,
// the value of relocation which should be applied. Currently,
diff --git a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
index 8052773812a2c..8fefc53f524d2 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
@@ -2061,7 +2061,7 @@ void DWARFLinker::generateUnitRanges(CompileUnit &Unit, const DWARFFile &File,
// Build set of linked address ranges for unit function ranges.
AddressRanges LinkedFunctionRanges;
- for (const AddressRangeValuePair &Range : FunctionRanges)
+ for (const AddressRangeValuePair<int64_t> &Range : FunctionRanges)
LinkedFunctionRanges.insert(
{Range.Range.start() + Range.Value, Range.Range.end() + Range.Value});
@@ -2074,7 +2074,7 @@ void DWARFLinker::generateUnitRanges(CompileUnit &Unit, const DWARFFile &File,
Unit.getUnitRangesAttribute();
if (!AllRngListAttributes.empty() || UnitRngListAttribute) {
- std::optional<AddressRangeValuePair> CachedRange;
+ std::optional<AddressRangeValuePair<int64_t>> CachedRange;
MCSymbol *EndLabel = TheDwarfEmitter->emitDwarfDebugRangeListHeader(Unit);
// Read original address ranges, apply relocation value, emit linked address
@@ -2329,7 +2329,7 @@ void DWARFLinker::DIECloner::generateLineTableForUnit(CompileUnit &Unit) {
Seq.reserve(InputRows.size());
const auto &FunctionRanges = Unit.getFunctionRanges();
- std::optional<AddressRangeValuePair> CurrRange;
+ std::optional<AddressRangeValuePair<int64_t>> CurrRange;
// FIXME: This logic is meant to generate exactly the same output as
// Darwin's classic dsymutil. There is a nicer way to implement this
@@ -2562,7 +2562,7 @@ void DWARFLinker::patchFrameInfoForObject(LinkContext &Context) {
// the function entry point, thus we can't just lookup the address
// in the debug map. Use the AddressInfo's range map to see if the FDE
// describes something that we can relocate.
- std::optional<AddressRangeValuePair> Range =
+ std::optional<AddressRangeValuePair<int64_t>> Range =
AllUnitsRanges.getRangeThatContains(Loc);
if (!Range) {
// The +4 is to account for the size of the InitialLength field itself.
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
index 8d065bf793f35..f1f8e5876640e 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
@@ -674,7 +674,7 @@ Error CompileUnit::cloneAndEmitRanges() {
// Build set of linked address ranges for unit function ranges.
AddressRanges LinkedFunctionRanges;
- for (const AddressRangeValuePair &Range : getFunctionRanges())
+ for (const AddressRangeValuePair<int64_t> &Range : getFunctionRanges())
LinkedFunctionRanges.insert(
{Range.Range.start() + Range.Value, Range.Range.end() + Range.Value});
@@ -697,7 +697,7 @@ void CompileUnit::cloneAndEmitRangeList(DebugSectionKind RngSectionKind,
getOrCreateSectionDescriptor(RngSectionKind);
if (!DebugInfoSection.ListDebugRangePatch.empty()) {
- std::optional<AddressRangeValuePair> CachedRange;
+ std::optional<AddressRangeValuePair<int64_t>> CachedRange;
uint64_t OffsetAfterUnitLength = emitRangeListHeader(OutRangeSection);
DebugRangePatch *CompileUnitRangePtr = nullptr;
@@ -1544,7 +1544,7 @@ Error CompileUnit::cloneAndEmitLineTable(const Triple &TargetTriple) {
std::vector<DWARFDebugLine::Row> Seq;
const auto &FunctionRanges = getFunctionRanges();
- std::optional<AddressRangeValuePair> CurrRange;
+ std::optional<AddressRangeValuePair<int64_t>> CurrRange;
// FIXME: This logic is meant to generate exactly the same output as
// Darwin's classic dsymutil. There is a nicer way to implement this
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
index e9ee3ce1b8b27..c4947e2a11c22 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
@@ -786,7 +786,7 @@ Error DWARFLinkerImpl::LinkContext::cloneAndEmitDebugFrame() {
// the function entry point, thus we can't just lookup the address
// in the debug map. Use the AddressInfo's range map to see if the FDE
// describes something that we can relocate.
- std::optional<AddressRangeValuePair> Range =
+ std::optional<AddressRangeValuePair<int64_t>> Range =
AllUnitsRanges.getRangeThatContains(Loc);
if (!Range) {
// The +4 is to account for the size of the InitialLength field itself.
diff --git a/llvm/unittests/Support/AddressRangeTest.cpp b/llvm/unittests/Support/AddressRangeTest.cpp
index 76e7e5e78d964..808eb5b4a3f11 100644
--- a/llvm/unittests/Support/AddressRangeTest.cpp
+++ b/llvm/unittests/Support/AddressRangeTest.cpp
@@ -172,7 +172,7 @@ TEST(AddressRangeTest, TestRangesRandom) {
}
TEST(AddressRangeTest, TestRangesMap) {
- AddressRangesMap Ranges;
+ AddressRangesMap<int64_t> Ranges;
EXPECT_EQ(Ranges.size(), 0u);
EXPECT_TRUE(Ranges.empty());
@@ -389,7 +389,7 @@ TEST(AddressRangeTest, TestRangesMap) {
}
TEST(AddressRangeTest, TestRangesMapRandom) {
- AddressRangesMap Ranges;
+ AddressRangesMap<int64_t> Ranges;
size_t NumElements = 100;
std::srand(std::time(nullptr));
|
|
@llvm/pr-subscribers-llvm-adt Author: Jessica Clarke (jrtc27) ChangesCurrently it hard-codes int64_t as the value type, but other types may Full diff: https://github.com/llvm/llvm-project/pull/160013.diff 7 Files Affected:
diff --git a/llvm/include/llvm/ADT/AddressRanges.h b/llvm/include/llvm/ADT/AddressRanges.h
index 79ba5d5a3eddb..f26a2ebfc7700 100644
--- a/llvm/include/llvm/ADT/AddressRanges.h
+++ b/llvm/include/llvm/ADT/AddressRanges.h
@@ -140,16 +140,17 @@ class AddressRanges : public AddressRangesBase<AddressRange> {
}
};
-class AddressRangeValuePair {
+template <typename T> class AddressRangeValuePair {
public:
explicit operator AddressRange() const { return Range; }
AddressRange Range;
- int64_t Value = 0;
+ T Value = T();
};
-inline bool operator==(const AddressRangeValuePair &LHS,
- const AddressRangeValuePair &RHS) {
+template <typename T>
+inline bool operator==(const AddressRangeValuePair<T> &LHS,
+ const AddressRangeValuePair<T> &RHS) {
return LHS.Range == RHS.Range && LHS.Value == RHS.Value;
}
@@ -160,15 +161,18 @@ inline bool operator==(const AddressRangeValuePair &LHS,
/// Intersecting([100,200), [150,300)) ranges splitted into non-conflicting
/// parts([100,200), [200,300)). Adjacent([100,200), [200,300)) address
/// ranges are not combined during insertion.
-class AddressRangesMap : public AddressRangesBase<AddressRangeValuePair> {
+template <typename T>
+class AddressRangesMap : public AddressRangesBase<AddressRangeValuePair<T>> {
+ using AddressRangesBase<AddressRangeValuePair<T>>::Ranges;
+
public:
- void insert(AddressRange Range, int64_t Value) {
+ void insert(AddressRange Range, T Value) {
if (Range.empty())
return;
// Search for range which is less than or equal incoming Range.
auto It =
- llvm::partition_point(Ranges, [=](const AddressRangeValuePair &R) {
+ llvm::partition_point(Ranges, [=](const AddressRangeValuePair<T> &R) {
return R.Range.start() <= Range.start();
});
diff --git a/llvm/include/llvm/DWARFLinker/AddressesMap.h b/llvm/include/llvm/DWARFLinker/AddressesMap.h
index e2215c70dc34e..c708c9c2a2d6c 100644
--- a/llvm/include/llvm/DWARFLinker/AddressesMap.h
+++ b/llvm/include/llvm/DWARFLinker/AddressesMap.h
@@ -21,7 +21,7 @@ namespace dwarf_linker {
/// Mapped value in the address map is the offset to apply to the
/// linked address.
-using RangesTy = AddressRangesMap;
+using RangesTy = AddressRangesMap<int64_t>;
/// AddressesMap represents information about valid addresses used
/// by debug information. Valid addresses are those which points to
diff --git a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h
index 714badfabf89c..0cd34d5be966a 100644
--- a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h
+++ b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerCompileUnit.h
@@ -24,7 +24,7 @@ class DeclContext;
/// Mapped value in the address map is the offset to apply to the
/// linked address.
-using RangesTy = AddressRangesMap;
+using RangesTy = AddressRangesMap<int64_t>;
// This structure keeps patch for the attribute and, optionally,
// the value of relocation which should be applied. Currently,
diff --git a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
index 8052773812a2c..8fefc53f524d2 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
@@ -2061,7 +2061,7 @@ void DWARFLinker::generateUnitRanges(CompileUnit &Unit, const DWARFFile &File,
// Build set of linked address ranges for unit function ranges.
AddressRanges LinkedFunctionRanges;
- for (const AddressRangeValuePair &Range : FunctionRanges)
+ for (const AddressRangeValuePair<int64_t> &Range : FunctionRanges)
LinkedFunctionRanges.insert(
{Range.Range.start() + Range.Value, Range.Range.end() + Range.Value});
@@ -2074,7 +2074,7 @@ void DWARFLinker::generateUnitRanges(CompileUnit &Unit, const DWARFFile &File,
Unit.getUnitRangesAttribute();
if (!AllRngListAttributes.empty() || UnitRngListAttribute) {
- std::optional<AddressRangeValuePair> CachedRange;
+ std::optional<AddressRangeValuePair<int64_t>> CachedRange;
MCSymbol *EndLabel = TheDwarfEmitter->emitDwarfDebugRangeListHeader(Unit);
// Read original address ranges, apply relocation value, emit linked address
@@ -2329,7 +2329,7 @@ void DWARFLinker::DIECloner::generateLineTableForUnit(CompileUnit &Unit) {
Seq.reserve(InputRows.size());
const auto &FunctionRanges = Unit.getFunctionRanges();
- std::optional<AddressRangeValuePair> CurrRange;
+ std::optional<AddressRangeValuePair<int64_t>> CurrRange;
// FIXME: This logic is meant to generate exactly the same output as
// Darwin's classic dsymutil. There is a nicer way to implement this
@@ -2562,7 +2562,7 @@ void DWARFLinker::patchFrameInfoForObject(LinkContext &Context) {
// the function entry point, thus we can't just lookup the address
// in the debug map. Use the AddressInfo's range map to see if the FDE
// describes something that we can relocate.
- std::optional<AddressRangeValuePair> Range =
+ std::optional<AddressRangeValuePair<int64_t>> Range =
AllUnitsRanges.getRangeThatContains(Loc);
if (!Range) {
// The +4 is to account for the size of the InitialLength field itself.
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
index 8d065bf793f35..f1f8e5876640e 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
@@ -674,7 +674,7 @@ Error CompileUnit::cloneAndEmitRanges() {
// Build set of linked address ranges for unit function ranges.
AddressRanges LinkedFunctionRanges;
- for (const AddressRangeValuePair &Range : getFunctionRanges())
+ for (const AddressRangeValuePair<int64_t> &Range : getFunctionRanges())
LinkedFunctionRanges.insert(
{Range.Range.start() + Range.Value, Range.Range.end() + Range.Value});
@@ -697,7 +697,7 @@ void CompileUnit::cloneAndEmitRangeList(DebugSectionKind RngSectionKind,
getOrCreateSectionDescriptor(RngSectionKind);
if (!DebugInfoSection.ListDebugRangePatch.empty()) {
- std::optional<AddressRangeValuePair> CachedRange;
+ std::optional<AddressRangeValuePair<int64_t>> CachedRange;
uint64_t OffsetAfterUnitLength = emitRangeListHeader(OutRangeSection);
DebugRangePatch *CompileUnitRangePtr = nullptr;
@@ -1544,7 +1544,7 @@ Error CompileUnit::cloneAndEmitLineTable(const Triple &TargetTriple) {
std::vector<DWARFDebugLine::Row> Seq;
const auto &FunctionRanges = getFunctionRanges();
- std::optional<AddressRangeValuePair> CurrRange;
+ std::optional<AddressRangeValuePair<int64_t>> CurrRange;
// FIXME: This logic is meant to generate exactly the same output as
// Darwin's classic dsymutil. There is a nicer way to implement this
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
index e9ee3ce1b8b27..c4947e2a11c22 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
@@ -786,7 +786,7 @@ Error DWARFLinkerImpl::LinkContext::cloneAndEmitDebugFrame() {
// the function entry point, thus we can't just lookup the address
// in the debug map. Use the AddressInfo's range map to see if the FDE
// describes something that we can relocate.
- std::optional<AddressRangeValuePair> Range =
+ std::optional<AddressRangeValuePair<int64_t>> Range =
AllUnitsRanges.getRangeThatContains(Loc);
if (!Range) {
// The +4 is to account for the size of the InitialLength field itself.
diff --git a/llvm/unittests/Support/AddressRangeTest.cpp b/llvm/unittests/Support/AddressRangeTest.cpp
index 76e7e5e78d964..808eb5b4a3f11 100644
--- a/llvm/unittests/Support/AddressRangeTest.cpp
+++ b/llvm/unittests/Support/AddressRangeTest.cpp
@@ -172,7 +172,7 @@ TEST(AddressRangeTest, TestRangesRandom) {
}
TEST(AddressRangeTest, TestRangesMap) {
- AddressRangesMap Ranges;
+ AddressRangesMap<int64_t> Ranges;
EXPECT_EQ(Ranges.size(), 0u);
EXPECT_TRUE(Ranges.empty());
@@ -389,7 +389,7 @@ TEST(AddressRangeTest, TestRangesMap) {
}
TEST(AddressRangeTest, TestRangesMapRandom) {
- AddressRangesMap Ranges;
+ AddressRangesMap<int64_t> Ranges;
size_t NumElements = 100;
std::srand(std::time(nullptr));
|
JDevlieghere
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Currently it hard-codes int64_t as the value type, but other types may
be desired.