LLVM  15.0.0git
AddressRanges.h
Go to the documentation of this file.
1 //===- AddressRanges.h ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_ADT_ADDRESSRANGES_H
10 #define LLVM_ADT_ADDRESSRANGES_H
11 
12 #include "llvm/ADT/Optional.h"
13 #include <cassert>
14 #include <stdint.h>
15 #include <vector>
16 
17 namespace llvm {
18 
19 /// A class that represents an address range. The range is specified using
20 /// a start and an end address: [Start, End).
21 class AddressRange {
22 public:
24  AddressRange(uint64_t S, uint64_t E) : Start(S), End(E) {
25  assert(Start <= End);
26  }
27  uint64_t start() const { return Start; }
28  uint64_t end() const { return End; }
29  uint64_t size() const { return End - Start; }
30  bool contains(uint64_t Addr) const { return Start <= Addr && Addr < End; }
31  bool intersects(const AddressRange &R) const {
32  return Start < R.End && R.Start < End;
33  }
34  bool operator==(const AddressRange &R) const {
35  return Start == R.Start && End == R.End;
36  }
37  bool operator!=(const AddressRange &R) const { return !(*this == R); }
38  bool operator<(const AddressRange &R) const {
39  return std::make_pair(Start, End) < std::make_pair(R.Start, R.End);
40  }
41 
42 private:
43  uint64_t Start = 0;
44  uint64_t End = 0;
45 };
46 
47 /// The AddressRanges class helps normalize address range collections.
48 /// This class keeps a sorted vector of AddressRange objects and can perform
49 /// insertions and searches efficiently. The address ranges are always sorted
50 /// and never contain any invalid or empty address ranges. Intersecting
51 /// address ranges are combined during insertion.
53 protected:
54  using Collection = std::vector<AddressRange>;
56 
57 public:
58  void clear() { Ranges.clear(); }
59  bool empty() const { return Ranges.empty(); }
60  bool contains(uint64_t Addr) const;
61  bool contains(AddressRange Range) const;
63  void insert(AddressRange Range);
64  void reserve(size_t Capacity) { Ranges.reserve(Capacity); }
65  size_t size() const { return Ranges.size(); }
66  bool operator==(const AddressRanges &RHS) const {
67  return Ranges == RHS.Ranges;
68  }
69  const AddressRange &operator[](size_t i) const {
70  assert(i < Ranges.size());
71  return Ranges[i];
72  }
73  Collection::const_iterator begin() const { return Ranges.begin(); }
74  Collection::const_iterator end() const { return Ranges.end(); }
75 };
76 
77 } // namespace llvm
78 
79 #endif // LLVM_ADT_ADDRESSRANGES_H
i
i
Definition: README.txt:29
llvm::AddressRange::AddressRange
AddressRange()
Definition: AddressRanges.h:23
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::AddressRanges::reserve
void reserve(size_t Capacity)
Definition: AddressRanges.h:64
Optional.h
llvm::AddressRanges::Collection
std::vector< AddressRange > Collection
Definition: AddressRanges.h:54
llvm::AddressRanges::begin
Collection::const_iterator begin() const
Definition: AddressRanges.h:73
llvm::Optional
Definition: APInt.h:33
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::AddressRanges::operator==
bool operator==(const AddressRanges &RHS) const
Definition: AddressRanges.h:66
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::AddressRanges::empty
bool empty() const
Definition: AddressRanges.h:59
llvm::AddressRanges::getRangeThatContains
Optional< AddressRange > getRangeThatContains(uint64_t Addr) const
Definition: AddressRanges.cpp:52
llvm::AddressRanges::contains
bool contains(uint64_t Addr) const
Definition: AddressRanges.cpp:33
llvm::AddressRange
A class that represents an address range.
Definition: AddressRanges.h:21
llvm::AddressRanges::insert
void insert(AddressRange Range)
Definition: AddressRanges.cpp:15
llvm::AddressRange::operator<
bool operator<(const AddressRange &R) const
Definition: AddressRanges.h:38
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
llvm::AddressRanges::operator[]
const AddressRange & operator[](size_t i) const
Definition: AddressRanges.h:69
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AddressRange::end
uint64_t end() const
Definition: AddressRanges.h:28
llvm::AddressRange::operator==
bool operator==(const AddressRange &R) const
Definition: AddressRanges.h:34
llvm::AddressRange::AddressRange
AddressRange(uint64_t S, uint64_t E)
Definition: AddressRanges.h:24
llvm::AddressRanges::clear
void clear()
Definition: AddressRanges.h:58
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::AddressRange::intersects
bool intersects(const AddressRange &R) const
Definition: AddressRanges.h:31
llvm::AddressRange::operator!=
bool operator!=(const AddressRange &R) const
Definition: AddressRanges.h:37
llvm::AddressRanges::size
size_t size() const
Definition: AddressRanges.h:65
llvm::AddressRange::size
uint64_t size() const
Definition: AddressRanges.h:29
llvm::AddressRanges
The AddressRanges class helps normalize address range collections.
Definition: AddressRanges.h:52
llvm::AddressRanges::end
Collection::const_iterator end() const
Definition: AddressRanges.h:74
llvm::AddressRanges::Ranges
Collection Ranges
Definition: AddressRanges.h:55
llvm::AddressRange::start
uint64_t start() const
Definition: AddressRanges.h:27
llvm::AddressRange::contains
bool contains(uint64_t Addr) const
Definition: AddressRanges.h:30