LLVM  10.0.0svn
MCSection.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCSection.cpp - Machine Code Section Representation ---------===//
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 #include "llvm/MC/MCSection.h"
10 #include "llvm/ADT/SmallVector.h"
11 #include "llvm/Config/llvm-config.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCFragment.h"
14 #include "llvm/MC/MCSymbol.h"
15 #include "llvm/Support/Compiler.h"
18 #include <algorithm>
19 #include <utility>
20 
21 using namespace llvm;
22 
24  : Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
25  HasData(false), IsRegistered(false), DummyFragment(this), Variant(V),
26  Kind(K) {}
27 
29  if (!End)
30  End = Ctx.createTempSymbol("sec_end", true);
31  return End;
32 }
33 
34 bool MCSection::hasEnded() const { return End && End->isInSection(); }
35 
36 MCSection::~MCSection() = default;
37 
39  if (NewState == NotBundleLocked) {
40  if (BundleLockNestingDepth == 0) {
41  report_fatal_error("Mismatched bundle_lock/unlock directives");
42  }
43  if (--BundleLockNestingDepth == 0) {
44  BundleLockState = NotBundleLocked;
45  }
46  return;
47  }
48 
49  // If any of the directives is an align_to_end directive, the whole nested
50  // group is align_to_end. So don't downgrade from align_to_end to just locked.
51  if (BundleLockState != BundleLockedAlignToEnd) {
52  BundleLockState = NewState;
53  }
54  ++BundleLockNestingDepth;
55 }
56 
59  if (Subsection == 0 && SubsectionFragmentMap.empty())
60  return end();
61 
63  std::lower_bound(SubsectionFragmentMap.begin(),
64  SubsectionFragmentMap.end(),
65  std::make_pair(Subsection, (MCFragment *)nullptr));
66  bool ExactMatch = false;
67  if (MI != SubsectionFragmentMap.end()) {
68  ExactMatch = MI->first == Subsection;
69  if (ExactMatch)
70  ++MI;
71  }
72  iterator IP;
73  if (MI == SubsectionFragmentMap.end())
74  IP = end();
75  else
76  IP = MI->second->getIterator();
77  if (!ExactMatch && Subsection != 0) {
78  // The GNU as documentation claims that subsections have an alignment of 4,
79  // although this appears not to be the case.
80  MCFragment *F = new MCDataFragment();
81  SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F));
82  getFragmentList().insert(IP, F);
83  F->setParent(this);
84  }
85 
86  return IP;
87 }
88 
89 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
91  raw_ostream &OS = errs();
92 
93  OS << "<MCSection";
94  OS << " Fragments:[\n ";
95  for (auto it = begin(), ie = end(); it != ie; ++it) {
96  if (it != begin())
97  OS << ",\n ";
98  it->dump();
99  }
100  OS << "]>";
101 }
102 #endif
auto lower_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1261
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:139
This class represents lattice values for constants.
Definition: AllocatorList.h:23
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:473
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
Definition: MCSection.cpp:23
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:38
F(f)
void dump() const
Definition: MCSection.cpp:90
BundleLockStateType
Express the state of bundle locked groups while emitting code.
Definition: MCSection.h:43
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
Definition: MCSymbol.h:253
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:28
Context object for machine code objects.
Definition: MCContext.h:65
bool hasEnded() const
Definition: MCSection.cpp:34
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:225
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
Iterator for intrusive lists based on ilist_node.
iterator insert(iterator where, pointer New)
Definition: ilist.h:226
Fragment for data and encoded instructions.
Definition: MCFragment.h:243
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection)
Definition: MCSection.cpp:58
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
IRTranslator LLVM IR MI
iterator end()
Definition: MCSection.h:165
void setParent(MCSection *Value)
Definition: MCFragment.h:99
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:149
iterator begin()
Definition: MCSection.h:162