1 //===-- LVRange.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 // This file defines the LVRange class, which is used to describe a debug 10 // information range. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVRANGE_H 15 #define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVRANGE_H 16 17 #include "llvm/ADT/IntervalTree.h" 18 #include "llvm/DebugInfo/LogicalView/Core/LVObject.h" 19 #include "llvm/Support/Compiler.h" 20 21 namespace llvm { 22 namespace logicalview { 23 24 using LVAddressRange = std::pair<LVAddress, LVAddress>; 25 26 class LVRangeEntry final { 27 LVAddress Lower = 0; 28 LVAddress Upper = 0; 29 LVScope *Scope = nullptr; 30 31 public: 32 using RangeType = LVAddress; 33 34 LVRangeEntry() = delete; LVRangeEntry(LVAddress LowerAddress,LVAddress UpperAddress,LVScope * Scope)35 LVRangeEntry(LVAddress LowerAddress, LVAddress UpperAddress, LVScope *Scope) 36 : Lower(LowerAddress), Upper(UpperAddress), Scope(Scope) {} 37 lower()38 RangeType lower() const { return Lower; } upper()39 RangeType upper() const { return Upper; } addressRange()40 LVAddressRange addressRange() const { 41 return LVAddressRange(lower(), upper()); 42 } scope()43 LVScope *scope() const { return Scope; } 44 }; 45 46 // Class to represent a list of range addresses associated with a 47 // scope; the addresses are stored in ascending order and can overlap. 48 using LVRangeEntries = std::vector<LVRangeEntry>; 49 50 class LLVM_ABI LVRange final : public LVObject { 51 /// Map of where a user value is live, and its location. 52 using LVRangesTree = IntervalTree<LVAddress, LVScope *>; 53 using LVAllocator = LVRangesTree::Allocator; 54 55 LVAllocator Allocator; 56 LVRangesTree RangesTree; 57 LVRangeEntries RangeEntries; 58 LVAddress Lower = MaxAddress; 59 LVAddress Upper = 0; 60 61 public: LVRange()62 LVRange() : LVObject(), RangesTree(Allocator) {} 63 LVRange(const LVRange &) = delete; 64 LVRange &operator=(const LVRange &) = delete; 65 ~LVRange() = default; 66 67 void addEntry(LVScope *Scope, LVAddress LowerAddress, LVAddress UpperAddress); 68 void addEntry(LVScope *Scope); 69 LVScope *getEntry(LVAddress Address) const; 70 LVScope *getEntry(LVAddress LowerAddress, LVAddress UpperAddress) const; 71 bool hasEntry(LVAddress Low, LVAddress High) const; getLower()72 LVAddress getLower() const { return Lower; } getUpper()73 LVAddress getUpper() const { return Upper; } 74 getEntries()75 const LVRangeEntries &getEntries() const { return RangeEntries; } 76 clear()77 void clear() { 78 RangeEntries.clear(); 79 Lower = MaxAddress; 80 Upper = 0; 81 } empty()82 bool empty() const { return RangeEntries.empty(); } 83 void sort(); 84 85 void startSearch(); endSearch()86 void endSearch() {} 87 88 void print(raw_ostream &OS, bool Full = true) const override; 89 void printExtra(raw_ostream &OS, bool Full = true) const override {} 90 }; 91 92 } // end namespace logicalview 93 } // end namespace llvm 94 95 #endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVRANGE_H 96