1 //===- MCAsmLayout.h - Assembly Layout Object -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCASMLAYOUT_H
11 #define LLVM_MC_MCASMLAYOUT_H
13 #include "llvm/ADT/SmallVector.h"
21 /// Encapsulates the layout of an assembly file at a particular point in time.
23 /// Assembly may requiring compute 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 addresses of any symbol in the assembly file,
27 /// even during the relaxation process.
30 typedef llvm::SmallVectorImpl<MCSectionData*>::const_iterator const_iterator;
31 typedef llvm::SmallVectorImpl<MCSectionData*>::iterator iterator;
34 MCAssembler &Assembler;
36 /// List of sections in layout order.
37 llvm::SmallVector<MCSectionData*, 16> SectionOrder;
39 /// The last fragment which was layed out, or 0 if nothing has been layed
40 /// out. Fragments are always layed out in order, so all fragments with a
41 /// lower ordinal will be up to date.
42 mutable MCFragment *LastValidFragment;
44 /// \brief Make sure that the layout for the given fragment is valid, lazily
45 /// computing it if necessary.
46 void EnsureValid(const MCFragment *F) const;
48 bool isSectionUpToDate(const MCSectionData *SD) const;
49 bool isFragmentUpToDate(const MCFragment *F) const;
52 MCAsmLayout(MCAssembler &_Assembler);
54 /// Get the assembler object this is a layout for.
55 MCAssembler &getAssembler() const { return Assembler; }
57 /// \brief Update the layout because a fragment has been resized. The
58 /// fragments size should have already been updated, the \arg SlideAmount is
59 /// the delta from the old size.
60 void UpdateForSlide(MCFragment *F, int SlideAmount);
62 /// \brief Update the layout, replacing Src with Dst. The contents
63 /// of Src and Dst are not modified, and must be copied by the caller.
64 /// Src will be removed from the layout, but not deleted.
65 void ReplaceFragment(MCFragment *Src, MCFragment *Dst);
67 /// \brief Update the layout to coalesce Src into Dst. The contents
68 /// of Src and Dst are not modified, and must be coalesced by the caller.
69 /// Src will be removed from the layout, but not deleted.
70 void CoalesceFragments(MCFragment *Src, MCFragment *Dst);
72 /// \brief Perform a full layout.
75 /// \brief Perform layout for a single fragment, assuming that the previous
76 /// fragment has already been layed out correctly, and the parent section has
78 void LayoutFragment(MCFragment *Fragment);
80 /// \brief Performs initial layout for a single section, assuming that the
81 /// previous section (including its fragments) has already been layed out
83 void LayoutSection(MCSectionData *SD);
85 /// @name Section Access (in layout order)
88 llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() {
91 const llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() const {
96 /// @name Fragment Layout Data
99 /// \brief Get the effective size of the given fragment, as computed in the
101 uint64_t getFragmentEffectiveSize(const MCFragment *F) const;
103 /// \brief Get the offset of the given fragment inside its containing section.
104 uint64_t getFragmentOffset(const MCFragment *F) const;
107 /// @name Section Layout Data
110 /// \brief Get the computed address of the given section.
111 uint64_t getSectionAddress(const MCSectionData *SD) const;
114 /// @name Utility Functions
117 /// \brief Get the address of the given fragment, as computed in the current
119 uint64_t getFragmentAddress(const MCFragment *F) const;
121 /// \brief Get the address space size of the given section, as it effects
122 /// layout. This may differ from the size reported by \see getSectionSize() by
123 /// not including section tail padding.
124 uint64_t getSectionAddressSize(const MCSectionData *SD) const;
126 /// \brief Get the data size of the given section, as emitted to the object
127 /// file. This may include additional padding, or be 0 for virtual sections.
128 uint64_t getSectionFileSize(const MCSectionData *SD) const;
130 /// \brief Get the logical data size of the given section.
131 uint64_t getSectionSize(const MCSectionData *SD) const;
133 /// \brief Get the address of the given symbol, as computed in the current
135 uint64_t getSymbolAddress(const MCSymbolData *SD) const;
140 } // end namespace llvm