1 //===- lib/MC/MCSection.cpp - Machine Code Section Representation ---------===//
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
7 //===----------------------------------------------------------------------===//
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"
16 #include "llvm/Support/ErrorHandling.h"
17 #include "llvm/Support/raw_ostream.h"
23 MCSection::MCSection(SectionVariant V
, SectionKind K
, MCSymbol
*Begin
)
24 : Begin(Begin
), BundleGroupBeforeFirstInst(false), HasInstructions(false),
25 HasData(false), IsRegistered(false), DummyFragment(this), Variant(V
),
28 MCSymbol
*MCSection::getEndSymbol(MCContext
&Ctx
) {
30 End
= Ctx
.createTempSymbol("sec_end", true);
34 bool MCSection::hasEnded() const { return End
&& End
->isInSection(); }
36 MCSection::~MCSection() = default;
38 void MCSection::setBundleLockState(BundleLockStateType NewState
) {
39 if (NewState
== NotBundleLocked
) {
40 if (BundleLockNestingDepth
== 0) {
41 report_fatal_error("Mismatched bundle_lock/unlock directives");
43 if (--BundleLockNestingDepth
== 0) {
44 BundleLockState
= NotBundleLocked
;
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
;
54 ++BundleLockNestingDepth
;
58 MCSection::getSubsectionInsertionPoint(unsigned Subsection
) {
59 if (Subsection
== 0 && SubsectionFragmentMap
.empty())
62 SmallVectorImpl
<std::pair
<unsigned, MCFragment
*>>::iterator MI
=
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
;
73 if (MI
== SubsectionFragmentMap
.end())
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
);
89 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
90 LLVM_DUMP_METHOD
void MCSection::dump() const {
91 raw_ostream
&OS
= errs();
94 OS
<< " Fragments:[\n ";
95 for (auto it
= begin(), ie
= end(); it
!= ie
; ++it
) {