LLVM  6.0.0svn
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 MCSection;
20 class MCSymbol;
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  MCAssembler &Assembler;
31 
32  /// List of sections in layout order.
34 
35  /// The last fragment which was laid out, or 0 if nothing has been laid
36  /// out. Fragments are always laid out in order, so all fragments with a
37  /// lower ordinal will be valid.
38  mutable DenseMap<const MCSection *, MCFragment *> LastValidFragment;
39 
40  /// \brief Make sure that the layout for the given fragment is valid, lazily
41  /// computing it if necessary.
42  void ensureValid(const MCFragment *F) const;
43 
44  /// \brief Is the layout for this fragment valid?
45  bool isFragmentValid(const MCFragment *F) const;
46 
47 public:
48  MCAsmLayout(MCAssembler &Assembler);
49 
50  /// Get the assembler object this is a layout for.
51  MCAssembler &getAssembler() const { return Assembler; }
52 
53  /// \brief Invalidate the fragments starting with F because it has been
54  /// resized. The fragment's size should have already been updated, but
55  /// its bundle padding will be recomputed.
57 
58  /// \brief Perform layout for a single fragment, assuming that the previous
59  /// fragment has already been laid out correctly, and the parent section has
60  /// been initialized.
61  void layoutFragment(MCFragment *Fragment);
62 
63  /// \name Section Access (in layout order)
64  /// @{
65 
68  return SectionOrder;
69  }
70 
71  /// @}
72  /// \name Fragment Layout Data
73  /// @{
74 
75  /// \brief Get the offset of the given fragment inside its containing section.
76  uint64_t getFragmentOffset(const MCFragment *F) const;
77 
78  /// @}
79  /// \name Utility Functions
80  /// @{
81 
82  /// \brief Get the address space size of the given section, as it effects
83  /// layout. This may differ from the size reported by \see getSectionSize() by
84  /// not including section tail padding.
85  uint64_t getSectionAddressSize(const MCSection *Sec) const;
86 
87  /// \brief Get the data size of the given section, as emitted to the object
88  /// file. This may include additional padding, or be 0 for virtual sections.
89  uint64_t getSectionFileSize(const MCSection *Sec) const;
90 
91  /// \brief Get the offset of the given symbol, as computed in the current
92  /// layout.
93  /// \return True on success.
94  bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const;
95 
96  /// \brief Variant that reports a fatal error if the offset is not computable.
97  uint64_t getSymbolOffset(const MCSymbol &S) const;
98 
99  /// \brief If this symbol is equivalent to A + Constant, return A.
100  const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
101 
102  /// @}
103 };
104 
105 } // end namespace llvm
106 
107 #endif
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
uint64_t getSectionAddressSize(const MCSection *Sec) const
Get the address space size of the given section, as it effects layout.
Definition: MCFragment.cpp:175
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
F(f)
const llvm::SmallVectorImpl< MCSection * > & getSectionOrder() const
Definition: MCAsmLayout.h:67
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:29
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
Definition: MCAsmLayout.h:51
void layoutFragment(MCFragment *Fragment)
Perform layout for a single fragment, assuming that the previous fragment has already been laid out c...
MCAsmLayout(MCAssembler &Assembler)
Definition: MCFragment.cpp:32
void invalidateFragmentsFrom(MCFragment *F)
Invalidate the fragments starting with F because it has been resized.
Definition: MCFragment.cpp:51
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:129
llvm::SmallVectorImpl< MCSection * > & getSectionOrder()
Definition: MCAsmLayout.h:66
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
Definition: MCFragment.cpp:77
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:864
uint64_t getSectionFileSize(const MCSection *Sec) const
Get the data size of the given section, as emitted to the object file.
Definition: MCFragment.cpp:181
const MCSymbol * getBaseSymbol(const MCSymbol &Symbol) const
If this symbol is equivalent to A + Constant, return A.
Definition: MCFragment.cpp:139