[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / include / llvm / DebugInfo / GSYM / Range.h
blobab17f060a731dfbee3b44c25ce7f4f249329215e
1 //===- AddressRange.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_GSYM_RANGE_H
10 #define LLVM_DEBUGINFO_GSYM_RANGE_H
12 #include "llvm/Support/Format.h"
13 #include "llvm/Support/raw_ostream.h"
14 #include <stdint.h>
15 #include <vector>
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)
22 namespace llvm {
23 class DataExtractor;
24 class raw_ostream;
26 namespace gsym {
28 class FileWriter;
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;
43 bool operator==(const AddressRange &R) const {
44 return Start == R.Start && End == R.End;
46 bool operator!=(const AddressRange &R) const {
47 return !(*this == R);
49 bool operator<(const AddressRange &R) const {
50 return std::make_pair(Start, End) < std::make_pair(R.Start, R.End);
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 /// @}
66 raw_ostream &operator<<(raw_ostream &OS, const AddressRange &R);
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.
75 class AddressRanges {
76 protected:
77 using Collection = std::vector<AddressRange>;
78 Collection Ranges;
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;
89 const AddressRange &operator[](size_t i) const {
90 assert(i < Ranges.size());
91 return Ranges[i];
93 Collection::const_iterator begin() const { return Ranges.begin(); }
94 Collection::const_iterator end() const { return Ranges.end(); }
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 /// @}
105 raw_ostream &operator<<(raw_ostream &OS, const AddressRanges &AR);
107 } // namespace gsym
108 } // namespace llvm
110 #endif // #ifndef LLVM_DEBUGINFO_GSYM_RANGE_H