| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | //- WebAssemblyISelLowering.h - WebAssembly DAG Lowering Interface -*- C++ -*-// |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 10 | /// This file defines the interfaces that WebAssembly uses to lower LLVM |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 11 | /// code into a selection DAG. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H |
| 16 | #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H |
| 17 | |
| David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/TargetLowering.h" |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | namespace WebAssemblyISD { |
| 23 | |
| JF Bastien | 480c840 | 2015-08-11 20:13:18 +0000 | [diff] [blame] | 24 | enum NodeType : unsigned { |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 25 | FIRST_NUMBER = ISD::BUILTIN_OP_END, |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 26 | #define HANDLE_NODETYPE(NODE) NODE, |
| Thomas Lively | 3479fd2 | 2019-10-31 20:01:02 -0700 | [diff] [blame] | 27 | #define HANDLE_MEM_NODETYPE(NODE) |
| 28 | #include "WebAssemblyISD.def" |
| 29 | FIRST_MEM_OPCODE = ISD::FIRST_TARGET_MEMORY_OPCODE, |
| 30 | #undef HANDLE_NODETYPE |
| 31 | #undef HANDLE_MEM_NODETYPE |
| 32 | #define HANDLE_NODETYPE(NODE) |
| 33 | #define HANDLE_MEM_NODETYPE(NODE) NODE, |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 34 | #include "WebAssemblyISD.def" |
| 35 | #undef HANDLE_NODETYPE |
| Thomas Lively | 3479fd2 | 2019-10-31 20:01:02 -0700 | [diff] [blame] | 36 | #undef HANDLE_MEM_NODETYPE |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 39 | } // end namespace WebAssemblyISD |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 40 | |
| 41 | class WebAssemblySubtarget; |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 42 | |
| 43 | class WebAssemblyTargetLowering final : public TargetLowering { |
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 44 | public: |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 45 | WebAssemblyTargetLowering(const TargetMachine &TM, |
| 46 | const WebAssemblySubtarget &STI); |
| 47 | |
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 48 | private: |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 49 | /// Keep a pointer to the WebAssemblySubtarget around so that we can make the |
| 50 | /// right decision when generating code for different targets. |
| 51 | const WebAssemblySubtarget *Subtarget; |
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 52 | |
| Heejin Ahn | e8653bb | 2018-08-07 00:22:22 +0000 | [diff] [blame] | 53 | AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override; |
| Dan Gohman | 7b63484 | 2015-08-24 18:44:37 +0000 | [diff] [blame] | 54 | FastISel *createFastISel(FunctionLoweringInfo &FuncInfo, |
| 55 | const TargetLibraryInfo *LibInfo) const override; |
| JF Bastien | fda5337 | 2015-08-03 00:00:11 +0000 | [diff] [blame] | 56 | MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override; |
| Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 57 | MachineBasicBlock * |
| 58 | EmitInstrWithCustomInserter(MachineInstr &MI, |
| 59 | MachineBasicBlock *MBB) const override; |
| JF Bastien | 480c840 | 2015-08-11 20:13:18 +0000 | [diff] [blame] | 60 | const char *getTargetNodeName(unsigned Opcode) const override; |
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 61 | std::pair<unsigned, const TargetRegisterClass *> |
| 62 | getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, |
| 63 | StringRef Constraint, MVT VT) const override; |
| Dan Gohman | 3192ddf | 2015-11-19 23:04:59 +0000 | [diff] [blame] | 64 | bool isCheapToSpeculateCttz() const override; |
| 65 | bool isCheapToSpeculateCtlz() const override; |
| Dan Gohman | 4b9d791 | 2015-12-15 22:01:29 +0000 | [diff] [blame] | 66 | bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, |
| Jonas Paulsson | 024e319 | 2017-07-21 11:59:37 +0000 | [diff] [blame] | 67 | unsigned AS, |
| 68 | Instruction *I = nullptr) const override; |
| Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 69 | bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, unsigned Align, |
| Simon Pilgrim | 4e0648a | 2019-06-12 17:14:03 +0000 | [diff] [blame] | 70 | MachineMemOperand::Flags Flags, |
| Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 71 | bool *Fast) const override; |
| Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 72 | bool isIntDivCheap(EVT VT, AttributeList Attr) const override; |
| Thomas Lively | 81125f7 | 2019-09-27 02:06:50 +0000 | [diff] [blame] | 73 | bool isVectorLoadExtDesirable(SDValue ExtVal) const override; |
| Simon Pilgrim | 99f7016 | 2018-06-28 17:27:09 +0000 | [diff] [blame] | 74 | EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, |
| 75 | EVT VT) const override; |
| Heejin Ahn | 4128cb0 | 2018-08-02 21:44:24 +0000 | [diff] [blame] | 76 | bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I, |
| 77 | MachineFunction &MF, |
| 78 | unsigned Intrinsic) const override; |
| Simon Pilgrim | 99f7016 | 2018-06-28 17:27:09 +0000 | [diff] [blame] | 79 | |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 80 | SDValue LowerCall(CallLoweringInfo &CLI, |
| 81 | SmallVectorImpl<SDValue> &InVals) const override; |
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 82 | bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, |
| 83 | bool isVarArg, |
| 84 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 85 | LLVMContext &Context) const override; |
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 86 | SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, |
| 87 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 88 | const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl, |
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 89 | SelectionDAG &DAG) const override; |
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 90 | SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, |
| 91 | bool IsVarArg, |
| 92 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 93 | const SDLoc &DL, SelectionDAG &DAG, |
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 94 | SmallVectorImpl<SDValue> &InVals) const override; |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 95 | |
| Thomas Lively | e18b5c6 | 2019-05-23 18:09:26 +0000 | [diff] [blame] | 96 | void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results, |
| 97 | SelectionDAG &DAG) const override; |
| 98 | |
| Heejin Ahn | 54c136b | 2019-07-11 05:55:47 +0000 | [diff] [blame] | 99 | const char *getClearCacheBuiltinName() const override { |
| 100 | report_fatal_error("llvm.clear_cache is not supported on wasm"); |
| 101 | } |
| 102 | |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 103 | // Custom lowering hooks. |
| 104 | SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; |
| Derek Schuff | 9769deb | 2015-12-11 23:49:46 +0000 | [diff] [blame] | 105 | SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const; |
| Thomas Lively | 1a3cbe7 | 2019-05-23 01:24:01 +0000 | [diff] [blame] | 106 | SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const; |
| Dan Gohman | 94c6566 | 2016-02-16 23:48:04 +0000 | [diff] [blame] | 107 | SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const; |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 108 | SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; |
| Dan Gohman | 81719f8 | 2015-11-25 16:55:01 +0000 | [diff] [blame] | 109 | SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const; |
| Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 110 | SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const; |
| 111 | SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const; |
| Dan Gohman | 35bfb24 | 2015-12-04 23:22:35 +0000 | [diff] [blame] | 112 | SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const; |
| Derek Schuff | aadc89c | 2016-02-16 18:18:36 +0000 | [diff] [blame] | 113 | SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const; |
| Heejin Ahn | d6f4878 | 2019-01-30 03:21:57 +0000 | [diff] [blame] | 114 | SDValue LowerIntrinsic(SDValue Op, SelectionDAG &DAG) const; |
| Thomas Lively | 64a39a1 | 2019-01-10 22:32:11 +0000 | [diff] [blame] | 115 | SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const; |
| Thomas Lively | 079816e | 2019-01-30 02:23:29 +0000 | [diff] [blame] | 116 | SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const; |
| Thomas Lively | a0d2581 | 2018-09-07 21:54:46 +0000 | [diff] [blame] | 117 | SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const; |
| Thomas Lively | ecb7daf | 2019-11-01 10:21:00 -0700 | [diff] [blame] | 118 | SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const; |
| Thomas Lively | fb84fd7 | 2018-11-02 00:06:56 +0000 | [diff] [blame] | 119 | SDValue LowerAccessVectorElement(SDValue Op, SelectionDAG &DAG) const; |
| Thomas Lively | 55735d5 | 2018-10-20 01:31:18 +0000 | [diff] [blame] | 120 | SDValue LowerShift(SDValue Op, SelectionDAG &DAG) const; |
| Thomas Lively | 40af481 | 2020-05-15 12:12:20 -0700 | [diff] [blame] | 121 | |
| 122 | // Custom DAG combine hooks |
| 123 | SDValue |
| 124 | PerformDAGCombine(SDNode *N, |
| 125 | TargetLowering::DAGCombinerInfo &DCI) const override; |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
| Dan Gohman | 7b63484 | 2015-08-24 18:44:37 +0000 | [diff] [blame] | 128 | namespace WebAssembly { |
| 129 | FastISel *createFastISel(FunctionLoweringInfo &funcInfo, |
| 130 | const TargetLibraryInfo *libInfo); |
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 131 | } // end namespace WebAssembly |
| Dan Gohman | 7b63484 | 2015-08-24 18:44:37 +0000 | [diff] [blame] | 132 | |
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 133 | } // end namespace llvm |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 134 | |
| 135 | #endif |