LLVM 20.0.0git
MCSymbolWasm.h
Go to the documentation of this file.
1//===- MCSymbolWasm.h - ----------------------------------------*- 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#ifndef LLVM_MC_MCSYMBOLWASM_H
9#define LLVM_MC_MCSYMBOLWASM_H
10
12#include "llvm/MC/MCSymbol.h"
14
15namespace llvm {
16
17class MCSymbolWasm : public MCSymbol {
18 std::optional<wasm::WasmSymbolType> Type;
19 bool IsWeak = false;
20 bool IsHidden = false;
21 bool IsComdat = false;
22 bool OmitFromLinkingSection = false;
23 mutable bool IsUsedInInitArray = false;
24 mutable bool IsUsedInGOT = false;
25 std::optional<StringRef> ImportModule;
26 std::optional<StringRef> ImportName;
27 std::optional<StringRef> ExportName;
28 wasm::WasmSignature *Signature = nullptr;
29 std::optional<wasm::WasmGlobalType> GlobalType;
30 std::optional<wasm::WasmTableType> TableType;
31
32 /// An expression describing how to calculate the size of a symbol. If a
33 /// symbol has no size this field will be NULL.
34 const MCExpr *SymbolSize = nullptr;
35
36public:
39 static bool classof(const MCSymbol *S) { return S->isWasm(); }
40
41 const MCExpr *getSize() const { return SymbolSize; }
42 void setSize(const MCExpr *SS) { SymbolSize = SS; }
43
45 // Data is the default value if not set.
46 bool isData() const { return !Type || Type == wasm::WASM_SYMBOL_TYPE_DATA; }
47 bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; }
48 bool isTable() const { return Type == wasm::WASM_SYMBOL_TYPE_TABLE; }
49 bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
50 bool isTag() const { return Type == wasm::WASM_SYMBOL_TYPE_TAG; }
51
52 std::optional<wasm::WasmSymbolType> getType() const { return Type; }
53
54 void setType(wasm::WasmSymbolType type) { Type = type; }
55
56 bool isExported() const {
58 }
59 void setExported() const {
61 }
62
63 bool isNoStrip() const {
65 }
66 void setNoStrip() const {
68 }
69
70 bool isTLS() const { return getFlags() & wasm::WASM_SYMBOL_TLS; }
71 void setTLS() const {
73 }
74
75 bool isWeak() const { return IsWeak; }
76 void setWeak(bool isWeak) { IsWeak = isWeak; }
77
78 bool isHidden() const { return IsHidden; }
79 void setHidden(bool isHidden) { IsHidden = isHidden; }
80
81 bool isComdat() const { return IsComdat; }
82 void setComdat(bool isComdat) { IsComdat = isComdat; }
83
84 // wasm-ld understands a finite set of symbol types. This flag allows the
85 // compiler to avoid emitting symbol table entries that would confuse the
86 // linker, unless the user specifically requests the feature.
87 bool omitFromLinkingSection() const { return OmitFromLinkingSection; }
88 void setOmitFromLinkingSection() { OmitFromLinkingSection = true; }
89
90 bool hasImportModule() const { return ImportModule.has_value(); }
92 if (ImportModule)
93 return *ImportModule;
94 // Use a default module name of "env" for now, for compatibility with
95 // existing tools.
96 // TODO(sbc): Find a way to specify a default value in the object format
97 // without picking a hardcoded value like this.
98 return "env";
99 }
100 void setImportModule(StringRef Name) { ImportModule = Name; }
101
102 bool hasImportName() const { return ImportName.has_value(); }
104 if (ImportName)
105 return *ImportName;
106 return getName();
107 }
108 void setImportName(StringRef Name) { ImportName = Name; }
109
110 bool hasExportName() const { return ExportName.has_value(); }
111 StringRef getExportName() const { return *ExportName; }
112 void setExportName(StringRef Name) { ExportName = Name; }
113
114 bool isFunctionTable() const {
115 return isTable() && hasTableType() &&
117 }
118 void setFunctionTable(bool is64) {
120 uint8_t flags =
123 }
124
125 void setUsedInGOT() const { IsUsedInGOT = true; }
126 bool isUsedInGOT() const { return IsUsedInGOT; }
127
128 void setUsedInInitArray() const { IsUsedInInitArray = true; }
129 bool isUsedInInitArray() const { return IsUsedInInitArray; }
130
131 const wasm::WasmSignature *getSignature() const { return Signature; }
132 void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
133
135 assert(GlobalType);
136 return *GlobalType;
137 }
138 void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
139
140 bool hasTableType() const { return TableType.has_value(); }
143 return *TableType;
144 }
145 void setTableType(wasm::WasmTableType TT) { TableType = TT; }
148 // Declare a table with element type VT and no limits (min size 0, no max
149 // size).
150 wasm::WasmLimits Limits = {flags, 0, 0};
151 setTableType({VT, Limits});
152 }
153};
154
155} // end namespace llvm
156
157#endif // LLVM_MC_MCSYMBOLWASM_H
std::string Name
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
bool isGlobal() const
Definition: MCSymbolWasm.h:47
void setTableType(wasm::WasmTableType TT)
Definition: MCSymbolWasm.h:145
static bool classof(const MCSymbol *S)
Definition: MCSymbolWasm.h:39
void setComdat(bool isComdat)
Definition: MCSymbolWasm.h:82
const wasm::WasmTableType & getTableType() const
Definition: MCSymbolWasm.h:141
void setImportModule(StringRef Name)
Definition: MCSymbolWasm.h:100
bool isUsedInGOT() const
Definition: MCSymbolWasm.h:126
StringRef getImportModule() const
Definition: MCSymbolWasm.h:91
bool isExported() const
Definition: MCSymbolWasm.h:56
const wasm::WasmSignature * getSignature() const
Definition: MCSymbolWasm.h:131
StringRef getImportName() const
Definition: MCSymbolWasm.h:103
MCSymbolWasm(const MCSymbolTableEntry *Name, bool isTemporary)
Definition: MCSymbolWasm.h:37
const MCExpr * getSize() const
Definition: MCSymbolWasm.h:41
bool hasImportModule() const
Definition: MCSymbolWasm.h:90
void setSignature(wasm::WasmSignature *Sig)
Definition: MCSymbolWasm.h:132
void setFunctionTable(bool is64)
Definition: MCSymbolWasm.h:118
bool isFunctionTable() const
Definition: MCSymbolWasm.h:114
bool hasTableType() const
Definition: MCSymbolWasm.h:140
void setTableType(wasm::ValType VT, uint8_t flags=wasm::WASM_LIMITS_FLAG_NONE)
Definition: MCSymbolWasm.h:146
void setNoStrip() const
Definition: MCSymbolWasm.h:66
void setImportName(StringRef Name)
Definition: MCSymbolWasm.h:108
void setWeak(bool isWeak)
Definition: MCSymbolWasm.h:76
void setType(wasm::WasmSymbolType type)
Definition: MCSymbolWasm.h:54
void setExportName(StringRef Name)
Definition: MCSymbolWasm.h:112
void setGlobalType(wasm::WasmGlobalType GT)
Definition: MCSymbolWasm.h:138
void setHidden(bool isHidden)
Definition: MCSymbolWasm.h:79
bool isNoStrip() const
Definition: MCSymbolWasm.h:63
void setOmitFromLinkingSection()
Definition: MCSymbolWasm.h:88
void setUsedInInitArray() const
Definition: MCSymbolWasm.h:128
bool isHidden() const
Definition: MCSymbolWasm.h:78
bool isSection() const
Definition: MCSymbolWasm.h:49
bool hasExportName() const
Definition: MCSymbolWasm.h:110
bool omitFromLinkingSection() const
Definition: MCSymbolWasm.h:87
void setExported() const
Definition: MCSymbolWasm.h:59
bool isTable() const
Definition: MCSymbolWasm.h:48
const wasm::WasmGlobalType & getGlobalType() const
Definition: MCSymbolWasm.h:134
StringRef getExportName() const
Definition: MCSymbolWasm.h:111
bool isComdat() const
Definition: MCSymbolWasm.h:81
bool isData() const
Definition: MCSymbolWasm.h:46
void setUsedInGOT() const
Definition: MCSymbolWasm.h:125
bool isTag() const
Definition: MCSymbolWasm.h:50
bool isUsedInInitArray() const
Definition: MCSymbolWasm.h:129
bool hasImportName() const
Definition: MCSymbolWasm.h:102
bool isTLS() const
Definition: MCSymbolWasm.h:70
bool isFunction() const
Definition: MCSymbolWasm.h:44
void setSize(const MCExpr *SS)
Definition: MCSymbolWasm.h:42
std::optional< wasm::WasmSymbolType > getType() const
Definition: MCSymbolWasm.h:52
void setTLS() const
Definition: MCSymbolWasm.h:71
bool isWeak() const
Definition: MCSymbolWasm.h:75
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
bool isWasm() const
Definition: MCSymbol.h:291
void modifyFlags(uint32_t Value, uint32_t Mask) const
Modify the flags via a mask.
Definition: MCSymbol.h:430
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
uint32_t getFlags() const
Get the (implementation defined) symbol flags.
Definition: MCSymbol.h:421
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:222
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
const unsigned WASM_SYMBOL_NO_STRIP
Definition: Wasm.h:246
const unsigned WASM_SYMBOL_TLS
Definition: Wasm.h:247
WasmSymbolType
Definition: Wasm.h:215
@ WASM_SYMBOL_TYPE_GLOBAL
Definition: Wasm.h:218
@ WASM_SYMBOL_TYPE_DATA
Definition: Wasm.h:217
@ WASM_SYMBOL_TYPE_TAG
Definition: Wasm.h:220
@ WASM_SYMBOL_TYPE_TABLE
Definition: Wasm.h:221
@ WASM_SYMBOL_TYPE_SECTION
Definition: Wasm.h:219
@ WASM_SYMBOL_TYPE_FUNCTION
Definition: Wasm.h:216
const unsigned WASM_SYMBOL_EXPORTED
Definition: Wasm.h:244
@ WASM_LIMITS_FLAG_IS_64
Definition: Wasm.h:159
@ WASM_LIMITS_FLAG_NONE
Definition: Wasm.h:156
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18