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/DenseMap.h"
14 #include "llvm/ADT/SmallVector.h"
22 /// Encapsulates the layout of an assembly file at a particular point in time.
24 /// Assembly may requiring compute 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 addresses of any symbol in the assembly file,
28 /// even during the relaxation process.
31 typedef llvm::SmallVectorImpl<MCSectionData*>::const_iterator const_iterator;
32 typedef llvm::SmallVectorImpl<MCSectionData*>::iterator iterator;
35 MCAssembler &Assembler;
37 /// List of sections in layout order.
38 llvm::SmallVector<MCSectionData*, 16> SectionOrder;
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 up to date.
43 mutable DenseMap<const MCSectionData*, MCFragment *> LastValidFragment;
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;
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 Invalidate all following fragments because a fragment has been
58 /// resized. The fragments size should have already been updated.
59 void Invalidate(MCFragment *F);
61 /// \brief Perform layout for a single fragment, assuming that the previous
62 /// fragment has already been laid out correctly, and the parent section has
64 void LayoutFragment(MCFragment *Fragment);
66 /// @name Section Access (in layout order)
69 llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() {
72 const llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() const {
77 /// @name Fragment Layout Data
80 /// \brief Get the offset of the given fragment inside its containing section.
81 uint64_t getFragmentOffset(const MCFragment *F) const;
84 /// @name Utility Functions
87 /// \brief Get the address space size of the given section, as it effects
88 /// layout. This may differ from the size reported by \see getSectionSize() by
89 /// not including section tail padding.
90 uint64_t getSectionAddressSize(const MCSectionData *SD) const;
92 /// \brief Get the data size of the given section, as emitted to the object
93 /// file. This may include additional padding, or be 0 for virtual sections.
94 uint64_t getSectionFileSize(const MCSectionData *SD) const;
96 /// \brief Get the offset of the given symbol, as computed in the current
98 uint64_t getSymbolOffset(const MCSymbolData *SD) const;
103 } // end namespace llvm