LLVM API Documentation

MCAsmLayout.h
Go to the documentation of this file.
00001 //===- MCAsmLayout.h - Assembly Layout Object -------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_MC_MCASMLAYOUT_H
00011 #define LLVM_MC_MCASMLAYOUT_H
00012 
00013 #include "llvm/ADT/DenseMap.h"
00014 #include "llvm/ADT/SmallVector.h"
00015 
00016 namespace llvm {
00017 class MCAssembler;
00018 class MCFragment;
00019 class MCSectionData;
00020 class MCSymbol;
00021 class MCSymbolData;
00022 
00023 /// Encapsulates the layout of an assembly file at a particular point in time.
00024 ///
00025 /// Assembly may require computing multiple layouts for a particular assembly
00026 /// file as part of the relaxation process. This class encapsulates the layout
00027 /// at a single point in time in such a way that it is always possible to
00028 /// efficiently compute the exact address of any symbol in the assembly file,
00029 /// even during the relaxation process.
00030 class MCAsmLayout {
00031 public:
00032   typedef llvm::SmallVectorImpl<MCSectionData*>::const_iterator const_iterator;
00033   typedef llvm::SmallVectorImpl<MCSectionData*>::iterator iterator;
00034 
00035 private:
00036   MCAssembler &Assembler;
00037 
00038   /// List of sections in layout order.
00039   llvm::SmallVector<MCSectionData*, 16> SectionOrder;
00040 
00041   /// The last fragment which was laid out, or 0 if nothing has been laid
00042   /// out. Fragments are always laid out in order, so all fragments with a
00043   /// lower ordinal will be valid.
00044   mutable DenseMap<const MCSectionData*, MCFragment*> LastValidFragment;
00045 
00046   /// \brief Make sure that the layout for the given fragment is valid, lazily
00047   /// computing it if necessary.
00048   void ensureValid(const MCFragment *F) const;
00049 
00050   /// \brief Is the layout for this fragment valid?
00051   bool isFragmentValid(const MCFragment *F) const;
00052 
00053   /// \brief Compute the amount of padding required before this fragment to
00054   /// obey bundling restrictions.
00055   uint64_t computeBundlePadding(const MCFragment *F,
00056                                 uint64_t FOffset, uint64_t FSize);
00057 
00058 public:
00059   MCAsmLayout(MCAssembler &_Assembler);
00060 
00061   /// Get the assembler object this is a layout for.
00062   MCAssembler &getAssembler() const { return Assembler; }
00063 
00064   /// \brief Invalidate the fragments starting with F because it has been
00065   /// resized. The fragment's size should have already been updated, but
00066   /// its bundle padding will be recomputed.
00067   void invalidateFragmentsFrom(MCFragment *F);
00068 
00069   /// \brief Perform layout for a single fragment, assuming that the previous
00070   /// fragment has already been laid out correctly, and the parent section has
00071   /// been initialized.
00072   void layoutFragment(MCFragment *Fragment);
00073 
00074   /// @name Section Access (in layout order)
00075   /// @{
00076 
00077   llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() {
00078     return SectionOrder;
00079   }
00080   const llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() const {
00081     return SectionOrder;
00082   }
00083 
00084   /// @}
00085   /// @name Fragment Layout Data
00086   /// @{
00087 
00088   /// \brief Get the offset of the given fragment inside its containing section.
00089   uint64_t getFragmentOffset(const MCFragment *F) const;
00090 
00091   /// @}
00092   /// @name Utility Functions
00093   /// @{
00094 
00095   /// \brief Get the address space size of the given section, as it effects
00096   /// layout. This may differ from the size reported by \see getSectionSize() by
00097   /// not including section tail padding.
00098   uint64_t getSectionAddressSize(const MCSectionData *SD) const;
00099 
00100   /// \brief Get the data size of the given section, as emitted to the object
00101   /// file. This may include additional padding, or be 0 for virtual sections.
00102   uint64_t getSectionFileSize(const MCSectionData *SD) const;
00103 
00104   /// \brief Get the offset of the given symbol, as computed in the current
00105   /// layout.
00106   /// \result True on success.
00107   bool getSymbolOffset(const MCSymbolData *SD, uint64_t &Val) const;
00108 
00109   /// \brief Variant that reports a fatal error if the offset is not computable.
00110   uint64_t getSymbolOffset(const MCSymbolData *SD) const;
00111 
00112   /// \brief If this symbol is equivalent to A + Constant, return A.
00113   const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
00114 
00115   /// @}
00116 };
00117 
00118 } // end namespace llvm
00119 
00120 #endif