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