LLVM  10.0.0
WebAssemblyISelLowering.cpp
Go to the documentation of this file.
1 //=- WebAssemblyISelLowering.cpp - WebAssembly DAG Lowering Implementation -==//
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 implements the WebAssemblyTargetLowering class.
11 ///
12 //===----------------------------------------------------------------------===//
13 
17 #include "WebAssemblySubtarget.h"
19 #include "llvm/CodeGen/Analysis.h"
27 #include "llvm/IR/DiagnosticInfo.h"
29 #include "llvm/IR/Function.h"
30 #include "llvm/IR/Intrinsics.h"
31 #include "llvm/IR/IntrinsicsWebAssembly.h"
32 #include "llvm/Support/Debug.h"
36 using namespace llvm;
37 
38 #define DEBUG_TYPE "wasm-lower"
39 
41  const TargetMachine &TM, const WebAssemblySubtarget &STI)
42  : TargetLowering(TM), Subtarget(&STI) {
43  auto MVTPtr = Subtarget->hasAddr64() ? MVT::i64 : MVT::i32;
44 
45  // Booleans always contain 0 or 1.
47  // Except in SIMD vectors
49  // We don't know the microarchitecture here, so just reduce register pressure.
51  // Tell ISel that we have a stack pointer.
53  Subtarget->hasAddr64() ? WebAssembly::SP64 : WebAssembly::SP32);
54  // Set up the register classes.
55  addRegisterClass(MVT::i32, &WebAssembly::I32RegClass);
56  addRegisterClass(MVT::i64, &WebAssembly::I64RegClass);
57  addRegisterClass(MVT::f32, &WebAssembly::F32RegClass);
58  addRegisterClass(MVT::f64, &WebAssembly::F64RegClass);
59  if (Subtarget->hasSIMD128()) {
60  addRegisterClass(MVT::v16i8, &WebAssembly::V128RegClass);
61  addRegisterClass(MVT::v8i16, &WebAssembly::V128RegClass);
62  addRegisterClass(MVT::v4i32, &WebAssembly::V128RegClass);
63  addRegisterClass(MVT::v4f32, &WebAssembly::V128RegClass);
64  }
65  if (Subtarget->hasUnimplementedSIMD128()) {
66  addRegisterClass(MVT::v2i64, &WebAssembly::V128RegClass);
67  addRegisterClass(MVT::v2f64, &WebAssembly::V128RegClass);
68  }
69  // Compute derived properties from the register classes.
71 
77 
78  // Take the default expansion for va_arg, va_copy, and va_end. There is no
79  // default action for va_start, so we do that custom.
84 
85  for (auto T : {MVT::f32, MVT::f64, MVT::v4f32, MVT::v2f64}) {
86  // Don't expand the floating-point types to constant pools.
88  // Expand floating-point comparisons.
89  for (auto CC : {ISD::SETO, ISD::SETUO, ISD::SETUEQ, ISD::SETONE,
92  // Expand floating-point library function operators.
93  for (auto Op :
96  // Note supported floating-point library function operators that otherwise
97  // default to expand.
98  for (auto Op :
101  // Support minimum and maximum, which otherwise default to expand.
104  // WebAssembly currently has no builtin f16 support.
109  }
110 
111  // Expand unavailable integer operations.
112  for (auto Op :
116  for (auto T : {MVT::i32, MVT::i64})
118  if (Subtarget->hasSIMD128())
119  for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32})
121  if (Subtarget->hasUnimplementedSIMD128())
123  }
124 
125  // SIMD-specific configuration
126  if (Subtarget->hasSIMD128()) {
127  // Support saturating add for i8x16 and i16x8
128  for (auto Op : {ISD::SADDSAT, ISD::UADDSAT})
129  for (auto T : {MVT::v16i8, MVT::v8i16})
131 
132  // Custom lower BUILD_VECTORs to minimize number of replace_lanes
133  for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v4f32})
135  if (Subtarget->hasUnimplementedSIMD128())
136  for (auto T : {MVT::v2i64, MVT::v2f64})
138 
139  // We have custom shuffle lowering to expose the shuffle mask
140  for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v4f32})
142  if (Subtarget->hasUnimplementedSIMD128())
143  for (auto T: {MVT::v2i64, MVT::v2f64})
145 
146  // Custom lowering since wasm shifts must have a scalar shift amount
147  for (auto Op : {ISD::SHL, ISD::SRA, ISD::SRL}) {
148  for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32})
150  if (Subtarget->hasUnimplementedSIMD128())
152  }
153 
154  // Custom lower lane accesses to expand out variable indices
156  for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v4f32})
158  if (Subtarget->hasUnimplementedSIMD128())
159  for (auto T : {MVT::v2i64, MVT::v2f64})
161  }
162 
163  // There is no i64x2.mul instruction
165 
166  // There are no vector select instructions
167  for (auto Op : {ISD::VSELECT, ISD::SELECT_CC, ISD::SELECT}) {
168  for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v4f32})
170  if (Subtarget->hasUnimplementedSIMD128())
171  for (auto T : {MVT::v2i64, MVT::v2f64})
173  }
174 
175  // Expand integer operations supported for scalars but not SIMD
178  for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32})
180  if (Subtarget->hasUnimplementedSIMD128())
182  }
183 
184  // But we do have integer min and max operations
185  if (Subtarget->hasUnimplementedSIMD128()) {
186  for (auto Op : {ISD::SMIN, ISD::SMAX, ISD::UMIN, ISD::UMAX})
187  for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32})
189  }
190 
191  // Expand float operations supported for scalars but not SIMD
196  if (Subtarget->hasUnimplementedSIMD128())
198  }
199 
200  // Expand operations not supported for i64x2 vectors
201  if (Subtarget->hasUnimplementedSIMD128())
202  for (unsigned CC = 0; CC < ISD::SETCC_INVALID; ++CC)
203  setCondCodeAction(static_cast<ISD::CondCode>(CC), MVT::v2i64, Custom);
204 
205  // Expand additional SIMD ops that V8 hasn't implemented yet
206  if (!Subtarget->hasUnimplementedSIMD128()) {
209  }
210  }
211 
212  // As a special case, these operators use the type to mean the type to
213  // sign-extend from.
215  if (!Subtarget->hasSignExt()) {
216  // Sign extends are legal only when extending a vector extract
217  auto Action = Subtarget->hasSIMD128() ? Custom : Expand;
218  for (auto T : {MVT::i8, MVT::i16, MVT::i32})
220  }
223 
224  // Dynamic stack allocation: use the default expansion.
228 
231 
232  // Expand these forms; we pattern-match the forms that we can handle in isel.
233  for (auto T : {MVT::i32, MVT::i64, MVT::f32, MVT::f64})
234  for (auto Op : {ISD::BR_CC, ISD::SELECT_CC})
236 
237  // We have custom switch handling.
239 
240  // WebAssembly doesn't have:
241  // - Floating-point extending loads.
242  // - Floating-point truncating stores.
243  // - i1 extending loads.
244  // - truncating SIMD stores and most extending loads
247  for (auto T : MVT::integer_valuetypes())
250  if (Subtarget->hasSIMD128()) {
252  MVT::v2f64}) {
253  for (auto MemT : MVT::fixedlen_vector_valuetypes()) {
254  if (MVT(T) != MemT) {
255  setTruncStoreAction(T, MemT, Expand);
257  setLoadExtAction(Ext, T, MemT, Expand);
258  }
259  }
260  }
261  // But some vector extending loads are legal
262  if (Subtarget->hasUnimplementedSIMD128()) {
263  for (auto Ext : {ISD::EXTLOAD, ISD::SEXTLOAD, ISD::ZEXTLOAD}) {
267  }
268  }
269  }
270 
271  // Don't do anything clever with build_pairs
273 
274  // Trap lowers to wasm unreachable
276 
277  // Exception handling intrinsics
280 
282 
283  // Override the __gnu_f2h_ieee/__gnu_h2f_ieee names so that the f32 name is
284  // consistent with the f64 and f128 names.
285  setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
286  setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
287 
288  // Define the emscripten name for return address helper.
289  // TODO: when implementing other WASM backends, make this generic or only do
290  // this on emscripten depending on what they end up doing.
291  setLibcallName(RTLIB::RETURN_ADDRESS, "emscripten_return_address");
292 
293  // Always convert switches to br_tables unless there is only one case, which
294  // is equivalent to a simple branch. This reduces code size for wasm, and we
295  // defer possible jump table optimizations to the VM.
297 }
298 
300 WebAssemblyTargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const {
301  // We have wasm instructions for these
302  switch (AI->getOperation()) {
303  case AtomicRMWInst::Add:
304  case AtomicRMWInst::Sub:
305  case AtomicRMWInst::And:
306  case AtomicRMWInst::Or:
307  case AtomicRMWInst::Xor:
308  case AtomicRMWInst::Xchg:
310  default:
311  break;
312  }
314 }
315 
316 FastISel *WebAssemblyTargetLowering::createFastISel(
317  FunctionLoweringInfo &FuncInfo, const TargetLibraryInfo *LibInfo) const {
318  return WebAssembly::createFastISel(FuncInfo, LibInfo);
319 }
320 
321 MVT WebAssemblyTargetLowering::getScalarShiftAmountTy(const DataLayout & /*DL*/,
322  EVT VT) const {
323  unsigned BitWidth = NextPowerOf2(VT.getSizeInBits() - 1);
324  if (BitWidth > 1 && BitWidth < 8)
325  BitWidth = 8;
326 
327  if (BitWidth > 64) {
328  // The shift will be lowered to a libcall, and compiler-rt libcalls expect
329  // the count to be an i32.
330  BitWidth = 32;
331  assert(BitWidth >= Log2_32_Ceil(VT.getSizeInBits()) &&
332  "32-bit shift counts ought to be enough for anyone");
333  }
334 
335  MVT Result = MVT::getIntegerVT(BitWidth);
337  "Unable to represent scalar shift amount type");
338  return Result;
339 }
340 
341 // Lower an fp-to-int conversion operator from the LLVM opcode, which has an
342 // undefined result on invalid/overflow, to the WebAssembly opcode, which
343 // traps on invalid/overflow.
345  MachineBasicBlock *BB,
346  const TargetInstrInfo &TII,
347  bool IsUnsigned, bool Int64,
348  bool Float64, unsigned LoweredOpcode) {
350 
351  Register OutReg = MI.getOperand(0).getReg();
352  Register InReg = MI.getOperand(1).getReg();
353 
354  unsigned Abs = Float64 ? WebAssembly::ABS_F64 : WebAssembly::ABS_F32;
355  unsigned FConst = Float64 ? WebAssembly::CONST_F64 : WebAssembly::CONST_F32;
356  unsigned LT = Float64 ? WebAssembly::LT_F64 : WebAssembly::LT_F32;
357  unsigned GE = Float64 ? WebAssembly::GE_F64 : WebAssembly::GE_F32;
358  unsigned IConst = Int64 ? WebAssembly::CONST_I64 : WebAssembly::CONST_I32;
359  unsigned Eqz = WebAssembly::EQZ_I32;
360  unsigned And = WebAssembly::AND_I32;
361  int64_t Limit = Int64 ? INT64_MIN : INT32_MIN;
362  int64_t Substitute = IsUnsigned ? 0 : Limit;
363  double CmpVal = IsUnsigned ? -(double)Limit * 2.0 : -(double)Limit;
364  auto &Context = BB->getParent()->getFunction().getContext();
366 
367  const BasicBlock *LLVMBB = BB->getBasicBlock();
368  MachineFunction *F = BB->getParent();
369  MachineBasicBlock *TrueMBB = F->CreateMachineBasicBlock(LLVMBB);
370  MachineBasicBlock *FalseMBB = F->CreateMachineBasicBlock(LLVMBB);
371  MachineBasicBlock *DoneMBB = F->CreateMachineBasicBlock(LLVMBB);
372 
374  F->insert(It, FalseMBB);
375  F->insert(It, TrueMBB);
376  F->insert(It, DoneMBB);
377 
378  // Transfer the remainder of BB and its successor edges to DoneMBB.
379  DoneMBB->splice(DoneMBB->begin(), BB, std::next(MI.getIterator()), BB->end());
380  DoneMBB->transferSuccessorsAndUpdatePHIs(BB);
381 
382  BB->addSuccessor(TrueMBB);
383  BB->addSuccessor(FalseMBB);
384  TrueMBB->addSuccessor(DoneMBB);
385  FalseMBB->addSuccessor(DoneMBB);
386 
387  unsigned Tmp0, Tmp1, CmpReg, EqzReg, FalseReg, TrueReg;
388  Tmp0 = MRI.createVirtualRegister(MRI.getRegClass(InReg));
389  Tmp1 = MRI.createVirtualRegister(MRI.getRegClass(InReg));
390  CmpReg = MRI.createVirtualRegister(&WebAssembly::I32RegClass);
391  EqzReg = MRI.createVirtualRegister(&WebAssembly::I32RegClass);
392  FalseReg = MRI.createVirtualRegister(MRI.getRegClass(OutReg));
393  TrueReg = MRI.createVirtualRegister(MRI.getRegClass(OutReg));
394 
395  MI.eraseFromParent();
396  // For signed numbers, we can do a single comparison to determine whether
397  // fabs(x) is within range.
398  if (IsUnsigned) {
399  Tmp0 = InReg;
400  } else {
401  BuildMI(BB, DL, TII.get(Abs), Tmp0).addReg(InReg);
402  }
403  BuildMI(BB, DL, TII.get(FConst), Tmp1)
404  .addFPImm(cast<ConstantFP>(ConstantFP::get(Ty, CmpVal)));
405  BuildMI(BB, DL, TII.get(LT), CmpReg).addReg(Tmp0).addReg(Tmp1);
406 
407  // For unsigned numbers, we have to do a separate comparison with zero.
408  if (IsUnsigned) {
409  Tmp1 = MRI.createVirtualRegister(MRI.getRegClass(InReg));
410  Register SecondCmpReg =
411  MRI.createVirtualRegister(&WebAssembly::I32RegClass);
412  Register AndReg = MRI.createVirtualRegister(&WebAssembly::I32RegClass);
413  BuildMI(BB, DL, TII.get(FConst), Tmp1)
414  .addFPImm(cast<ConstantFP>(ConstantFP::get(Ty, 0.0)));
415  BuildMI(BB, DL, TII.get(GE), SecondCmpReg).addReg(Tmp0).addReg(Tmp1);
416  BuildMI(BB, DL, TII.get(And), AndReg).addReg(CmpReg).addReg(SecondCmpReg);
417  CmpReg = AndReg;
418  }
419 
420  BuildMI(BB, DL, TII.get(Eqz), EqzReg).addReg(CmpReg);
421 
422  // Create the CFG diamond to select between doing the conversion or using
423  // the substitute value.
424  BuildMI(BB, DL, TII.get(WebAssembly::BR_IF)).addMBB(TrueMBB).addReg(EqzReg);
425  BuildMI(FalseMBB, DL, TII.get(LoweredOpcode), FalseReg).addReg(InReg);
426  BuildMI(FalseMBB, DL, TII.get(WebAssembly::BR)).addMBB(DoneMBB);
427  BuildMI(TrueMBB, DL, TII.get(IConst), TrueReg).addImm(Substitute);
428  BuildMI(*DoneMBB, DoneMBB->begin(), DL, TII.get(TargetOpcode::PHI), OutReg)
429  .addReg(FalseReg)
430  .addMBB(FalseMBB)
431  .addReg(TrueReg)
432  .addMBB(TrueMBB);
433 
434  return DoneMBB;
435 }
436 
437 MachineBasicBlock *WebAssemblyTargetLowering::EmitInstrWithCustomInserter(
438  MachineInstr &MI, MachineBasicBlock *BB) const {
439  const TargetInstrInfo &TII = *Subtarget->getInstrInfo();
440  DebugLoc DL = MI.getDebugLoc();
441 
442  switch (MI.getOpcode()) {
443  default:
444  llvm_unreachable("Unexpected instr type to insert");
445  case WebAssembly::FP_TO_SINT_I32_F32:
446  return LowerFPToInt(MI, DL, BB, TII, false, false, false,
447  WebAssembly::I32_TRUNC_S_F32);
448  case WebAssembly::FP_TO_UINT_I32_F32:
449  return LowerFPToInt(MI, DL, BB, TII, true, false, false,
450  WebAssembly::I32_TRUNC_U_F32);
451  case WebAssembly::FP_TO_SINT_I64_F32:
452  return LowerFPToInt(MI, DL, BB, TII, false, true, false,
453  WebAssembly::I64_TRUNC_S_F32);
454  case WebAssembly::FP_TO_UINT_I64_F32:
455  return LowerFPToInt(MI, DL, BB, TII, true, true, false,
456  WebAssembly::I64_TRUNC_U_F32);
457  case WebAssembly::FP_TO_SINT_I32_F64:
458  return LowerFPToInt(MI, DL, BB, TII, false, false, true,
459  WebAssembly::I32_TRUNC_S_F64);
460  case WebAssembly::FP_TO_UINT_I32_F64:
461  return LowerFPToInt(MI, DL, BB, TII, true, false, true,
462  WebAssembly::I32_TRUNC_U_F64);
463  case WebAssembly::FP_TO_SINT_I64_F64:
464  return LowerFPToInt(MI, DL, BB, TII, false, true, true,
465  WebAssembly::I64_TRUNC_S_F64);
466  case WebAssembly::FP_TO_UINT_I64_F64:
467  return LowerFPToInt(MI, DL, BB, TII, true, true, true,
468  WebAssembly::I64_TRUNC_U_F64);
469  llvm_unreachable("Unexpected instruction to emit with custom inserter");
470  }
471 }
472 
473 const char *
474 WebAssemblyTargetLowering::getTargetNodeName(unsigned Opcode) const {
475  switch (static_cast<WebAssemblyISD::NodeType>(Opcode)) {
478  break;
479 #define HANDLE_NODETYPE(NODE) \
480  case WebAssemblyISD::NODE: \
481  return "WebAssemblyISD::" #NODE;
482 #define HANDLE_MEM_NODETYPE(NODE) HANDLE_NODETYPE(NODE)
483 #include "WebAssemblyISD.def"
484 #undef HANDLE_MEM_NODETYPE
485 #undef HANDLE_NODETYPE
486  }
487  return nullptr;
488 }
489 
490 std::pair<unsigned, const TargetRegisterClass *>
491 WebAssemblyTargetLowering::getRegForInlineAsmConstraint(
492  const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const {
493  // First, see if this is a constraint that directly corresponds to a
494  // WebAssembly register class.
495  if (Constraint.size() == 1) {
496  switch (Constraint[0]) {
497  case 'r':
498  assert(VT != MVT::iPTR && "Pointer MVT not expected here");
499  if (Subtarget->hasSIMD128() && VT.isVector()) {
500  if (VT.getSizeInBits() == 128)
501  return std::make_pair(0U, &WebAssembly::V128RegClass);
502  }
503  if (VT.isInteger() && !VT.isVector()) {
504  if (VT.getSizeInBits() <= 32)
505  return std::make_pair(0U, &WebAssembly::I32RegClass);
506  if (VT.getSizeInBits() <= 64)
507  return std::make_pair(0U, &WebAssembly::I64RegClass);
508  }
509  break;
510  default:
511  break;
512  }
513  }
514 
515  return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
516 }
517 
518 bool WebAssemblyTargetLowering::isCheapToSpeculateCttz() const {
519  // Assume ctz is a relatively cheap operation.
520  return true;
521 }
522 
523 bool WebAssemblyTargetLowering::isCheapToSpeculateCtlz() const {
524  // Assume clz is a relatively cheap operation.
525  return true;
526 }
527 
528 bool WebAssemblyTargetLowering::isLegalAddressingMode(const DataLayout &DL,
529  const AddrMode &AM,
530  Type *Ty, unsigned AS,
531  Instruction *I) const {
532  // WebAssembly offsets are added as unsigned without wrapping. The
533  // isLegalAddressingMode gives us no way to determine if wrapping could be
534  // happening, so we approximate this by accepting only non-negative offsets.
535  if (AM.BaseOffs < 0)
536  return false;
537 
538  // WebAssembly has no scale register operands.
539  if (AM.Scale != 0)
540  return false;
541 
542  // Everything else is legal.
543  return true;
544 }
545 
546 bool WebAssemblyTargetLowering::allowsMisalignedMemoryAccesses(
547  EVT /*VT*/, unsigned /*AddrSpace*/, unsigned /*Align*/,
548  MachineMemOperand::Flags /*Flags*/, bool *Fast) const {
549  // WebAssembly supports unaligned accesses, though it should be declared
550  // with the p2align attribute on loads and stores which do so, and there
551  // may be a performance impact. We tell LLVM they're "fast" because
552  // for the kinds of things that LLVM uses this for (merging adjacent stores
553  // of constants, etc.), WebAssembly implementations will either want the
554  // unaligned access or they'll split anyway.
555  if (Fast)
556  *Fast = true;
557  return true;
558 }
559 
560 bool WebAssemblyTargetLowering::isIntDivCheap(EVT VT,
561  AttributeList Attr) const {
562  // The current thinking is that wasm engines will perform this optimization,
563  // so we can save on code size.
564  return true;
565 }
566 
567 bool WebAssemblyTargetLowering::isVectorLoadExtDesirable(SDValue ExtVal) const {
568  if (!Subtarget->hasUnimplementedSIMD128())
569  return false;
570  MVT ExtT = ExtVal.getSimpleValueType();
571  MVT MemT = cast<LoadSDNode>(ExtVal->getOperand(0))->getSimpleValueType(0);
572  return (ExtT == MVT::v8i16 && MemT == MVT::v8i8) ||
573  (ExtT == MVT::v4i32 && MemT == MVT::v4i16) ||
574  (ExtT == MVT::v2i64 && MemT == MVT::v2i32);
575 }
576 
577 EVT WebAssemblyTargetLowering::getSetCCResultType(const DataLayout &DL,
578  LLVMContext &C,
579  EVT VT) const {
580  if (VT.isVector())
582 
583  return TargetLowering::getSetCCResultType(DL, C, VT);
584 }
585 
586 bool WebAssemblyTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info,
587  const CallInst &I,
588  MachineFunction &MF,
589  unsigned Intrinsic) const {
590  switch (Intrinsic) {
591  case Intrinsic::wasm_atomic_notify:
593  Info.memVT = MVT::i32;
594  Info.ptrVal = I.getArgOperand(0);
595  Info.offset = 0;
596  Info.align = Align(4);
597  // atomic.notify instruction does not really load the memory specified with
598  // this argument, but MachineMemOperand should either be load or store, so
599  // we set this to a load.
600  // FIXME Volatile isn't really correct, but currently all LLVM atomic
601  // instructions are treated as volatiles in the backend, so we should be
602  // consistent. The same applies for wasm_atomic_wait intrinsics too.
604  return true;
605  case Intrinsic::wasm_atomic_wait_i32:
607  Info.memVT = MVT::i32;
608  Info.ptrVal = I.getArgOperand(0);
609  Info.offset = 0;
610  Info.align = Align(4);
612  return true;
613  case Intrinsic::wasm_atomic_wait_i64:
615  Info.memVT = MVT::i64;
616  Info.ptrVal = I.getArgOperand(0);
617  Info.offset = 0;
618  Info.align = Align(8);
620  return true;
621  default:
622  return false;
623  }
624 }
625 
626 //===----------------------------------------------------------------------===//
627 // WebAssembly Lowering private implementation.
628 //===----------------------------------------------------------------------===//
629 
630 //===----------------------------------------------------------------------===//
631 // Lowering Code
632 //===----------------------------------------------------------------------===//
633 
634 static void fail(const SDLoc &DL, SelectionDAG &DAG, const char *Msg) {
636  DAG.getContext()->diagnose(
638 }
639 
640 // Test whether the given calling convention is supported.
641 static bool callingConvSupported(CallingConv::ID CallConv) {
642  // We currently support the language-independent target-independent
643  // conventions. We don't yet have a way to annotate calls with properties like
644  // "cold", and we don't have any call-clobbered registers, so these are mostly
645  // all handled the same.
646  return CallConv == CallingConv::C || CallConv == CallingConv::Fast ||
647  CallConv == CallingConv::Cold ||
648  CallConv == CallingConv::PreserveMost ||
649  CallConv == CallingConv::PreserveAll ||
650  CallConv == CallingConv::CXX_FAST_TLS ||
652 }
653 
654 SDValue
655 WebAssemblyTargetLowering::LowerCall(CallLoweringInfo &CLI,
656  SmallVectorImpl<SDValue> &InVals) const {
657  SelectionDAG &DAG = CLI.DAG;
658  SDLoc DL = CLI.DL;
659  SDValue Chain = CLI.Chain;
660  SDValue Callee = CLI.Callee;
662  auto Layout = MF.getDataLayout();
663 
664  CallingConv::ID CallConv = CLI.CallConv;
665  if (!callingConvSupported(CallConv))
666  fail(DL, DAG,
667  "WebAssembly doesn't support language-specific or target-specific "
668  "calling conventions yet");
669  if (CLI.IsPatchPoint)
670  fail(DL, DAG, "WebAssembly doesn't support patch point yet");
671 
672  if (CLI.IsTailCall) {
673  bool MustTail = CLI.CS && CLI.CS.isMustTailCall();
674  if (Subtarget->hasTailCall() && !CLI.IsVarArg) {
675  // Do not tail call unless caller and callee return types match
676  const Function &F = MF.getFunction();
677  const TargetMachine &TM = getTargetMachine();
678  Type *RetTy = F.getReturnType();
679  SmallVector<MVT, 4> CallerRetTys;
680  SmallVector<MVT, 4> CalleeRetTys;
681  computeLegalValueVTs(F, TM, RetTy, CallerRetTys);
682  computeLegalValueVTs(F, TM, CLI.RetTy, CalleeRetTys);
683  bool TypesMatch = CallerRetTys.size() == CalleeRetTys.size() &&
684  std::equal(CallerRetTys.begin(), CallerRetTys.end(),
685  CalleeRetTys.begin());
686  if (!TypesMatch) {
687  // musttail in this case would be an LLVM IR validation failure
688  assert(!MustTail);
689  CLI.IsTailCall = false;
690  }
691  } else {
692  CLI.IsTailCall = false;
693  if (MustTail) {
694  if (CLI.IsVarArg) {
695  // The return would pop the argument buffer
696  fail(DL, DAG, "WebAssembly does not support varargs tail calls");
697  } else {
698  fail(DL, DAG, "WebAssembly 'tail-call' feature not enabled");
699  }
700  }
701  }
702  }
703 
705  if (Ins.size() > 1)
706  fail(DL, DAG, "WebAssembly doesn't support more than 1 returned value yet");
707 
708  SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs;
709  SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
710 
711  // The generic code may have added an sret argument. If we're lowering an
712  // invoke function, the ABI requires that the function pointer be the first
713  // argument, so we may have to swap the arguments.
714  if (CallConv == CallingConv::WASM_EmscriptenInvoke && Outs.size() >= 2 &&
715  Outs[0].Flags.isSRet()) {
716  std::swap(Outs[0], Outs[1]);
717  std::swap(OutVals[0], OutVals[1]);
718  }
719 
720  unsigned NumFixedArgs = 0;
721  for (unsigned I = 0; I < Outs.size(); ++I) {
722  const ISD::OutputArg &Out = Outs[I];
723  SDValue &OutVal = OutVals[I];
724  if (Out.Flags.isNest())
725  fail(DL, DAG, "WebAssembly hasn't implemented nest arguments");
726  if (Out.Flags.isInAlloca())
727  fail(DL, DAG, "WebAssembly hasn't implemented inalloca arguments");
728  if (Out.Flags.isInConsecutiveRegs())
729  fail(DL, DAG, "WebAssembly hasn't implemented cons regs arguments");
730  if (Out.Flags.isInConsecutiveRegsLast())
731  fail(DL, DAG, "WebAssembly hasn't implemented cons regs last arguments");
732  if (Out.Flags.isByVal() && Out.Flags.getByValSize() != 0) {
733  auto &MFI = MF.getFrameInfo();
734  int FI = MFI.CreateStackObject(Out.Flags.getByValSize(),
735  Out.Flags.getByValAlign(),
736  /*isSS=*/false);
737  SDValue SizeNode =
738  DAG.getConstant(Out.Flags.getByValSize(), DL, MVT::i32);
739  SDValue FINode = DAG.getFrameIndex(FI, getPointerTy(Layout));
740  Chain = DAG.getMemcpy(
741  Chain, DL, FINode, OutVal, SizeNode, Out.Flags.getByValAlign(),
742  /*isVolatile*/ false, /*AlwaysInline=*/false,
743  /*isTailCall*/ false, MachinePointerInfo(), MachinePointerInfo());
744  OutVal = FINode;
745  }
746  // Count the number of fixed args *after* legalization.
747  NumFixedArgs += Out.IsFixed;
748  }
749 
750  bool IsVarArg = CLI.IsVarArg;
751  auto PtrVT = getPointerTy(Layout);
752 
753  // Analyze operands of the call, assigning locations to each operand.
755  CCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext());
756 
757  if (IsVarArg) {
758  // Outgoing non-fixed arguments are placed in a buffer. First
759  // compute their offsets and the total amount of buffer space needed.
760  for (unsigned I = NumFixedArgs; I < Outs.size(); ++I) {
761  const ISD::OutputArg &Out = Outs[I];
762  SDValue &Arg = OutVals[I];
763  EVT VT = Arg.getValueType();
764  assert(VT != MVT::iPTR && "Legalized args should be concrete");
765  Type *Ty = VT.getTypeForEVT(*DAG.getContext());
766  unsigned Align = std::max(Out.Flags.getOrigAlign(),
767  Layout.getABITypeAlignment(Ty));
768  unsigned Offset = CCInfo.AllocateStack(Layout.getTypeAllocSize(Ty),
769  Align);
770  CCInfo.addLoc(CCValAssign::getMem(ArgLocs.size(), VT.getSimpleVT(),
771  Offset, VT.getSimpleVT(),
773  }
774  }
775 
776  unsigned NumBytes = CCInfo.getAlignedCallFrameSize();
777 
778  SDValue FINode;
779  if (IsVarArg && NumBytes) {
780  // For non-fixed arguments, next emit stores to store the argument values
781  // to the stack buffer at the offsets computed above.
782  int FI = MF.getFrameInfo().CreateStackObject(NumBytes,
783  Layout.getStackAlignment(),
784  /*isSS=*/false);
785  unsigned ValNo = 0;
787  for (SDValue Arg :
788  make_range(OutVals.begin() + NumFixedArgs, OutVals.end())) {
789  assert(ArgLocs[ValNo].getValNo() == ValNo &&
790  "ArgLocs should remain in order and only hold varargs args");
791  unsigned Offset = ArgLocs[ValNo++].getLocMemOffset();
792  FINode = DAG.getFrameIndex(FI, getPointerTy(Layout));
793  SDValue Add = DAG.getNode(ISD::ADD, DL, PtrVT, FINode,
794  DAG.getConstant(Offset, DL, PtrVT));
795  Chains.push_back(
796  DAG.getStore(Chain, DL, Arg, Add,
797  MachinePointerInfo::getFixedStack(MF, FI, Offset), 0));
798  }
799  if (!Chains.empty())
800  Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chains);
801  } else if (IsVarArg) {
802  FINode = DAG.getIntPtrConstant(0, DL);
803  }
804 
805  if (Callee->getOpcode() == ISD::GlobalAddress) {
806  // If the callee is a GlobalAddress node (quite common, every direct call
807  // is) turn it into a TargetGlobalAddress node so that LowerGlobalAddress
808  // doesn't at MO_GOT which is not needed for direct calls.
809  GlobalAddressSDNode* GA = cast<GlobalAddressSDNode>(Callee);
810  Callee = DAG.getTargetGlobalAddress(GA->getGlobal(), DL,
812  GA->getOffset());
813  Callee = DAG.getNode(WebAssemblyISD::Wrapper, DL,
814  getPointerTy(DAG.getDataLayout()), Callee);
815  }
816 
817  // Compute the operands for the CALLn node.
819  Ops.push_back(Chain);
820  Ops.push_back(Callee);
821 
822  // Add all fixed arguments. Note that for non-varargs calls, NumFixedArgs
823  // isn't reliable.
824  Ops.append(OutVals.begin(),
825  IsVarArg ? OutVals.begin() + NumFixedArgs : OutVals.end());
826  // Add a pointer to the vararg buffer.
827  if (IsVarArg)
828  Ops.push_back(FINode);
829 
830  SmallVector<EVT, 8> InTys;
831  for (const auto &In : Ins) {
832  assert(!In.Flags.isByVal() && "byval is not valid for return values");
833  assert(!In.Flags.isNest() && "nest is not valid for return values");
834  if (In.Flags.isInAlloca())
835  fail(DL, DAG, "WebAssembly hasn't implemented inalloca return values");
836  if (In.Flags.isInConsecutiveRegs())
837  fail(DL, DAG, "WebAssembly hasn't implemented cons regs return values");
838  if (In.Flags.isInConsecutiveRegsLast())
839  fail(DL, DAG,
840  "WebAssembly hasn't implemented cons regs last return values");
841  // Ignore In.getOrigAlign() because all our arguments are passed in
842  // registers.
843  InTys.push_back(In.VT);
844  }
845 
846  if (CLI.IsTailCall) {
847  // ret_calls do not return values to the current frame
848  SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
849  return DAG.getNode(WebAssemblyISD::RET_CALL, DL, NodeTys, Ops);
850  }
851 
852  InTys.push_back(MVT::Other);
853  SDVTList InTyList = DAG.getVTList(InTys);
854  SDValue Res =
855  DAG.getNode(Ins.empty() ? WebAssemblyISD::CALL0 : WebAssemblyISD::CALL1,
856  DL, InTyList, Ops);
857  if (Ins.empty()) {
858  Chain = Res;
859  } else {
860  InVals.push_back(Res);
861  Chain = Res.getValue(1);
862  }
863 
864  return Chain;
865 }
866 
867 bool WebAssemblyTargetLowering::CanLowerReturn(
868  CallingConv::ID /*CallConv*/, MachineFunction & /*MF*/, bool /*IsVarArg*/,
870  LLVMContext & /*Context*/) const {
871  // WebAssembly can only handle returning tuples with multivalue enabled
872  return Subtarget->hasMultivalue() || Outs.size() <= 1;
873 }
874 
875 SDValue WebAssemblyTargetLowering::LowerReturn(
876  SDValue Chain, CallingConv::ID CallConv, bool /*IsVarArg*/,
878  const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
879  SelectionDAG &DAG) const {
880  assert((Subtarget->hasMultivalue() || Outs.size() <= 1) &&
881  "MVP WebAssembly can only return up to one value");
882  if (!callingConvSupported(CallConv))
883  fail(DL, DAG, "WebAssembly doesn't support non-C calling conventions");
884 
885  SmallVector<SDValue, 4> RetOps(1, Chain);
886  RetOps.append(OutVals.begin(), OutVals.end());
887  Chain = DAG.getNode(WebAssemblyISD::RETURN, DL, MVT::Other, RetOps);
888 
889  // Record the number and types of the return values.
890  for (const ISD::OutputArg &Out : Outs) {
891  assert(!Out.Flags.isByVal() && "byval is not valid for return values");
892  assert(!Out.Flags.isNest() && "nest is not valid for return values");
893  assert(Out.IsFixed && "non-fixed return value is not valid");
894  if (Out.Flags.isInAlloca())
895  fail(DL, DAG, "WebAssembly hasn't implemented inalloca results");
896  if (Out.Flags.isInConsecutiveRegs())
897  fail(DL, DAG, "WebAssembly hasn't implemented cons regs results");
898  if (Out.Flags.isInConsecutiveRegsLast())
899  fail(DL, DAG, "WebAssembly hasn't implemented cons regs last results");
900  }
901 
902  return Chain;
903 }
904 
905 SDValue WebAssemblyTargetLowering::LowerFormalArguments(
906  SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
907  const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
908  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
909  if (!callingConvSupported(CallConv))
910  fail(DL, DAG, "WebAssembly doesn't support non-C calling conventions");
911 
913  auto *MFI = MF.getInfo<WebAssemblyFunctionInfo>();
914 
915  // Set up the incoming ARGUMENTS value, which serves to represent the liveness
916  // of the incoming values before they're represented by virtual registers.
917  MF.getRegInfo().addLiveIn(WebAssembly::ARGUMENTS);
918 
919  for (const ISD::InputArg &In : Ins) {
920  if (In.Flags.isInAlloca())
921  fail(DL, DAG, "WebAssembly hasn't implemented inalloca arguments");
922  if (In.Flags.isNest())
923  fail(DL, DAG, "WebAssembly hasn't implemented nest arguments");
924  if (In.Flags.isInConsecutiveRegs())
925  fail(DL, DAG, "WebAssembly hasn't implemented cons regs arguments");
926  if (In.Flags.isInConsecutiveRegsLast())
927  fail(DL, DAG, "WebAssembly hasn't implemented cons regs last arguments");
928  // Ignore In.getOrigAlign() because all our arguments are passed in
929  // registers.
930  InVals.push_back(In.Used ? DAG.getNode(WebAssemblyISD::ARGUMENT, DL, In.VT,
931  DAG.getTargetConstant(InVals.size(),
932  DL, MVT::i32))
933  : DAG.getUNDEF(In.VT));
934 
935  // Record the number and types of arguments.
936  MFI->addParam(In.VT);
937  }
938 
939  // Varargs are copied into a buffer allocated by the caller, and a pointer to
940  // the buffer is passed as an argument.
941  if (IsVarArg) {
942  MVT PtrVT = getPointerTy(MF.getDataLayout());
943  Register VarargVreg =
945  MFI->setVarargBufferVreg(VarargVreg);
946  Chain = DAG.getCopyToReg(
947  Chain, DL, VarargVreg,
948  DAG.getNode(WebAssemblyISD::ARGUMENT, DL, PtrVT,
949  DAG.getTargetConstant(Ins.size(), DL, MVT::i32)));
950  MFI->addParam(PtrVT);
951  }
952 
953  // Record the number and types of arguments and results.
954  SmallVector<MVT, 4> Params;
957  DAG.getTarget(), Params, Results);
958  for (MVT VT : Results)
959  MFI->addResult(VT);
960  // TODO: Use signatures in WebAssemblyMachineFunctionInfo too and unify
961  // the param logic here with ComputeSignatureVTs
962  assert(MFI->getParams().size() == Params.size() &&
963  std::equal(MFI->getParams().begin(), MFI->getParams().end(),
964  Params.begin()));
965 
966  return Chain;
967 }
968 
969 void WebAssemblyTargetLowering::ReplaceNodeResults(
971  switch (N->getOpcode()) {
973  // Do not add any results, signifying that N should not be custom lowered
974  // after all. This happens because simd128 turns on custom lowering for
975  // SIGN_EXTEND_INREG, but for non-vector sign extends the result might be an
976  // illegal type.
977  break;
978  default:
980  "ReplaceNodeResults not implemented for this op for WebAssembly!");
981  }
982 }
983 
984 //===----------------------------------------------------------------------===//
985 // Custom lowering hooks.
986 //===----------------------------------------------------------------------===//
987 
988 SDValue WebAssemblyTargetLowering::LowerOperation(SDValue Op,
989  SelectionDAG &DAG) const {
990  SDLoc DL(Op);
991  switch (Op.getOpcode()) {
992  default:
993  llvm_unreachable("unimplemented operation lowering");
994  return SDValue();
995  case ISD::FrameIndex:
996  return LowerFrameIndex(Op, DAG);
997  case ISD::GlobalAddress:
998  return LowerGlobalAddress(Op, DAG);
999  case ISD::ExternalSymbol:
1000  return LowerExternalSymbol(Op, DAG);
1001  case ISD::JumpTable:
1002  return LowerJumpTable(Op, DAG);
1003  case ISD::BR_JT:
1004  return LowerBR_JT(Op, DAG);
1005  case ISD::VASTART:
1006  return LowerVASTART(Op, DAG);
1007  case ISD::BlockAddress:
1008  case ISD::BRIND:
1009  fail(DL, DAG, "WebAssembly hasn't implemented computed gotos");
1010  return SDValue();
1011  case ISD::RETURNADDR:
1012  return LowerRETURNADDR(Op, DAG);
1013  case ISD::FRAMEADDR:
1014  return LowerFRAMEADDR(Op, DAG);
1015  case ISD::CopyToReg:
1016  return LowerCopyToReg(Op, DAG);
1019  return LowerAccessVectorElement(Op, DAG);
1020  case ISD::INTRINSIC_VOID:
1023  return LowerIntrinsic(Op, DAG);
1025  return LowerSIGN_EXTEND_INREG(Op, DAG);
1026  case ISD::BUILD_VECTOR:
1027  return LowerBUILD_VECTOR(Op, DAG);
1028  case ISD::VECTOR_SHUFFLE:
1029  return LowerVECTOR_SHUFFLE(Op, DAG);
1030  case ISD::SETCC:
1031  return LowerSETCC(Op, DAG);
1032  case ISD::SHL:
1033  case ISD::SRA:
1034  case ISD::SRL:
1035  return LowerShift(Op, DAG);
1036  }
1037 }
1038 
1039 SDValue WebAssemblyTargetLowering::LowerCopyToReg(SDValue Op,
1040  SelectionDAG &DAG) const {
1041  SDValue Src = Op.getOperand(2);
1042  if (isa<FrameIndexSDNode>(Src.getNode())) {
1043  // CopyToReg nodes don't support FrameIndex operands. Other targets select
1044  // the FI to some LEA-like instruction, but since we don't have that, we
1045  // need to insert some kind of instruction that can take an FI operand and
1046  // produces a value usable by CopyToReg (i.e. in a vreg). So insert a dummy
1047  // local.copy between Op and its FI operand.
1048  SDValue Chain = Op.getOperand(0);
1049  SDLoc DL(Op);
1050  unsigned Reg = cast<RegisterSDNode>(Op.getOperand(1))->getReg();
1051  EVT VT = Src.getValueType();
1052  SDValue Copy(DAG.getMachineNode(VT == MVT::i32 ? WebAssembly::COPY_I32
1053  : WebAssembly::COPY_I64,
1054  DL, VT, Src),
1055  0);
1056  return Op.getNode()->getNumValues() == 1
1057  ? DAG.getCopyToReg(Chain, DL, Reg, Copy)
1058  : DAG.getCopyToReg(Chain, DL, Reg, Copy,
1059  Op.getNumOperands() == 4 ? Op.getOperand(3)
1060  : SDValue());
1061  }
1062  return SDValue();
1063 }
1064 
1065 SDValue WebAssemblyTargetLowering::LowerFrameIndex(SDValue Op,
1066  SelectionDAG &DAG) const {
1067  int FI = cast<FrameIndexSDNode>(Op)->getIndex();
1068  return DAG.getTargetFrameIndex(FI, Op.getValueType());
1069 }
1070 
1071 SDValue WebAssemblyTargetLowering::LowerRETURNADDR(SDValue Op,
1072  SelectionDAG &DAG) const {
1073  SDLoc DL(Op);
1074 
1075  if (!Subtarget->getTargetTriple().isOSEmscripten()) {
1076  fail(DL, DAG,
1077  "Non-Emscripten WebAssembly hasn't implemented "
1078  "__builtin_return_address");
1079  return SDValue();
1080  }
1081 
1083  return SDValue();
1084 
1085  unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
1086  MakeLibCallOptions CallOptions;
1087  return makeLibCall(DAG, RTLIB::RETURN_ADDRESS, Op.getValueType(),
1088  {DAG.getConstant(Depth, DL, MVT::i32)}, CallOptions, DL)
1089  .first;
1090 }
1091 
1092 SDValue WebAssemblyTargetLowering::LowerFRAMEADDR(SDValue Op,
1093  SelectionDAG &DAG) const {
1094  // Non-zero depths are not supported by WebAssembly currently. Use the
1095  // legalizer's default expansion, which is to return 0 (what this function is
1096  // documented to do).
1097  if (Op.getConstantOperandVal(0) > 0)
1098  return SDValue();
1099 
1101  EVT VT = Op.getValueType();
1102  Register FP =
1104  return DAG.getCopyFromReg(DAG.getEntryNode(), SDLoc(Op), FP, VT);
1105 }
1106 
1107 SDValue WebAssemblyTargetLowering::LowerGlobalAddress(SDValue Op,
1108  SelectionDAG &DAG) const {
1109  SDLoc DL(Op);
1110  const auto *GA = cast<GlobalAddressSDNode>(Op);
1111  EVT VT = Op.getValueType();
1112  assert(GA->getTargetFlags() == 0 &&
1113  "Unexpected target flags on generic GlobalAddressSDNode");
1114  if (GA->getAddressSpace() != 0)
1115  fail(DL, DAG, "WebAssembly only expects the 0 address space");
1116 
1117  unsigned OperandFlags = 0;
1118  if (isPositionIndependent()) {
1119  const GlobalValue *GV = GA->getGlobal();
1120  if (getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV)) {
1121  MachineFunction &MF = DAG.getMachineFunction();
1122  MVT PtrVT = getPointerTy(MF.getDataLayout());
1123  const char *BaseName;
1124  if (GV->getValueType()->isFunctionTy()) {
1125  BaseName = MF.createExternalSymbolName("__table_base");
1126  OperandFlags = WebAssemblyII::MO_TABLE_BASE_REL;
1127  }
1128  else {
1129  BaseName = MF.createExternalSymbolName("__memory_base");
1130  OperandFlags = WebAssemblyII::MO_MEMORY_BASE_REL;
1131  }
1132  SDValue BaseAddr =
1133  DAG.getNode(WebAssemblyISD::Wrapper, DL, PtrVT,
1134  DAG.getTargetExternalSymbol(BaseName, PtrVT));
1135 
1136  SDValue SymAddr = DAG.getNode(
1138  DAG.getTargetGlobalAddress(GA->getGlobal(), DL, VT, GA->getOffset(),
1139  OperandFlags));
1140 
1141  return DAG.getNode(ISD::ADD, DL, VT, BaseAddr, SymAddr);
1142  } else {
1143  OperandFlags = WebAssemblyII::MO_GOT;
1144  }
1145  }
1146 
1147  return DAG.getNode(WebAssemblyISD::Wrapper, DL, VT,
1148  DAG.getTargetGlobalAddress(GA->getGlobal(), DL, VT,
1149  GA->getOffset(), OperandFlags));
1150 }
1151 
1152 SDValue
1153 WebAssemblyTargetLowering::LowerExternalSymbol(SDValue Op,
1154  SelectionDAG &DAG) const {
1155  SDLoc DL(Op);
1156  const auto *ES = cast<ExternalSymbolSDNode>(Op);
1157  EVT VT = Op.getValueType();
1158  assert(ES->getTargetFlags() == 0 &&
1159  "Unexpected target flags on generic ExternalSymbolSDNode");
1160  return DAG.getNode(WebAssemblyISD::Wrapper, DL, VT,
1161  DAG.getTargetExternalSymbol(ES->getSymbol(), VT));
1162 }
1163 
1164 SDValue WebAssemblyTargetLowering::LowerJumpTable(SDValue Op,
1165  SelectionDAG &DAG) const {
1166  // There's no need for a Wrapper node because we always incorporate a jump
1167  // table operand into a BR_TABLE instruction, rather than ever
1168  // materializing it in a register.
1169  const JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
1170  return DAG.getTargetJumpTable(JT->getIndex(), Op.getValueType(),
1171  JT->getTargetFlags());
1172 }
1173 
1174 SDValue WebAssemblyTargetLowering::LowerBR_JT(SDValue Op,
1175  SelectionDAG &DAG) const {
1176  SDLoc DL(Op);
1177  SDValue Chain = Op.getOperand(0);
1178  const auto *JT = cast<JumpTableSDNode>(Op.getOperand(1));
1179  SDValue Index = Op.getOperand(2);
1180  assert(JT->getTargetFlags() == 0 && "WebAssembly doesn't set target flags");
1181 
1183  Ops.push_back(Chain);
1184  Ops.push_back(Index);
1185 
1187  const auto &MBBs = MJTI->getJumpTables()[JT->getIndex()].MBBs;
1188 
1189  // Add an operand for each case.
1190  for (auto MBB : MBBs)
1191  Ops.push_back(DAG.getBasicBlock(MBB));
1192 
1193  // TODO: For now, we just pick something arbitrary for a default case for now.
1194  // We really want to sniff out the guard and put in the real default case (and
1195  // delete the guard).
1196  Ops.push_back(DAG.getBasicBlock(MBBs[0]));
1197 
1198  return DAG.getNode(WebAssemblyISD::BR_TABLE, DL, MVT::Other, Ops);
1199 }
1200 
1201 SDValue WebAssemblyTargetLowering::LowerVASTART(SDValue Op,
1202  SelectionDAG &DAG) const {
1203  SDLoc DL(Op);
1205 
1206  auto *MFI = DAG.getMachineFunction().getInfo<WebAssemblyFunctionInfo>();
1207  const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
1208 
1209  SDValue ArgN = DAG.getCopyFromReg(DAG.getEntryNode(), DL,
1210  MFI->getVarargBufferVreg(), PtrVT);
1211  return DAG.getStore(Op.getOperand(0), DL, ArgN, Op.getOperand(1),
1212  MachinePointerInfo(SV), 0);
1213 }
1214 
1215 SDValue WebAssemblyTargetLowering::LowerIntrinsic(SDValue Op,
1216  SelectionDAG &DAG) const {
1217  MachineFunction &MF = DAG.getMachineFunction();
1218  unsigned IntNo;
1219  switch (Op.getOpcode()) {
1220  case ISD::INTRINSIC_VOID:
1222  IntNo = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue();
1223  break;
1225  IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
1226  break;
1227  default:
1228  llvm_unreachable("Invalid intrinsic");
1229  }
1230  SDLoc DL(Op);
1231 
1232  switch (IntNo) {
1233  default:
1234  return SDValue(); // Don't custom lower most intrinsics.
1235 
1236  case Intrinsic::wasm_lsda: {
1237  EVT VT = Op.getValueType();
1238  const TargetLowering &TLI = DAG.getTargetLoweringInfo();
1239  MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
1240  auto &Context = MF.getMMI().getContext();
1241  MCSymbol *S = Context.getOrCreateSymbol(Twine("GCC_except_table") +
1242  Twine(MF.getFunctionNumber()));
1243  return DAG.getNode(WebAssemblyISD::Wrapper, DL, VT,
1244  DAG.getMCSymbol(S, PtrVT));
1245  }
1246 
1247  case Intrinsic::wasm_throw: {
1248  // We only support C++ exceptions for now
1249  int Tag = cast<ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1250  if (Tag != CPP_EXCEPTION)
1251  llvm_unreachable("Invalid tag!");
1252  const TargetLowering &TLI = DAG.getTargetLoweringInfo();
1253  MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
1254  const char *SymName = MF.createExternalSymbolName("__cpp_exception");
1255  SDValue SymNode = DAG.getNode(WebAssemblyISD::Wrapper, DL, PtrVT,
1256  DAG.getTargetExternalSymbol(SymName, PtrVT));
1257  return DAG.getNode(WebAssemblyISD::THROW, DL,
1258  MVT::Other, // outchain type
1259  {
1260  Op.getOperand(0), // inchain
1261  SymNode, // exception symbol
1262  Op.getOperand(3) // thrown value
1263  });
1264  }
1265  }
1266 }
1267 
1268 SDValue
1269 WebAssemblyTargetLowering::LowerSIGN_EXTEND_INREG(SDValue Op,
1270  SelectionDAG &DAG) const {
1271  SDLoc DL(Op);
1272  // If sign extension operations are disabled, allow sext_inreg only if operand
1273  // is a vector extract. SIMD does not depend on sign extension operations, but
1274  // allowing sext_inreg in this context lets us have simple patterns to select
1275  // extract_lane_s instructions. Expanding sext_inreg everywhere would be
1276  // simpler in this file, but would necessitate large and brittle patterns to
1277  // undo the expansion and select extract_lane_s instructions.
1278  assert(!Subtarget->hasSignExt() && Subtarget->hasSIMD128());
1279  if (Op.getOperand(0).getOpcode() == ISD::EXTRACT_VECTOR_ELT) {
1280  const SDValue &Extract = Op.getOperand(0);
1281  MVT VecT = Extract.getOperand(0).getSimpleValueType();
1282  MVT ExtractedLaneT = static_cast<VTSDNode *>(Op.getOperand(1).getNode())
1283  ->getVT()
1284  .getSimpleVT();
1285  MVT ExtractedVecT =
1286  MVT::getVectorVT(ExtractedLaneT, 128 / ExtractedLaneT.getSizeInBits());
1287  if (ExtractedVecT == VecT)
1288  return Op;
1289  // Bitcast vector to appropriate type to ensure ISel pattern coverage
1290  const SDValue &Index = Extract.getOperand(1);
1291  unsigned IndexVal =
1292  static_cast<ConstantSDNode *>(Index.getNode())->getZExtValue();
1293  unsigned Scale =
1294  ExtractedVecT.getVectorNumElements() / VecT.getVectorNumElements();
1295  assert(Scale > 1);
1296  SDValue NewIndex =
1297  DAG.getConstant(IndexVal * Scale, DL, Index.getValueType());
1298  SDValue NewExtract = DAG.getNode(
1299  ISD::EXTRACT_VECTOR_ELT, DL, Extract.getValueType(),
1300  DAG.getBitcast(ExtractedVecT, Extract.getOperand(0)), NewIndex);
1301  return DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, Op.getValueType(),
1302  NewExtract, Op.getOperand(1));
1303  }
1304  // Otherwise expand
1305  return SDValue();
1306 }
1307 
1308 SDValue WebAssemblyTargetLowering::LowerBUILD_VECTOR(SDValue Op,
1309  SelectionDAG &DAG) const {
1310  SDLoc DL(Op);
1311  const EVT VecT = Op.getValueType();
1312  const EVT LaneT = Op.getOperand(0).getValueType();
1313  const size_t Lanes = Op.getNumOperands();
1314  bool CanSwizzle = Subtarget->hasUnimplementedSIMD128() && VecT == MVT::v16i8;
1315 
1316  // BUILD_VECTORs are lowered to the instruction that initializes the highest
1317  // possible number of lanes at once followed by a sequence of replace_lane
1318  // instructions to individually initialize any remaining lanes.
1319 
1320  // TODO: Tune this. For example, lanewise swizzling is very expensive, so
1321  // swizzled lanes should be given greater weight.
1322 
1323  // TODO: Investigate building vectors by shuffling together vectors built by
1324  // separately specialized means.
1325 
1326  auto IsConstant = [](const SDValue &V) {
1327  return V.getOpcode() == ISD::Constant || V.getOpcode() == ISD::ConstantFP;
1328  };
1329 
1330  // Returns the source vector and index vector pair if they exist. Checks for:
1331  // (extract_vector_elt
1332  // $src,
1333  // (sign_extend_inreg (extract_vector_elt $indices, $i))
1334  // )
1335  auto GetSwizzleSrcs = [](size_t I, const SDValue &Lane) {
1336  auto Bail = std::make_pair(SDValue(), SDValue());
1337  if (Lane->getOpcode() != ISD::EXTRACT_VECTOR_ELT)
1338  return Bail;
1339  const SDValue &SwizzleSrc = Lane->getOperand(0);
1340  const SDValue &IndexExt = Lane->getOperand(1);
1341  if (IndexExt->getOpcode() != ISD::SIGN_EXTEND_INREG)
1342  return Bail;
1343  const SDValue &Index = IndexExt->getOperand(0);
1344  if (Index->getOpcode() != ISD::EXTRACT_VECTOR_ELT)
1345  return Bail;
1346  const SDValue &SwizzleIndices = Index->getOperand(0);
1347  if (SwizzleSrc.getValueType() != MVT::v16i8 ||
1348  SwizzleIndices.getValueType() != MVT::v16i8 ||
1349  Index->getOperand(1)->getOpcode() != ISD::Constant ||
1350  Index->getConstantOperandVal(1) != I)
1351  return Bail;
1352  return std::make_pair(SwizzleSrc, SwizzleIndices);
1353  };
1354 
1355  using ValueEntry = std::pair<SDValue, size_t>;
1356  SmallVector<ValueEntry, 16> SplatValueCounts;
1357 
1358  using SwizzleEntry = std::pair<std::pair<SDValue, SDValue>, size_t>;
1359  SmallVector<SwizzleEntry, 16> SwizzleCounts;
1360 
1361  auto AddCount = [](auto &Counts, const auto &Val) {
1362  auto CountIt = std::find_if(Counts.begin(), Counts.end(),
1363  [&Val](auto E) { return E.first == Val; });
1364  if (CountIt == Counts.end()) {
1365  Counts.emplace_back(Val, 1);
1366  } else {
1367  CountIt->second++;
1368  }
1369  };
1370 
1371  auto GetMostCommon = [](auto &Counts) {
1372  auto CommonIt =
1373  std::max_element(Counts.begin(), Counts.end(),
1374  [](auto A, auto B) { return A.second < B.second; });
1375  assert(CommonIt != Counts.end() && "Unexpected all-undef build_vector");
1376  return *CommonIt;
1377  };
1378 
1379  size_t NumConstantLanes = 0;
1380 
1381  // Count eligible lanes for each type of vector creation op
1382  for (size_t I = 0; I < Lanes; ++I) {
1383  const SDValue &Lane = Op->getOperand(I);
1384  if (Lane.isUndef())
1385  continue;
1386 
1387  AddCount(SplatValueCounts, Lane);
1388 
1389  if (IsConstant(Lane)) {
1390  NumConstantLanes++;
1391  } else if (CanSwizzle) {
1392  auto SwizzleSrcs = GetSwizzleSrcs(I, Lane);
1393  if (SwizzleSrcs.first)
1394  AddCount(SwizzleCounts, SwizzleSrcs);
1395  }
1396  }
1397 
1398  SDValue SplatValue;
1399  size_t NumSplatLanes;
1400  std::tie(SplatValue, NumSplatLanes) = GetMostCommon(SplatValueCounts);
1401 
1402  SDValue SwizzleSrc;
1403  SDValue SwizzleIndices;
1404  size_t NumSwizzleLanes = 0;
1405  if (SwizzleCounts.size())
1406  std::forward_as_tuple(std::tie(SwizzleSrc, SwizzleIndices),
1407  NumSwizzleLanes) = GetMostCommon(SwizzleCounts);
1408 
1409  // Predicate returning true if the lane is properly initialized by the
1410  // original instruction
1411  std::function<bool(size_t, const SDValue &)> IsLaneConstructed;
1412  SDValue Result;
1413  if (Subtarget->hasUnimplementedSIMD128()) {
1414  // Prefer swizzles over vector consts over splats
1415  if (NumSwizzleLanes >= NumSplatLanes &&
1416  NumSwizzleLanes >= NumConstantLanes) {
1417  Result = DAG.getNode(WebAssemblyISD::SWIZZLE, DL, VecT, SwizzleSrc,
1418  SwizzleIndices);
1419  auto Swizzled = std::make_pair(SwizzleSrc, SwizzleIndices);
1420  IsLaneConstructed = [&, Swizzled](size_t I, const SDValue &Lane) {
1421  return Swizzled == GetSwizzleSrcs(I, Lane);
1422  };
1423  } else if (NumConstantLanes >= NumSplatLanes) {
1424  SmallVector<SDValue, 16> ConstLanes;
1425  for (const SDValue &Lane : Op->op_values()) {
1426  if (IsConstant(Lane)) {
1427  ConstLanes.push_back(Lane);
1428  } else if (LaneT.isFloatingPoint()) {
1429  ConstLanes.push_back(DAG.getConstantFP(0, DL, LaneT));
1430  } else {
1431  ConstLanes.push_back(DAG.getConstant(0, DL, LaneT));
1432  }
1433  }
1434  Result = DAG.getBuildVector(VecT, DL, ConstLanes);
1435  IsLaneConstructed = [&](size_t _, const SDValue &Lane) {
1436  return IsConstant(Lane);
1437  };
1438  }
1439  }
1440  if (!Result) {
1441  // Use a splat, but possibly a load_splat
1442  LoadSDNode *SplattedLoad;
1443  if (Subtarget->hasUnimplementedSIMD128() &&
1444  (SplattedLoad = dyn_cast<LoadSDNode>(SplatValue)) &&
1445  SplattedLoad->getMemoryVT() == VecT.getVectorElementType()) {
1446  Result = DAG.getMemIntrinsicNode(
1447  WebAssemblyISD::LOAD_SPLAT, DL, DAG.getVTList(VecT),
1448  {SplattedLoad->getChain(), SplattedLoad->getBasePtr(),
1449  SplattedLoad->getOffset()},
1450  SplattedLoad->getMemoryVT(), SplattedLoad->getMemOperand());
1451  } else {
1452  Result = DAG.getSplatBuildVector(VecT, DL, SplatValue);
1453  }
1454  IsLaneConstructed = [&](size_t _, const SDValue &Lane) {
1455  return Lane == SplatValue;
1456  };
1457  }
1458 
1459  // Add replace_lane instructions for any unhandled values
1460  for (size_t I = 0; I < Lanes; ++I) {
1461  const SDValue &Lane = Op->getOperand(I);
1462  if (!Lane.isUndef() && !IsLaneConstructed(I, Lane))
1463  Result = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, VecT, Result, Lane,
1464  DAG.getConstant(I, DL, MVT::i32));
1465  }
1466 
1467  return Result;
1468 }
1469 
1470 SDValue
1471 WebAssemblyTargetLowering::LowerVECTOR_SHUFFLE(SDValue Op,
1472  SelectionDAG &DAG) const {
1473  SDLoc DL(Op);
1474  ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(Op.getNode())->getMask();
1476  assert(VecType.is128BitVector() && "Unexpected shuffle vector type");
1477  size_t LaneBytes = VecType.getVectorElementType().getSizeInBits() / 8;
1478 
1479  // Space for two vector args and sixteen mask indices
1480  SDValue Ops[18];
1481  size_t OpIdx = 0;
1482  Ops[OpIdx++] = Op.getOperand(0);
1483  Ops[OpIdx++] = Op.getOperand(1);
1484 
1485  // Expand mask indices to byte indices and materialize them as operands
1486  for (int M : Mask) {
1487  for (size_t J = 0; J < LaneBytes; ++J) {
1488  // Lower undefs (represented by -1 in mask) to zero
1489  uint64_t ByteIndex = M == -1 ? 0 : (uint64_t)M * LaneBytes + J;
1490  Ops[OpIdx++] = DAG.getConstant(ByteIndex, DL, MVT::i32);
1491  }
1492  }
1493 
1494  return DAG.getNode(WebAssemblyISD::SHUFFLE, DL, Op.getValueType(), Ops);
1495 }
1496 
1497 SDValue WebAssemblyTargetLowering::LowerSETCC(SDValue Op,
1498  SelectionDAG &DAG) const {
1499  SDLoc DL(Op);
1500  // The legalizer does not know how to expand the comparison modes of i64x2
1501  // vectors because no comparison modes are supported. We could solve this by
1502  // expanding all i64x2 SETCC nodes, but that seems to expand f64x2 SETCC nodes
1503  // (which return i64x2 results) as well. So instead we manually unroll i64x2
1504  // comparisons here.
1505  assert(Subtarget->hasUnimplementedSIMD128());
1507  SmallVector<SDValue, 2> LHS, RHS;
1508  DAG.ExtractVectorElements(Op->getOperand(0), LHS);
1509  DAG.ExtractVectorElements(Op->getOperand(1), RHS);
1510  const SDValue &CC = Op->getOperand(2);
1511  auto MakeLane = [&](unsigned I) {
1512  return DAG.getNode(ISD::SELECT_CC, DL, MVT::i64, LHS[I], RHS[I],
1513  DAG.getConstant(uint64_t(-1), DL, MVT::i64),
1514  DAG.getConstant(uint64_t(0), DL, MVT::i64), CC);
1515  };
1516  return DAG.getBuildVector(Op->getValueType(0), DL,
1517  {MakeLane(0), MakeLane(1)});
1518 }
1519 
1520 SDValue
1521 WebAssemblyTargetLowering::LowerAccessVectorElement(SDValue Op,
1522  SelectionDAG &DAG) const {
1523  // Allow constant lane indices, expand variable lane indices
1524  SDNode *IdxNode = Op.getOperand(Op.getNumOperands() - 1).getNode();
1525  if (isa<ConstantSDNode>(IdxNode) || IdxNode->isUndef())
1526  return Op;
1527  else
1528  // Perform default expansion
1529  return SDValue();
1530 }
1531 
1534  // 32-bit and 64-bit unrolled shifts will have proper semantics
1535  if (LaneT.bitsGE(MVT::i32))
1536  return DAG.UnrollVectorOp(Op.getNode());
1537  // Otherwise mask the shift value to get proper semantics from 32-bit shift
1538  SDLoc DL(Op);
1539  SDValue ShiftVal = Op.getOperand(1);
1540  uint64_t MaskVal = LaneT.getSizeInBits() - 1;
1541  SDValue MaskedShiftVal = DAG.getNode(
1542  ISD::AND, // mask opcode
1543  DL, ShiftVal.getValueType(), // masked value type
1544  ShiftVal, // original shift value operand
1545  DAG.getConstant(MaskVal, DL, ShiftVal.getValueType()) // mask operand
1546  );
1547 
1548  return DAG.UnrollVectorOp(
1549  DAG.getNode(Op.getOpcode(), // original shift opcode
1550  DL, Op.getValueType(), // original return type
1551  Op.getOperand(0), // original vector operand,
1552  MaskedShiftVal // new masked shift value operand
1553  )
1554  .getNode());
1555 }
1556 
1557 SDValue WebAssemblyTargetLowering::LowerShift(SDValue Op,
1558  SelectionDAG &DAG) const {
1559  SDLoc DL(Op);
1560 
1561  // Only manually lower vector shifts
1563 
1564  // Unroll non-splat vector shifts
1565  BuildVectorSDNode *ShiftVec;
1566  SDValue SplatVal;
1567  if (!(ShiftVec = dyn_cast<BuildVectorSDNode>(Op.getOperand(1).getNode())) ||
1568  !(SplatVal = ShiftVec->getSplatValue()))
1569  return unrollVectorShift(Op, DAG);
1570 
1571  // All splats except i64x2 const splats are handled by patterns
1572  auto *SplatConst = dyn_cast<ConstantSDNode>(SplatVal);
1573  if (!SplatConst || Op.getSimpleValueType() != MVT::v2i64)
1574  return Op;
1575 
1576  // i64x2 const splats are custom lowered to avoid unnecessary wraps
1577  unsigned Opcode;
1578  switch (Op.getOpcode()) {
1579  case ISD::SHL:
1580  Opcode = WebAssemblyISD::VEC_SHL;
1581  break;
1582  case ISD::SRA:
1583  Opcode = WebAssemblyISD::VEC_SHR_S;
1584  break;
1585  case ISD::SRL:
1586  Opcode = WebAssemblyISD::VEC_SHR_U;
1587  break;
1588  default:
1589  llvm_unreachable("unexpected opcode");
1590  }
1591  APInt Shift = SplatConst->getAPIntValue().zextOrTrunc(32);
1592  return DAG.getNode(Opcode, DL, Op.getValueType(), Op.getOperand(0),
1593  DAG.getConstant(Shift, DL, MVT::i32));
1594 }
1595 
1596 //===----------------------------------------------------------------------===//
1597 // WebAssembly Optimization Hooks
1598 //===----------------------------------------------------------------------===//
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
void setFrameAddressIsTaken(bool T)
uint64_t CallInst * C
static MVT getIntegerVT(unsigned BitWidth)
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition: MathExtras.h:598
This file defines the interfaces that WebAssembly uses to lower LLVM code into a selection DAG...
bool isOSEmscripten() const
Tests whether the OS is Emscripten.
Definition: Triple.h:607
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
EVT getValueType() const
Return the ValueType of the referenced return value.
bool isInteger() const
Return true if this is an integer or a vector integer type.
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
const SDValue & getOffset() const
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:169
bool isUndef() const
const std::vector< MachineJumpTableEntry > & getJumpTables() const
const GlobalValue * getGlobal() const
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
LLVMContext & Context
Diagnostic information for unsupported feature in backend.
SDValue UnrollVectorOp(SDNode *N, unsigned ResNE=0)
Utility function used by legalize and lowering to "unroll" a vector operation by splitting out the sc...
void setMinimumJumpTableEntries(unsigned Val)
Indicate the minimum number of blocks to generate jump tables.
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
BR_CC - Conditional branch.
Definition: ISDOpcodes.h:708
This class represents lattice values for constants.
Definition: AllocatorList.h:23
InputArg - This struct carries flags and type information about a single incoming (formal) argument o...
static MVT getVectorVT(MVT VT, unsigned NumElements)
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0...
Definition: ISDOpcodes.h:663
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition: ISDOpcodes.h:421
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool isVector() const
Return true if this is a vector value type.
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
const SDValue & getBasePtr() const
Carry-setting nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:224
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition: MachineInstr.h:400
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain...
Definition: ISDOpcodes.h:760
This class represents a function call, abstracting a target machine&#39;s calling convention.
unsigned Reg
SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned TargetFlags=0)
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:255
SDValue getBasicBlock(MachineBasicBlock *MBB)
unsigned getVectorNumElements() const
const SDValue & getChain() const
Function Alias Analysis Results
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
void setBooleanVectorContents(BooleanContent Ty)
Specify how the target extends the result of a vector boolean value from a vector of i1 to a wider ty...
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
unsigned const TargetRegisterInfo * TRI
A debug info location.
Definition: DebugLoc.h:33
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
F(f)
MachineModuleInfo & getMMI() const
[US]{MIN/MAX} - Binary minimum or maximum or signed or unsigned integers.
Definition: ISDOpcodes.h:445
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Definition: APInt.cpp:955
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:710
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
void computeSignatureVTs(const FunctionType *Ty, const Function &F, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:496
SDValue getMCSymbol(MCSymbol *Sym, EVT VT)
Register getFrameRegister(const MachineFunction &MF) const override
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
Definition: ISDOpcodes.h:160
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:211
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1246
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition: ValueTypes.h:136
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations...
Definition: ISDOpcodes.h:517
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo)
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
void setMaxAtomicSizeInBitsSupported(unsigned SizeInBits)
Set the maximum atomic operation size supported by the backend.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
const HexagonInstrInfo * TII
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:168
#define INT64_MIN
Definition: DataTypes.h:80
Shift and rotation operations.
Definition: ISDOpcodes.h:471
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition: ValueTypes.cpp:140
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s), MachineInstr opcode, and operands.
BinOp getOperation() const
Definition: Instructions.h:769
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition: ISDOpcodes.h:192
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
void eraseFromParent()
Unlink &#39;this&#39; from the containing basic block and delete it.
CopyToReg - This node has three operands: a chain, a register number to set to this value...
Definition: ISDOpcodes.h:171
uint64_t getConstantOperandVal(unsigned i) const
SDValue getTargetJumpTable(int JTI, EVT VT, unsigned TargetFlags=0)
Definition: SelectionDAG.h:660
void setCondCodeAction(ISD::CondCode CC, MVT VT, LegalizeAction Action)
Indicate that the specified condition code is or isn&#39;t supported on the target and indicate what to d...
bool isInConsecutiveRegs() const
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:426
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:485
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:423
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
This class is used to represent EVT&#39;s, which are used to parameterize some operations.
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG...
Definition: ISDOpcodes.h:74
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
static mvt_range integer_fixedlen_vector_valuetypes()
OutputArg - This struct carries flags and a value for a single outgoing (actual) argument or outgoing...
This represents a list of ValueType&#39;s that has been intern&#39;d by a SelectionDAG.
STACKSAVE - STACKSAVE has one operand, an input chain.
Definition: ISDOpcodes.h:756
This is a fast-path instruction selection class that generates poor code and doesn&#39;t support illegal ...
Definition: FastISel.h:66
This file declares the WebAssembly-specific subclass of TargetMachine.
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:420
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose...
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
SDValue getTargetFrameIndex(int FI, EVT VT)
Definition: SelectionDAG.h:655
const TargetMachine & getTarget() const
Definition: SelectionDAG.h:424
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition: ISDOpcodes.h:490
const MCContext & getContext() const
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:202
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:151
unsigned getTargetFlags() const
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
Definition: SelectionDAG.h:911
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:604
SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op)
Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all elements. ...
Definition: SelectionDAG.h:775
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition: ISDOpcodes.h:152
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
MVT getVectorElementType() const
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
unsigned getByValSize() const
bool IsFixed
IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
Definition: ISDOpcodes.h:381
TargetInstrInfo - Interface to description of machine instruction set.
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
static SDValue unrollVectorShift(SDValue Op, SelectionDAG &DAG)
bool is128BitVector() const
Return true if this is a 128-bit vector type.
The memory access is volatile.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
Definition: ValueTypes.h:237
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:168
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
Definition: ISDOpcodes.h:167
MVT getSimpleValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the MVT corresponding to this LLVM type. See getValueType.
Control flow instructions. These all have token chains.
Definition: ISDOpcodes.h:687
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
Machine Value Type.
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
unsigned getOrigAlign() const
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
const Triple & getTargetTriple() const
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:63
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type...
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE...
Definition: ISDOpcodes.h:789
iterator_range< value_op_iterator > op_values() const
const SDValue & getOperand(unsigned Num) const
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL...
Definition: ISDOpcodes.h:386
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:233
OperandFlags
These are flags set on operands, but should be considered private, all access should go through the M...
Definition: MCInstrDesc.h:40
This file provides WebAssembly-specific target descriptions.
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
TRAP - Trapping instruction.
Definition: ISDOpcodes.h:828
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
self_iterator getIterator()
Definition: ilist_node.h:81
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
Definition: ISDOpcodes.h:780
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1210
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:223
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
static unsigned NumFixedArgs
Extended Value Type.
Definition: ValueTypes.h:34
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Definition: MathExtras.h:672
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:298
bool isPositionIndependent() const
size_t size() const
Definition: SmallVector.h:52
const TargetMachine & getTargetMachine() const
This class contains a discriminated union of information about pointers in memory operands...
const char * createExternalSymbolName(StringRef Name)
Allocate a string and populate it with the given external symbol name.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
unsigned first
WebAssemblyTargetLowering(const TargetMachine &TM, const WebAssemblySubtarget &STI)
SDValue getBitcast(EVT VT, SDValue V)
Return a bitcast using the SDLoc of the value operand, and casting to the provided type...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition: ISDOpcodes.h:266
TokenFactor - This node takes multiple tokens as input and produces a single token result...
Definition: ISDOpcodes.h:51
static MachineBasicBlock * LowerFPToInt(MachineInstr &MI, DebugLoc DL, MachineBasicBlock *BB, const TargetInstrInfo &TII, bool IsUnsigned, bool Int64, bool Float64, unsigned LoweredOpcode)
This file declares the WebAssembly-specific subclass of TargetSubtarget.
const TargetLowering & getTargetLoweringInfo() const
Definition: SelectionDAG.h:426
Iterator for intrusive lists based on ilist_node.
CCState - This class holds information needed while lowering arguments and return values...
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:650
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:390
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:393
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:267
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:223
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
Definition: SelectionDAG.h:758
Provides information about what library functions are available for the current target.
const DebugLoc & getDebugLoc() const
SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, unsigned Align, bool isVol, bool AlwaysInline, bool isTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo)
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
Definition: ValueTypes.h:96
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:474
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
Definition: ISDOpcodes.h:635
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
void ExtractVectorElements(SDValue Op, SmallVectorImpl< SDValue > &Args, unsigned Start=0, unsigned Count=0)
Append the extracted elements from Start to Count out of the vector Op in Args.
Represents one node in the SelectionDAG.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constants.cpp:767
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N)
Definition: SelectionDAG.h:703
const Function & getFunction() const
Return the LLVM function that this machine code represents.
static mvt_range integer_valuetypes()
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:940
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:163
Calling convention for emscripten __invoke_* functions.
Definition: CallingConv.h:242
EVT getMemoryVT() const
Return the type of the in-memory value.
Class for arbitrary precision integers.
Definition: APInt.h:69
unsigned getByValAlign() const
SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
amdgpu Simplify well known AMD library false FunctionCallee Callee
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
A "pseudo-class" with methods for operating on BUILD_VECTORs.
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:481
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:366
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:387
const WebAssemblyRegisterInfo * getRegisterInfo() const override
Flags
Flags values. These may be or&#39;d together.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
The memory access reads data.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
BR_JT - Jumptable branch.
Definition: ISDOpcodes.h:696
Representation of each machine instruction.
Definition: MachineInstr.h:63
VACOPY - VACOPY has 5 operands: an input chain, a destination pointer, a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the source.
Definition: ISDOpcodes.h:785
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:151
bool isFunctionTy() const
True if this is an instance of FunctionType.
Definition: Type.h:215
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:448
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB &#39;Other&#39; at the position From, and insert it into this MBB right before &#39;...
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT)
Definition: SelectionDAG.h:729
static bool callingConvSupported(CallingConv::ID CallConv)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:207
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:547
bool isInConsecutiveRegsLast() const
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:44
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const
Return the ValueType of the result of SETCC operations.
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
This file declares WebAssembly-specific per-machine-function information.
void setStackPointerRegisterToSaveRestore(unsigned R)
If set to a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save and restore.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
void setLibcallName(RTLIB::Libcall Call, const char *Name)
Rename the default libcall routine name for the specified libcall.
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:332
Type * getValueType() const
Definition: GlobalValue.h:279
static CCValAssign getMem(unsigned ValNo, MVT ValVT, unsigned Offset, MVT LocVT, LocInfo HTP)
unsigned getOpcode() const
FSINCOS - Compute both fsin and fcos as a single operation.
Definition: ISDOpcodes.h:666
SDValue getValue(unsigned R) const
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, unsigned Align=0, MachineMemOperand::Flags Flags=MachineMemOperand::MOLoad|MachineMemOperand::MOStore, uint64_t Size=0, const AAMDNodes &AAInfo=AAMDNodes())
Creates a MemIntrinsicNode that may produce a result and takes a list of operands.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
void setSchedulingPreference(Sched::Preference Pref)
Specify the target scheduling preference.
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:74
void computeLegalValueVTs(const Function &F, const TargetMachine &TM, Type *Ty, SmallVectorImpl< MVT > &ValueVTs)
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
FMA - Perform a * b + c with no intermediate rounding step.
Definition: ISDOpcodes.h:356
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:42
std::pair< SDValue, SDValue > makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT, ArrayRef< SDValue > Ops, MakeLibCallOptions CallOptions, const SDLoc &dl, SDValue Chain=SDValue()) const
Returns a pair of (return value, chain).
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:80
bool isUndef() const
Return true if the type of the node type undefined.
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
static mvt_range fixedlen_vector_valuetypes()
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:504
const WebAssemblyInstrInfo * getInstrInfo() const override
unsigned getNumOperands() const
Register getReg() const
getReg - Returns the register number.
const SDValue & getOperand(unsigned i) const
bool verifyReturnAddressArgumentIsConstant(SDValue Op, SelectionDAG &DAG) const
static void fail(const SDLoc &DL, SelectionDAG &DAG, const char *Msg)
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:431
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
#define _
LLVMContext * getContext() const
Definition: SelectionDAG.h:430
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition: ISDOpcodes.h:441
BRIND - Indirect branch.
Definition: ISDOpcodes.h:692
This class is used to represent ISD::LOAD nodes.
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary...
Definition: ISDOpcodes.h:681