-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[llvm][ADT] Some AddressRanges.h improvements #132847
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
VoltrexKeyva
commented
Mar 25, 2025
•
edited
Loading
edited
- Rename parameter to adhere to the project's parameter naming convention.
- Remove redundant template argument.
- Remove redundant name-qualification.
- Change non-explicit conversion operator to an explicit one to avoid surprising implicit conversions.
@llvm/pr-subscribers-llvm-adt Author: Mohammed Keyvanzadeh (VoltrexKeyva) Changes
Full diff: https://github.com/llvm/llvm-project/pull/132847.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/AddressRanges.h b/llvm/include/llvm/ADT/AddressRanges.h
index 415d30bbb5cf9..635fe856f99a5 100644
--- a/llvm/include/llvm/ADT/AddressRanges.h
+++ b/llvm/include/llvm/ADT/AddressRanges.h
@@ -22,14 +22,16 @@ namespace llvm {
class AddressRange {
public:
AddressRange() {}
- AddressRange(uint64_t S, uint64_t E) : Start(S), End(E) {
+ AddressRange(const uint64_t S, const uint64_t E) : Start(S), End(E) {
assert(Start <= End);
}
uint64_t start() const { return Start; }
uint64_t end() const { return End; }
uint64_t size() const { return End - Start; }
uint64_t empty() const { return size() == 0; }
- bool contains(uint64_t Addr) const { return Start <= Addr && Addr < End; }
+ bool contains(const uint64_t Addr) const {
+ return Start <= Addr && Addr < End;
+ }
bool contains(const AddressRange &R) const {
return Start <= R.Start && R.End <= End;
}
@@ -63,16 +65,16 @@ template <typename T> class AddressRangesBase {
public:
void clear() { Ranges.clear(); }
bool empty() const { return Ranges.empty(); }
- bool contains(uint64_t Addr) const {
+ bool contains(const uint64_t Addr) const {
return find(Addr, Addr + 1) != Ranges.end();
}
- bool contains(AddressRange Range) const {
+ bool contains(const AddressRange Range) const {
return find(Range.start(), Range.end()) != Ranges.end();
}
void reserve(size_t Capacity) { Ranges.reserve(Capacity); }
size_t size() const { return Ranges.size(); }
- std::optional<T> getRangeThatContains(uint64_t Addr) const {
+ std::optional<T> getRangeThatContains(const uint64_t Addr) const {
typename Collection::const_iterator It = find(Addr, Addr + 1);
if (It == Ranges.end())
return std::nullopt;
@@ -83,17 +85,18 @@ template <typename T> class AddressRangesBase {
typename Collection::const_iterator begin() const { return Ranges.begin(); }
typename Collection::const_iterator end() const { return Ranges.end(); }
- const T &operator[](size_t i) const {
- assert(i < Ranges.size());
- return Ranges[i];
+ const T &operator[](size_t I) const {
+ assert(I < Ranges.size());
+ return Ranges[I];
}
- bool operator==(const AddressRangesBase<T> &RHS) const {
+ bool operator==(const AddressRangesBase &RHS) const {
return Ranges == RHS.Ranges;
}
protected:
- typename Collection::const_iterator find(uint64_t Start, uint64_t End) const {
+ typename Collection::const_iterator find(const uint64_t Start,
+ const uint64_t End) const {
if (Start >= End)
return Ranges.end();
@@ -124,8 +127,8 @@ class AddressRanges : public AddressRangesBase<AddressRange> {
if (Range.empty())
return Ranges.end();
- auto It = llvm::upper_bound(Ranges, Range);
- auto It2 = It;
+ auto *It = upper_bound(Ranges, Range);
+ auto *It2 = It;
while (It2 != Ranges.end() && It2->start() <= Range.end())
++It2;
if (It != It2) {
@@ -144,7 +147,7 @@ class AddressRanges : public AddressRangesBase<AddressRange> {
class AddressRangeValuePair {
public:
- operator AddressRange() const { return Range; }
+ explicit operator AddressRange() const { return Range; }
AddressRange Range;
int64_t Value = 0;
@@ -164,15 +167,15 @@ inline bool operator==(const AddressRangeValuePair &LHS,
/// ranges are not combined during insertion.
class AddressRangesMap : public AddressRangesBase<AddressRangeValuePair> {
public:
- void insert(AddressRange Range, int64_t Value) {
+ void insert(AddressRange Range, const int64_t Value) {
if (Range.empty())
return;
// Search for range which is less than or equal incoming Range.
- auto It = std::partition_point(Ranges.begin(), Ranges.end(),
- [=](const AddressRangeValuePair &R) {
- return R.Range.start() <= Range.start();
- });
+ auto *It = std::partition_point(Ranges.begin(), Ranges.end(),
+ [=](const AddressRangeValuePair &R) {
+ return R.Range.start() <= Range.start();
+ });
if (It != Ranges.begin())
It--;
|
kuhar
requested changes
Mar 25, 2025
- Rename parameter to adhere to the project's parameter naming convention. - Remove redundant template argument. - Remove redundant name-qualification. - Change non-explicit conversion operator to an explicit one to avoid surprising implicit conversions.
e283c6e
to
b14ec80
Compare
kuhar
approved these changes
Mar 26, 2025
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/133/builds/13649 Here is the relevant piece of the build log for the reference
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.