LLVM 19.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"
13
14namespace llvm {
15
16class MCSymbolWasm : public MCSymbol {
17 std::optional<wasm::WasmSymbolType> Type;
18 bool IsWeak = false;
19 bool IsHidden = false;
20 bool IsComdat = false;
21 bool OmitFromLinkingSection = false;
22 mutable bool IsUsedInInitArray = false;
23 mutable bool IsUsedInGOT = false;
24 std::optional<StringRef> ImportModule;
25 std::optional<StringRef> ImportName;
26 std::optional<StringRef> ExportName;
27 wasm::WasmSignature *Signature = nullptr;
28 std::optional<wasm::WasmGlobalType> GlobalType;
29 std::optional<wasm::WasmTableType> TableType;
30
31 /// An expression describing how to calculate the size of a symbol. If a
32 /// symbol has no size this field will be NULL.
33 const MCExpr *SymbolSize = nullptr;
34
35public:
38 static bool classof(const MCSymbol *S) { return S->isWasm(); }
39
40 const MCExpr *getSize() const { return SymbolSize; }
41 void setSize(const MCExpr *SS) { SymbolSize = SS; }
42
44 // Data is the default value if not set.
45 bool isData() const { return !Type || Type == wasm::WASM_SYMBOL_TYPE_DATA; }
46 bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; }
47 bool isTable() const { return Type == wasm::WASM_SYMBOL_TYPE_TABLE; }
48 bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; }
49 bool isTag() const { return Type == wasm::WASM_SYMBOL_TYPE_TAG; }
50
51 std::optional<wasm::WasmSymbolType> getType() const { return Type; }
52
53 void setType(wasm::WasmSymbolType type) { Type = type; }
54
55 bool isExported() const {
57 }
58 void setExported() const {
60 }
61
62 bool isNoStrip() const {
64 }
65 void setNoStrip() const {
67 }
68
69 bool isTLS() const { return getFlags() & wasm::WASM_SYMBOL_TLS; }
70 void setTLS() const {
72 }
73
74 bool isWeak() const { return IsWeak; }
75 void setWeak(bool isWeak) { IsWeak = isWeak; }
76
77 bool isHidden() const { return IsHidden; }
78 void setHidden(bool isHidden) { IsHidden = isHidden; }
79
80 bool isComdat() const { return IsComdat; }
81 void setComdat(bool isComdat) { IsComdat = isComdat; }
82
83 // wasm-ld understands a finite set of symbol types. This flag allows the
84 // compiler to avoid emitting symbol table entries that would confuse the
85 // linker, unless the user specifically requests the feature.
86 bool omitFromLinkingSection() const { return OmitFromLinkingSection; }
87 void setOmitFromLinkingSection() { OmitFromLinkingSection = true; }
88
89 bool hasImportModule() const { return ImportModule.has_value(); }
91 if (ImportModule)
92 return *ImportModule;
93 // Use a default module name of "env" for now, for compatibility with
94 // existing tools.
95 // TODO(sbc): Find a way to specify a default value in the object format
96 // without picking a hardcoded value like this.
97 return "env";
98 }
99 void setImportModule(StringRef Name) { ImportModule = Name; }
100
101 bool hasImportName() const { return ImportName.has_value(); }
103 if (ImportName)
104 return *ImportName;
105 return getName();
106 }
107 void setImportName(StringRef Name) { ImportName = Name; }
108
109 bool hasExportName() const { return ExportName.has_value(); }
110 StringRef getExportName() const { return *ExportName; }
111 void setExportName(StringRef Name) { ExportName = Name; }
112
113 bool isFunctionTable() const {
114 return isTable() && hasTableType() &&
116 }
117 void setFunctionTable(bool is64) {
119 uint8_t flags =
122 }
123
124 void setUsedInGOT() const { IsUsedInGOT = true; }
125 bool isUsedInGOT() const { return IsUsedInGOT; }
126
127 void setUsedInInitArray() const { IsUsedInInitArray = true; }
128 bool isUsedInInitArray() const { return IsUsedInInitArray; }
129
130 const wasm::WasmSignature *getSignature() const { return Signature; }
131 void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
132
134 assert(GlobalType);
135 return *GlobalType;
136 }
137 void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
138
139 bool hasTableType() const { return TableType.has_value(); }
142 return *TableType;
143 }
144 void setTableType(wasm::WasmTableType TT) { TableType = TT; }
146 uint8_t flags = wasm::WASM_LIMITS_FLAG_NONE) {
147 // Declare a table with element type VT and no limits (min size 0, no max
148 // size).
149 wasm::WasmLimits Limits = {flags, 0, 0};
150 setTableType({VT, Limits});
151 }
152};
153
154} // end namespace llvm
155
156#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:35
bool isGlobal() const
Definition: MCSymbolWasm.h:46
void setTableType(wasm::WasmTableType TT)
Definition: MCSymbolWasm.h:144
MCSymbolWasm(const StringMapEntry< bool > *Name, bool isTemporary)
Definition: MCSymbolWasm.h:36
static bool classof(const MCSymbol *S)
Definition: MCSymbolWasm.h:38
void setComdat(bool isComdat)
Definition: MCSymbolWasm.h:81
const wasm::WasmTableType & getTableType() const
Definition: MCSymbolWasm.h:140
void setImportModule(StringRef Name)
Definition: MCSymbolWasm.h:99
bool isUsedInGOT() const
Definition: MCSymbolWasm.h:125
StringRef getImportModule() const
Definition: MCSymbolWasm.h:90
bool isExported() const
Definition: MCSymbolWasm.h:55
const wasm::WasmSignature * getSignature() const
Definition: MCSymbolWasm.h:130
StringRef getImportName() const
Definition: MCSymbolWasm.h:102
const MCExpr * getSize() const
Definition: MCSymbolWasm.h:40
bool hasImportModule() const
Definition: MCSymbolWasm.h:89
void setSignature(wasm::WasmSignature *Sig)
Definition: MCSymbolWasm.h:131
void setFunctionTable(bool is64)
Definition: MCSymbolWasm.h:117
bool isFunctionTable() const
Definition: MCSymbolWasm.h:113
bool hasTableType() const
Definition: MCSymbolWasm.h:139
void setTableType(wasm::ValType VT, uint8_t flags=wasm::WASM_LIMITS_FLAG_NONE)
Definition: MCSymbolWasm.h:145
void setNoStrip() const
Definition: MCSymbolWasm.h:65
void setImportName(StringRef Name)
Definition: MCSymbolWasm.h:107
void setWeak(bool isWeak)
Definition: MCSymbolWasm.h:75
void setType(wasm::WasmSymbolType type)
Definition: MCSymbolWasm.h:53
void setExportName(StringRef Name)
Definition: MCSymbolWasm.h:111
void setGlobalType(wasm::WasmGlobalType GT)
Definition: MCSymbolWasm.h:137
void setHidden(bool isHidden)
Definition: MCSymbolWasm.h:78
bool isNoStrip() const
Definition: MCSymbolWasm.h:62
void setOmitFromLinkingSection()
Definition: MCSymbolWasm.h:87
void setUsedInInitArray() const
Definition: MCSymbolWasm.h:127
bool isHidden() const
Definition: MCSymbolWasm.h:77
bool isSection() const
Definition: MCSymbolWasm.h:48
bool hasExportName() const
Definition: MCSymbolWasm.h:109
bool omitFromLinkingSection() const
Definition: MCSymbolWasm.h:86
void setExported() const
Definition: MCSymbolWasm.h:58
bool isTable() const
Definition: MCSymbolWasm.h:47
const wasm::WasmGlobalType & getGlobalType() const
Definition: MCSymbolWasm.h:133
StringRef getExportName() const
Definition: MCSymbolWasm.h:110
bool isComdat() const
Definition: MCSymbolWasm.h:80
bool isData() const
Definition: MCSymbolWasm.h:45
void setUsedInGOT() const
Definition: MCSymbolWasm.h:124
bool isTag() const
Definition: MCSymbolWasm.h:49
bool isUsedInInitArray() const
Definition: MCSymbolWasm.h:128
bool hasImportName() const
Definition: MCSymbolWasm.h:101
bool isTLS() const
Definition: MCSymbolWasm.h:69
bool isFunction() const
Definition: MCSymbolWasm.h:43
void setSize(const MCExpr *SS)
Definition: MCSymbolWasm.h:41
std::optional< wasm::WasmSymbolType > getType() const
Definition: MCSymbolWasm.h:51
void setTLS() const
Definition: MCSymbolWasm.h:70
bool isWeak() const
Definition: MCSymbolWasm.h:74
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
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:431
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:422
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:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
@ WASM_LIMITS_FLAG_IS_64
Definition: Wasm.h:151
@ WASM_LIMITS_FLAG_NONE
Definition: Wasm.h:148
const unsigned WASM_SYMBOL_NO_STRIP
Definition: Wasm.h:239
const unsigned WASM_SYMBOL_TLS
Definition: Wasm.h:240
WasmSymbolType
Definition: Wasm.h:208
@ WASM_SYMBOL_TYPE_GLOBAL
Definition: Wasm.h:211
@ WASM_SYMBOL_TYPE_DATA
Definition: Wasm.h:210
@ WASM_SYMBOL_TYPE_TAG
Definition: Wasm.h:213
@ WASM_SYMBOL_TYPE_TABLE
Definition: Wasm.h:214
@ WASM_SYMBOL_TYPE_SECTION
Definition: Wasm.h:212
@ WASM_SYMBOL_TYPE_FUNCTION
Definition: Wasm.h:209
const unsigned WASM_SYMBOL_EXPORTED
Definition: Wasm.h:237
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18