LLVM  13.0.0git
DWARFAddressRange.h
Go to the documentation of this file.
1 //===- DWARFAddressRange.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_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
10 #define LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
11 
13 #include <cstdint>
14 #include <tuple>
15 #include <vector>
16 
17 namespace llvm {
18 
19 class raw_ostream;
20 class DWARFObject;
21 
23  uint64_t LowPC;
24  uint64_t HighPC;
25  uint64_t SectionIndex;
26 
27  DWARFAddressRange() = default;
28 
29  /// Used for unit testing.
31  uint64_t LowPC, uint64_t HighPC,
34 
35  /// Returns true if LowPC is smaller or equal to HighPC. This accounts for
36  /// dead-stripped ranges.
37  bool valid() const { return LowPC <= HighPC; }
38 
39  /// Returns true if [LowPC, HighPC) intersects with [RHS.LowPC, RHS.HighPC).
40  bool intersects(const DWARFAddressRange &RHS) const {
41  assert(valid() && RHS.valid());
42  // Empty ranges can't intersect.
43  if (LowPC == HighPC || RHS.LowPC == RHS.HighPC)
44  return false;
45  return LowPC < RHS.HighPC && RHS.LowPC < HighPC;
46  }
47 
48  /// Union two address ranges if they intersect.
49  ///
50  /// This function will union two address ranges if they intersect by
51  /// modifying this range to be the union of both ranges. If the two ranges
52  /// don't intersect this range will be left alone.
53  ///
54  /// \param RHS Another address range to combine with.
55  ///
56  /// \returns false if the ranges don't intersect, true if they do and the
57  /// ranges were combined.
58  bool merge(const DWARFAddressRange &RHS) {
59  if (!intersects(RHS))
60  return false;
61  LowPC = std::min<uint64_t>(LowPC, RHS.LowPC);
62  HighPC = std::max<uint64_t>(HighPC, RHS.HighPC);
63  return true;
64  }
65 
66  void dump(raw_ostream &OS, uint32_t AddressSize, DIDumpOptions DumpOpts = {},
67  const DWARFObject *Obj = nullptr) const;
68 };
69 
70 inline bool operator<(const DWARFAddressRange &LHS,
71  const DWARFAddressRange &RHS) {
72  return std::tie(LHS.LowPC, LHS.HighPC) < std::tie(RHS.LowPC, RHS.HighPC);
73 }
74 
75 inline bool operator==(const DWARFAddressRange &LHS,
76  const DWARFAddressRange &RHS) {
77  return std::tie(LHS.LowPC, LHS.HighPC) == std::tie(RHS.LowPC, RHS.HighPC);
78 }
79 
80 raw_ostream &operator<<(raw_ostream &OS, const DWARFAddressRange &R);
81 
82 /// DWARFAddressRangesVector - represents a set of absolute address ranges.
83 using DWARFAddressRangesVector = std::vector<DWARFAddressRange>;
84 
85 } // end namespace llvm
86 
87 #endif // LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
llvm::DWARFAddressRange::DWARFAddressRange
DWARFAddressRange(uint64_t LowPC, uint64_t HighPC, uint64_t SectionIndex=object::SectionedAddress::UndefSection)
Used for unit testing.
Definition: DWARFAddressRange.h:30
llvm::DWARFAddressRange::intersects
bool intersects(const DWARFAddressRange &RHS) const
Returns true if [LowPC, HighPC) intersects with [RHS.LowPC, RHS.HighPC).
Definition: DWARFAddressRange.h:40
llvm::DWARFAddressRange::LowPC
uint64_t LowPC
Definition: DWARFAddressRange.h:23
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
llvm::DWARFAddressRange::SectionIndex
uint64_t SectionIndex
Definition: DWARFAddressRange.h:25
llvm::DWARFAddressRange::valid
bool valid() const
Returns true if LowPC is smaller or equal to HighPC.
Definition: DWARFAddressRange.h:37
llvm::DWARFAddressRange::HighPC
uint64_t HighPC
Definition: DWARFAddressRange.h:24
llvm::object::SectionedAddress::UndefSection
const static uint64_t UndefSection
Definition: ObjectFile.h:142
llvm::operator<
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:343
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::DWARFAddressRange::dump
void dump(raw_ostream &OS, uint32_t AddressSize, DIDumpOptions DumpOpts={}, const DWARFObject *Obj=nullptr) const
Definition: DWARFAddressRange.cpp:16
llvm::operator==
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:2035
uint32_t
DIContext.h
llvm::DWARFAddressRangesVector
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
Definition: DWARFAddressRange.h:83
llvm::DWARFAddressRange::merge
bool merge(const DWARFAddressRange &RHS)
Union two address ranges if they intersect.
Definition: DWARFAddressRange.h:58
llvm::DWARFAddressRange::DWARFAddressRange
DWARFAddressRange()=default
llvm::DWARFAddressRange
Definition: DWARFAddressRange.h:22
llvm::DIDumpOptions
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:187