Line data Source code
1 : //===- lib/MC/MCSection.cpp - Machine Code Section Representation ---------===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #include "llvm/MC/MCSection.h"
11 : #include "llvm/ADT/SmallVector.h"
12 : #include "llvm/Config/llvm-config.h"
13 : #include "llvm/MC/MCContext.h"
14 : #include "llvm/MC/MCFragment.h"
15 : #include "llvm/MC/MCSymbol.h"
16 : #include "llvm/Support/Compiler.h"
17 : #include "llvm/Support/ErrorHandling.h"
18 : #include "llvm/Support/raw_ostream.h"
19 : #include <algorithm>
20 : #include <utility>
21 :
22 : using namespace llvm;
23 :
24 2956449 : MCSection::MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
25 : : Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
26 : HasData(false), IsRegistered(false), DummyFragment(this), Variant(V),
27 2956449 : Kind(K) {}
28 :
29 8167 : MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
30 8167 : if (!End)
31 8065 : End = Ctx.createTempSymbol("sec_end", true);
32 8167 : return End;
33 : }
34 :
35 0 : bool MCSection::hasEnded() const { return End && End->isInSection(); }
36 :
37 : MCSection::~MCSection() = default;
38 :
39 1190 : void MCSection::setBundleLockState(BundleLockStateType NewState) {
40 1190 : if (NewState == NotBundleLocked) {
41 593 : if (BundleLockNestingDepth == 0) {
42 0 : report_fatal_error("Mismatched bundle_lock/unlock directives");
43 : }
44 593 : if (--BundleLockNestingDepth == 0) {
45 585 : BundleLockState = NotBundleLocked;
46 : }
47 593 : 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 597 : if (BundleLockState != BundleLockedAlignToEnd) {
53 595 : BundleLockState = NewState;
54 : }
55 597 : ++BundleLockNestingDepth;
56 : }
57 :
58 : MCSection::iterator
59 803449 : MCSection::getSubsectionInsertionPoint(unsigned Subsection) {
60 803449 : if (Subsection == 0 && SubsectionFragmentMap.empty())
61 : return end();
62 :
63 : SmallVectorImpl<std::pair<unsigned, MCFragment *>>::iterator MI =
64 : std::lower_bound(SubsectionFragmentMap.begin(),
65 : SubsectionFragmentMap.end(),
66 8 : std::make_pair(Subsection, (MCFragment *)nullptr));
67 : bool ExactMatch = false;
68 8 : if (MI != SubsectionFragmentMap.end()) {
69 4 : ExactMatch = MI->first == Subsection;
70 4 : if (ExactMatch)
71 1 : ++MI;
72 : }
73 : iterator IP;
74 8 : if (MI == SubsectionFragmentMap.end())
75 : IP = end();
76 : else
77 4 : IP = MI->second->getIterator();
78 8 : if (!ExactMatch && Subsection != 0) {
79 : // The GNU as documentation claims that subsections have an alignment of 4,
80 : // although this appears not to be the case.
81 5 : MCFragment *F = new MCDataFragment();
82 5 : SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F));
83 : getFragmentList().insert(IP, F);
84 : F->setParent(this);
85 : }
86 :
87 8 : return IP;
88 : }
89 :
90 : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
91 : LLVM_DUMP_METHOD void MCSection::dump() const {
92 : raw_ostream &OS = errs();
93 :
94 : OS << "<MCSection";
95 : OS << " Fragments:[\n ";
96 : for (auto it = begin(), ie = end(); it != ie; ++it) {
97 : if (it != begin())
98 : OS << ",\n ";
99 : it->dump();
100 : }
101 : OS << "]>";
102 : }
103 : #endif
|