LLVM  13.0.0git
MCLinkerOptimizationHint.cpp
Go to the documentation of this file.
1 //===- llvm/MC/MCLinkerOptimizationHint.cpp ----- LOH handling ------------===//
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 
10 #include "llvm/MC/MCAsmLayout.h"
12 #include "llvm/Support/LEB128.h"
14 #include <cstddef>
15 #include <cstdint>
16 
17 using namespace llvm;
18 
19 // Each LOH is composed by, in this order (each field is encoded using ULEB128):
20 // - Its kind.
21 // - Its number of arguments (let say N).
22 // - Its arg1.
23 // - ...
24 // - Its argN.
25 // <arg1> to <argN> are absolute addresses in the object file, i.e.,
26 // relative addresses from the beginning of the object file.
27 void MCLOHDirective::emit_impl(raw_ostream &OutStream,
28  const MachObjectWriter &ObjWriter,
29  const MCAsmLayout &Layout) const {
30  encodeULEB128(Kind, OutStream);
31  encodeULEB128(Args.size(), OutStream);
32  for (const MCSymbol *Arg : Args)
33  encodeULEB128(ObjWriter.getSymbolAddress(*Arg, Layout), OutStream);
34 }
35 
37  const MCAsmLayout &Layout) const {
38  raw_ostream &OutStream = ObjWriter.W.OS;
39  emit_impl(OutStream, ObjWriter, Layout);
40 }
41 
43  const MCAsmLayout &Layout) const {
44  class raw_counting_ostream : public raw_ostream {
45  uint64_t Count = 0;
46 
47  void write_impl(const char *, size_t size) override { Count += size; }
48 
49  uint64_t current_pos() const override { return Count; }
50 
51  public:
52  raw_counting_ostream() = default;
53  ~raw_counting_ostream() override { flush(); }
54  };
55 
56  raw_counting_ostream OutStream;
57  emit_impl(OutStream, ObjWriter, Layout);
58  return OutStream.tell();
59 }
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::MachObjectWriter
Definition: MCMachObjectWriter.h:84
llvm::support::endian::Writer::OS
raw_ostream & OS
Definition: EndianStream.h:53
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
MCMachObjectWriter.h
LEB128.h
llvm::MCLOHDirective::emit
void emit(MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const
Emit this directive as: <kind, numArgs, addr1, ..., addrN>
Definition: MCLinkerOptimizationHint.cpp:36
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1515
llvm::MachObjectWriter::getSymbolAddress
uint64_t getSymbolAddress(const MCSymbol &S, const MCAsmLayout &Layout) const
Definition: MachObjectWriter.cpp:87
MCAsmLayout.h
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
llvm::MachObjectWriter::W
support::endian::Writer W
Definition: MCMachObjectWriter.h:136
MCLinkerOptimizationHint.h
llvm::MCLOHDirective::getEmitSize
uint64_t getEmitSize(const MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const
Get the size in bytes of this directive if emitted in ObjWriter with the given Layout.
Definition: MCLinkerOptimizationHint.cpp:42
llvm::encodeULEB128
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:80
raw_ostream.h