LLVM 19.0.0git
MCAsmLayout.h
Go to the documentation of this file.
1//===- MCAsmLayout.h - Assembly Layout Object -------------------*- 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_MC_MCASMLAYOUT_H
10#define LLVM_MC_MCASMLAYOUT_H
11
12#include "llvm/ADT/DenseMap.h"
14
15namespace llvm {
16class MCAssembler;
17class MCFragment;
18class MCSection;
19class MCSymbol;
20
21/// Encapsulates the layout of an assembly file at a particular point in time.
22///
23/// Assembly may require computing multiple layouts for a particular assembly
24/// file as part of the relaxation process. This class encapsulates the layout
25/// at a single point in time in such a way that it is always possible to
26/// efficiently compute the exact address of any symbol in the assembly file,
27/// even during the relaxation process.
29 MCAssembler &Assembler;
30
31 /// List of sections in layout order.
33
34 /// Compute the layout for the section if necessary.
35 void ensureValid(const MCFragment *F) const;
36
37public:
38 MCAsmLayout(MCAssembler &Assembler);
39
40 /// Get the assembler object this is a layout for.
41 MCAssembler &getAssembler() const { return Assembler; }
42
43 /// Invalidate the fragments starting with F because it has been
44 /// resized. The fragment's size should have already been updated, but
45 /// its bundle padding will be recomputed.
47
49
50 /// \name Section Access (in layout order)
51 /// @{
52
55 return SectionOrder;
56 }
57
58 /// @}
59 /// \name Fragment Layout Data
60 /// @{
61
62 /// Get the offset of the given fragment inside its containing section.
64
65 /// @}
66 /// \name Utility Functions
67 /// @{
68
69 /// Get the address space size of the given section, as it effects
70 /// layout. This may differ from the size reported by \see
71 /// getSectionFileSize() by not including section tail padding.
73
74 /// Get the data size of the given section, as emitted to the object
75 /// file. This may include additional padding, or be 0 for virtual sections.
76 uint64_t getSectionFileSize(const MCSection *Sec) const;
77
78 /// Get the offset of the given symbol, as computed in the current
79 /// layout.
80 /// \return True on success.
81 bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const;
82
83 /// Variant that reports a fatal error if the offset is not computable.
84 uint64_t getSymbolOffset(const MCSymbol &S) const;
85
86 /// If this symbol is equivalent to A + Constant, return A.
87 const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
88
89 /// @}
90};
91
92} // end namespace llvm
93
94#endif
This file defines the DenseMap class.
#define F(x, y, z)
Definition: MD5.cpp:55
This file defines the SmallVector class.
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
void layoutBundle(MCFragment *F)
void invalidateFragmentsFrom(MCFragment *F)
Invalidate the fragments starting with F because it has been resized.
Definition: MCFragment.cpp:43
const MCSymbol * getBaseSymbol(const MCSymbol &Symbol) const
If this symbol is equivalent to A + Constant, return A.
Definition: MCFragment.cpp:107
uint64_t getSectionAddressSize(const MCSection *Sec) const
Get the address space size of the given section, as it effects layout.
Definition: MCFragment.cpp:143
llvm::SmallVectorImpl< MCSection * > & getSectionOrder()
Definition: MCAsmLayout.h:53
uint64_t getSectionFileSize(const MCSection *Sec) const
Get the data size of the given section, as emitted to the object file.
Definition: MCFragment.cpp:149
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
Get the offset of the given symbol, as computed in the current layout.
Definition: MCFragment.cpp:97
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
const llvm::SmallVectorImpl< MCSection * > & getSectionOrder() const
Definition: MCAsmLayout.h:54
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
Definition: MCAsmLayout.h:41
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:35
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18