LLVM 22.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
15#include <algorithm>
16#include <cassert>
17#include <cstdint>
18#include <tuple>
19#include <vector>
20
21namespace llvm {
22
23class raw_ostream;
24class DWARFObject;
25
30
31 DWARFAddressRange() = default;
32
33 /// Used for unit testing.
38
39 /// Returns true if LowPC is smaller or equal to HighPC. This accounts for
40 /// dead-stripped ranges.
41 bool valid() const { return LowPC <= HighPC; }
42
43 /// Returns true if [LowPC, HighPC) intersects with [RHS.LowPC, RHS.HighPC).
44 bool intersects(const DWARFAddressRange &RHS) const {
45 assert(valid() && RHS.valid());
46 if (SectionIndex != RHS.SectionIndex)
47 return false;
48 // Empty ranges can't intersect.
49 if (LowPC == HighPC || RHS.LowPC == RHS.HighPC)
50 return false;
51 return LowPC < RHS.HighPC && RHS.LowPC < HighPC;
52 }
53
54 /// Union two address ranges if they intersect.
55 ///
56 /// This function will union two address ranges if they intersect by
57 /// modifying this range to be the union of both ranges. If the two ranges
58 /// don't intersect this range will be left alone.
59 ///
60 /// \param RHS Another address range to combine with.
61 ///
62 /// \returns false if the ranges don't intersect, true if they do and the
63 /// ranges were combined.
65 if (!intersects(RHS))
66 return false;
67 LowPC = std::min<uint64_t>(LowPC, RHS.LowPC);
68 HighPC = std::max<uint64_t>(HighPC, RHS.HighPC);
69 return true;
70 }
71
72 LLVM_ABI void dump(raw_ostream &OS, uint32_t AddressSize,
73 DIDumpOptions DumpOpts = {},
74 const DWARFObject *Obj = nullptr) const;
75};
76
77inline bool operator<(const DWARFAddressRange &LHS,
78 const DWARFAddressRange &RHS) {
79 return std::tie(LHS.SectionIndex, LHS.LowPC, LHS.HighPC) < std::tie(RHS.SectionIndex, RHS.LowPC, RHS.HighPC);
80}
81
82inline bool operator==(const DWARFAddressRange &LHS,
83 const DWARFAddressRange &RHS) {
84 return std::tie(LHS.SectionIndex, LHS.LowPC, LHS.HighPC) == std::tie(RHS.SectionIndex, RHS.LowPC, RHS.HighPC);
85}
86
87LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DWARFAddressRange &R);
88
89/// DWARFAddressRangesVector - represents a set of absolute address ranges.
90using DWARFAddressRangesVector = std::vector<DWARFAddressRange>;
91
92} // end namespace llvm
93
94#endif // LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition: Compiler.h:213
raw_pwrite_stream & OS
Value * RHS
Value * LHS
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:362
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:312
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:196
bool valid() const
Returns true if LowPC is smaller or equal to HighPC.
bool intersects(const DWARFAddressRange &RHS) const
Returns true if [LowPC, HighPC) intersects with [RHS.LowPC, RHS.HighPC).
bool merge(const DWARFAddressRange &RHS)
Union two address ranges if they intersect.
DWARFAddressRange(uint64_t LowPC, uint64_t HighPC, uint64_t SectionIndex=object::SectionedAddress::UndefSection)
Used for unit testing.
LLVM_ABI void dump(raw_ostream &OS, uint32_t AddressSize, DIDumpOptions DumpOpts={}, const DWARFObject *Obj=nullptr) const
static const uint64_t UndefSection
Definition: ObjectFile.h:148