LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCAsmLayout.h
Go to the documentation of this file.
1 //===- MCAsmLayout.h - Assembly Layout Object -------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_MC_MCASMLAYOUT_H
11 #define LLVM_MC_MCASMLAYOUT_H
12 
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/SmallVector.h"
15 
16 namespace llvm {
17 class MCAssembler;
18 class MCFragment;
19 class MCSectionData;
20 class MCSymbolData;
21 
22 /// Encapsulates the layout of an assembly file at a particular point in time.
23 ///
24 /// Assembly may require computing multiple layouts for a particular assembly
25 /// file as part of the relaxation process. This class encapsulates the layout
26 /// at a single point in time in such a way that it is always possible to
27 /// efficiently compute the exact address of any symbol in the assembly file,
28 /// even during the relaxation process.
29 class MCAsmLayout {
30 public:
33 
34 private:
35  MCAssembler &Assembler;
36 
37  /// List of sections in layout order.
39 
40  /// The last fragment which was laid out, or 0 if nothing has been laid
41  /// out. Fragments are always laid out in order, so all fragments with a
42  /// lower ordinal will be valid.
43  mutable DenseMap<const MCSectionData*, MCFragment*> LastValidFragment;
44 
45  /// \brief Make sure that the layout for the given fragment is valid, lazily
46  /// computing it if necessary.
47  void ensureValid(const MCFragment *F) const;
48 
49  /// \brief Is the layout for this fragment valid?
50  bool isFragmentValid(const MCFragment *F) const;
51 
52  /// \brief Compute the amount of padding required before this fragment to
53  /// obey bundling restrictions.
54  uint64_t computeBundlePadding(const MCFragment *F,
55  uint64_t FOffset, uint64_t FSize);
56 
57 public:
58  MCAsmLayout(MCAssembler &_Assembler);
59 
60  /// Get the assembler object this is a layout for.
61  MCAssembler &getAssembler() const { return Assembler; }
62 
63  /// \brief Invalidate the fragments starting with F because it has been
64  /// resized. The fragment's size should have already been updated, but
65  /// its bundle padding will be recomputed.
67 
68  /// \brief Perform layout for a single fragment, assuming that the previous
69  /// fragment has already been laid out correctly, and the parent section has
70  /// been initialized.
71  void layoutFragment(MCFragment *Fragment);
72 
73  /// @name Section Access (in layout order)
74  /// @{
75 
77  return SectionOrder;
78  }
80  return SectionOrder;
81  }
82 
83  /// @}
84  /// @name Fragment Layout Data
85  /// @{
86 
87  /// \brief Get the offset of the given fragment inside its containing section.
88  uint64_t getFragmentOffset(const MCFragment *F) const;
89 
90  /// @}
91  /// @name Utility Functions
92  /// @{
93 
94  /// \brief Get the address space size of the given section, as it effects
95  /// layout. This may differ from the size reported by \see getSectionSize() by
96  /// not including section tail padding.
97  uint64_t getSectionAddressSize(const MCSectionData *SD) const;
98 
99  /// \brief Get the data size of the given section, as emitted to the object
100  /// file. This may include additional padding, or be 0 for virtual sections.
101  uint64_t getSectionFileSize(const MCSectionData *SD) const;
102 
103  /// \brief Get the offset of the given symbol, as computed in the current
104  /// layout.
105  uint64_t getSymbolOffset(const MCSymbolData *SD) const;
106 
107  /// @}
108 };
109 
110 } // end namespace llvm
111 
112 #endif
llvm::SmallVectorImpl< MCSectionData * >::iterator iterator
Definition: MCAsmLayout.h:32
MCAsmLayout(MCAssembler &_Assembler)
Definition: MCAssembler.cpp:64
const llvm::SmallVectorImpl< MCSectionData * > & getSectionOrder() const
Definition: MCAsmLayout.h:79
F(f)
void layoutFragment(MCFragment *Fragment)
Perform layout for a single fragment, assuming that the previous fragment has already been laid out c...
llvm::SmallVectorImpl< MCSectionData * >::const_iterator const_iterator
Definition: MCAsmLayout.h:31
void invalidateFragmentsFrom(MCFragment *F)
Invalidate the fragments starting with F because it has been resized. The fragment's size should have...
Definition: MCAssembler.cpp:85
llvm::SmallVectorImpl< MCSectionData * > & getSectionOrder()
Definition: MCAsmLayout.h:76
uint64_t getSectionFileSize(const MCSectionData *SD) const
Get the data size of the given section, as emitted to the object file. This may include additional pa...
uint64_t getSymbolOffset(const MCSymbolData *SD) const
Get the offset of the given symbol, as computed in the current layout.
uint64_t getSectionAddressSize(const MCSectionData *SD) const
Get the address space size of the given section, as it effects layout. This may differ from the size ...
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
Definition: MCAsmLayout.h:61