LLVM  14.0.0git
MCSectionWasm.h
Go to the documentation of this file.
1 //===- MCSectionWasm.h - Wasm Machine Code Sections -------------*- C++ -*-===//
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 // This file declares the MCSectionWasm class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_MC_MCSECTIONWASM_H
14 #define LLVM_MC_MCSECTIONWASM_H
15 
16 #include "llvm/MC/MCSection.h"
17 
18 namespace llvm {
19 
20 class MCSymbol;
21 class MCSymbolWasm;
22 class StringRef;
23 class raw_ostream;
24 
25 /// This represents a section on wasm.
26 class MCSectionWasm final : public MCSection {
27  unsigned UniqueID;
28 
29  const MCSymbolWasm *Group;
30 
31  // The offset of the MC function/data section in the wasm code/data section.
32  // For data relocations the offset is relative to start of the data payload
33  // itself and does not include the size of the section header.
34  uint64_t SectionOffset = 0;
35 
36  // For data sections, this is the index of of the corresponding wasm data
37  // segment
38  uint32_t SegmentIndex = 0;
39 
40  // For data sections, whether to use a passive segment
41  bool IsPassive = false;
42 
43  // For data sections, bitfield of WasmSegmentFlag
44  unsigned SegmentFlags;
45 
46  // The storage of Name is owned by MCContext's WasmUniquingMap.
47  friend class MCContext;
48  MCSectionWasm(StringRef Name, SectionKind K, unsigned SegmentFlags,
49  const MCSymbolWasm *Group, unsigned UniqueID, MCSymbol *Begin)
50  : MCSection(SV_Wasm, Name, K, Begin), UniqueID(UniqueID), Group(Group),
51  SegmentFlags(SegmentFlags) {}
52 
53 public:
54  /// Decides whether a '.section' directive should be printed before the
55  /// section name
56  bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
57 
58  const MCSymbolWasm *getGroup() const { return Group; }
59  unsigned getSegmentFlags() const { return SegmentFlags; }
60 
61  void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
62  raw_ostream &OS,
63  const MCExpr *Subsection) const override;
64  bool UseCodeAlign() const override;
65  bool isVirtualSection() const override;
66 
67  bool isWasmData() const {
68  return Kind.isGlobalWriteableData() || Kind.isReadOnly() ||
70  }
71 
72  bool isUnique() const { return UniqueID != ~0U; }
73  unsigned getUniqueID() const { return UniqueID; }
74 
75  uint64_t getSectionOffset() const { return SectionOffset; }
76  void setSectionOffset(uint64_t Offset) { SectionOffset = Offset; }
77 
78  uint32_t getSegmentIndex() const { return SegmentIndex; }
79  void setSegmentIndex(uint32_t Index) { SegmentIndex = Index; }
80 
81  bool getPassive() const {
82  assert(isWasmData());
83  return IsPassive;
84  }
85  void setPassive(bool V = true) {
86  assert(isWasmData());
87  IsPassive = V;
88  }
89  static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; }
90 };
91 
92 } // end namespace llvm
93 
94 #endif
llvm::MCSection::Name
StringRef Name
Definition: MCSection.h:111
llvm::SectionKind::isThreadLocal
bool isThreadLocal() const
Definition: SectionKind.h:151
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::SectionKind::isReadOnly
bool isReadOnly() const
Definition: SectionKind.h:125
llvm::MCSectionWasm::getUniqueID
unsigned getUniqueID() const
Definition: MCSectionWasm.h:73
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::MCSectionWasm::PrintSwitchToSection
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
Definition: MCSectionWasm.cpp:48
T
#define T
Definition: Mips16ISelLowering.cpp:341
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::MCSectionWasm::getSegmentFlags
unsigned getSegmentFlags() const
Definition: MCSectionWasm.h:59
llvm::MCSectionWasm
This represents a section on wasm.
Definition: MCSectionWasm.h:26
llvm::MCSectionWasm::getGroup
const MCSymbolWasm * getGroup() const
Definition: MCSectionWasm.h:58
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCSectionWasm::isWasmData
bool isWasmData() const
Definition: MCSectionWasm.h:67
llvm::MCSectionWasm::isVirtualSection
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
Definition: MCSectionWasm.cpp:107
llvm::MCSectionWasm::shouldOmitSectionDirective
bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
Decides whether a '.section' directive should be printed before the section name.
Definition: MCSectionWasm.cpp:20
llvm::MCSectionWasm::classof
static bool classof(const MCSection *S)
Definition: MCSectionWasm.h:89
llvm::MCSectionWasm::setSegmentIndex
void setSegmentIndex(uint32_t Index)
Definition: MCSectionWasm.h:79
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
uint64_t
llvm::MCSymbolWasm
Definition: MCSymbolWasm.h:16
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSection.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCSectionWasm::setPassive
void setPassive(bool V=true)
Definition: MCSectionWasm.h:85
llvm::MCSectionWasm::getSectionOffset
uint64_t getSectionOffset() const
Definition: MCSectionWasm.h:75
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::MCSectionWasm::getPassive
bool getPassive() const
Definition: MCSectionWasm.h:81
llvm::MCSectionWasm::getSegmentIndex
uint32_t getSegmentIndex() const
Definition: MCSectionWasm.h:78
llvm::MCSectionWasm::setSectionOffset
void setSectionOffset(uint64_t Offset)
Definition: MCSectionWasm.h:76
llvm::SectionKind::isGlobalWriteableData
bool isGlobalWriteableData() const
Definition: SectionKind.h:159
llvm::MCSection::Kind
SectionKind Kind
Definition: MCSection.h:113
llvm::MCSectionWasm::UseCodeAlign
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
Definition: MCSectionWasm.cpp:105
llvm::MCSectionWasm::isUnique
bool isUnique() const
Definition: MCSectionWasm.h:72
llvm::MCSection::SV_Wasm
@ SV_Wasm
Definition: MCSection.h:48
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172