LLVM  10.0.0svn
Range.h
Go to the documentation of this file.
1 //===- Range.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_GSYM_RANGE_H
10 #define LLVM_DEBUGINFO_GSYM_RANGE_H
11 
12 #include "llvm/Support/Format.h"
14 #include <stdint.h>
15 #include <vector>
16 
17 #define HEX8(v) llvm::format_hex(v, 4)
18 #define HEX16(v) llvm::format_hex(v, 6)
19 #define HEX32(v) llvm::format_hex(v, 10)
20 #define HEX64(v) llvm::format_hex(v, 18)
21 
22 namespace llvm {
23 class DataExtractor;
24 class raw_ostream;
25 
26 namespace gsym {
27 
28 class FileWriter;
29 
30 /// A class that represents an address range. The range is specified using
31 /// a start and an end address.
32 struct AddressRange {
33  uint64_t Start;
34  uint64_t End;
35  AddressRange() : Start(0), End(0) {}
36  AddressRange(uint64_t S, uint64_t E) : Start(S), End(E) {}
37  uint64_t size() const { return End - Start; }
38  bool contains(uint64_t Addr) const { return Start <= Addr && Addr < End; }
39  bool intersects(const AddressRange &R) const {
40  return Start < R.End && R.Start < End;
41  }
42 
43  bool operator==(const AddressRange &R) const {
44  return Start == R.Start && End == R.End;
45  }
46  bool operator!=(const AddressRange &R) const {
47  return !(*this == R);
48  }
49  bool operator<(const AddressRange &R) const {
50  return std::make_pair(Start, End) < std::make_pair(R.Start, R.End);
51  }
52  /// AddressRange objects are encoded and decoded to be relative to a base
53  /// address. This will be the FunctionInfo's start address if the AddressRange
54  /// is directly contained in a FunctionInfo, or a base address of the
55  /// containing parent AddressRange or AddressRanges. This allows address
56  /// ranges to be efficiently encoded using ULEB128 encodings as we encode the
57  /// offset and size of each range instead of full addresses. This also makes
58  /// encoded addresses easy to relocate as we just need to relocate one base
59  /// address.
60  /// @{
61  void decode(DataExtractor &Data, uint64_t BaseAddr, uint64_t &Offset);
62  void encode(FileWriter &O, uint64_t BaseAddr) const;
63  /// @}
64 };
65 
67 
68 /// The AddressRanges class helps normalize address range collections.
69 /// This class keeps a sorted vector of AddressRange objects and can perform
70 /// insertions and searches efficiently. The address ranges are always sorted
71 /// and never contain any invalid or empty address ranges. This allows us to
72 /// emit address ranges into the GSYM file efficiently. Intersecting address
73 /// ranges are combined during insertion so that we can emit the most compact
74 /// representation for address ranges when writing to disk.
76 protected:
77  using Collection = std::vector<AddressRange>;
79 public:
80  void clear() { Ranges.clear(); }
81  bool empty() const { return Ranges.empty(); }
82  bool contains(uint64_t Addr) const;
83  bool contains(AddressRange Range) const;
84  void insert(AddressRange Range);
85  size_t size() const { return Ranges.size(); }
86  bool operator==(const AddressRanges &RHS) const {
87  return Ranges == RHS.Ranges;
88  }
89  const AddressRange &operator[](size_t i) const {
90  assert(i < Ranges.size());
91  return Ranges[i];
92  }
93  Collection::const_iterator begin() const { return Ranges.begin(); }
94  Collection::const_iterator end() const { return Ranges.end(); }
95 
96  /// Address ranges are decoded and encoded to be relative to a base address.
97  /// See the AddressRange comment for the encode and decode methods for full
98  /// details.
99  /// @{
100  void decode(DataExtractor &Data, uint64_t BaseAddr, uint64_t &Offset);
101  void encode(FileWriter &O, uint64_t BaseAddr) const;
102  /// @}
103 };
104 
106 
107 } // namespace gsym
108 } // namespace llvm
109 
110 #endif // #ifndef LLVM_DEBUGINFO_GSYM_RANGE_H
Collection::const_iterator end() const
Definition: Range.h:94
AddressRange(uint64_t S, uint64_t E)
Definition: Range.h:36
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Collection Ranges
Definition: Range.h:78
void encode(FileWriter &O, uint64_t BaseAddr) const
Definition: Range.cpp:70
bool contains(uint64_t Addr) const
Definition: Range.h:38
bool operator!=(const AddressRange &R) const
Definition: Range.h:46
void decode(DataExtractor &Data, uint64_t BaseAddr, uint64_t &Offset)
AddressRange objects are encoded and decoded to be relative to a base address.
Definition: Range.cpp:76
The AddressRanges class helps normalize address range collections.
Definition: Range.h:75
bool operator==(const AddressRange &R) const
Definition: Range.h:43
bool operator<(const AddressRange &R) const
Definition: Range.h:49
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
A simplified binary data writer class that doesn&#39;t require targets, target definitions, architectures, or require any other optional compile time libraries to be enabled via the build process.
Definition: FileWriter.h:29
bool empty() const
Definition: Range.h:81
size_t size() const
Definition: Range.h:85
A class that represents an address range.
Definition: Range.h:32
const AddressRange & operator[](size_t i) const
Definition: Range.h:89
std::vector< AddressRange > Collection
Definition: Range.h:77
bool intersects(const AddressRange &R) const
Definition: Range.h:39
bool operator==(const AddressRanges &RHS) const
Definition: Range.h:86
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint64_t size() const
Definition: Range.h:37
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Collection::const_iterator begin() const
Definition: Range.h:93
raw_ostream & operator<<(raw_ostream &OS, const FunctionInfo &R)