Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:41

0001 //===- DWARFAddressRange.h --------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
0010 #define LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H
0011 
0012 #include "llvm/DebugInfo/DIContext.h"
0013 #include "llvm/Object/ObjectFile.h"
0014 #include <algorithm>
0015 #include <cassert>
0016 #include <cstdint>
0017 #include <tuple>
0018 #include <vector>
0019 
0020 namespace llvm {
0021 
0022 class raw_ostream;
0023 class DWARFObject;
0024 
0025 struct DWARFAddressRange {
0026   uint64_t LowPC;
0027   uint64_t HighPC;
0028   uint64_t SectionIndex;
0029 
0030   DWARFAddressRange() = default;
0031 
0032   /// Used for unit testing.
0033   DWARFAddressRange(
0034       uint64_t LowPC, uint64_t HighPC,
0035       uint64_t SectionIndex = object::SectionedAddress::UndefSection)
0036       : LowPC(LowPC), HighPC(HighPC), SectionIndex(SectionIndex) {}
0037 
0038   /// Returns true if LowPC is smaller or equal to HighPC. This accounts for
0039   /// dead-stripped ranges.
0040   bool valid() const { return LowPC <= HighPC; }
0041 
0042   /// Returns true if [LowPC, HighPC) intersects with [RHS.LowPC, RHS.HighPC).
0043   bool intersects(const DWARFAddressRange &RHS) const {
0044     assert(valid() && RHS.valid());
0045     if (SectionIndex != RHS.SectionIndex)
0046       return false;
0047     // Empty ranges can't intersect.
0048     if (LowPC == HighPC || RHS.LowPC == RHS.HighPC)
0049       return false;
0050     return LowPC < RHS.HighPC && RHS.LowPC < HighPC;
0051   }
0052 
0053   /// Union two address ranges if they intersect.
0054   ///
0055   /// This function will union two address ranges if they intersect by
0056   /// modifying this range to be the union of both ranges. If the two ranges
0057   /// don't intersect this range will be left alone.
0058   ///
0059   /// \param RHS Another address range to combine with.
0060   ///
0061   /// \returns false if the ranges don't intersect, true if they do and the
0062   /// ranges were combined.
0063   bool merge(const DWARFAddressRange &RHS) {
0064     if (!intersects(RHS))
0065       return false;
0066     LowPC = std::min<uint64_t>(LowPC, RHS.LowPC);
0067     HighPC = std::max<uint64_t>(HighPC, RHS.HighPC);
0068     return true;
0069   }
0070 
0071   void dump(raw_ostream &OS, uint32_t AddressSize, DIDumpOptions DumpOpts = {},
0072             const DWARFObject *Obj = nullptr) const;
0073 };
0074 
0075 inline bool operator<(const DWARFAddressRange &LHS,
0076                       const DWARFAddressRange &RHS) {
0077   return std::tie(LHS.SectionIndex, LHS.LowPC, LHS.HighPC) < std::tie(RHS.SectionIndex, RHS.LowPC, RHS.HighPC);
0078 }
0079 
0080 inline bool operator==(const DWARFAddressRange &LHS,
0081                        const DWARFAddressRange &RHS) {
0082   return std::tie(LHS.SectionIndex, LHS.LowPC, LHS.HighPC) == std::tie(RHS.SectionIndex, RHS.LowPC, RHS.HighPC);
0083 }
0084 
0085 raw_ostream &operator<<(raw_ostream &OS, const DWARFAddressRange &R);
0086 
0087 /// DWARFAddressRangesVector - represents a set of absolute address ranges.
0088 using DWARFAddressRangesVector = std::vector<DWARFAddressRange>;
0089 
0090 } // end namespace llvm
0091 
0092 #endif // LLVM_DEBUGINFO_DWARF_DWARFADDRESSRANGE_H