LLVM  14.0.0git
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  MCSymbol *Begin)
25  : Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
26  IsRegistered(false), DummyFragment(this), Name(Name), Variant(V),
27  Kind(K) {}
28 
30  if (!End)
31  End = Ctx.createTempSymbol("sec_end");
32  return End;
33 }
34 
35 bool MCSection::hasEnded() const { return End && End->isInSection(); }
36 
37 MCSection::~MCSection() = default;
38 
40  if (NewState == NotBundleLocked) {
41  if (BundleLockNestingDepth == 0) {
42  report_fatal_error("Mismatched bundle_lock/unlock directives");
43  }
44  if (--BundleLockNestingDepth == 0) {
45  BundleLockState = NotBundleLocked;
46  }
47  return;
48  }
49 
50  // If any of the directives is an align_to_end directive, the whole nested
51  // group is align_to_end. So don't downgrade from align_to_end to just locked.
52  if (BundleLockState != BundleLockedAlignToEnd) {
53  BundleLockState = NewState;
54  }
55  ++BundleLockNestingDepth;
56 }
57 
60  if (Subsection == 0 && SubsectionFragmentMap.empty())
61  return end();
62 
64  SubsectionFragmentMap, std::make_pair(Subsection, (MCFragment *)nullptr));
65  bool ExactMatch = false;
66  if (MI != SubsectionFragmentMap.end()) {
67  ExactMatch = MI->first == Subsection;
68  if (ExactMatch)
69  ++MI;
70  }
71  iterator IP;
72  if (MI == SubsectionFragmentMap.end())
73  IP = end();
74  else
75  IP = MI->second->getIterator();
76  if (!ExactMatch && Subsection != 0) {
77  // The GNU as documentation claims that subsections have an alignment of 4,
78  // although this appears not to be the case.
79  MCFragment *F = new MCDataFragment();
80  SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F));
82  F->setParent(this);
83  F->setSubsectionNumber(Subsection);
84  }
85 
86  return IP;
87 }
88 
89 StringRef MCSection::getVirtualSectionKind() const { return "virtual"; }
90 
91 void MCSection::addPendingLabel(MCSymbol *label, unsigned Subsection) {
92  PendingLabels.push_back(PendingLabel(label, Subsection));
93 }
94 
96  unsigned Subsection) {
97  if (PendingLabels.empty())
98  return;
99 
100  // Set the fragment and fragment offset for all pending symbols in the
101  // specified Subsection, and remove those symbols from the pending list.
102  for (auto It = PendingLabels.begin(); It != PendingLabels.end(); ++It) {
103  PendingLabel& Label = *It;
104  if (Label.Subsection == Subsection) {
105  Label.Sym->setFragment(F);
106  Label.Sym->setOffset(FOffset);
107  PendingLabels.erase(It--);
108  }
109  }
110 }
111 
113  // Make sure all remaining pending labels point to data fragments, by
114  // creating new empty data fragments for each Subsection with labels pending.
115  while (!PendingLabels.empty()) {
116  PendingLabel& Label = PendingLabels[0];
117  iterator CurInsertionPoint =
118  this->getSubsectionInsertionPoint(Label.Subsection);
119  MCFragment *F = new MCDataFragment();
120  getFragmentList().insert(CurInsertionPoint, F);
121  F->setParent(this);
122  flushPendingLabels(F, 0, Label.Subsection);
123  }
124 }
125 
126 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
128  raw_ostream &OS = errs();
129 
130  OS << "<MCSection";
131  OS << " Fragments:[\n ";
132  for (auto it = begin(), ie = end(); it != ie; ++it) {
133  if (it != begin())
134  OS << ",\n ";
135  it->dump();
136  }
137  OS << "]>";
138 }
139 #endif
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:506
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::SmallVectorImpl::erase
iterator erase(const_iterator CI)
Definition: SmallVector.h:705
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
it
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in it
Definition: README-SSE.txt:81
llvm::MCSection::setBundleLockState
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:39
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::lower_bound
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1661
llvm::MCSection::addPendingLabel
void addPendingLabel(MCSymbol *label, unsigned Subsection=0)
Add a pending label for the requested subsection.
Definition: MCSection.cpp:91
llvm::MCSection::dump
void dump() const
Definition: MCSection.cpp:127
ErrorHandling.h
MCFragment.h
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:893
llvm::MCSection::getSubsectionInsertionPoint
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection)
Definition: MCSection.cpp:59
llvm::MCSection::MCSection
MCSection(SectionVariant V, StringRef Name, SectionKind K, MCSymbol *Begin)
Definition: MCSection.cpp:23
llvm::MCSection::getFragmentList
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:164
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MCSection::end
iterator end()
Definition: MCSection.h:180
llvm::MCFragment
Definition: MCFragment.h:31
MCContext.h
MCSymbol.h
llvm::MCSection::hasEnded
bool hasEnded() const
Definition: MCSection.cpp:35
IP
Definition: NVPTXLowerArgs.cpp:166
false
Definition: StackSlotColoring.cpp:142
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCSection::getEndSymbol
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:29
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::MCSection::BundleLockedAlignToEnd
@ BundleLockedAlignToEnd
Definition: MCSection.h:56
llvm::MCSection::~MCSection
~MCSection()
uint64_t
llvm::MCSection::getVirtualSectionKind
virtual StringRef getVirtualSectionKind() const
Definition: MCSection.cpp:89
MCSection.h
llvm::MCSection::BundleLockStateType
BundleLockStateType
Express the state of bundle locked groups while emitting code.
Definition: MCSection.h:53
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
this
Analysis the ScalarEvolution expression for r is this
Definition: README.txt:8
Compiler.h
llvm::MCContext::createTempSymbol
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:303
llvm::MCSection::SectionVariant
SectionVariant
Definition: MCSection.h:43
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::ilist_iterator
Iterator for intrusive lists based on ilist_node.
Definition: ilist_iterator.h:57
llvm::MCSection::flushPendingLabels
void flushPendingLabels()
Associate all pending labels with empty data fragments.
Definition: MCSection.cpp:112
llvm::MCSection::NotBundleLocked
@ NotBundleLocked
Definition: MCSection.h:54
llvm::iplist_impl::insert
iterator insert(iterator where, pointer New)
Definition: ilist.h:228
llvm::MCSection::begin
iterator begin()
Definition: MCSection.h:177
SmallVector.h
llvm::MCSymbol::isInSection
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
Definition: MCSymbol.h:247
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
raw_ostream.h
llvm::MCDataFragment
Fragment for data and encoded instructions.
Definition: MCFragment.h:242