Path: blob/main/contrib/llvm-project/llvm/lib/MC/MCSection.cpp
35233 views
//===- lib/MC/MCSection.cpp - Machine Code Section Representation ---------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/MC/MCSection.h"9#include "llvm/ADT/STLExtras.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"18#include <utility>1920using namespace llvm;2122MCSection::MCSection(SectionVariant V, StringRef Name, bool IsText,23bool IsVirtual, MCSymbol *Begin)24: Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),25HasLayout(false), IsRegistered(false), IsText(IsText),26IsVirtual(IsVirtual), Name(Name), Variant(V) {27DummyFragment.setParent(this);28// The initial subsection number is 0. Create a fragment list.29CurFragList = &Subsections.emplace_back(0u, FragList{}).second;30}3132MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {33if (!End)34End = Ctx.createTempSymbol("sec_end");35return End;36}3738bool MCSection::hasEnded() const { return End && End->isInSection(); }3940MCSection::~MCSection() {41for (auto &[_, Chain] : Subsections) {42for (MCFragment *X = Chain.Head, *Y; X; X = Y) {43Y = X->Next;44X->destroy();45}46}47}4849void MCSection::setBundleLockState(BundleLockStateType NewState) {50if (NewState == NotBundleLocked) {51if (BundleLockNestingDepth == 0) {52report_fatal_error("Mismatched bundle_lock/unlock directives");53}54if (--BundleLockNestingDepth == 0) {55BundleLockState = NotBundleLocked;56}57return;58}5960// If any of the directives is an align_to_end directive, the whole nested61// group is align_to_end. So don't downgrade from align_to_end to just locked.62if (BundleLockState != BundleLockedAlignToEnd) {63BundleLockState = NewState;64}65++BundleLockNestingDepth;66}6768StringRef MCSection::getVirtualSectionKind() const { return "virtual"; }6970#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)71LLVM_DUMP_METHOD void MCSection::dump() const {72raw_ostream &OS = errs();7374OS << "<MCSection Name:" << getName();75OS << " Fragments:[\n ";76bool First = true;77for (auto &F : *this) {78if (First)79First = false;80else81OS << ",\n ";82F.dump();83}84OS << "]>";85}86#endif878889