]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/MC/MCAsmLayout.h
Merge clang trunk r238337 from ^/vendor/clang/dist, resolve conflicts,
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / MC / MCAsmLayout.h
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 class MCSymbolData;
22
23 /// Encapsulates the layout of an assembly file at a particular point in time.
24 ///
25 /// Assembly may require computing multiple layouts for a particular assembly
26 /// file as part of the relaxation process. This class encapsulates the layout
27 /// at a single point in time in such a way that it is always possible to
28 /// efficiently compute the exact address of any symbol in the assembly file,
29 /// even during the relaxation process.
30 class MCAsmLayout {
31   MCAssembler &Assembler;
32
33   /// List of sections in layout order.
34   llvm::SmallVector<MCSection *, 16> SectionOrder;
35
36   /// The last fragment which was laid out, or 0 if nothing has been laid
37   /// out. Fragments are always laid out in order, so all fragments with a
38   /// lower ordinal will be valid.
39   mutable DenseMap<const MCSection *, MCFragment *> LastValidFragment;
40
41   /// \brief Make sure that the layout for the given fragment is valid, lazily
42   /// computing it if necessary.
43   void ensureValid(const MCFragment *F) const;
44
45   /// \brief Is the layout for this fragment valid?
46   bool isFragmentValid(const MCFragment *F) const;
47
48 public:
49   MCAsmLayout(MCAssembler &Assembler);
50
51   /// Get the assembler object this is a layout for.
52   MCAssembler &getAssembler() const { return Assembler; }
53
54   /// \brief Invalidate the fragments starting with F because it has been
55   /// resized. The fragment's size should have already been updated, but
56   /// its bundle padding will be recomputed.
57   void invalidateFragmentsFrom(MCFragment *F);
58
59   /// \brief Perform layout for a single fragment, assuming that the previous
60   /// fragment has already been laid out correctly, and the parent section has
61   /// been initialized.
62   void layoutFragment(MCFragment *Fragment);
63
64   /// \name Section Access (in layout order)
65   /// @{
66
67   llvm::SmallVectorImpl<MCSection *> &getSectionOrder() { return SectionOrder; }
68   const llvm::SmallVectorImpl<MCSection *> &getSectionOrder() const {
69     return SectionOrder;
70   }
71
72   /// @}
73   /// \name Fragment Layout Data
74   /// @{
75
76   /// \brief Get the offset of the given fragment inside its containing section.
77   uint64_t getFragmentOffset(const MCFragment *F) const;
78
79   /// @}
80   /// \name Utility Functions
81   /// @{
82
83   /// \brief Get the address space size of the given section, as it effects
84   /// layout. This may differ from the size reported by \see getSectionSize() by
85   /// not including section tail padding.
86   uint64_t getSectionAddressSize(const MCSection *Sec) const;
87
88   /// \brief Get the data size of the given section, as emitted to the object
89   /// file. This may include additional padding, or be 0 for virtual sections.
90   uint64_t getSectionFileSize(const MCSection *Sec) const;
91
92   /// \brief Get the offset of the given symbol, as computed in the current
93   /// layout.
94   /// \return True on success.
95   bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const;
96
97   /// \brief Variant that reports a fatal error if the offset is not computable.
98   uint64_t getSymbolOffset(const MCSymbol &S) const;
99
100   /// \brief If this symbol is equivalent to A + Constant, return A.
101   const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
102
103   /// @}
104 };
105
106 } // end namespace llvm
107
108 #endif