LLVM  15.0.0git
AddressRanges.cpp
Go to the documentation of this file.
1 //===- AddressRanges.cpp ----------------------------------------*- 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 
10 #include "llvm/ADT/STLExtras.h"
11 #include <inttypes.h>
12 
13 using namespace llvm;
14 
16  if (Range.size() == 0)
17  return;
18 
19  auto It = llvm::upper_bound(Ranges, Range);
20  auto It2 = It;
21  while (It2 != Ranges.end() && It2->start() < Range.end())
22  ++It2;
23  if (It != It2) {
24  Range = {Range.start(), std::max(Range.end(), It2[-1].end())};
25  It = Ranges.erase(It, It2);
26  }
27  if (It != Ranges.begin() && Range.start() < It[-1].end())
28  It[-1] = {It[-1].start(), std::max(It[-1].end(), Range.end())};
29  else
30  Ranges.insert(It, Range);
31 }
32 
34  auto It = std::partition_point(
35  Ranges.begin(), Ranges.end(),
36  [=](const AddressRange &R) { return R.start() <= Addr; });
37  return It != Ranges.begin() && Addr < It[-1].end();
38 }
39 
41  if (Range.size() == 0)
42  return false;
43  auto It = std::partition_point(
44  Ranges.begin(), Ranges.end(),
45  [=](const AddressRange &R) { return R.start() <= Range.start(); });
46  if (It == Ranges.begin())
47  return false;
48  return Range.end() <= It[-1].end();
49 }
50 
53  auto It = std::partition_point(
54  Ranges.begin(), Ranges.end(),
55  [=](const AddressRange &R) { return R.start() <= Addr; });
56  if (It != Ranges.begin() && Addr < It[-1].end())
57  return It[-1];
58  return llvm::None;
59 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::upper_bound
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1749
llvm::Optional
Definition: APInt.h:33
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
STLExtras.h
AddressRanges.h
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::None
const NoneType None
Definition: None.h:24
llvm::AddressRange
A class that represents an address range.
Definition: AddressRanges.h:21
llvm::AddressRanges::insert
void insert(AddressRange Range)
Definition: AddressRanges.cpp:15
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
llvm::AddressRange::end
uint64_t end() const
Definition: AddressRanges.h:28
llvm::partition_point
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition: STLExtras.h:1774
llvm::AddressRange::size
uint64_t size() const
Definition: AddressRanges.h:29
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