LLVM  13.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 
11 #include "llvm/BinaryFormat/Wasm.h"
12 #include "llvm/MC/MCSymbol.h"
13 
14 namespace llvm {
15 
16 class MCSymbolWasm : public MCSymbol {
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  Optional<StringRef> ImportModule;
25  Optional<StringRef> ImportName;
26  Optional<StringRef> ExportName;
27  wasm::WasmSignature *Signature = nullptr;
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 
36 public:
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 
44  bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; }
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 
53 
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 isWeak() const { return IsWeak; }
71  void setWeak(bool isWeak) { IsWeak = isWeak; }
72 
73  bool isHidden() const { return IsHidden; }
74  void setHidden(bool isHidden) { IsHidden = isHidden; }
75 
76  bool isComdat() const { return IsComdat; }
77  void setComdat(bool isComdat) { IsComdat = isComdat; }
78 
79  // wasm-ld understands a finite set of symbol types. This flag allows the
80  // compiler to avoid emitting symbol table entries that would confuse the
81  // linker, unless the user specifically requests the feature.
82  bool omitFromLinkingSection() const { return OmitFromLinkingSection; }
83  void setOmitFromLinkingSection() { OmitFromLinkingSection = true; }
84 
85  bool hasImportModule() const { return ImportModule.hasValue(); }
87  if (ImportModule.hasValue())
88  return ImportModule.getValue();
89  // Use a default module name of "env" for now, for compatibility with
90  // existing tools.
91  // TODO(sbc): Find a way to specify a default value in the object format
92  // without picking a hardcoded value like this.
93  return "env";
94  }
95  void setImportModule(StringRef Name) { ImportModule = Name; }
96 
97  bool hasImportName() const { return ImportName.hasValue(); }
99  if (ImportName.hasValue())
100  return ImportName.getValue();
101  return getName();
102  }
103  void setImportName(StringRef Name) { ImportName = Name; }
104 
105  bool hasExportName() const { return ExportName.hasValue(); }
106  StringRef getExportName() const { return ExportName.getValue(); }
107  void setExportName(StringRef Name) { ExportName = Name; }
108 
109  bool isFunctionTable() const {
110  return isTable() && hasTableType() &&
112  }
116  }
117 
118  void setUsedInGOT() const { IsUsedInGOT = true; }
119  bool isUsedInGOT() const { return IsUsedInGOT; }
120 
121  void setUsedInInitArray() const { IsUsedInInitArray = true; }
122  bool isUsedInInitArray() const { return IsUsedInInitArray; }
123 
124  const wasm::WasmSignature *getSignature() const { return Signature; }
125  void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
126 
128  assert(GlobalType.hasValue());
129  return GlobalType.getValue();
130  }
131  void setGlobalType(wasm::WasmGlobalType GT) { GlobalType = GT; }
132 
133  bool hasTableType() const { return TableType.hasValue(); }
135  assert(hasTableType());
136  return TableType.getValue();
137  }
138  void setTableType(wasm::WasmTableType TT) { TableType = TT; }
140  // Declare a table with element type VT and no limits (min size 0, no max
141  // size).
143  setTableType({uint8_t(VT), Limits});
144  }
145 
146  const wasm::WasmTagType &getTagType() const {
147  assert(TagType.hasValue());
148  return TagType.getValue();
149  }
150  void setTagType(wasm::WasmTagType ET) { TagType = ET; }
151 };
152 
153 } // end namespace llvm
154 
155 #endif // LLVM_MC_MCSYMBOLWASM_H
llvm::wasm::WASM_SYMBOL_TYPE_SECTION
@ WASM_SYMBOL_TYPE_SECTION
Definition: Wasm.h:355
llvm::wasm::WASM_SYMBOL_EXPORTED
const unsigned WASM_SYMBOL_EXPORTED
Definition: Wasm.h:379
llvm::MCSymbolWasm::isSection
bool isSection() const
Definition: MCSymbolWasm.h:49
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSymbolWasm::isComdat
bool isComdat() const
Definition: MCSymbolWasm.h:76
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::StringMapEntry
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMapEntry.h:98
llvm::wasm::WASM_LIMITS_FLAG_NONE
@ WASM_LIMITS_FLAG_NONE
Definition: Wasm.h:301
llvm::MCSymbolWasm::isNoStrip
bool isNoStrip() const
Definition: MCSymbolWasm.h:63
llvm::MCSymbolWasm::getType
Optional< wasm::WasmSymbolType > getType() const
Definition: MCSymbolWasm.h:52
llvm::MCSymbol::isTemporary
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:214
llvm::MCSymbolWasm::setOmitFromLinkingSection
void setOmitFromLinkingSection()
Definition: MCSymbolWasm.h:83
llvm::wasm::WASM_SYMBOL_NO_STRIP
const unsigned WASM_SYMBOL_NO_STRIP
Definition: Wasm.h:381
llvm::MCSymbolWasm::isHidden
bool isHidden() const
Definition: MCSymbolWasm.h:73
llvm::MCSymbolWasm::getTableType
const wasm::WasmTableType & getTableType() const
Definition: MCSymbolWasm.h:134
llvm::wasm::WASM_SYMBOL_TYPE_TABLE
@ WASM_SYMBOL_TYPE_TABLE
Definition: Wasm.h:357
llvm::wasm::WASM_SYMBOL_TYPE_GLOBAL
@ WASM_SYMBOL_TYPE_GLOBAL
Definition: Wasm.h:354
llvm::MCSymbolWasm::setTagType
void setTagType(wasm::WasmTagType ET)
Definition: MCSymbolWasm.h:150
llvm::MCSymbolWasm::isGlobal
bool isGlobal() const
Definition: MCSymbolWasm.h:47
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::MCSymbolWasm::setSize
void setSize(const MCExpr *SS)
Definition: MCSymbolWasm.h:42
llvm::Optional< wasm::WasmSymbolType >
llvm::MCSymbolWasm::setHidden
void setHidden(bool isHidden)
Definition: MCSymbolWasm.h:74
llvm::MCSymbolWasm::setSignature
void setSignature(wasm::WasmSignature *Sig)
Definition: MCSymbolWasm.h:125
llvm::MCSymbolWasm::hasTableType
bool hasTableType() const
Definition: MCSymbolWasm.h:133
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:288
llvm::wasm::WasmLimits
Definition: Wasm.h:64
llvm::MCSymbolWasm::setImportName
void setImportName(StringRef Name)
Definition: MCSymbolWasm.h:103
llvm::wasm::WasmTableType::ElemType
uint8_t ElemType
Definition: Wasm.h:71
llvm::MCSymbolWasm::isUsedInGOT
bool isUsedInGOT() const
Definition: MCSymbolWasm.h:119
MCSymbol.h
llvm::MCSymbolWasm::getExportName
StringRef getExportName() const
Definition: MCSymbolWasm.h:106
llvm::MCSymbolWasm::setComdat
void setComdat(bool isComdat)
Definition: MCSymbolWasm.h:77
llvm::wasm::WasmGlobalType
Definition: Wasm.h:92
llvm::MCSymbolWasm::setType
void setType(wasm::WasmSymbolType type)
Definition: MCSymbolWasm.h:54
llvm::MCSymbolWasm::isExported
bool isExported() const
Definition: MCSymbolWasm.h:56
llvm::MCSymbolWasm::getImportName
StringRef getImportName() const
Definition: MCSymbolWasm.h:98
llvm::wasm::WASM_SYMBOL_TYPE_FUNCTION
@ WASM_SYMBOL_TYPE_FUNCTION
Definition: Wasm.h:352
llvm::MCSymbolWasm::classof
static bool classof(const MCSymbol *S)
Definition: MCSymbolWasm.h:39
llvm::wasm::ValType
ValType
Definition: Wasm.h:392
llvm::MCSymbolWasm::isData
bool isData() const
Definition: MCSymbolWasm.h:46
llvm::MCSymbol::getName
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:197
llvm::MCSymbolWasm::getGlobalType
const wasm::WasmGlobalType & getGlobalType() const
Definition: MCSymbolWasm.h:127
llvm::MCSymbolWasm::setImportModule
void setImportModule(StringRef Name)
Definition: MCSymbolWasm.h:95
llvm::MCSymbolWasm::getImportModule
StringRef getImportModule() const
Definition: MCSymbolWasm.h:86
llvm::MCSymbolWasm::MCSymbolWasm
MCSymbolWasm(const StringMapEntry< bool > *Name, bool isTemporary)
Definition: MCSymbolWasm.h:37
llvm::MCSymbolWasm::hasImportModule
bool hasImportModule() const
Definition: MCSymbolWasm.h:85
type
AMD64 Optimization Manual has some nice information about optimizing integer multiplication by a constant How much of it applies to Intel s X86 implementation There are definite trade offs to xmm0 cvttss2siq rdx jb L3 subss xmm0 rax cvttss2siq rdx xorq rdx rax ret instead of xmm1 cvttss2siq rcx movaps xmm2 subss xmm2 cvttss2siq rax rdx xorq rax ucomiss xmm0 cmovb rax ret Seems like the jb branch has high likelihood of being taken It would have saved a few instructions It s not possible to reference and DH registers in an instruction requiring REX prefix divb and mulb both produce results in AH If isel emits a CopyFromReg which gets turned into a movb and that can be allocated a r8b r15b To get around isel emits a CopyFromReg from AX and then right shift it down by and truncate it It s not pretty but it works We need some register allocation magic to make the hack go which would often require a callee saved register Callees usually need to keep this value live for most of their body so it doesn t add a significant burden on them We currently implement this in however this is suboptimal because it means that it would be quite awkward to implement the optimization for callers A better implementation would be to relax the LLVM IR rules for sret arguments to allow a function with an sret argument to have a non void return type
Definition: README-X86-64.txt:70
llvm::MCSymbolWasm::setTableType
void setTableType(wasm::WasmTableType TT)
Definition: MCSymbolWasm.h:138
llvm::MCSymbol::SymbolKindWasm
@ SymbolKindWasm
Definition: MCSymbol.h:50
llvm::MCSymbolWasm
Definition: MCSymbolWasm.h:16
llvm::wasm::ValType::FUNCREF
@ FUNCREF
llvm::MCSymbol::modifyFlags
void modifyFlags(uint32_t Value, uint32_t Mask) const
Modify the flags via a mask.
Definition: MCSymbol.h:421
llvm::MCSymbolWasm::setWeak
void setWeak(bool isWeak)
Definition: MCSymbolWasm.h:71
llvm::MCSymbolWasm::isUsedInInitArray
bool isUsedInInitArray() const
Definition: MCSymbolWasm.h:122
llvm::MCSymbol::getFlags
uint32_t getFlags() const
Get the (implementation defined) symbol flags.
Definition: MCSymbol.h:412
llvm::wasm::WASM_SYMBOL_TYPE_TAG
@ WASM_SYMBOL_TYPE_TAG
Definition: Wasm.h:356
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MCSymbolWasm::isTag
bool isTag() const
Definition: MCSymbolWasm.h:50
llvm::MCSymbolWasm::omitFromLinkingSection
bool omitFromLinkingSection() const
Definition: MCSymbolWasm.h:82
llvm::wasm::WasmTagType
Definition: Wasm.h:104
llvm::MCSymbolWasm::isWeak
bool isWeak() const
Definition: MCSymbolWasm.h:70
llvm::MCSymbolWasm::hasExportName
bool hasExportName() const
Definition: MCSymbolWasm.h:105
llvm::MCSymbolWasm::setNoStrip
void setNoStrip() const
Definition: MCSymbolWasm.h:66
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::wasm::WASM_TYPE_FUNCREF
@ WASM_TYPE_FUNCREF
Definition: Wasm.h:251
llvm::MCSymbolWasm::setUsedInGOT
void setUsedInGOT() const
Definition: MCSymbolWasm.h:118
llvm::wasm::WasmSymbolType
WasmSymbolType
Definition: Wasm.h:351
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::X86AS::SS
@ SS
Definition: X86.h:189
llvm::MCSymbolWasm::setExported
void setExported() const
Definition: MCSymbolWasm.h:59
llvm::MCSymbolWasm::getSize
const MCExpr * getSize() const
Definition: MCSymbolWasm.h:41
llvm::MCSymbolWasm::setUsedInInitArray
void setUsedInInitArray() const
Definition: MCSymbolWasm.h:121
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::MCSymbolWasm::isFunctionTable
bool isFunctionTable() const
Definition: MCSymbolWasm.h:109
llvm::MCSymbolWasm::getSignature
const wasm::WasmSignature * getSignature() const
Definition: MCSymbolWasm.h:124
llvm::MCSymbolWasm::hasImportName
bool hasImportName() const
Definition: MCSymbolWasm.h:97
llvm::MCSymbolWasm::setFunctionTable
void setFunctionTable()
Definition: MCSymbolWasm.h:113
Wasm.h
llvm::AArch64CC::GT
@ GT
Definition: AArch64BaseInfo.h:248
llvm::MCSymbolWasm::isFunction
bool isFunction() const
Definition: MCSymbolWasm.h:44
llvm::MCSymbolWasm::setExportName
void setExportName(StringRef Name)
Definition: MCSymbolWasm.h:107
llvm::MCSymbolWasm::setGlobalType
void setGlobalType(wasm::WasmGlobalType GT)
Definition: MCSymbolWasm.h:131
llvm::MCSymbolWasm::isTable
bool isTable() const
Definition: MCSymbolWasm.h:48
llvm::MCSymbolWasm::setTableType
void setTableType(wasm::ValType VT)
Definition: MCSymbolWasm.h:139
llvm::wasm::WasmTableType
Definition: Wasm.h:70
llvm::MCSymbolWasm::getTagType
const wasm::WasmTagType & getTagType() const
Definition: MCSymbolWasm.h:146
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::wasm::WASM_SYMBOL_TYPE_DATA
@ WASM_SYMBOL_TYPE_DATA
Definition: Wasm.h:353
llvm::wasm::WasmSignature
Definition: Wasm.h:402
llvm::Optional::getValue
constexpr const T & getValue() const LLVM_LVALUE_FUNCTION
Definition: Optional.h:282