[ORC] Add ordering to ExecutorAddrRanges.

This allows ranges to be sorted and used as map keys.
This commit is contained in:
Lang Hames
2023-01-29 15:08:02 -08:00
parent 88f7b4d5b6
commit c0320e731f
2 changed files with 26 additions and 0 deletions

View File

@@ -206,6 +206,27 @@ struct ExecutorAddrRange {
const ExecutorAddrRange &RHS) {
return !(LHS == RHS);
}
friend bool operator<(const ExecutorAddrRange &LHS,
const ExecutorAddrRange &RHS) {
return LHS.Start < RHS.Start ||
(LHS.Start == RHS.Start && LHS.End < RHS.End);
}
friend bool operator<=(const ExecutorAddrRange &LHS,
const ExecutorAddrRange &RHS) {
return LHS.Start < RHS.Start ||
(LHS.Start == RHS.Start && LHS.End <= RHS.End);
}
friend bool operator>(const ExecutorAddrRange &LHS,
const ExecutorAddrRange &RHS) {
return LHS.Start > RHS.Start ||
(LHS.Start == RHS.Start && LHS.End > RHS.End);
}
friend bool operator>=(const ExecutorAddrRange &LHS,
const ExecutorAddrRange &RHS) {
return LHS.Start > RHS.Start ||
(LHS.Start == RHS.Start && LHS.End >= RHS.End);
}
bool contains(ExecutorAddr Addr) const { return Start <= Addr && Addr < End; }
bool overlaps(const ExecutorAddrRange &Other) {
return !(Other.End <= Start || End <= Other.Start);

View File

@@ -100,6 +100,11 @@ TEST(ExecutorAddrTest, AddrRanges) {
EXPECT_FALSE(R1.overlaps(R2));
EXPECT_TRUE(R1.overlaps(R3));
EXPECT_TRUE(R1.overlaps(R4));
EXPECT_LE(R0, R0);
EXPECT_LT(R0, R1);
EXPECT_GE(R0, R0);
EXPECT_GT(R1, R0);
}
} // namespace