1 //===- lib/MC/MCSection.cpp - Machine Code Section Representation ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCSection.h"
11 #include "llvm/MC/MCAssembler.h"
12 #include "llvm/MC/MCAsmInfo.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCSymbol.h"
15 #include "llvm/Support/raw_ostream.h"
18 //===----------------------------------------------------------------------===//
20 //===----------------------------------------------------------------------===//
22 MCSection::MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
23 : Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
24 IsRegistered(false), Variant(V), Kind(K) {}
26 MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
28 End = Ctx.createTempSymbol("sec_end", true);
32 bool MCSection::hasEnded() const { return End && End->isInSection(); }
34 MCSection::~MCSection() {
37 void MCSection::setBundleLockState(BundleLockStateType NewState) {
38 if (NewState == NotBundleLocked) {
39 if (BundleLockNestingDepth == 0) {
40 report_fatal_error("Mismatched bundle_lock/unlock directives");
42 if (--BundleLockNestingDepth == 0) {
43 BundleLockState = NotBundleLocked;
48 // If any of the directives is an align_to_end directive, the whole nested
49 // group is align_to_end. So don't downgrade from align_to_end to just locked.
50 if (BundleLockState != BundleLockedAlignToEnd) {
51 BundleLockState = NewState;
53 ++BundleLockNestingDepth;
57 MCSection::getSubsectionInsertionPoint(unsigned Subsection) {
58 if (Subsection == 0 && SubsectionFragmentMap.empty())
61 SmallVectorImpl<std::pair<unsigned, MCFragment *>>::iterator MI =
62 std::lower_bound(SubsectionFragmentMap.begin(),
63 SubsectionFragmentMap.end(),
64 std::make_pair(Subsection, (MCFragment *)nullptr));
65 bool ExactMatch = false;
66 if (MI != SubsectionFragmentMap.end()) {
67 ExactMatch = MI->first == Subsection;
72 if (MI == SubsectionFragmentMap.end())
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));
81 getFragmentList().insert(IP, F);
88 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
89 void MCSection::dump() {
90 raw_ostream &OS = llvm::errs();
93 OS << " Fragments:[\n ";
94 for (auto it = begin(), ie = end(); it != ie; ++it) {
103 MCSection::iterator MCSection::begin() { return Fragments.begin(); }
105 MCSection::iterator MCSection::end() { return Fragments.end(); }
107 MCSection::reverse_iterator MCSection::rbegin() { return Fragments.rbegin(); }
109 MCSection::reverse_iterator MCSection::rend() { return Fragments.rend(); }