WebAssemblyISelLowering.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //- WebAssemblyISelLowering.h - WebAssembly DAG Lowering Interface -*- C++ -*-//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. ///
  9. /// \file
  10. /// This file defines the interfaces that WebAssembly uses to lower LLVM
  11. /// code into a selection DAG.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
  15. #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
  16. #include "llvm/CodeGen/TargetLowering.h"
  17. namespace llvm {
  18. namespace WebAssemblyISD {
  19. enum NodeType : unsigned {
  20. FIRST_NUMBER = ISD::BUILTIN_OP_END,
  21. #define HANDLE_NODETYPE(NODE) NODE,
  22. #define HANDLE_MEM_NODETYPE(NODE)
  23. #include "WebAssemblyISD.def"
  24. FIRST_MEM_OPCODE = ISD::FIRST_TARGET_MEMORY_OPCODE,
  25. #undef HANDLE_NODETYPE
  26. #undef HANDLE_MEM_NODETYPE
  27. #define HANDLE_NODETYPE(NODE)
  28. #define HANDLE_MEM_NODETYPE(NODE) NODE,
  29. #include "WebAssemblyISD.def"
  30. #undef HANDLE_NODETYPE
  31. #undef HANDLE_MEM_NODETYPE
  32. };
  33. } // end namespace WebAssemblyISD
  34. class WebAssemblySubtarget;
  35. class WebAssemblyTargetLowering final : public TargetLowering {
  36. public:
  37. WebAssemblyTargetLowering(const TargetMachine &TM,
  38. const WebAssemblySubtarget &STI);
  39. MVT getPointerTy(const DataLayout &DL, uint32_t AS = 0) const override;
  40. MVT getPointerMemTy(const DataLayout &DL, uint32_t AS = 0) const override;
  41. private:
  42. /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
  43. /// right decision when generating code for different targets.
  44. const WebAssemblySubtarget *Subtarget;
  45. AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override;
  46. bool shouldScalarizeBinop(SDValue VecOp) const override;
  47. FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
  48. const TargetLibraryInfo *LibInfo) const override;
  49. MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
  50. MachineBasicBlock *
  51. EmitInstrWithCustomInserter(MachineInstr &MI,
  52. MachineBasicBlock *MBB) const override;
  53. const char *getTargetNodeName(unsigned Opcode) const override;
  54. std::pair<unsigned, const TargetRegisterClass *>
  55. getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
  56. StringRef Constraint, MVT VT) const override;
  57. bool isCheapToSpeculateCttz(Type *Ty) const override;
  58. bool isCheapToSpeculateCtlz(Type *Ty) const override;
  59. bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
  60. unsigned AS,
  61. Instruction *I = nullptr) const override;
  62. bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, Align Alignment,
  63. MachineMemOperand::Flags Flags,
  64. unsigned *Fast) const override;
  65. bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
  66. bool isVectorLoadExtDesirable(SDValue ExtVal) const override;
  67. bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
  68. EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
  69. EVT VT) const override;
  70. bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
  71. MachineFunction &MF,
  72. unsigned Intrinsic) const override;
  73. void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known,
  74. const APInt &DemandedElts,
  75. const SelectionDAG &DAG,
  76. unsigned Depth) const override;
  77. TargetLoweringBase::LegalizeTypeAction
  78. getPreferredVectorAction(MVT VT) const override;
  79. SDValue LowerCall(CallLoweringInfo &CLI,
  80. SmallVectorImpl<SDValue> &InVals) const override;
  81. bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
  82. bool isVarArg,
  83. const SmallVectorImpl<ISD::OutputArg> &Outs,
  84. LLVMContext &Context) const override;
  85. SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
  86. const SmallVectorImpl<ISD::OutputArg> &Outs,
  87. const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
  88. SelectionDAG &DAG) const override;
  89. SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
  90. bool IsVarArg,
  91. const SmallVectorImpl<ISD::InputArg> &Ins,
  92. const SDLoc &DL, SelectionDAG &DAG,
  93. SmallVectorImpl<SDValue> &InVals) const override;
  94. void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
  95. SelectionDAG &DAG) const override;
  96. const char *getClearCacheBuiltinName() const override {
  97. report_fatal_error("llvm.clear_cache is not supported on wasm");
  98. }
  99. bool
  100. shouldSimplifyDemandedVectorElts(SDValue Op,
  101. const TargetLoweringOpt &TLO) const override;
  102. // Custom lowering hooks.
  103. SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
  104. SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
  105. SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
  106. SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
  107. SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
  108. SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
  109. SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
  110. SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
  111. SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
  112. SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
  113. SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
  114. SDValue LowerIntrinsic(SDValue Op, SelectionDAG &DAG) const;
  115. SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
  116. SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
  117. SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
  118. SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
  119. SDValue LowerAccessVectorElement(SDValue Op, SelectionDAG &DAG) const;
  120. SDValue LowerShift(SDValue Op, SelectionDAG &DAG) const;
  121. SDValue LowerFP_TO_INT_SAT(SDValue Op, SelectionDAG &DAG) const;
  122. SDValue LowerLoad(SDValue Op, SelectionDAG &DAG) const;
  123. SDValue LowerStore(SDValue Op, SelectionDAG &DAG) const;
  124. // Helper for LoadLoad and LowerStore
  125. bool MatchTableForLowering(SelectionDAG &DAG, const SDLoc &DL,
  126. const SDValue &Base, GlobalAddressSDNode *&GA,
  127. SDValue &Idx) const;
  128. // Custom DAG combine hooks
  129. SDValue
  130. PerformDAGCombine(SDNode *N,
  131. TargetLowering::DAGCombinerInfo &DCI) const override;
  132. };
  133. namespace WebAssembly {
  134. FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
  135. const TargetLibraryInfo *libInfo);
  136. } // end namespace WebAssembly
  137. } // end namespace llvm
  138. #endif