| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | //- WebAssemblyISelLowering.h - WebAssembly DAG Lowering Interface -*- C++ -*-// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | /// | 
|  | 10 | /// \file | 
| Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 11 | /// This file defines the interfaces that WebAssembly uses to lower LLVM | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 12 | /// code into a selection DAG. | 
|  | 13 | /// | 
|  | 14 | //===----------------------------------------------------------------------===// | 
|  | 15 |  | 
|  | 16 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H | 
|  | 17 | #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H | 
|  | 18 |  | 
| David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/TargetLowering.h" | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 20 |  | 
|  | 21 | namespace llvm { | 
|  | 22 |  | 
|  | 23 | namespace WebAssemblyISD { | 
|  | 24 |  | 
| JF Bastien | 480c840 | 2015-08-11 20:13:18 +0000 | [diff] [blame] | 25 | enum NodeType : unsigned { | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 26 | FIRST_NUMBER = ISD::BUILTIN_OP_END, | 
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 27 | #define HANDLE_NODETYPE(NODE) NODE, | 
|  | 28 | #include "WebAssemblyISD.def" | 
|  | 29 | #undef HANDLE_NODETYPE | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 30 | }; | 
|  | 31 |  | 
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 32 | } // end namespace WebAssemblyISD | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 33 |  | 
|  | 34 | class WebAssemblySubtarget; | 
|  | 35 | class WebAssemblyTargetMachine; | 
|  | 36 |  | 
|  | 37 | class WebAssemblyTargetLowering final : public TargetLowering { | 
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 38 | public: | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 39 | WebAssemblyTargetLowering(const TargetMachine &TM, | 
|  | 40 | const WebAssemblySubtarget &STI); | 
|  | 41 |  | 
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 42 | private: | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 43 | /// Keep a pointer to the WebAssemblySubtarget around so that we can make the | 
|  | 44 | /// right decision when generating code for different targets. | 
|  | 45 | const WebAssemblySubtarget *Subtarget; | 
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 46 |  | 
| Heejin Ahn | e8653bb | 2018-08-07 00:22:22 +0000 | [diff] [blame] | 47 | AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override; | 
| Dan Gohman | 7b63484 | 2015-08-24 18:44:37 +0000 | [diff] [blame] | 48 | FastISel *createFastISel(FunctionLoweringInfo &FuncInfo, | 
|  | 49 | const TargetLibraryInfo *LibInfo) const override; | 
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 50 | bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override; | 
| JF Bastien | fda5337 | 2015-08-03 00:00:11 +0000 | [diff] [blame] | 51 | MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override; | 
| Dan Gohman | cdd48b8 | 2017-11-28 01:13:40 +0000 | [diff] [blame] | 52 | MachineBasicBlock * | 
|  | 53 | EmitInstrWithCustomInserter(MachineInstr &MI, | 
|  | 54 | MachineBasicBlock *MBB) const override; | 
| JF Bastien | 480c840 | 2015-08-11 20:13:18 +0000 | [diff] [blame] | 55 | const char *getTargetNodeName(unsigned Opcode) const override; | 
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 56 | std::pair<unsigned, const TargetRegisterClass *> | 
|  | 57 | getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, | 
|  | 58 | StringRef Constraint, MVT VT) const override; | 
| Dan Gohman | 3192ddf | 2015-11-19 23:04:59 +0000 | [diff] [blame] | 59 | bool isCheapToSpeculateCttz() const override; | 
|  | 60 | bool isCheapToSpeculateCtlz() const override; | 
| Dan Gohman | 4b9d791 | 2015-12-15 22:01:29 +0000 | [diff] [blame] | 61 | bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, | 
| Jonas Paulsson | 024e319 | 2017-07-21 11:59:37 +0000 | [diff] [blame] | 62 | unsigned AS, | 
|  | 63 | Instruction *I = nullptr) const override; | 
| Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 64 | bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, unsigned Align, | 
|  | 65 | bool *Fast) const override; | 
| Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 66 | bool isIntDivCheap(EVT VT, AttributeList Attr) const override; | 
| JF Bastien | 480c840 | 2015-08-11 20:13:18 +0000 | [diff] [blame] | 67 |  | 
| Simon Pilgrim | 99f7016 | 2018-06-28 17:27:09 +0000 | [diff] [blame] | 68 | EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, | 
|  | 69 | EVT VT) const override; | 
| Heejin Ahn | 4128cb0 | 2018-08-02 21:44:24 +0000 | [diff] [blame] | 70 | bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I, | 
|  | 71 | MachineFunction &MF, | 
|  | 72 | unsigned Intrinsic) const override; | 
| Simon Pilgrim | 99f7016 | 2018-06-28 17:27:09 +0000 | [diff] [blame] | 73 |  | 
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 74 | SDValue LowerCall(CallLoweringInfo &CLI, | 
|  | 75 | SmallVectorImpl<SDValue> &InVals) const override; | 
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 76 | bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, | 
|  | 77 | bool isVarArg, | 
|  | 78 | const SmallVectorImpl<ISD::OutputArg> &Outs, | 
|  | 79 | LLVMContext &Context) const override; | 
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 80 | SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, | 
|  | 81 | const SmallVectorImpl<ISD::OutputArg> &Outs, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 82 | const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl, | 
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 83 | SelectionDAG &DAG) const override; | 
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 84 | SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, | 
|  | 85 | bool IsVarArg, | 
|  | 86 | const SmallVectorImpl<ISD::InputArg> &Ins, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 87 | const SDLoc &DL, SelectionDAG &DAG, | 
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 88 | SmallVectorImpl<SDValue> &InVals) const override; | 
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 89 |  | 
|  | 90 | // Custom lowering hooks. | 
|  | 91 | SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; | 
| Derek Schuff | 9769deb | 2015-12-11 23:49:46 +0000 | [diff] [blame] | 92 | SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const; | 
| Dan Gohman | 94c6566 | 2016-02-16 23:48:04 +0000 | [diff] [blame] | 93 | SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const; | 
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 94 | SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; | 
| Dan Gohman | 81719f8 | 2015-11-25 16:55:01 +0000 | [diff] [blame] | 95 | SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const; | 
| Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 96 | SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const; | 
|  | 97 | SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const; | 
| Dan Gohman | 35bfb24 | 2015-12-04 23:22:35 +0000 | [diff] [blame] | 98 | SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const; | 
| Derek Schuff | aadc89c | 2016-02-16 18:18:36 +0000 | [diff] [blame] | 99 | SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const; | 
| Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 100 | SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const; | 
| Thomas Lively | a0d2581 | 2018-09-07 21:54:46 +0000 | [diff] [blame] | 101 | SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const; | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 102 | }; | 
|  | 103 |  | 
| Dan Gohman | 7b63484 | 2015-08-24 18:44:37 +0000 | [diff] [blame] | 104 | namespace WebAssembly { | 
|  | 105 | FastISel *createFastISel(FunctionLoweringInfo &funcInfo, | 
|  | 106 | const TargetLibraryInfo *libInfo); | 
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 107 | } // end namespace WebAssembly | 
| Dan Gohman | 7b63484 | 2015-08-24 18:44:37 +0000 | [diff] [blame] | 108 |  | 
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 109 | } // end namespace llvm | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 110 |  | 
|  | 111 | #endif |