LLVM  13.0.0git
WebAssemblyMCInstLower.cpp
Go to the documentation of this file.
1 // WebAssemblyMCInstLower.cpp - Convert WebAssembly MachineInstr to an MCInst //
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 code to lower WebAssembly MachineInstrs to their
11 /// corresponding MCInst records.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "WebAssemblyMCInstLower.h"
19 #include "WebAssemblyAsmPrinter.h"
24 #include "llvm/IR/Constants.h"
25 #include "llvm/MC/MCAsmInfo.h"
26 #include "llvm/MC/MCContext.h"
27 #include "llvm/MC/MCExpr.h"
28 #include "llvm/MC/MCInst.h"
29 #include "llvm/MC/MCSymbolWasm.h"
32 using namespace llvm;
33 
34 // This disables the removal of registers when lowering into MC, as required
35 // by some current tests.
37  WasmKeepRegisters("wasm-keep-registers", cl::Hidden,
38  cl::desc("WebAssembly: output stack registers in"
39  " instruction output for test purposes only."),
40  cl::init(false));
41 
44 
45 static void removeRegisterOperands(const MachineInstr *MI, MCInst &OutMI);
46 
47 MCSymbol *
48 WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
49  const GlobalValue *Global = MO.getGlobal();
50  if (!isa<Function>(Global)) {
51  auto *WasmSym = cast<MCSymbolWasm>(Printer.getSymbol(Global));
52  // If the symbol doesn't have an explicit WasmSymbolType yet and the
53  // GlobalValue is actually a WebAssembly global, then ensure the symbol is a
54  // WASM_SYMBOL_TYPE_GLOBAL.
55  if (WebAssembly::isWasmVarAddressSpace(Global->getAddressSpace()) &&
56  !WasmSym->getType()) {
57  const MachineFunction &MF = *MO.getParent()->getParent()->getParent();
58  const TargetMachine &TM = MF.getTarget();
59  const Function &CurrentFunc = MF.getFunction();
61  computeLegalValueVTs(CurrentFunc, TM, Global->getValueType(), VTs);
62  if (VTs.size() != 1)
63  report_fatal_error("Aggregate globals not yet implemented");
64 
65  bool Mutable = true;
67  WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
68  WasmSym->setGlobalType(wasm::WasmGlobalType{uint8_t(Type), Mutable});
69  }
70  return WasmSym;
71  }
72 
73  const auto *FuncTy = cast<FunctionType>(Global->getValueType());
74  const MachineFunction &MF = *MO.getParent()->getParent()->getParent();
75  const TargetMachine &TM = MF.getTarget();
76  const Function &CurrentFunc = MF.getFunction();
77 
78  SmallVector<MVT, 1> ResultMVTs;
79  SmallVector<MVT, 4> ParamMVTs;
80  const auto *const F = dyn_cast<Function>(Global);
81  computeSignatureVTs(FuncTy, F, CurrentFunc, TM, ParamMVTs, ResultMVTs);
82  auto Signature = signatureFromMVTs(ResultMVTs, ParamMVTs);
83 
84  bool InvokeDetected = false;
85  auto *WasmSym = Printer.getMCSymbolForFunction(
86  F, EnableEmException || EnableEmSjLj, Signature.get(), InvokeDetected);
87  WasmSym->setSignature(Signature.get());
88  Printer.addSignature(std::move(Signature));
89  WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
90  return WasmSym;
91 }
92 
93 MCSymbol *WebAssemblyMCInstLower::GetExternalSymbolSymbol(
94  const MachineOperand &MO) const {
95  const char *Name = MO.getSymbolName();
96  auto *WasmSym = cast<MCSymbolWasm>(Printer.GetExternalSymbolSymbol(Name));
97  const WebAssemblySubtarget &Subtarget = Printer.getSubtarget();
98 
99  // Except for certain known symbols, all symbols used by CodeGen are
100  // functions. It's OK to hardcode knowledge of specific symbols here; this
101  // method is precisely there for fetching the signatures of known
102  // Clang-provided symbols.
103  if (strcmp(Name, "__stack_pointer") == 0 || strcmp(Name, "__tls_base") == 0 ||
104  strcmp(Name, "__memory_base") == 0 || strcmp(Name, "__table_base") == 0 ||
105  strcmp(Name, "__tls_size") == 0 || strcmp(Name, "__tls_align") == 0) {
106  bool Mutable =
107  strcmp(Name, "__stack_pointer") == 0 || strcmp(Name, "__tls_base") == 0;
108  WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
109  WasmSym->setGlobalType(wasm::WasmGlobalType{
110  uint8_t(Subtarget.hasAddr64() ? wasm::WASM_TYPE_I64
112  Mutable});
113  return WasmSym;
114  }
115 
118  if (strcmp(Name, "__cpp_exception") == 0) {
119  WasmSym->setType(wasm::WASM_SYMBOL_TYPE_EVENT);
120  // We can't confirm its signature index for now because there can be
121  // imported exceptions. Set it to be 0 for now.
122  WasmSym->setEventType(
123  {wasm::WASM_EVENT_ATTRIBUTE_EXCEPTION, /* SigIndex */ 0});
124  // We may have multiple C++ compilation units to be linked together, each of
125  // which defines the exception symbol. To resolve them, we declare them as
126  // weak.
127  WasmSym->setWeak(true);
128  WasmSym->setExternal(true);
129 
130  // All C++ exceptions are assumed to have a single i32 (for wasm32) or i64
131  // (for wasm64) param type and void return type. The reaon is, all C++
132  // exception values are pointers, and to share the type section with
133  // functions, exceptions are assumed to have void return type.
134  Params.push_back(Subtarget.hasAddr64() ? wasm::ValType::I64
136  } else { // Function symbols
137  WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
138  getLibcallSignature(Subtarget, Name, Returns, Params);
139  }
140  auto Signature =
141  std::make_unique<wasm::WasmSignature>(std::move(Returns), std::move(Params));
142  WasmSym->setSignature(Signature.get());
143  Printer.addSignature(std::move(Signature));
144 
145  return WasmSym;
146 }
147 
148 MCOperand WebAssemblyMCInstLower::lowerSymbolOperand(const MachineOperand &MO,
149  MCSymbol *Sym) const {
151  unsigned TargetFlags = MO.getTargetFlags();
152 
153  switch (TargetFlags) {
155  break;
158  break;
161  break;
164  break;
167  break;
168  default:
169  llvm_unreachable("Unknown target flag on GV operand");
170  }
171 
172  const MCExpr *Expr = MCSymbolRefExpr::create(Sym, Kind, Ctx);
173 
174  if (MO.getOffset() != 0) {
175  const auto *WasmSym = cast<MCSymbolWasm>(Sym);
176  if (TargetFlags == WebAssemblyII::MO_GOT)
177  report_fatal_error("GOT symbol references do not support offsets");
178  if (WasmSym->isFunction())
179  report_fatal_error("Function addresses with offsets not supported");
180  if (WasmSym->isGlobal())
181  report_fatal_error("Global indexes with offsets not supported");
182  if (WasmSym->isEvent())
183  report_fatal_error("Event indexes with offsets not supported");
184  if (WasmSym->isTable())
185  report_fatal_error("Table indexes with offsets not supported");
186 
188  Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
189  }
190 
191  return MCOperand::createExpr(Expr);
192 }
193 
194 MCOperand WebAssemblyMCInstLower::lowerTypeIndexOperand(
196  SmallVector<wasm::ValType, 4> &&Params) const {
197  auto Signature = std::make_unique<wasm::WasmSignature>(std::move(Returns),
198  std::move(Params));
199  MCSymbol *Sym = Printer.createTempSymbol("typeindex");
200  auto *WasmSym = cast<MCSymbolWasm>(Sym);
201  WasmSym->setSignature(Signature.get());
202  Printer.addSignature(std::move(Signature));
203  WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
204  const MCExpr *Expr =
206  return MCOperand::createExpr(Expr);
207 }
208 
209 // Return the WebAssembly type associated with the given register class.
211  if (RC == &WebAssembly::I32RegClass)
212  return wasm::ValType::I32;
213  if (RC == &WebAssembly::I64RegClass)
214  return wasm::ValType::I64;
215  if (RC == &WebAssembly::F32RegClass)
216  return wasm::ValType::F32;
217  if (RC == &WebAssembly::F64RegClass)
218  return wasm::ValType::F64;
219  if (RC == &WebAssembly::V128RegClass)
220  return wasm::ValType::V128;
221  llvm_unreachable("Unexpected register class");
222 }
223 
224 static void getFunctionReturns(const MachineInstr *MI,
226  const Function &F = MI->getMF()->getFunction();
227  const TargetMachine &TM = MI->getMF()->getTarget();
228  Type *RetTy = F.getReturnType();
229  SmallVector<MVT, 4> CallerRetTys;
230  computeLegalValueVTs(F, TM, RetTy, CallerRetTys);
231  valTypesFromMVTs(CallerRetTys, Returns);
232 }
233 
235  MCInst &OutMI) const {
236  OutMI.setOpcode(MI->getOpcode());
237 
238  const MCInstrDesc &Desc = MI->getDesc();
239  unsigned NumVariadicDefs = MI->getNumExplicitDefs() - Desc.getNumDefs();
240  for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
241  const MachineOperand &MO = MI->getOperand(I);
242 
243  MCOperand MCOp;
244  switch (MO.getType()) {
245  default:
246  MI->print(errs());
247  llvm_unreachable("unknown operand type");
249  MI->print(errs());
250  llvm_unreachable("MachineBasicBlock operand should have been rewritten");
252  // Ignore all implicit register operands.
253  if (MO.isImplicit())
254  continue;
255  const WebAssemblyFunctionInfo &MFI =
256  *MI->getParent()->getParent()->getInfo<WebAssemblyFunctionInfo>();
257  unsigned WAReg = MFI.getWAReg(MO.getReg());
258  MCOp = MCOperand::createReg(WAReg);
259  break;
260  }
262  unsigned DescIndex = I - NumVariadicDefs;
263  if (DescIndex < Desc.NumOperands) {
264  const MCOperandInfo &Info = Desc.OpInfo[DescIndex];
265  if (Info.OperandType == WebAssembly::OPERAND_TYPEINDEX) {
268 
269  const MachineRegisterInfo &MRI =
270  MI->getParent()->getParent()->getRegInfo();
271  for (const MachineOperand &MO : MI->defs())
272  Returns.push_back(getType(MRI.getRegClass(MO.getReg())));
273  for (const MachineOperand &MO : MI->explicit_uses())
274  if (MO.isReg())
275  Params.push_back(getType(MRI.getRegClass(MO.getReg())));
276 
277  // call_indirect instructions have a callee operand at the end which
278  // doesn't count as a param.
279  if (WebAssembly::isCallIndirect(MI->getOpcode()))
280  Params.pop_back();
281 
282  // return_call_indirect instructions have the return type of the
283  // caller
284  if (MI->getOpcode() == WebAssembly::RET_CALL_INDIRECT)
285  getFunctionReturns(MI, Returns);
286 
287  MCOp = lowerTypeIndexOperand(std::move(Returns), std::move(Params));
288  break;
289  } else if (Info.OperandType == WebAssembly::OPERAND_SIGNATURE) {
290  auto BT = static_cast<WebAssembly::BlockType>(MO.getImm());
294  getFunctionReturns(MI, Returns);
295  MCOp = lowerTypeIndexOperand(std::move(Returns),
297  break;
298  }
299  } else if (Info.OperandType == WebAssembly::OPERAND_HEAPTYPE) {
300  assert(static_cast<WebAssembly::HeapType>(MO.getImm()) !=
302  // With typed function references, this will need a case for type
303  // index operands. Otherwise, fall through.
304  }
305  }
306  MCOp = MCOperand::createImm(MO.getImm());
307  break;
308  }
310  const ConstantFP *Imm = MO.getFPImm();
311  const uint64_t BitPattern =
313  if (Imm->getType()->isFloatTy())
314  MCOp = MCOperand::createSFPImm(static_cast<uint32_t>(BitPattern));
315  else if (Imm->getType()->isDoubleTy())
316  MCOp = MCOperand::createDFPImm(BitPattern);
317  else
318  llvm_unreachable("unknown floating point immediate type");
319  break;
320  }
322  MCOp = lowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
323  break;
325  // The target flag indicates whether this is a symbol for a
326  // variable or a function.
327  assert(MO.getTargetFlags() == 0 &&
328  "WebAssembly uses only symbol flags on ExternalSymbols");
329  MCOp = lowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
330  break;
332  // This is currently used only for LSDA symbols (GCC_except_table),
333  // because global addresses or other external symbols are handled above.
334  assert(MO.getTargetFlags() == 0 &&
335  "WebAssembly does not use target flags on MCSymbol");
336  MCOp = lowerSymbolOperand(MO, MO.getMCSymbol());
337  break;
338  }
339 
340  OutMI.addOperand(MCOp);
341  }
342 
343  if (!WasmKeepRegisters)
344  removeRegisterOperands(MI, OutMI);
345  else if (Desc.variadicOpsAreDefs())
346  OutMI.insert(OutMI.begin(), MCOperand::createImm(MI->getNumExplicitDefs()));
347 }
348 
349 static void removeRegisterOperands(const MachineInstr *MI, MCInst &OutMI) {
350  // Remove all uses of stackified registers to bring the instruction format
351  // into its final stack form used thruout MC, and transition opcodes to
352  // their _S variant.
353  // We do this separate from the above code that still may need these
354  // registers for e.g. call_indirect signatures.
355  // See comments in lib/Target/WebAssembly/WebAssemblyInstrFormats.td for
356  // details.
357  // TODO: the code above creates new registers which are then removed here.
358  // That code could be slightly simplified by not doing that, though maybe
359  // it is simpler conceptually to keep the code above in "register mode"
360  // until this transition point.
361  // FIXME: we are not processing inline assembly, which contains register
362  // operands, because it is used by later target generic code.
363  if (MI->isDebugInstr() || MI->isLabel() || MI->isInlineAsm())
364  return;
365 
366  // Transform to _S instruction.
367  auto RegOpcode = OutMI.getOpcode();
368  auto StackOpcode = WebAssembly::getStackOpcode(RegOpcode);
369  assert(StackOpcode != -1 && "Failed to stackify instruction");
370  OutMI.setOpcode(StackOpcode);
371 
372  // Remove register operands.
373  for (auto I = OutMI.getNumOperands(); I; --I) {
374  auto &MO = OutMI.getOperand(I - 1);
375  if (MO.isReg()) {
376  OutMI.erase(&MO);
377  }
378  }
379 }
llvm::MCInstrDesc::getNumDefs
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Definition: MCInstrDesc.h:243
AsmPrinter.h
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:102
llvm::MachineOperand::MO_Immediate
@ MO_Immediate
Immediate operand.
Definition: MachineOperand.h:53
llvm
Definition: AllocatorList.h:23
llvm::wasm::ValType::I32
@ I32
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::WebAssembly::OPERAND_HEAPTYPE
@ OPERAND_HEAPTYPE
heap type immediate for ref.null.
Definition: WebAssemblyMCTargetDesc.h:82
llvm::MCSymbolRefExpr::VK_GOT
@ VK_GOT
Definition: MCExpr.h:198
llvm::MCOperand::createExpr
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:162
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::MachineOperand::getGlobal
const GlobalValue * getGlobal() const
Definition: MachineOperand.h:563
llvm::AsmPrinter::createTempSymbol
MCSymbol * createTempSymbol(const Twine &Name) const
Definition: AsmPrinter.cpp:3085
llvm::WebAssembly::HeapType
HeapType
Used as immediate MachineOperands for heap types, e.g. for ref.null.
Definition: WebAssemblyTypeUtilities.h:45
llvm::MCOperand::createImm
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:141
llvm::Function
Definition: Function.h:61
llvm::MCInst::insert
iterator insert(iterator I, const MCOperand &Op)
Definition: MCInst.h:224
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
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:1167
WebAssemblyMCInstLower.h
ErrorHandling.h
llvm::WebAssemblyAsmPrinter::getSubtarget
const WebAssemblySubtarget & getSubtarget() const
Definition: WebAssemblyAsmPrinter.h:45
llvm::WebAssemblyII::MO_NO_FLAG
@ MO_NO_FLAG
Definition: WebAssemblyMCTargetDesc.h:90
llvm::wasm::WASM_SYMBOL_TYPE_GLOBAL
@ WASM_SYMBOL_TYPE_GLOBAL
Definition: Wasm.h:354
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
EnableEmException
cl::opt< bool > EnableEmException
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::WebAssemblySubtarget::hasAddr64
bool hasAddr64() const
Definition: WebAssemblySubtarget.h:90
llvm::ConstantFP::getValueAPF
const APFloat & getValueAPF() const
Definition: Constants.h:295
llvm::WebAssembly::BlockType::Invalid
@ Invalid
llvm::WebAssembly::OPERAND_SIGNATURE
@ OPERAND_SIGNATURE
signature immediate for block/loop.
Definition: WebAssemblyMCTargetDesc.h:72
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::MCSymbolWasm::setSignature
void setSignature(wasm::WasmSignature *Sig)
Definition: MCSymbolWasm.h:125
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
getType
static wasm::ValType getType(const TargetRegisterClass *RC)
Definition: WebAssemblyMCInstLower.cpp:210
llvm::MachineOperand::getOffset
int64_t getOffset() const
Return the offset from the symbol in this operand.
Definition: MachineOperand.h:600
llvm::MCInst::getNumOperands
unsigned getNumOperands() const
Definition: MCInst.h:208
removeRegisterOperands
static void removeRegisterOperands(const MachineInstr *MI, MCInst &OutMI)
Definition: WebAssemblyMCInstLower.cpp:349
llvm::MachineOperand::getMCSymbol
MCSymbol * getMCSymbol() const
Definition: MachineOperand.h:573
llvm::MachineOperand::MO_Register
@ MO_Register
Register operand.
Definition: MachineOperand.h:52
F
#define F(x, y, z)
Definition: MD5.cpp:56
EnableEmSjLj
cl::opt< bool > EnableEmSjLj
llvm::MCInst::setOpcode
void setOpcode(unsigned Op)
Definition: MCInst.h:197
llvm::MCSymbolRefExpr::VK_WASM_MBREL
@ VK_WASM_MBREL
Definition: MCExpr.h:329
llvm::MCOperandInfo
This holds information about one operand of a machine instruction, indicating the register class for ...
Definition: MCInstrDesc.h:83
llvm::WebAssemblyII::MO_TLS_BASE_REL
@ MO_TLS_BASE_REL
Definition: WebAssemblyMCTargetDesc.h:106
llvm::MachineOperand::isImplicit
bool isImplicit() const
Definition: MachineOperand.h:380
llvm::WebAssemblyMCInstLower::lower
void lower(const MachineInstr *MI, MCInst &OutMI) const
Definition: WebAssemblyMCInstLower.cpp:234
llvm::MCSymbolRefExpr::VK_WASM_TBREL
@ VK_WASM_TBREL
Definition: MCExpr.h:330
Constants.h
llvm::wasm::ValType::F64
@ F64
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
MCSymbolWasm.h
getFunctionReturns
static void getFunctionReturns(const MachineInstr *MI, SmallVectorImpl< wasm::ValType > &Returns)
Definition: WebAssemblyMCInstLower.cpp:224
llvm::WebAssemblyAsmPrinter::addSignature
void addSignature(std::unique_ptr< wasm::WasmSignature > &&Sig)
Definition: WebAssemblyAsmPrinter.h:46
MCContext.h
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
llvm::wasm::ValType::F32
@ F32
llvm::WebAssembly::toValType
wasm::ValType toValType(MVT Type)
Definition: WebAssemblyTypeUtilities.cpp:127
llvm::BitTracker
Definition: BitTracker.h:35
WebAssemblyRuntimeLibcallSignatures.h
MCInst.h
llvm::wasm::WasmGlobalType
Definition: Wasm.h:92
llvm::MCInstrDesc
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:195
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
WebAssemblyTypeUtilities.h
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::APInt::getZExtValue
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1631
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:255
llvm::wasm::WASM_SYMBOL_TYPE_FUNCTION
@ WASM_SYMBOL_TYPE_FUNCTION
Definition: Wasm.h:352
llvm::wasm::ValType
ValType
Definition: Wasm.h:392
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::APFloat::bitcastToAPInt
APInt bitcastToAPInt() const
Definition: APFloat.h:1132
llvm::MachineOperand::getParent
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
Definition: MachineOperand.h:238
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::MCInst::erase
void erase(iterator I)
Definition: MCInst.h:216
WebAssemblyUtilities.h
llvm::MCInst::addOperand
void addOperand(const MCOperand Op)
Definition: MCInst.h:210
llvm::Pass::print
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:125
llvm::MachineRegisterInfo::getRegClass
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
Definition: MachineRegisterInfo.h:634
llvm::wasm::WASM_EVENT_ATTRIBUTE_EXCEPTION
@ WASM_EVENT_ATTRIBUTE_EXCEPTION
Definition: Wasm.h:367
llvm::cl::opt< bool >
llvm::MCInstrDesc::NumOperands
unsigned short NumOperands
Definition: MCInstrDesc.h:198
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::MCSymbolRefExpr::VariantKind
VariantKind
Definition: MCExpr.h:194
llvm::MachineOperand::getTargetFlags
unsigned getTargetFlags() const
Definition: MachineOperand.h:221
llvm::MachineOperand::isReg
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Definition: MachineOperand.h:321
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::wasm::ValType::I64
@ I64
llvm::MCSymbolRefExpr::VK_WASM_TLSREL
@ VK_WASM_TLSREL
Definition: MCExpr.h:328
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::MCInst::begin
iterator begin()
Definition: MCInst.h:219
llvm::valTypesFromMVTs
void valTypesFromMVTs(const ArrayRef< MVT > &In, SmallVectorImpl< wasm::ValType > &Out)
Definition: WebAssemblyMachineFunctionInfo.cpp:93
WasmKeepRegisters
cl::opt< bool > WasmKeepRegisters("wasm-keep-registers", cl::Hidden, cl::desc("WebAssembly: output stack registers in" " instruction output for test purposes only."), cl::init(false))
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::getLibcallSignature
void getLibcallSignature(const WebAssemblySubtarget &Subtarget, RTLIB::Libcall LC, SmallVectorImpl< wasm::ValType > &Rets, SmallVectorImpl< wasm::ValType > &Params)
Definition: WebAssemblyRuntimeLibcallSignatures.cpp:516
WebAssemblyTargetInfo.h
llvm::MachineOperand::MO_MCSymbol
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
Definition: MachineOperand.h:67
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
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::WebAssembly::BlockType::Multivalue
@ Multivalue
llvm::MachineOperand::getFPImm
const ConstantFP * getFPImm() const
Definition: MachineOperand.h:547
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AsmPrinter::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:478
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
llvm::WebAssembly::isCallIndirect
bool isCallIndirect(unsigned Opc)
Definition: WebAssemblyMCTargetDesc.h:362
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition: MachineBasicBlock.h:225
llvm::MCInstrDesc::OpInfo
const MCOperandInfo * OpInfo
Definition: MCInstrDesc.h:206
llvm::MachineOperand::MO_FPImmediate
@ MO_FPImmediate
Floating-point immediate operand.
Definition: MachineOperand.h:55
llvm::WebAssemblyFunctionInfo
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
Definition: WebAssemblyMachineFunctionInfo.h:33
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:360
WebAssemblyMachineFunctionInfo.h
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::WebAssemblyII::MO_MEMORY_BASE_REL
@ MO_MEMORY_BASE_REL
Definition: WebAssemblyMCTargetDesc.h:101
llvm::MCBinaryExpr::createAdd
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:523
llvm::AsmPrinter::GetExternalSymbolSymbol
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
Definition: AsmPrinter.cpp:3145
llvm::computeLegalValueVTs
void computeLegalValueVTs(const Function &F, const TargetMachine &TM, Type *Ty, SmallVectorImpl< MVT > &ValueVTs)
Definition: WebAssemblyMachineFunctionInfo.cpp:33
WebAssemblyAsmPrinter.h
MCAsmInfo.h
llvm::WebAssemblyII::MO_GOT
@ MO_GOT
Definition: WebAssemblyMCTargetDesc.h:96
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
llvm::MCOperand::createReg
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:134
uint32_t
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
llvm::WebAssemblySubtarget
Definition: WebAssemblySubtarget.h:35
llvm::MCInstrDesc::variadicOpsAreDefs
bool variadicOpsAreDefs() const
Return true if variadic operands of this instruction are definitions.
Definition: MCInstrDesc.h:409
llvm::MachineInstr::getParent
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:286
llvm::MCOperand::createSFPImm
static MCOperand createSFPImm(uint32_t Val)
Definition: MCInst.h:148
llvm::WebAssembly::OPERAND_TYPEINDEX
@ OPERAND_TYPEINDEX
type signature immediate for call_indirect.
Definition: WebAssemblyMCTargetDesc.h:74
llvm::MCOperand::createDFPImm
static MCOperand createDFPImm(uint64_t Val)
Definition: MCInst.h:155
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::wasm::WASM_TYPE_I64
@ WASM_TYPE_I64
Definition: Wasm.h:247
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:542
llvm::Type::isFloatTy
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:148
llvm::MachineFunction::getTarget
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition: MachineFunction.h:572
llvm::wasm::WASM_TYPE_I32
@ WASM_TYPE_I32
Definition: Wasm.h:246
llvm::MachineOperand::MO_ExternalSymbol
@ MO_ExternalSymbol
Name of external global symbol.
Definition: MachineOperand.h:61
llvm::MCSymbolRefExpr::VK_WASM_TYPEINDEX
@ VK_WASM_TYPEINDEX
Definition: MCExpr.h:327
llvm::Type::isDoubleTy
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:151
llvm::MCInst::getOpcode
unsigned getOpcode() const
Definition: MCInst.h:198
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:384
llvm::WebAssemblyAsmPrinter::getMCSymbolForFunction
MCSymbolWasm * getMCSymbolForFunction(const Function *F, bool EnableEmEH, wasm::WasmSignature *Sig, bool &InvokeDetected)
Definition: WebAssemblyAsmPrinter.cpp:151
llvm::wasm::ValType::V128
@ V128
llvm::MachineOperand::getSymbolName
const char * getSymbolName() const
Definition: MachineOperand.h:608
llvm::WebAssembly::HeapType::Invalid
@ Invalid
llvm::WebAssembly::isWasmVarAddressSpace
bool isWasmVarAddressSpace(unsigned AS)
Definition: WebAssemblyUtilities.h:44
llvm::MCInst::getOperand
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
llvm::WebAssembly::BlockType
BlockType
Used as immediate MachineOperands for block signatures.
Definition: WebAssemblyTypeUtilities.h:26
llvm::pdb::PDB_DataKind::Global
@ Global
llvm::WebAssemblyII::MO_TABLE_BASE_REL
@ MO_TABLE_BASE_REL
Definition: WebAssemblyMCTargetDesc.h:111
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
llvm::cl::desc
Definition: CommandLine.h:414
raw_ostream.h
MachineFunction.h
MCExpr.h
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::WebAssembly::getStackOpcode
int getStackOpcode(unsigned short Opcode)