Coverage Report

Created: 2019-02-20 00:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/MC/MCSection.h
Line
Count
Source (jump to first uncovered line)
1
//===- MCSection.h - Machine Code Sections ----------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file declares the MCSection class.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_MC_MCSECTION_H
14
#define LLVM_MC_MCSECTION_H
15
16
#include "llvm/ADT/SmallVector.h"
17
#include "llvm/ADT/ilist.h"
18
#include "llvm/MC/MCFragment.h"
19
#include "llvm/MC/SectionKind.h"
20
#include <cassert>
21
#include <utility>
22
23
namespace llvm {
24
25
class MCAsmInfo;
26
class MCContext;
27
class MCExpr;
28
class MCSymbol;
29
class raw_ostream;
30
class Triple;
31
32
template <> struct ilist_alloc_traits<MCFragment> {
33
  static void deleteNode(MCFragment *V);
34
};
35
36
/// Instances of this class represent a uniqued identifier for a section in the
37
/// current translation unit.  The MCContext class uniques and creates these.
38
class MCSection {
39
public:
40
  enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO, SV_Wasm };
41
42
  /// Express the state of bundle locked groups while emitting code.
43
  enum BundleLockStateType {
44
    NotBundleLocked,
45
    BundleLocked,
46
    BundleLockedAlignToEnd
47
  };
48
49
  using FragmentListType = iplist<MCFragment>;
50
51
  using const_iterator = FragmentListType::const_iterator;
52
  using iterator = FragmentListType::iterator;
53
54
  using const_reverse_iterator = FragmentListType::const_reverse_iterator;
55
  using reverse_iterator = FragmentListType::reverse_iterator;
56
57
private:
58
  MCSymbol *Begin;
59
  MCSymbol *End = nullptr;
60
  /// The alignment requirement of this section.
61
  unsigned Alignment = 1;
62
  /// The section index in the assemblers section list.
63
  unsigned Ordinal = 0;
64
  /// The index of this section in the layout order.
65
  unsigned LayoutOrder;
66
67
  /// Keeping track of bundle-locked state.
68
  BundleLockStateType BundleLockState = NotBundleLocked;
69
70
  /// Current nesting depth of bundle_lock directives.
71
  unsigned BundleLockNestingDepth = 0;
72
73
  /// We've seen a bundle_lock directive but not its first instruction
74
  /// yet.
75
  bool BundleGroupBeforeFirstInst : 1;
76
77
  /// Whether this section has had instructions emitted into it.
78
  bool HasInstructions : 1;
79
80
  /// Whether this section has had data emitted into it.
81
  /// Right now this is only used by the ARM backend.
82
  bool HasData : 1;
83
84
  bool IsRegistered : 1;
85
86
  MCDummyFragment DummyFragment;
87
88
  FragmentListType Fragments;
89
90
  /// Mapping from subsection number to insertion point for subsection numbers
91
  /// below that number.
92
  SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
93
94
protected:
95
  SectionVariant Variant;
96
  SectionKind Kind;
97
98
  MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin);
99
  ~MCSection();
100
101
public:
102
  MCSection(const MCSection &) = delete;
103
  MCSection &operator=(const MCSection &) = delete;
104
105
680k
  SectionKind getKind() const { return Kind; }
106
107
524
  SectionVariant getVariant() const { return Variant; }
108
109
1.28M
  MCSymbol *getBeginSymbol() { return Begin; }
110
11.0k
  const MCSymbol *getBeginSymbol() const {
111
11.0k
    return const_cast<MCSection *>(this)->getBeginSymbol();
112
11.0k
  }
113
36.4k
  void setBeginSymbol(MCSymbol *Sym) {
114
36.4k
    assert(!Begin);
115
36.4k
    Begin = Sym;
116
36.4k
  }
117
  MCSymbol *getEndSymbol(MCContext &Ctx);
118
  bool hasEnded() const;
119
120
1.66M
  unsigned getAlignment() const { return Alignment; }
121
67.4k
  void setAlignment(unsigned Value) { Alignment = Value; }
122
123
713k
  unsigned getOrdinal() const { return Ordinal; }
124
488k
  void setOrdinal(unsigned Value) { Ordinal = Value; }
125
126
224k
  unsigned getLayoutOrder() const { return LayoutOrder; }
127
488k
  void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
128
129
4.66k
  BundleLockStateType getBundleLockState() const { return BundleLockState; }
130
  void setBundleLockState(BundleLockStateType NewState);
131
442k
  bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
132
133
5.06k
  bool isBundleGroupBeforeFirstInst() const {
134
5.06k
    return BundleGroupBeforeFirstInst;
135
5.06k
  }
136
5.23k
  void setBundleGroupBeforeFirstInst(bool IsFirst) {
137
5.23k
    BundleGroupBeforeFirstInst = IsFirst;
138
5.23k
  }
139
140
74.8k
  bool hasInstructions() const { return HasInstructions; }
141
17.4M
  void setHasInstructions(bool Value) { HasInstructions = Value; }
142
143
2
  bool hasData() const { return HasData; }
144
9.80M
  void setHasData(bool Value) { HasData = Value; }
145
146
596k
  bool isRegistered() const { return IsRegistered; }
147
488k
  void setIsRegistered(bool Value) { IsRegistered = Value; }
148
149
60.6M
  MCSection::FragmentListType &getFragmentList() { return Fragments; }
150
528k
  const MCSection::FragmentListType &getFragmentList() const {
151
528k
    return const_cast<MCSection *>(this)->getFragmentList();
152
528k
  }
153
154
  /// Support for MCFragment::getNextNode().
155
6.44M
  static FragmentListType MCSection::*getSublistAccess(MCFragment *) {
156
6.44M
    return &MCSection::Fragments;
157
6.44M
  }
158
159
0
  const MCDummyFragment &getDummyFragment() const { return DummyFragment; }
160
6.25M
  MCDummyFragment &getDummyFragment() { return DummyFragment; }
161
162
3.90M
  iterator begin() { return Fragments.begin(); }
163
488k
  const_iterator begin() const { return Fragments.begin(); }
164
165
2.14M
  iterator end() { return Fragments.end(); }
166
488k
  const_iterator end() const { return Fragments.end(); }
167
168
976k
  reverse_iterator rbegin() { return Fragments.rbegin(); }
169
0
  const_reverse_iterator rbegin() const { return Fragments.rbegin(); }
170
171
0
  reverse_iterator rend() { return Fragments.rend(); }
172
0
  const_reverse_iterator rend() const  { return Fragments.rend(); }
173
174
  MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection);
175
176
  void dump() const;
177
178
  virtual void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
179
                                    raw_ostream &OS,
180
                                    const MCExpr *Subsection) const = 0;
181
182
  /// Return true if a .align directive should use "optimized nops" to fill
183
  /// instead of 0s.
184
  virtual bool UseCodeAlign() const = 0;
185
186
  /// Check whether this section is "virtual", that is has no actual object
187
  /// file contents.
188
  virtual bool isVirtualSection() const = 0;
189
};
190
191
} // end namespace llvm
192
193
#endif // LLVM_MC_MCSECTION_H