LLVM  13.0.0git
WebAssemblyAsmPrinter.cpp
Go to the documentation of this file.
1 //===-- WebAssemblyAsmPrinter.cpp - WebAssembly LLVM assembly writer ------===//
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 /// \file
10 /// This file contains a printer that converts from our internal
11 /// representation of machine-dependent LLVM code to the WebAssembly assembly
12 /// language.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #include "WebAssemblyAsmPrinter.h"
22 #include "WebAssembly.h"
23 #include "WebAssemblyMCInstLower.h"
27 #include "llvm/ADT/SmallSet.h"
28 #include "llvm/ADT/StringExtras.h"
29 #include "llvm/BinaryFormat/Wasm.h"
30 #include "llvm/CodeGen/Analysis.h"
35 #include "llvm/IR/DataLayout.h"
37 #include "llvm/IR/GlobalVariable.h"
38 #include "llvm/IR/Metadata.h"
39 #include "llvm/MC/MCContext.h"
40 #include "llvm/MC/MCSectionWasm.h"
41 #include "llvm/MC/MCStreamer.h"
42 #include "llvm/MC/MCSymbol.h"
43 #include "llvm/MC/MCSymbolWasm.h"
44 #include "llvm/Support/Debug.h"
47 
48 using namespace llvm;
49 
50 #define DEBUG_TYPE "asm-printer"
51 
55 
56 //===----------------------------------------------------------------------===//
57 // Helpers.
58 //===----------------------------------------------------------------------===//
59 
60 MVT WebAssemblyAsmPrinter::getRegType(unsigned RegNo) const {
61  const TargetRegisterInfo *TRI = Subtarget->getRegisterInfo();
62  const TargetRegisterClass *TRC = MRI->getRegClass(RegNo);
65  if (TRI->isTypeLegalForClass(*TRC, T))
66  return T;
67  LLVM_DEBUG(errs() << "Unknown type for register number: " << RegNo);
68  llvm_unreachable("Unknown register type");
69  return MVT::Other;
70 }
71 
73  Register RegNo = MO.getReg();
75  "Unlowered physical register encountered during assembly printing");
76  assert(!MFI->isVRegStackified(RegNo));
77  unsigned WAReg = MFI->getWAReg(RegNo);
79  return '$' + utostr(WAReg);
80 }
81 
83  MCTargetStreamer *TS = OutStreamer->getTargetStreamer();
84  return static_cast<WebAssemblyTargetStreamer *>(TS);
85 }
86 
87 // Emscripten exception handling helpers
88 //
89 // This converts invoke names generated by LowerEmscriptenEHSjLj to real names
90 // that are expected by JavaScript glue code. The invoke names generated by
91 // Emscripten JS glue code are based on their argument and return types; for
92 // example, for a function that takes an i32 and returns nothing, it is
93 // 'invoke_vi'. But the format of invoke generated by LowerEmscriptenEHSjLj pass
94 // contains a mangled string generated from their IR types, for example,
95 // "__invoke_void_%struct.mystruct*_int", because final wasm types are not
96 // available in the IR pass. So we convert those names to the form that
97 // Emscripten JS code expects.
98 //
99 // Refer to LowerEmscriptenEHSjLj pass for more details.
100 
101 // Returns true if the given function name is an invoke name generated by
102 // LowerEmscriptenEHSjLj pass.
104  if (Name.front() == '"' && Name.back() == '"')
105  Name = Name.substr(1, Name.size() - 2);
106  return Name.startswith("__invoke_");
107 }
108 
109 // Returns a character that represents the given wasm value type in invoke
110 // signatures.
111 static char getInvokeSig(wasm::ValType VT) {
112  switch (VT) {
113  case wasm::ValType::I32:
114  return 'i';
115  case wasm::ValType::I64:
116  return 'j';
117  case wasm::ValType::F32:
118  return 'f';
119  case wasm::ValType::F64:
120  return 'd';
121  case wasm::ValType::V128:
122  return 'V';
124  return 'F';
126  return 'X';
127  }
128  llvm_unreachable("Unhandled wasm::ValType enum");
129 }
130 
131 // Given the wasm signature, generate the invoke name in the format JS glue code
132 // expects.
134  assert(Sig->Returns.size() <= 1);
135  std::string Ret = "invoke_";
136  if (!Sig->Returns.empty())
137  for (auto VT : Sig->Returns)
138  Ret += getInvokeSig(VT);
139  else
140  Ret += 'v';
141  // Invokes' first argument is a pointer to the original function, so skip it
142  for (unsigned I = 1, E = Sig->Params.size(); I < E; I++)
143  Ret += getInvokeSig(Sig->Params[I]);
144  return Ret;
145 }
146 
147 //===----------------------------------------------------------------------===//
148 // WebAssemblyAsmPrinter Implementation.
149 //===----------------------------------------------------------------------===//
150 
152  const Function *F, bool EnableEmEH, wasm::WasmSignature *Sig,
153  bool &InvokeDetected) {
154  MCSymbolWasm *WasmSym = nullptr;
155  if (EnableEmEH && isEmscriptenInvokeName(F->getName())) {
156  assert(Sig);
157  InvokeDetected = true;
158  if (Sig->Returns.size() > 1) {
159  std::string Msg =
160  "Emscripten EH/SjLj does not support multivalue returns: " +
161  std::string(F->getName()) + ": " +
163  report_fatal_error(Msg);
164  }
165  WasmSym = cast<MCSymbolWasm>(
167  } else {
168  WasmSym = cast<MCSymbolWasm>(getSymbol(F));
169  }
170  return WasmSym;
171 }
172 
174  for (auto &It : OutContext.getSymbols()) {
175  // Emit .globaltype, .eventtype, or .tabletype declarations.
176  auto Sym = cast<MCSymbolWasm>(It.getValue());
177  if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_GLOBAL)
179  else if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_EVENT)
181  else if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_TABLE)
183  }
184 
185  DenseSet<MCSymbol *> InvokeSymbols;
186  bool HasAddressTakenFunction = false;
187  for (const auto &F : M) {
188  if (F.isIntrinsic())
189  continue;
190 
191  if (F.hasAddressTaken())
192  HasAddressTakenFunction = true;
193 
194  // Emit function type info for all undefined functions
195  if (F.isDeclarationForLinker()) {
197  SmallVector<MVT, 4> Params;
198  computeSignatureVTs(F.getFunctionType(), &F, F, TM, Params, Results);
199  // At this point these MCSymbols may or may not have been created already
200  // and thus also contain a signature, but we need to get the signature
201  // anyway here in case it is an invoke that has not yet been created. We
202  // will discard it later if it turns out not to be necessary.
203  auto Signature = signatureFromMVTs(Results, Params);
204  bool InvokeDetected = false;
206  Signature.get(), InvokeDetected);
207 
208  // Multiple functions can be mapped to the same invoke symbol. For
209  // example, two IR functions '__invoke_void_i8*' and '__invoke_void_i32'
210  // are both mapped to '__invoke_vi'. We keep them in a set once we emit an
211  // Emscripten EH symbol so we don't emit the same symbol twice.
212  if (InvokeDetected && !InvokeSymbols.insert(Sym).second)
213  continue;
214 
215  Sym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
216  if (!Sym->getSignature()) {
217  Sym->setSignature(Signature.get());
218  addSignature(std::move(Signature));
219  } else {
220  // This symbol has already been created and had a signature. Discard it.
221  Signature.reset();
222  }
223 
225 
226  if (F.hasFnAttribute("wasm-import-module")) {
227  StringRef Name =
228  F.getFnAttribute("wasm-import-module").getValueAsString();
229  Sym->setImportModule(storeName(Name));
231  }
232  if (F.hasFnAttribute("wasm-import-name")) {
233  // If this is a converted Emscripten EH/SjLj symbol, we shouldn't use
234  // the original function name but the converted symbol name.
235  StringRef Name =
236  InvokeDetected
237  ? Sym->getName()
238  : F.getFnAttribute("wasm-import-name").getValueAsString();
239  Sym->setImportName(storeName(Name));
241  }
242  }
243 
244  if (F.hasFnAttribute("wasm-export-name")) {
245  auto *Sym = cast<MCSymbolWasm>(getSymbol(&F));
246  StringRef Name = F.getFnAttribute("wasm-export-name").getValueAsString();
247  Sym->setExportName(storeName(Name));
249  }
250  }
251 
252  // When a function's address is taken, a TABLE_INDEX relocation is emitted
253  // against the function symbol at the use site. However the relocation
254  // doesn't explicitly refer to the table. In the future we may want to
255  // define a new kind of reloc against both the function and the table, so
256  // that the linker can see that the function symbol keeps the table alive,
257  // but for now manually mark the table as live.
258  if (HasAddressTakenFunction) {
259  MCSymbolWasm *FunctionTable =
261  OutStreamer->emitSymbolAttribute(FunctionTable, MCSA_NoDeadStrip);
262  }
263 
264  for (const auto &G : M.globals()) {
265  if (!G.hasInitializer() && G.hasExternalLinkage()) {
266  if (G.getValueType()->isSized()) {
267  uint16_t Size = M.getDataLayout().getTypeAllocSize(G.getValueType());
268  OutStreamer->emitELFSize(getSymbol(&G),
270  }
271  }
272  }
273 
274  if (const NamedMDNode *Named = M.getNamedMetadata("wasm.custom_sections")) {
275  for (const Metadata *MD : Named->operands()) {
276  const auto *Tuple = dyn_cast<MDTuple>(MD);
277  if (!Tuple || Tuple->getNumOperands() != 2)
278  continue;
279  const MDString *Name = dyn_cast<MDString>(Tuple->getOperand(0));
280  const MDString *Contents = dyn_cast<MDString>(Tuple->getOperand(1));
281  if (!Name || !Contents)
282  continue;
283 
284  OutStreamer->PushSection();
285  std::string SectionName = (".custom_section." + Name->getString()).str();
286  MCSectionWasm *MySection =
288  OutStreamer->SwitchSection(MySection);
289  OutStreamer->emitBytes(Contents->getString());
290  OutStreamer->PopSection();
291  }
292  }
293 
296 }
297 
300  if (const NamedMDNode *Debug = M.getNamedMetadata("llvm.dbg.cu")) {
301  llvm::SmallSet<StringRef, 4> SeenLanguages;
302  for (size_t I = 0, E = Debug->getNumOperands(); I < E; ++I) {
303  const auto *CU = cast<DICompileUnit>(Debug->getOperand(I));
304  StringRef Language = dwarf::LanguageString(CU->getSourceLanguage());
305  Language.consume_front("DW_LANG_");
306  if (SeenLanguages.insert(Language).second)
307  Languages.emplace_back(Language.str(), "");
308  }
309  }
310 
312  if (const NamedMDNode *Ident = M.getNamedMetadata("llvm.ident")) {
314  for (size_t I = 0, E = Ident->getNumOperands(); I < E; ++I) {
315  const auto *S = cast<MDString>(Ident->getOperand(I)->getOperand(0));
316  std::pair<StringRef, StringRef> Field = S->getString().split("version");
317  StringRef Name = Field.first.trim();
318  StringRef Version = Field.second.trim();
319  if (SeenTools.insert(Name).second)
320  Tools.emplace_back(Name.str(), Version.str());
321  }
322  }
323 
324  int FieldCount = int(!Languages.empty()) + int(!Tools.empty());
325  if (FieldCount != 0) {
327  ".custom_section.producers", SectionKind::getMetadata());
328  OutStreamer->PushSection();
329  OutStreamer->SwitchSection(Producers);
330  OutStreamer->emitULEB128IntValue(FieldCount);
331  for (auto &Producers : {std::make_pair("language", &Languages),
332  std::make_pair("processed-by", &Tools)}) {
333  if (Producers.second->empty())
334  continue;
335  OutStreamer->emitULEB128IntValue(strlen(Producers.first));
336  OutStreamer->emitBytes(Producers.first);
337  OutStreamer->emitULEB128IntValue(Producers.second->size());
338  for (auto &Producer : *Producers.second) {
339  OutStreamer->emitULEB128IntValue(Producer.first.size());
340  OutStreamer->emitBytes(Producer.first);
341  OutStreamer->emitULEB128IntValue(Producer.second.size());
342  OutStreamer->emitBytes(Producer.second);
343  }
344  }
345  OutStreamer->PopSection();
346  }
347 }
348 
350  struct FeatureEntry {
351  uint8_t Prefix;
352  std::string Name;
353  };
354 
355  // Read target features and linkage policies from module metadata
356  SmallVector<FeatureEntry, 4> EmittedFeatures;
357  auto EmitFeature = [&](std::string Feature) {
358  std::string MDKey = (StringRef("wasm-feature-") + Feature).str();
359  Metadata *Policy = M.getModuleFlag(MDKey);
360  if (Policy == nullptr)
361  return;
362 
363  FeatureEntry Entry;
364  Entry.Prefix = 0;
365  Entry.Name = Feature;
366 
367  if (auto *MD = cast<ConstantAsMetadata>(Policy))
368  if (auto *I = cast<ConstantInt>(MD->getValue()))
369  Entry.Prefix = I->getZExtValue();
370 
371  // Silently ignore invalid metadata
372  if (Entry.Prefix != wasm::WASM_FEATURE_PREFIX_USED &&
373  Entry.Prefix != wasm::WASM_FEATURE_PREFIX_REQUIRED &&
374  Entry.Prefix != wasm::WASM_FEATURE_PREFIX_DISALLOWED)
375  return;
376 
377  EmittedFeatures.push_back(Entry);
378  };
379 
380  for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
381  EmitFeature(KV.Key);
382  }
383  // This pseudo-feature tells the linker whether shared memory would be safe
384  EmitFeature("shared-mem");
385 
386  if (EmittedFeatures.size() == 0)
387  return;
388 
389  // Emit features and linkage policies into the "target_features" section
390  MCSectionWasm *FeaturesSection = OutContext.getWasmSection(
391  ".custom_section.target_features", SectionKind::getMetadata());
392  OutStreamer->PushSection();
393  OutStreamer->SwitchSection(FeaturesSection);
394 
395  OutStreamer->emitULEB128IntValue(EmittedFeatures.size());
396  for (auto &F : EmittedFeatures) {
397  OutStreamer->emitIntValue(F.Prefix, 1);
398  OutStreamer->emitULEB128IntValue(F.Name.size());
399  OutStreamer->emitBytes(F.Name);
400  }
401 
402  OutStreamer->PopSection();
403 }
404 
406  assert(MF->getConstantPool()->getConstants().empty() &&
407  "WebAssembly disables constant pools");
408 }
409 
411  // Nothing to do; jump tables are incorporated into the instruction stream.
412 }
413 
415  const Function &F = MF->getFunction();
416  SmallVector<MVT, 1> ResultVTs;
417  SmallVector<MVT, 4> ParamVTs;
418  computeSignatureVTs(F.getFunctionType(), &F, F, TM, ParamVTs, ResultVTs);
419 
420  auto Signature = signatureFromMVTs(ResultVTs, ParamVTs);
421  auto *WasmSym = cast<MCSymbolWasm>(CurrentFnSym);
422  WasmSym->setSignature(Signature.get());
423  addSignature(std::move(Signature));
424  WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
425 
427 
428  // Emit the function index.
429  if (MDNode *Idx = F.getMetadata("wasm.index")) {
430  assert(Idx->getNumOperands() == 1);
431 
433  cast<ConstantAsMetadata>(Idx->getOperand(0))->getValue()));
434  }
435 
437  valTypesFromMVTs(MFI->getLocals(), Locals);
438  getTargetStreamer()->emitLocal(Locals);
439 
441 }
442 
444  LLVM_DEBUG(dbgs() << "EmitInstruction: " << *MI << '\n');
445 
446  switch (MI->getOpcode()) {
447  case WebAssembly::ARGUMENT_i32:
448  case WebAssembly::ARGUMENT_i32_S:
449  case WebAssembly::ARGUMENT_i64:
450  case WebAssembly::ARGUMENT_i64_S:
451  case WebAssembly::ARGUMENT_f32:
452  case WebAssembly::ARGUMENT_f32_S:
453  case WebAssembly::ARGUMENT_f64:
454  case WebAssembly::ARGUMENT_f64_S:
455  case WebAssembly::ARGUMENT_v16i8:
456  case WebAssembly::ARGUMENT_v16i8_S:
457  case WebAssembly::ARGUMENT_v8i16:
458  case WebAssembly::ARGUMENT_v8i16_S:
459  case WebAssembly::ARGUMENT_v4i32:
460  case WebAssembly::ARGUMENT_v4i32_S:
461  case WebAssembly::ARGUMENT_v2i64:
462  case WebAssembly::ARGUMENT_v2i64_S:
463  case WebAssembly::ARGUMENT_v4f32:
464  case WebAssembly::ARGUMENT_v4f32_S:
465  case WebAssembly::ARGUMENT_v2f64:
466  case WebAssembly::ARGUMENT_v2f64_S:
467  // These represent values which are live into the function entry, so there's
468  // no instruction to emit.
469  break;
470  case WebAssembly::FALLTHROUGH_RETURN: {
471  // These instructions represent the implicit return at the end of a
472  // function body.
473  if (isVerbose()) {
474  OutStreamer->AddComment("fallthrough-return");
475  OutStreamer->AddBlankLine();
476  }
477  break;
478  }
479  case WebAssembly::COMPILER_FENCE:
480  // This is a compiler barrier that prevents instruction reordering during
481  // backend compilation, and should not be emitted.
482  break;
483  default: {
484  WebAssemblyMCInstLower MCInstLowering(OutContext, *this);
485  MCInst TmpInst;
486  MCInstLowering.lower(MI, TmpInst);
487  EmitToStreamer(*OutStreamer, TmpInst);
488  break;
489  }
490  }
491 }
492 
494  unsigned OpNo,
495  const char *ExtraCode,
496  raw_ostream &OS) {
497  // First try the generic code, which knows about modifiers like 'c' and 'n'.
498  if (!AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS))
499  return false;
500 
501  if (!ExtraCode) {
502  const MachineOperand &MO = MI->getOperand(OpNo);
503  switch (MO.getType()) {
505  OS << MO.getImm();
506  return false;
508  // FIXME: only opcode that still contains registers, as required by
509  // MachineInstr::getDebugVariable().
510  assert(MI->getOpcode() == WebAssembly::INLINEASM);
511  OS << regToString(MO);
512  return false;
514  PrintSymbolOperand(MO, OS);
515  return false;
518  printOffset(MO.getOffset(), OS);
519  return false;
521  MO.getMBB()->getSymbol()->print(OS, MAI);
522  return false;
523  default:
524  break;
525  }
526  }
527 
528  return true;
529 }
530 
532  unsigned OpNo,
533  const char *ExtraCode,
534  raw_ostream &OS) {
535  // The current approach to inline asm is that "r" constraints are expressed
536  // as local indices, rather than values on the operand stack. This simplifies
537  // using "r" as it eliminates the need to push and pop the values in a
538  // particular order, however it also makes it impossible to have an "m"
539  // constraint. So we don't support it.
540 
541  return AsmPrinter::PrintAsmMemoryOperand(MI, OpNo, ExtraCode, OS);
542 }
543 
544 // Force static initialization.
548 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::WebAssemblyTargetStreamer::emitLocal
virtual void emitLocal(ArrayRef< wasm::ValType > Types)=0
.local
AsmPrinter.h
llvm::WebAssemblySubtarget::getRegisterInfo
const WebAssemblyRegisterInfo * getRegisterInfo() const override
Definition: WebAssemblySubtarget.h:80
llvm::WebAssemblyFeatureKV
const SubtargetFeatureKV WebAssemblyFeatureKV[WebAssembly::NumSubtargetFeatures]
WasmKeepRegisters
cl::opt< bool > WasmKeepRegisters
MachineModuleInfoImpls.h
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:100
MachineInstr.h
llvm::MachineOperand::MO_Immediate
@ MO_Immediate
Immediate operand.
Definition: MachineOperand.h:53
llvm
Definition: AllocatorList.h:23
llvm::WebAssemblyTargetStreamer
WebAssembly-specific streamer interface, to implement support WebAssembly-specific assembly directive...
Definition: WebAssemblyTargetStreamer.h:29
llvm::wasm::ValType::I32
@ I32
llvm::AsmPrinter::printOffset
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
Definition: AsmPrinter.cpp:3032
WebAssembly.h
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::WebAssemblyFunctionInfo::getLocals
const std::vector< MVT > & getLocals() const
Definition: WebAssemblyMachineFunctionInfo.h:95
llvm::NamedMDNode
A tuple of MDNodes.
Definition: Metadata.h:1386
llvm::SectionKind::getMetadata
static SectionKind getMetadata()
Definition: SectionKind.h:182
Metadata.h
llvm::AsmPrinter::lowerConstant
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
Definition: AsmPrinter.cpp:2409
llvm::getTheWebAssemblyTarget32
Target & getTheWebAssemblyTarget32()
Definition: WebAssemblyTargetInfo.cpp:20
DebugInfoMetadata.h
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:164
llvm::Function
Definition: Function.h:61
llvm::MCContext::getSymbols
const SymbolTable & getSymbols() const
getSymbols - Get a reference for the symbol table for clients that want to, for example,...
Definition: MCContext.h:498
llvm::WebAssemblyTargetStreamer::emitIndIdx
virtual void emitIndIdx(const MCExpr *Value)=0
.indidx
llvm::AsmPrinter::MAI
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:88
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
llvm::WebAssembly::getOrCreateFunctionTableSymbol
MCSymbolWasm * getOrCreateFunctionTableSymbol(MCContext &Ctx, const WebAssemblySubtarget *Subtarget)
Returns the __indirect_function_table, for use in call_indirect and in function bitcasts.
Definition: WebAssemblyUtilities.cpp:100
llvm::signatureFromMVTs
std::unique_ptr< wasm::WasmSignature > signatureFromMVTs(const SmallVectorImpl< MVT > &Results, const SmallVectorImpl< MVT > &Params)
Definition: WebAssemblyMachineFunctionInfo.cpp:100
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
WebAssemblyMCInstLower.h
llvm::WebAssemblyAsmPrinter::PrintAsmMemoryOperand
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
Definition: WebAssemblyAsmPrinter.cpp:531
isEmscriptenInvokeName
static bool isEmscriptenInvokeName(StringRef Name)
Definition: WebAssemblyAsmPrinter.cpp:103
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::WebAssembly::signatureToString
std::string signatureToString(const wasm::WasmSignature *Sig)
Definition: WebAssemblyTypeUtilities.cpp:118
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:231
llvm::AsmPrinter::PrintSymbolOperand
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
Definition: AsmPrinterInlineAsm.cpp:590
EnableEmException
cl::opt< bool > EnableEmException
llvm::wasm::WASM_FEATURE_PREFIX_REQUIRED
@ WASM_FEATURE_PREFIX_REQUIRED
Definition: Wasm.h:322
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:134
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::WebAssemblyAsmPrinter::regToString
std::string regToString(const MachineOperand &MO)
Definition: WebAssemblyAsmPrinter.cpp:72
Results
Function Alias Analysis Results
Definition: AliasAnalysis.cpp:849
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
WebAssemblyTargetMachine.h
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:183
llvm::MVT::v2f64
@ v2f64
Definition: MachineValueType.h:160
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
llvm::MachineOperand::getOffset
int64_t getOffset() const
Return the offset from the symbol in this operand.
Definition: MachineOperand.h:600
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1567
llvm::WebAssemblyTargetStreamer::emitImportModule
virtual void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule)=0
.import_module
llvm::WebAssemblyMCInstLower
This class is used to lower an MachineInstr into an MCInst.
Definition: WebAssemblyMCInstLower.h:30
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:122
llvm::MachineOperand::MO_Register
@ MO_Register
Register operand.
Definition: MachineOperand.h:52
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::AsmPrinter::EmitToStreamer
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:242
llvm::ISD::INLINEASM
@ INLINEASM
INLINEASM - Represents an inline asm block.
Definition: ISDOpcodes.h:970
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
llvm::MCSA_NoDeadStrip
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
Definition: MCDirectives.h:38
llvm::WebAssemblyTargetStreamer::emitFunctionType
virtual void emitFunctionType(const MCSymbolWasm *Sym)=0
.functype
llvm::MachineBasicBlock::getSymbol
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Definition: MachineBasicBlock.cpp:59
llvm::WebAssemblyTargetStreamer::emitExportName
virtual void emitExportName(const MCSymbolWasm *Sym, StringRef ExportName)=0
.export_name
llvm::WebAssemblyMCInstLower::lower
void lower(const MachineInstr *MI, MCInst &OutMI) const
Definition: WebAssemblyMCInstLower.cpp:214
llvm::dwarf::LanguageString
StringRef LanguageString(unsigned Language)
Definition: Dwarf.cpp:327
llvm::wasm::ValType::F64
@ F64
llvm::WebAssemblyTargetStreamer::emitTableType
virtual void emitTableType(const MCSymbolWasm *Sym)=0
.tabletype
llvm::WebAssemblyTargetStreamer::emitImportName
virtual void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName)=0
.import_name
llvm::MachineOperand::MO_GlobalAddress
@ MO_GlobalAddress
Address of a global value.
Definition: MachineOperand.h:62
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MachineOperand::getImm
int64_t getImm() const
Definition: MachineOperand.h:537
llvm::AMDGPU::HSAMD::Kernel::Key::Language
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
Definition: AMDGPUMetadata.h:383
llvm::MCSectionWasm
This represents a section on wasm.
Definition: MCSectionWasm.h:26
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:97
llvm::AsmPrinter::PrintAsmMemoryOperand
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
Definition: AsmPrinterInlineAsm.cpp:642
MCSymbolWasm.h
llvm::MVT::f64
@ f64
Definition: MachineValueType.h:53
int
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
Definition: README.txt:536
llvm::WebAssemblyAsmPrinter::addSignature
void addSignature(std::unique_ptr< wasm::WasmSignature > &&Sig)
Definition: WebAssemblyAsmPrinter.h:46
MCContext.h
Y
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
llvm::WebAssemblyAsmPrinter::getRegType
MVT getRegType(unsigned RegNo) const
Definition: WebAssemblyAsmPrinter.cpp:60
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
MCSymbol.h
llvm::wasm::ValType::F32
@ F32
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::WebAssemblyAsmPrinter::emitJumpTableInfo
void emitJumpTableInfo() override
Print assembly representations of the jump tables used by the current function to the current output ...
Definition: WebAssemblyAsmPrinter.cpp:410
WebAssemblyTypeUtilities.h
llvm::AsmPrinter::CurrentFnSym
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:119
llvm::report_fatal_error
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::wasm::WASM_SYMBOL_TYPE_FUNCTION
@ WASM_SYMBOL_TYPE_FUNCTION
Definition: Wasm.h:352
llvm::wasm::ValType
ValType
Definition: Wasm.h:387
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:991
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:91
llvm::AsmPrinter::emitFunctionBodyStart
virtual void emitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
Definition: AsmPrinter.h:478
llvm::SubtargetFeatureKV
Used to provide key value pairs for feature and CPU bit flags.
Definition: MCSubtargetInfo.h:34
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::MCSymbol::print
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:59
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
WebAssemblyUtilities.h
WebAssemblyMCTargetDesc.h
llvm::MachineRegisterInfo::getRegClass
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
Definition: MachineRegisterInfo.h:634
llvm::WebAssemblyAsmPrinter::EmitTargetFeatures
void EmitTargetFeatures(Module &M)
Definition: WebAssemblyAsmPrinter.cpp:349
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
WebAssemblyTargetStreamer.h
llvm::WebAssemblyFunctionInfo::UnusedReg
static const unsigned UnusedReg
Definition: WebAssemblyMachineFunctionInfo.h:122
llvm::cl::opt< bool >
llvm::WebAssemblyAsmPrinter::emitFunctionBodyStart
void emitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
Definition: WebAssemblyAsmPrinter.cpp:414
llvm::MVT::v16i8
@ v16i8
Definition: MachineValueType.h:77
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MVT::v2i64
@ v2i64
Definition: MachineValueType.h:110
LLVM_EXTERNAL_VISIBILITY
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:132
llvm::wasm::ValType::EXTERNREF
@ EXTERNREF
llvm::wasm::ValType::I64
@ I64
llvm::MCSymbolWasm
Definition: MCSymbolWasm.h:16
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::wasm::ValType::FUNCREF
@ FUNCREF
llvm::valTypesFromMVTs
void valTypesFromMVTs(const ArrayRef< MVT > &In, SmallVectorImpl< wasm::ValType > &Out)
Definition: WebAssemblyMachineFunctionInfo.cpp:93
I
#define I(x, y, z)
Definition: MD5.cpp:59
WebAssemblyTargetInfo.h
llvm::wasm::WasmSignature::Returns
SmallVector< ValType, 1 > Returns
Definition: Wasm.h:398
Analysis.h
StringExtras.h
MachineConstantPool.h
llvm::WebAssemblyAsmPrinter::EmitProducerInfo
void EmitProducerInfo(Module &M)
Definition: WebAssemblyAsmPrinter.cpp:298
llvm::MachineOperand::getType
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
Definition: MachineOperand.h:219
llvm::WebAssemblyFunctionInfo::getWAReg
unsigned getWAReg(unsigned VReg) const
Definition: WebAssemblyMachineFunctionInfo.h:150
llvm::Register::isVirtualRegister
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
Definition: Register.h:71
llvm::MVT::v4f32
@ v4f32
Definition: MachineValueType.h:147
llvm::WebAssemblyFunctionInfo::isVRegStackified
bool isVRegStackified(unsigned VReg) const
Definition: WebAssemblyMachineFunctionInfo.h:136
llvm::MachineFunction::getConstantPool
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
Definition: MachineFunction.h:590
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AsmPrinter::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:478
llvm::MVT::Other
@ Other
Definition: MachineValueType.h:39
llvm::wasm::WASM_FEATURE_PREFIX_USED
@ WASM_FEATURE_PREFIX_USED
Definition: Wasm.h:321
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:100
llvm::AsmPrinter::OutContext
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:92
llvm::MVT
Machine Value Type.
Definition: MachineValueType.h:30
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:360
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
WebAssemblyMachineFunctionInfo.h
getInvokeSig
static char getInvokeSig(wasm::ValType VT)
Definition: WebAssemblyAsmPrinter.cpp:111
llvm::AsmPrinter::GetExternalSymbolSymbol
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
Definition: AsmPrinter.cpp:3109
llvm::MachineOperand::getMBB
MachineBasicBlock * getMBB() const
Definition: MachineOperand.h:552
WebAssemblyAsmPrinter.h
DataLayout.h
llvm::MVT::i64
@ i64
Definition: MachineValueType.h:44
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::WebAssemblyAsmPrinter::PrintAsmOperand
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
Definition: WebAssemblyAsmPrinter.cpp:493
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::TargetRegisterInfo::isTypeLegalForClass
bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const
Return true if the given TargetRegisterClass has the ValueType T.
Definition: TargetRegisterInfo.h:297
llvm::wasm::WASM_SYMBOL_TYPE_EVENT
@ WASM_SYMBOL_TYPE_EVENT
Definition: Wasm.h:356
llvm::MachineOperand::MO_MachineBasicBlock
@ MO_MachineBasicBlock
MachineBasicBlock reference.
Definition: MachineOperand.h:56
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::MVT::v4i32
@ v4i32
Definition: MachineValueType.h:97
llvm::SmallSet::insert
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:180
LLVMInitializeWebAssemblyAsmPrinter
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyAsmPrinter()
Definition: WebAssemblyAsmPrinter.cpp:545
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::getTheWebAssemblyTarget64
Target & getTheWebAssemblyTarget64()
Definition: WebAssemblyTargetInfo.cpp:24
llvm::WebAssemblyAsmPrinter::getTargetStreamer
WebAssemblyTargetStreamer * getTargetStreamer()
Definition: WebAssemblyAsmPrinter.cpp:82
llvm::WebAssemblyAsmPrinter::emitConstantPool
void emitConstantPool() override
Print to the current output stream assembly representations of the constants in the constant pool MCP...
Definition: WebAssemblyAsmPrinter.cpp:405
llvm::WebAssemblyAsmPrinter::emitInstruction
void emitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
Definition: WebAssemblyAsmPrinter.cpp:443
llvm::computeSignatureVTs
void computeSignatureVTs(const FunctionType *Ty, const Function *TargetFunc, const Function &ContextFunc, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
Definition: WebAssemblyMachineFunctionInfo.cpp:49
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:524
uint16_t
llvm::MachineConstantPool::getConstants
const std::vector< MachineConstantPoolEntry > & getConstants() const
Definition: MachineConstantPool.h:145
llvm::SectionName
Definition: DWARFSection.h:21
llvm::MachineOperand::MO_ExternalSymbol
@ MO_ExternalSymbol
Name of external global symbol.
Definition: MachineOperand.h:61
GlobalVariable.h
llvm::MVT::v8i16
@ v8i16
Definition: MachineValueType.h:87
WebAssemblyRegisterInfo.h
llvm::MVT::i32
@ i32
Definition: MachineValueType.h:43
llvm::WebAssemblyAsmPrinter::getMCSymbolForFunction
MCSymbolWasm * getMCSymbolForFunction(const Function *F, bool EnableEmEH, wasm::WasmSignature *Sig, bool &InvokeDetected)
Definition: WebAssemblyAsmPrinter.cpp:151
Wasm.h
llvm::MCContext::getWasmSection
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K)
Definition: MCContext.h:613
llvm::wasm::ValType::V128
@ V128
llvm::AsmPrinter::TM
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:85
EnableEmSjLj
cl::opt< bool > EnableEmSjLj
llvm::MachineOperand::getSymbolName
const char * getSymbolName() const
Definition: MachineOperand.h:608
MCStreamer.h
llvm::OptimizedStructLayoutField
A field in a structure.
Definition: OptimizedStructLayout.h:45
llvm::RegisterAsmPrinter
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...
Definition: TargetRegistry.h:1196
llvm::WebAssemblyTargetStreamer::emitEventType
virtual void emitEventType(const MCSymbolWasm *Sym)=0
.eventtype
llvm::MDString::getString
StringRef getString() const
Definition: Metadata.cpp:477
llvm::AsmPrinter::isVerbose
bool isVerbose() const
Return true if assembly output should contain comments.
Definition: AsmPrinter.h:235
raw_ostream.h
llvm::MDString
A single uniqued string.
Definition: Metadata.h:611
TargetRegistry.h
CU
Definition: AArch64AsmBackend.cpp:506
llvm::MVT::f32
@ f32
Definition: MachineValueType.h:52
llvm::WebAssemblyTargetStreamer::emitGlobalType
virtual void emitGlobalType(const MCSymbolWasm *Sym)=0
.globaltype
llvm::wasm::WasmSignature::Params
SmallVector< ValType, 4 > Params
Definition: Wasm.h:399
Debug.h
getEmscriptenInvokeSymbolName
static std::string getEmscriptenInvokeSymbolName(wasm::WasmSignature *Sig)
Definition: WebAssemblyAsmPrinter.cpp:133
llvm::AsmPrinter::PrintAsmOperand
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
Definition: AsmPrinterInlineAsm.cpp:600
llvm::wasm::WasmSignature
Definition: Wasm.h:397
llvm::WebAssemblyAsmPrinter::emitEndOfAsmFile
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
Definition: WebAssemblyAsmPrinter.cpp:173
llvm::wasm::WASM_FEATURE_PREFIX_DISALLOWED
@ WASM_FEATURE_PREFIX_DISALLOWED
Definition: Wasm.h:323
MCSectionWasm.h
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:908
SmallSet.h