LLVM  13.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"
13 #include "llvm/ADT/SmallVector.h"
14 
15 namespace llvm {
16 class MCAssembler;
17 class MCFragment;
18 class MCSection;
19 class 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.
28 class MCAsmLayout {
29  MCAssembler &Assembler;
30 
31  /// List of sections in layout order.
33 
34  /// The last fragment which was laid out, or 0 if nothing has been laid
35  /// out. Fragments are always laid out in order, so all fragments with a
36  /// lower ordinal will be valid.
37  mutable DenseMap<const MCSection *, MCFragment *> LastValidFragment;
38 
39  /// Make sure that the layout for the given fragment is valid, lazily
40  /// computing it if necessary.
41  void ensureValid(const MCFragment *F) const;
42 
43  /// Is the layout for this fragment valid?
44  bool isFragmentValid(const MCFragment *F) const;
45 
46 public:
47  MCAsmLayout(MCAssembler &Assembler);
48 
49  /// Get the assembler object this is a layout for.
50  MCAssembler &getAssembler() const { return Assembler; }
51 
52  /// \returns whether the offset of fragment \p F can be obtained via
53  /// getFragmentOffset.
54  bool canGetFragmentOffset(const MCFragment *F) const;
55 
56  /// Invalidate the fragments starting with F because it has been
57  /// resized. The fragment's size should have already been updated, but
58  /// its bundle padding will be recomputed.
60 
61  /// Perform layout for a single fragment, assuming that the previous
62  /// fragment has already been laid out correctly, and the parent section has
63  /// been initialized.
64  void layoutFragment(MCFragment *Fragment);
65 
66  /// \name Section Access (in layout order)
67  /// @{
68 
71  return SectionOrder;
72  }
73 
74  /// @}
75  /// \name Fragment Layout Data
76  /// @{
77 
78  /// Get the offset of the given fragment inside its containing section.
79  uint64_t getFragmentOffset(const MCFragment *F) const;
80 
81  /// @}
82  /// \name Utility Functions
83  /// @{
84 
85  /// Get the address space size of the given section, as it effects
86  /// layout. This may differ from the size reported by \see getSectionSize() by
87  /// not including section tail padding.
88  uint64_t getSectionAddressSize(const MCSection *Sec) const;
89 
90  /// Get the data size of the given section, as emitted to the object
91  /// file. This may include additional padding, or be 0 for virtual sections.
92  uint64_t getSectionFileSize(const MCSection *Sec) const;
93 
94  /// Get the offset of the given symbol, as computed in the current
95  /// layout.
96  /// \return True on success.
97  bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const;
98 
99  /// Variant that reports a fatal error if the offset is not computable.
100  uint64_t getSymbolOffset(const MCSymbol &S) const;
101 
102  /// If this symbol is equivalent to A + Constant, return A.
103  const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
104 
105  /// @}
106 };
107 
108 } // end namespace llvm
109 
110 #endif
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
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
DenseMap.h
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MCFragment
Definition: MCFragment.h:31
llvm::MCAsmLayout::invalidateFragmentsFrom
void invalidateFragmentsFrom(MCFragment *F)
Invalidate the fragments starting with F because it has been resized.
Definition: MCFragment.cpp:70
llvm::MCAsmLayout::layoutFragment
void layoutFragment(MCFragment *Fragment)
Perform layout for a single fragment, assuming that the previous fragment has already been laid out c...
Definition: MCAssembler.cpp:395
llvm::MCAsmLayout::getSectionOrder
llvm::SmallVectorImpl< MCSection * > & getSectionOrder()
Definition: MCAsmLayout.h:69
llvm::MCAsmLayout::getSectionFileSize
uint64_t getSectionFileSize(const MCSection *Sec) const
Get the data size of the given section, as emitted to the object file.
Definition: MCFragment.cpp:200
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::MCAsmLayout::getBaseSymbol
const MCSymbol * getBaseSymbol(const MCSymbol &Symbol) const
If this symbol is equivalent to A + Constant, return A.
Definition: MCFragment.cpp:158
llvm::DenseMap
Definition: DenseMap.h:714
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCAsmLayout::getFragmentOffset
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
Definition: MCFragment.cpp:96
llvm::MCAsmLayout::MCAsmLayout
MCAsmLayout(MCAssembler &Assembler)
Definition: MCFragment.cpp:32
llvm::MCAsmLayout::getSectionOrder
const llvm::SmallVectorImpl< MCSection * > & getSectionOrder() const
Definition: MCAsmLayout.h:70
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
llvm::MCAsmLayout::getSymbolOffset
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:148
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
SmallVector.h
llvm::MCAsmLayout::canGetFragmentOffset
bool canGetFragmentOffset(const MCFragment *F) const
Definition: MCFragment.cpp:51
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::MCAsmLayout::getAssembler
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
Definition: MCAsmLayout.h:50
llvm::MCAsmLayout::getSectionAddressSize
uint64_t getSectionAddressSize(const MCSection *Sec) const
Get the address space size of the given section, as it effects layout.
Definition: MCFragment.cpp:194
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172