LLVM  15.0.0git
ExtractRanges.cpp
Go to the documentation of this file.
1 //===- ExtractRanges.cpp ----------------------------------------*- 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 
12 #include <algorithm>
13 #include <inttypes.h>
14 
15 namespace llvm {
16 namespace gsym {
17 
18 void encodeRange(const AddressRange &Range, FileWriter &O, uint64_t BaseAddr) {
19  assert(Range.start() >= BaseAddr);
20  O.writeULEB(Range.start() - BaseAddr);
21  O.writeULEB(Range.size());
22 }
23 
25  uint64_t &Offset) {
26  const uint64_t AddrOffset = Data.getULEB128(&Offset);
27  const uint64_t Size = Data.getULEB128(&Offset);
28  const uint64_t StartAddr = BaseAddr + AddrOffset;
29 
30  return {StartAddr, StartAddr + Size};
31 }
32 
33 void encodeRanges(const AddressRanges &Ranges, FileWriter &O,
34  uint64_t BaseAddr) {
35  O.writeULEB(Ranges.size());
36  if (Ranges.empty())
37  return;
38  for (auto Range : Ranges)
39  encodeRange(Range, O, BaseAddr);
40 }
41 
42 void decodeRanges(AddressRanges &Ranges, DataExtractor &Data, uint64_t BaseAddr,
43  uint64_t &Offset) {
44  Ranges.clear();
45  uint64_t NumRanges = Data.getULEB128(&Offset);
46  Ranges.reserve(NumRanges);
47  for (uint64_t RangeIdx = 0; RangeIdx < NumRanges; RangeIdx++)
48  Ranges.insert(decodeRange(Data, BaseAddr, Offset));
49 }
50 
51 void skipRange(DataExtractor &Data, uint64_t &Offset) {
52  Data.getULEB128(&Offset);
53  Data.getULEB128(&Offset);
54 }
55 
57  uint64_t NumRanges = Data.getULEB128(&Offset);
58  for (uint64_t I = 0; I < NumRanges; ++I)
59  skipRange(Data, Offset);
60  return NumRanges;
61 }
62 
63 } // namespace gsym
64 
66  return OS << '[' << HEX64(R.start()) << " - " << HEX64(R.end()) << ")";
67 }
68 
70  size_t Size = AR.size();
71  for (size_t I = 0; I < Size; ++I) {
72  if (I)
73  OS << ' ';
74  OS << AR[I];
75  }
76  return OS;
77 }
78 
79 } // namespace llvm
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::AddressRanges::reserve
void reserve(size_t Capacity)
Definition: AddressRanges.h:64
llvm::gsym::decodeRange
AddressRange decodeRange(DataExtractor &Data, uint64_t BaseAddr, uint64_t &Offset)
AddressRange objects are encoded and decoded to be relative to a base address.
Definition: ExtractRanges.cpp:24
ExtractRanges.h
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::gsym::decodeRanges
void decodeRanges(AddressRanges &Ranges, DataExtractor &Data, uint64_t BaseAddr, uint64_t &Offset)
Address ranges are decoded and encoded to be relative to a base address.
Definition: ExtractRanges.cpp:42
llvm::AddressRanges::empty
bool empty() const
Definition: AddressRanges.h:59
llvm::gsym::skipRange
void skipRange(DataExtractor &Data, uint64_t &Offset)
Skip an address range object in the specified data a the specified offset.
Definition: ExtractRanges.cpp:51
llvm::gsym::skipRanges
uint64_t skipRanges(DataExtractor &Data, uint64_t &Offset)
Skip an address range object in the specified data a the specified offset.
Definition: ExtractRanges.cpp:56
llvm::gsym::encodeRange
void encodeRange(const AddressRange &Range, FileWriter &O, uint64_t BaseAddr)
Definition: ExtractRanges.cpp:18
HEX64
#define HEX64(v)
Definition: ExtractRanges.h:21
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
llvm::AddressRange
A class that represents an address range.
Definition: AddressRanges.h:21
llvm::AddressRanges::insert
void insert(AddressRange Range)
Definition: AddressRanges.cpp:15
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:240
uint64_t
I
#define I(x, y, z)
Definition: MD5.cpp:58
FileWriter.h
llvm::gsym::FileWriter
A simplified binary data writer class that doesn't require targets, target definitions,...
Definition: FileWriter.h:29
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AddressRanges::clear
void clear()
Definition: AddressRanges.h:58
llvm::gsym::encodeRanges
void encodeRanges(const AddressRanges &Ranges, FileWriter &O, uint64_t BaseAddr)
Definition: ExtractRanges.cpp:33
DataExtractor.h
llvm::AddressRanges::size
size_t size() const
Definition: AddressRanges.h:65
llvm::AddressRange::size
uint64_t size() const
Definition: AddressRanges.h:29
llvm::DataExtractor
Definition: DataExtractor.h:41
llvm::AddressRanges
The AddressRanges class helps normalize address range collections.
Definition: AddressRanges.h:52
llvm::AddressRange::start
uint64_t start() const
Definition: AddressRanges.h:27