LLVM  9.0.0svn
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"
20 #include "WebAssembly.h"
21 #include "WebAssemblyMCInstLower.h"
25 #include "llvm/ADT/SmallSet.h"
26 #include "llvm/ADT/StringExtras.h"
27 #include "llvm/BinaryFormat/Wasm.h"
28 #include "llvm/CodeGen/Analysis.h"
33 #include "llvm/IR/DataLayout.h"
35 #include "llvm/IR/GlobalVariable.h"
36 #include "llvm/MC/MCContext.h"
37 #include "llvm/MC/MCSectionWasm.h"
38 #include "llvm/MC/MCStreamer.h"
39 #include "llvm/MC/MCSymbol.h"
40 #include "llvm/MC/MCSymbolWasm.h"
41 #include "llvm/Support/Debug.h"
44 
45 using namespace llvm;
46 
47 #define DEBUG_TYPE "asm-printer"
48 
50 
51 //===----------------------------------------------------------------------===//
52 // Helpers.
53 //===----------------------------------------------------------------------===//
54 
55 MVT WebAssemblyAsmPrinter::getRegType(unsigned RegNo) const {
56  const TargetRegisterInfo *TRI = Subtarget->getRegisterInfo();
57  const TargetRegisterClass *TRC = MRI->getRegClass(RegNo);
60  if (TRI->isTypeLegalForClass(*TRC, T))
61  return T;
62  LLVM_DEBUG(errs() << "Unknown type for register number: " << RegNo);
63  llvm_unreachable("Unknown register type");
64  return MVT::Other;
65 }
66 
68  unsigned RegNo = MO.getReg();
70  "Unlowered physical register encountered during assembly printing");
71  assert(!MFI->isVRegStackified(RegNo));
72  unsigned WAReg = MFI->getWAReg(RegNo);
74  return '$' + utostr(WAReg);
75 }
76 
78  MCTargetStreamer *TS = OutStreamer->getTargetStreamer();
79  return static_cast<WebAssemblyTargetStreamer *>(TS);
80 }
81 
82 //===----------------------------------------------------------------------===//
83 // WebAssemblyAsmPrinter Implementation.
84 //===----------------------------------------------------------------------===//
85 
87  for (auto &It : OutContext.getSymbols()) {
88  // Emit a .globaltype and .eventtype declaration.
89  auto Sym = cast<MCSymbolWasm>(It.getValue());
90  if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_GLOBAL)
92  else if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_EVENT)
94  }
95 
96  for (const auto &F : M) {
97  // Emit function type info for all undefined functions
98  if (F.isDeclarationForLinker() && !F.isIntrinsic()) {
100  SmallVector<MVT, 4> Params;
101  computeSignatureVTs(F.getFunctionType(), F, TM, Params, Results);
102  auto *Sym = cast<MCSymbolWasm>(getSymbol(&F));
103  Sym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
104  if (!Sym->getSignature()) {
105  auto Signature = signatureFromMVTs(Results, Params);
106  Sym->setSignature(Signature.get());
107  addSignature(std::move(Signature));
108  }
109  // FIXME: this was originally intended for post-linking and was only used
110  // for imports that were only called indirectly (i.e. s2wasm could not
111  // infer the type from a call). With object files it applies to all
112  // imports. so fix the names and the tests, or rethink how import
113  // delcarations work in asm files.
115 
116  if (TM.getTargetTriple().isOSBinFormatWasm() &&
117  F.hasFnAttribute("wasm-import-module")) {
118  StringRef Name =
119  F.getFnAttribute("wasm-import-module").getValueAsString();
120  Sym->setImportModule(Name);
121  getTargetStreamer()->emitImportModule(Sym, Name);
122  }
123  if (TM.getTargetTriple().isOSBinFormatWasm() &&
124  F.hasFnAttribute("wasm-import-name")) {
125  StringRef Name =
126  F.getFnAttribute("wasm-import-name").getValueAsString();
127  Sym->setImportName(Name);
128  getTargetStreamer()->emitImportName(Sym, Name);
129  }
130  }
131  }
132 
133  for (const auto &G : M.globals()) {
134  if (!G.hasInitializer() && G.hasExternalLinkage()) {
135  if (G.getValueType()->isSized()) {
136  uint16_t Size = M.getDataLayout().getTypeAllocSize(G.getValueType());
137  OutStreamer->emitELFSize(getSymbol(&G),
139  }
140  }
141  }
142 
143  if (const NamedMDNode *Named = M.getNamedMetadata("wasm.custom_sections")) {
144  for (const Metadata *MD : Named->operands()) {
145  const auto *Tuple = dyn_cast<MDTuple>(MD);
146  if (!Tuple || Tuple->getNumOperands() != 2)
147  continue;
148  const MDString *Name = dyn_cast<MDString>(Tuple->getOperand(0));
149  const MDString *Contents = dyn_cast<MDString>(Tuple->getOperand(1));
150  if (!Name || !Contents)
151  continue;
152 
153  OutStreamer->PushSection();
154  std::string SectionName = (".custom_section." + Name->getString()).str();
155  MCSectionWasm *MySection =
157  OutStreamer->SwitchSection(MySection);
158  OutStreamer->EmitBytes(Contents->getString());
159  OutStreamer->PopSection();
160  }
161  }
162 
163  EmitProducerInfo(M);
165 }
166 
169  if (const NamedMDNode *Debug = M.getNamedMetadata("llvm.dbg.cu")) {
170  llvm::SmallSet<StringRef, 4> SeenLanguages;
171  for (size_t I = 0, E = Debug->getNumOperands(); I < E; ++I) {
172  const auto *CU = cast<DICompileUnit>(Debug->getOperand(I));
173  StringRef Language = dwarf::LanguageString(CU->getSourceLanguage());
174  Language.consume_front("DW_LANG_");
175  if (SeenLanguages.insert(Language).second)
176  Languages.emplace_back(Language.str(), "");
177  }
178  }
179 
181  if (const NamedMDNode *Ident = M.getNamedMetadata("llvm.ident")) {
183  for (size_t I = 0, E = Ident->getNumOperands(); I < E; ++I) {
184  const auto *S = cast<MDString>(Ident->getOperand(I)->getOperand(0));
185  std::pair<StringRef, StringRef> Field = S->getString().split("version");
186  StringRef Name = Field.first.trim();
187  StringRef Version = Field.second.trim();
188  if (SeenTools.insert(Name).second)
189  Tools.emplace_back(Name.str(), Version.str());
190  }
191  }
192 
193  int FieldCount = int(!Languages.empty()) + int(!Tools.empty());
194  if (FieldCount != 0) {
196  ".custom_section.producers", SectionKind::getMetadata());
197  OutStreamer->PushSection();
198  OutStreamer->SwitchSection(Producers);
199  OutStreamer->EmitULEB128IntValue(FieldCount);
200  for (auto &Producers : {std::make_pair("language", &Languages),
201  std::make_pair("processed-by", &Tools)}) {
202  if (Producers.second->empty())
203  continue;
204  OutStreamer->EmitULEB128IntValue(strlen(Producers.first));
205  OutStreamer->EmitBytes(Producers.first);
206  OutStreamer->EmitULEB128IntValue(Producers.second->size());
207  for (auto &Producer : *Producers.second) {
208  OutStreamer->EmitULEB128IntValue(Producer.first.size());
209  OutStreamer->EmitBytes(Producer.first);
210  OutStreamer->EmitULEB128IntValue(Producer.second.size());
211  OutStreamer->EmitBytes(Producer.second);
212  }
213  }
214  OutStreamer->PopSection();
215  }
216 }
217 
219  static const std::pair<unsigned, const char *> FeaturePairs[] = {
220  {WebAssembly::FeatureAtomics, "atomics"},
221  {WebAssembly::FeatureBulkMemory, "bulk-memory"},
222  {WebAssembly::FeatureExceptionHandling, "exception-handling"},
223  {WebAssembly::FeatureNontrappingFPToInt, "nontrapping-fptoint"},
224  {WebAssembly::FeatureSignExt, "sign-ext"},
225  {WebAssembly::FeatureSIMD128, "simd128"},
226  };
227 
228  struct FeatureEntry {
229  uint8_t Prefix;
230  StringRef Name;
231  };
232 
233  FeatureBitset UsedFeatures =
234  static_cast<WebAssemblyTargetMachine &>(TM).getUsedFeatures();
235 
236  // Calculate the features and linkage policies to emit
237  SmallVector<FeatureEntry, 4> EmittedFeatures;
238  for (auto &F : FeaturePairs) {
239  FeatureEntry Entry;
240  Entry.Name = F.second;
241  if (F.first == WebAssembly::FeatureAtomics) {
242  // "atomics" is special: code compiled without atomics may have had its
243  // atomics lowered to nonatomic operations. Such code would be dangerous
244  // to mix with proper atomics, so it is always Required or Disallowed.
245  Entry.Prefix = UsedFeatures[F.first]
248  EmittedFeatures.push_back(Entry);
249  } else {
250  // Other features are marked Used or not mentioned
251  if (UsedFeatures[F.first]) {
252  Entry.Prefix = wasm::WASM_FEATURE_PREFIX_USED;
253  EmittedFeatures.push_back(Entry);
254  }
255  }
256  }
257 
258  // Emit features and linkage policies into the "target_features" section
259  MCSectionWasm *FeaturesSection = OutContext.getWasmSection(
260  ".custom_section.target_features", SectionKind::getMetadata());
261  OutStreamer->PushSection();
262  OutStreamer->SwitchSection(FeaturesSection);
263 
264  OutStreamer->EmitULEB128IntValue(EmittedFeatures.size());
265  for (auto &F : EmittedFeatures) {
266  OutStreamer->EmitIntValue(F.Prefix, 1);
267  OutStreamer->EmitULEB128IntValue(F.Name.size());
268  OutStreamer->EmitBytes(F.Name);
269  }
270 
271  OutStreamer->PopSection();
272 }
273 
275  assert(MF->getConstantPool()->getConstants().empty() &&
276  "WebAssembly disables constant pools");
277 }
278 
280  // Nothing to do; jump tables are incorporated into the instruction stream.
281 }
282 
284  const Function &F = MF->getFunction();
285  SmallVector<MVT, 1> ResultVTs;
286  SmallVector<MVT, 4> ParamVTs;
287  computeSignatureVTs(F.getFunctionType(), F, TM, ParamVTs, ResultVTs);
288  auto Signature = signatureFromMVTs(ResultVTs, ParamVTs);
289  auto *WasmSym = cast<MCSymbolWasm>(CurrentFnSym);
290  WasmSym->setSignature(Signature.get());
291  addSignature(std::move(Signature));
292  WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
293 
294  // FIXME: clean up how params and results are emitted (use signatures)
296 
297  // Emit the function index.
298  if (MDNode *Idx = F.getMetadata("wasm.index")) {
299  assert(Idx->getNumOperands() == 1);
300 
302  cast<ConstantAsMetadata>(Idx->getOperand(0))->getValue()));
303  }
304 
306  valTypesFromMVTs(MFI->getLocals(), Locals);
307  getTargetStreamer()->emitLocal(Locals);
308 
310 }
311 
313  LLVM_DEBUG(dbgs() << "EmitInstruction: " << *MI << '\n');
314 
315  switch (MI->getOpcode()) {
316  case WebAssembly::ARGUMENT_i32:
317  case WebAssembly::ARGUMENT_i32_S:
318  case WebAssembly::ARGUMENT_i64:
319  case WebAssembly::ARGUMENT_i64_S:
320  case WebAssembly::ARGUMENT_f32:
321  case WebAssembly::ARGUMENT_f32_S:
322  case WebAssembly::ARGUMENT_f64:
323  case WebAssembly::ARGUMENT_f64_S:
324  case WebAssembly::ARGUMENT_v16i8:
325  case WebAssembly::ARGUMENT_v16i8_S:
326  case WebAssembly::ARGUMENT_v8i16:
327  case WebAssembly::ARGUMENT_v8i16_S:
328  case WebAssembly::ARGUMENT_v4i32:
329  case WebAssembly::ARGUMENT_v4i32_S:
330  case WebAssembly::ARGUMENT_v2i64:
331  case WebAssembly::ARGUMENT_v2i64_S:
332  case WebAssembly::ARGUMENT_v4f32:
333  case WebAssembly::ARGUMENT_v4f32_S:
334  case WebAssembly::ARGUMENT_v2f64:
335  case WebAssembly::ARGUMENT_v2f64_S:
336  // These represent values which are live into the function entry, so there's
337  // no instruction to emit.
338  break;
339  case WebAssembly::FALLTHROUGH_RETURN_I32:
340  case WebAssembly::FALLTHROUGH_RETURN_I32_S:
341  case WebAssembly::FALLTHROUGH_RETURN_I64:
342  case WebAssembly::FALLTHROUGH_RETURN_I64_S:
343  case WebAssembly::FALLTHROUGH_RETURN_F32:
344  case WebAssembly::FALLTHROUGH_RETURN_F32_S:
345  case WebAssembly::FALLTHROUGH_RETURN_F64:
346  case WebAssembly::FALLTHROUGH_RETURN_F64_S:
347  case WebAssembly::FALLTHROUGH_RETURN_v16i8:
348  case WebAssembly::FALLTHROUGH_RETURN_v16i8_S:
349  case WebAssembly::FALLTHROUGH_RETURN_v8i16:
350  case WebAssembly::FALLTHROUGH_RETURN_v8i16_S:
351  case WebAssembly::FALLTHROUGH_RETURN_v4i32:
352  case WebAssembly::FALLTHROUGH_RETURN_v4i32_S:
353  case WebAssembly::FALLTHROUGH_RETURN_v2i64:
354  case WebAssembly::FALLTHROUGH_RETURN_v2i64_S:
355  case WebAssembly::FALLTHROUGH_RETURN_v4f32:
356  case WebAssembly::FALLTHROUGH_RETURN_v4f32_S:
357  case WebAssembly::FALLTHROUGH_RETURN_v2f64:
358  case WebAssembly::FALLTHROUGH_RETURN_v2f64_S: {
359  // These instructions represent the implicit return at the end of a
360  // function body. Always pops one value off the stack.
361  if (isVerbose()) {
362  OutStreamer->AddComment("fallthrough-return-value");
363  OutStreamer->AddBlankLine();
364  }
365  break;
366  }
367  case WebAssembly::FALLTHROUGH_RETURN_VOID:
368  case WebAssembly::FALLTHROUGH_RETURN_VOID_S:
369  // This instruction represents the implicit return at the end of a
370  // function body with no return value.
371  if (isVerbose()) {
372  OutStreamer->AddComment("fallthrough-return-void");
373  OutStreamer->AddBlankLine();
374  }
375  break;
376  case WebAssembly::EXTRACT_EXCEPTION_I32:
377  case WebAssembly::EXTRACT_EXCEPTION_I32_S:
378  // These are pseudo instructions that simulates popping values from stack.
379  // We print these only when we have -wasm-keep-registers on for assembly
380  // readability.
381  if (!WasmKeepRegisters)
382  break;
384  default: {
385  WebAssemblyMCInstLower MCInstLowering(OutContext, *this);
386  MCInst TmpInst;
387  MCInstLowering.lower(MI, TmpInst);
388  EmitToStreamer(*OutStreamer, TmpInst);
389  break;
390  }
391  }
392 }
393 
395  unsigned OpNo, unsigned AsmVariant,
396  const char *ExtraCode,
397  raw_ostream &OS) {
398  if (AsmVariant != 0)
399  report_fatal_error("There are no defined alternate asm variants");
400 
401  // First try the generic code, which knows about modifiers like 'c' and 'n'.
402  if (!AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS))
403  return false;
404 
405  if (!ExtraCode) {
406  const MachineOperand &MO = MI->getOperand(OpNo);
407  switch (MO.getType()) {
409  OS << MO.getImm();
410  return false;
412  // FIXME: only opcode that still contains registers, as required by
413  // MachineInstr::getDebugVariable().
415  OS << regToString(MO);
416  return false;
418  getSymbol(MO.getGlobal())->print(OS, MAI);
419  printOffset(MO.getOffset(), OS);
420  return false;
423  printOffset(MO.getOffset(), OS);
424  return false;
426  MO.getMBB()->getSymbol()->print(OS, MAI);
427  return false;
428  default:
429  break;
430  }
431  }
432 
433  return true;
434 }
435 
437  unsigned OpNo,
438  unsigned AsmVariant,
439  const char *ExtraCode,
440  raw_ostream &OS) {
441  if (AsmVariant != 0)
442  report_fatal_error("There are no defined alternate asm variants");
443 
444  // The current approach to inline asm is that "r" constraints are expressed
445  // as local indices, rather than values on the operand stack. This simplifies
446  // using "r" as it eliminates the need to push and pop the values in a
447  // particular order, however it also makes it impossible to have an "m"
448  // constraint. So we don't support it.
449 
450  return AsmPrinter::PrintAsmMemoryOperand(MI, OpNo, AsmVariant, ExtraCode, OS);
451 }
452 
453 // Force static initialization.
457 }
cl::opt< bool > WasmKeepRegisters
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:645
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:218
MachineBasicBlock * getMBB() const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
This class is used to lower an MachineInstr into an MCInst.
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:139
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:88
virtual void emitGlobalType(const MCSymbolWasm *Sym)=0
.globaltype
This class prints an WebAssembly MCInst to wasm file syntax.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
Target specific streamer interface.
Definition: MCStreamer.h:83
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:649
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K)
Definition: MCContext.h:453
This file declares the class to lower WebAssembly MachineInstrs to their corresponding MCInst records...
void EmitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
Function Alias Analysis Results
virtual void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule)=0
.import_module
MachineBasicBlock reference.
unsigned const TargetRegisterInfo * TRI
Metadata node.
Definition: Metadata.h:863
F(f)
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:96
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
void computeSignatureVTs(const FunctionType *Ty, const Function &F, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
Tuple of metadata.
Definition: Metadata.h:1105
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
A tuple of MDNodes.
Definition: Metadata.h:1325
MVT getRegType(unsigned RegNo) const
std::unique_ptr< wasm::WasmSignature > signatureFromMVTs(const SmallVectorImpl< MVT > &Results, const SmallVectorImpl< MVT > &Params)
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1443
Name of external global symbol.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:408
const char * getSymbolName() const
INLINEASM - Represents an inline asm block.
Definition: ISDOpcodes.h:668
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
This file declares the WebAssembly-specific subclass of TargetMachine.
std::string regToString(const MachineOperand &MO)
StringRef LanguageString(unsigned Language)
Definition: Dwarf.cpp:302
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
Definition: Module.cpp:250
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
const SymbolTable & getSymbols() const
getSymbols - Get a reference for the symbol table for clients that want to, for example, iterate over all symbols.
Definition: MCContext.h:360
bool isVerbose() const
Return true if assembly output should contain comments.
Definition: AsmPrinter.h:199
bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const
Return true if the given TargetRegisterClass has the ValueType T.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
WebAssembly-specific streamer interface, to implement support WebAssembly-specific assembly directive...
StringRef getString() const
Definition: Metadata.cpp:463
Address of a global value.
Container class for subtarget features.
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:112
Machine Value Type.
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:84
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void EmitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
This represents a section on wasm.
Definition: MCSectionWasm.h:27
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:134
const GlobalValue * getGlobal() const
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
This file provides WebAssembly-specific target descriptions.
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:81
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn&#39;t already there.
Definition: SmallSet.h:180
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
size_t size() const
Definition: SmallVector.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void addSignature(std::unique_ptr< wasm::WasmSignature > &&Sig)
This file declares WebAssembly-specific target streamer classes.
const std::vector< MachineConstantPoolEntry > & getConstants() const
This file contains the WebAssembly implementation of the WebAssemblyRegisterInfo class.
void LLVMInitializeWebAssemblyAsmPrinter()
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:430
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
MachineOperand class - Representation of each machine instruction operand.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:841
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:225
static SectionKind getMetadata()
Definition: SectionKind.h:178
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:223
int64_t getImm() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:163
virtual void EmitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
Definition: AsmPrinter.h:391
void EmitConstantPool() override
Print to the current output stream assembly representations of the constants in the constant pool MCP...
const WebAssemblyRegisterInfo * getRegisterInfo() const override
void EmitJumpTableInfo() override
Print assembly representations of the jump tables used by the current function to the current output ...
Representation of each machine instruction.
Definition: MachineInstr.h:63
virtual void emitFunctionType(const MCSymbolWasm *Sym)=0
.functype
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
virtual void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName)=0
.import_name
int64_t getOffset() const
Return the offset from the symbol in this operand.
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
#define I(x, y, z)
Definition: MD5.cpp:58
This file declares WebAssembly-specific per-machine-function information.
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:128
void EmitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:322
uint32_t Size
Definition: Profile.cpp:46
virtual void emitEventType(const MCSymbolWasm *Sym)=0
.eventtype
unsigned getWAReg(unsigned VReg) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
void valTypesFromMVTs(const ArrayRef< MVT > &In, SmallVectorImpl< wasm::ValType > &Out)
void lower(const MachineInstr *MI, MCInst &OutMI) const
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:250
virtual void emitLocal(ArrayRef< wasm::ValType > Types)=0
.local
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
A single uniqued string.
Definition: Metadata.h:603
Target & getTheWebAssemblyTarget32()
#define LLVM_DEBUG(X)
Definition: Debug.h:122
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:413
Target & getTheWebAssemblyTarget64()
WebAssemblyTargetStreamer * getTargetStreamer()
Root of the metadata hierarchy.
Definition: Metadata.h:57
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const uint64_t Version
Definition: InstrProf.h:904
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:163
virtual void emitIndIdx(const MCExpr *Value)=0
.indidx
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:59