LLVM 19.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/STLExtras.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"
19#include <utility>
20
21using namespace llvm;
22
24 MCSymbol *Begin)
25 : Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
26 HasLayout(false), IsRegistered(false), IsText(IsText), Name(Name),
27 Variant(V) {
28 DummyFragment.setParent(this);
29 // The initial subsection number is 0. Create a fragment list.
30 CurFragList = &Subsections.emplace_back(0u, FragList{}).second;
31}
32
34 if (!End)
35 End = Ctx.createTempSymbol("sec_end");
36 return End;
37}
38
39bool MCSection::hasEnded() const { return End && End->isInSection(); }
40
42 for (auto &[_, Chain] : Subsections) {
43 for (MCFragment *X = Chain.Head, *Y; X; X = Y) {
44 Y = X->Next;
45 X->destroy();
46 }
47 }
48}
49
51 if (NewState == NotBundleLocked) {
52 if (BundleLockNestingDepth == 0) {
53 report_fatal_error("Mismatched bundle_lock/unlock directives");
54 }
55 if (--BundleLockNestingDepth == 0) {
56 BundleLockState = NotBundleLocked;
57 }
58 return;
59 }
60
61 // If any of the directives is an align_to_end directive, the whole nested
62 // group is align_to_end. So don't downgrade from align_to_end to just locked.
63 if (BundleLockState != BundleLockedAlignToEnd) {
64 BundleLockState = NewState;
65 }
66 ++BundleLockNestingDepth;
67}
68
69void MCSection::switchSubsection(unsigned Subsection) {
70 size_t I = 0, E = Subsections.size();
71 while (I != E && Subsections[I].first < Subsection)
72 ++I;
73 // If the subsection number is not in the sorted Subsections list, create a
74 // new fragment list.
75 if (I == E || Subsections[I].first != Subsection)
76 Subsections.insert(Subsections.begin() + I, {Subsection, FragList{}});
77 CurFragList = &Subsections[I].second;
78}
79
80StringRef MCSection::getVirtualSectionKind() const { return "virtual"; }
81
82#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
84 raw_ostream &OS = errs();
85
86 OS << "<MCSection Name:" << getName();
87 OS << " Fragments:[\n ";
88 bool First = true;
89 for (auto &F : *this) {
90 if (First)
91 First = false;
92 else
93 OS << ",\n ";
94 F.dump();
95 }
96 OS << "]>";
97}
98#endif
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:537
std::string Name
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
#define _
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
This file defines the SmallVector class.
Context object for machine code objects.
Definition: MCContext.h:83
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:345
void setParent(MCSection *Value)
Definition: MCFragment.h:93
virtual StringRef getVirtualSectionKind() const
Definition: MCSection.cpp:80
void dump() const
Definition: MCSection.cpp:83
void switchSubsection(unsigned Subsection)
Definition: MCSection.cpp:69
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:33
MCSection(SectionVariant V, StringRef Name, bool IsText, MCSymbol *Begin)
Definition: MCSection.cpp:23
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:50
StringRef getName() const
Definition: MCSection.h:137
bool hasEnded() const
Definition: MCSection.cpp:39
BundleLockStateType
Express the state of bundle locked groups while emitting code.
Definition: MCSection.h:52
@ BundleLockedAlignToEnd
Definition: MCSection.h:55
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.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:254
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.