[Alignment][NFC] Migrate Instructions to Align
[llvm-core.git] / include / llvm / DebugInfo / DWARF / DWARFAddressRange.h
blob2d5f9f3c7658547860af88fd78f5da0fa1c5d84a
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
10 #define LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
12 #include "llvm/DebugInfo/DIContext.h"
13 #include <cstdint>
14 #include <tuple>
15 #include <vector>
17 namespace llvm {
19 class raw_ostream;
21 struct DWARFAddressRange {
22 uint64_t LowPC;
23 uint64_t HighPC;
24 uint64_t SectionIndex;
26 DWARFAddressRange() = default;
28 /// Used for unit testing.
29 DWARFAddressRange(uint64_t LowPC, uint64_t HighPC, uint64_t SectionIndex = 0)
30 : LowPC(LowPC), HighPC(HighPC), SectionIndex(SectionIndex) {}
32 /// Returns true if LowPC is smaller or equal to HighPC. This accounts for
33 /// dead-stripped ranges.
34 bool valid() const { return LowPC <= HighPC; }
36 /// Returns true if [LowPC, HighPC) intersects with [RHS.LowPC, RHS.HighPC).
37 bool intersects(const DWARFAddressRange &RHS) const {
38 assert(valid() && RHS.valid());
39 // Empty ranges can't intersect.
40 if (LowPC == HighPC || RHS.LowPC == RHS.HighPC)
41 return false;
42 return LowPC < RHS.HighPC && RHS.LowPC < HighPC;
45 void dump(raw_ostream &OS, uint32_t AddressSize,
46 DIDumpOptions DumpOpts = {}) const;
49 static inline bool operator<(const DWARFAddressRange &LHS,
50 const DWARFAddressRange &RHS) {
51 return std::tie(LHS.LowPC, LHS.HighPC) < std::tie(RHS.LowPC, RHS.HighPC);
54 raw_ostream &operator<<(raw_ostream &OS, const DWARFAddressRange &R);
56 /// DWARFAddressRangesVector - represents a set of absolute address ranges.
57 using DWARFAddressRangesVector = std::vector<DWARFAddressRange>;
59 } // end namespace llvm
61 #endif // LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H