blob: 59f4230ed8895a1cf11503ff9c1c40f00e3b9c98 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001//- 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 Prantl5f8f34e42018-05-01 15:54:18 +000011/// This file defines the interfaces that WebAssembly uses to lower LLVM
Dan Gohman10e730a2015-06-29 23:51:55 +000012/// 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 Blaikieb3bde2e2017-11-17 01:07:10 +000019#include "llvm/CodeGen/TargetLowering.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000020
21namespace llvm {
22
23namespace WebAssemblyISD {
24
JF Bastien480c8402015-08-11 20:13:18 +000025enum NodeType : unsigned {
Dan Gohman10e730a2015-06-29 23:51:55 +000026 FIRST_NUMBER = ISD::BUILTIN_OP_END,
JF Bastienaf111db2015-08-24 22:16:48 +000027#define HANDLE_NODETYPE(NODE) NODE,
28#include "WebAssemblyISD.def"
29#undef HANDLE_NODETYPE
Dan Gohman10e730a2015-06-29 23:51:55 +000030};
31
Heejin Ahnf208f632018-09-05 01:27:38 +000032} // end namespace WebAssemblyISD
Dan Gohman10e730a2015-06-29 23:51:55 +000033
34class WebAssemblySubtarget;
35class WebAssemblyTargetMachine;
36
37class WebAssemblyTargetLowering final : public TargetLowering {
Heejin Ahnf208f632018-09-05 01:27:38 +000038public:
Dan Gohman10e730a2015-06-29 23:51:55 +000039 WebAssemblyTargetLowering(const TargetMachine &TM,
40 const WebAssemblySubtarget &STI);
41
Heejin Ahnf208f632018-09-05 01:27:38 +000042private:
Dan Gohman10e730a2015-06-29 23:51:55 +000043 /// 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 Bastienb9073fb2015-07-22 21:28:15 +000046
Heejin Ahne8653bb2018-08-07 00:22:22 +000047 AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override;
Dan Gohman7b634842015-08-24 18:44:37 +000048 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
49 const TargetLibraryInfo *LibInfo) const override;
JF Bastienaf111db2015-08-24 22:16:48 +000050 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
JF Bastienfda53372015-08-03 00:00:11 +000051 MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
Dan Gohmancdd48b82017-11-28 01:13:40 +000052 MachineBasicBlock *
53 EmitInstrWithCustomInserter(MachineInstr &MI,
54 MachineBasicBlock *MBB) const override;
JF Bastien480c8402015-08-11 20:13:18 +000055 const char *getTargetNodeName(unsigned Opcode) const override;
Heejin Ahnf208f632018-09-05 01:27:38 +000056 std::pair<unsigned, const TargetRegisterClass *>
57 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
58 StringRef Constraint, MVT VT) const override;
Dan Gohman3192ddf2015-11-19 23:04:59 +000059 bool isCheapToSpeculateCttz() const override;
60 bool isCheapToSpeculateCtlz() const override;
Dan Gohman4b9d7912015-12-15 22:01:29 +000061 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
Jonas Paulsson024e3192017-07-21 11:59:37 +000062 unsigned AS,
63 Instruction *I = nullptr) const override;
Dan Gohmanbb372242016-01-26 03:39:31 +000064 bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, unsigned Align,
65 bool *Fast) const override;
Reid Klecknerb5180542017-03-21 16:57:19 +000066 bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
JF Bastien480c8402015-08-11 20:13:18 +000067
Simon Pilgrim99f70162018-06-28 17:27:09 +000068 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
69 EVT VT) const override;
Heejin Ahn4128cb02018-08-02 21:44:24 +000070 bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
71 MachineFunction &MF,
72 unsigned Intrinsic) const override;
Simon Pilgrim99f70162018-06-28 17:27:09 +000073
JF Bastienaf111db2015-08-24 22:16:48 +000074 SDValue LowerCall(CallLoweringInfo &CLI,
75 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000076 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
77 bool isVarArg,
78 const SmallVectorImpl<ISD::OutputArg> &Outs,
79 LLVMContext &Context) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000080 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
81 const SmallVectorImpl<ISD::OutputArg> &Outs,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000082 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
JF Bastienb9073fb2015-07-22 21:28:15 +000083 SelectionDAG &DAG) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000084 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
85 bool IsVarArg,
86 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000087 const SDLoc &DL, SelectionDAG &DAG,
JF Bastienb9073fb2015-07-22 21:28:15 +000088 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienaf111db2015-08-24 22:16:48 +000089
90 // Custom lowering hooks.
91 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Derek Schuff9769deb2015-12-11 23:49:46 +000092 SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman94c65662016-02-16 23:48:04 +000093 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
JF Bastienaf111db2015-08-24 22:16:48 +000094 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman81719f82015-11-25 16:55:01 +000095 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman950a13c2015-09-16 16:51:30 +000096 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
97 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman35bfb242015-12-04 23:22:35 +000098 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Derek Schuffaadc89c2016-02-16 18:18:36 +000099 SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +0000100 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
Heejin Ahnda419bd2018-11-14 02:46:21 +0000101 SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively64a39a12019-01-10 22:32:11 +0000102 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelya0d25812018-09-07 21:54:46 +0000103 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelyfb84fd72018-11-02 00:06:56 +0000104 SDValue LowerAccessVectorElement(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively55735d52018-10-20 01:31:18 +0000105 SDValue LowerShift(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman10e730a2015-06-29 23:51:55 +0000106};
107
Dan Gohman7b634842015-08-24 18:44:37 +0000108namespace WebAssembly {
109FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
110 const TargetLibraryInfo *libInfo);
Heejin Ahnf208f632018-09-05 01:27:38 +0000111} // end namespace WebAssembly
Dan Gohman7b634842015-08-24 18:44:37 +0000112
Heejin Ahnf208f632018-09-05 01:27:38 +0000113} // end namespace llvm
Dan Gohman10e730a2015-06-29 23:51:55 +0000114
115#endif