blob: 80fca287647245e9691eb93a79db89d381ce4f91 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001//- WebAssemblyISelLowering.h - WebAssembly DAG Lowering Interface -*- C++ -*-//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Gohman10e730a2015-06-29 23:51:55 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// This file defines the interfaces that WebAssembly uses to lower LLVM
Dan Gohman10e730a2015-06-29 23:51:55 +000011/// 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 Blaikieb3bde2e2017-11-17 01:07:10 +000018#include "llvm/CodeGen/TargetLowering.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000019
20namespace llvm {
21
22namespace WebAssemblyISD {
23
JF Bastien480c8402015-08-11 20:13:18 +000024enum NodeType : unsigned {
Dan Gohman10e730a2015-06-29 23:51:55 +000025 FIRST_NUMBER = ISD::BUILTIN_OP_END,
JF Bastienaf111db2015-08-24 22:16:48 +000026#define HANDLE_NODETYPE(NODE) NODE,
27#include "WebAssemblyISD.def"
28#undef HANDLE_NODETYPE
Dan Gohman10e730a2015-06-29 23:51:55 +000029};
30
Heejin Ahnf208f632018-09-05 01:27:38 +000031} // end namespace WebAssemblyISD
Dan Gohman10e730a2015-06-29 23:51:55 +000032
33class WebAssemblySubtarget;
34class WebAssemblyTargetMachine;
35
36class WebAssemblyTargetLowering final : public TargetLowering {
Heejin Ahnf208f632018-09-05 01:27:38 +000037public:
Dan Gohman10e730a2015-06-29 23:51:55 +000038 WebAssemblyTargetLowering(const TargetMachine &TM,
39 const WebAssemblySubtarget &STI);
40
Heejin Ahnf208f632018-09-05 01:27:38 +000041private:
Dan Gohman10e730a2015-06-29 23:51:55 +000042 /// 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;
JF Bastienb9073fb2015-07-22 21:28:15 +000045
Heejin Ahne8653bb2018-08-07 00:22:22 +000046 AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override;
Dan Gohman7b634842015-08-24 18:44:37 +000047 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
48 const TargetLibraryInfo *LibInfo) const override;
JF Bastienfda53372015-08-03 00:00:11 +000049 MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
Dan Gohmancdd48b82017-11-28 01:13:40 +000050 MachineBasicBlock *
51 EmitInstrWithCustomInserter(MachineInstr &MI,
52 MachineBasicBlock *MBB) const override;
JF Bastien480c8402015-08-11 20:13:18 +000053 const char *getTargetNodeName(unsigned Opcode) const override;
Heejin Ahnf208f632018-09-05 01:27:38 +000054 std::pair<unsigned, const TargetRegisterClass *>
55 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
56 StringRef Constraint, MVT VT) const override;
Dan Gohman3192ddf2015-11-19 23:04:59 +000057 bool isCheapToSpeculateCttz() const override;
58 bool isCheapToSpeculateCtlz() const override;
Dan Gohman4b9d7912015-12-15 22:01:29 +000059 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
Jonas Paulsson024e3192017-07-21 11:59:37 +000060 unsigned AS,
61 Instruction *I = nullptr) const override;
Dan Gohmanbb372242016-01-26 03:39:31 +000062 bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, unsigned Align,
63 bool *Fast) const override;
Reid Klecknerb5180542017-03-21 16:57:19 +000064 bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
JF Bastien480c8402015-08-11 20:13:18 +000065
Simon Pilgrim99f70162018-06-28 17:27:09 +000066 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
67 EVT VT) const override;
Heejin Ahn4128cb02018-08-02 21:44:24 +000068 bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
69 MachineFunction &MF,
70 unsigned Intrinsic) const override;
Simon Pilgrim99f70162018-06-28 17:27:09 +000071
JF Bastienaf111db2015-08-24 22:16:48 +000072 SDValue LowerCall(CallLoweringInfo &CLI,
73 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000074 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
75 bool isVarArg,
76 const SmallVectorImpl<ISD::OutputArg> &Outs,
77 LLVMContext &Context) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000078 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
79 const SmallVectorImpl<ISD::OutputArg> &Outs,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000080 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
JF Bastienb9073fb2015-07-22 21:28:15 +000081 SelectionDAG &DAG) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000082 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
83 bool IsVarArg,
84 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000085 const SDLoc &DL, SelectionDAG &DAG,
JF Bastienb9073fb2015-07-22 21:28:15 +000086 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienaf111db2015-08-24 22:16:48 +000087
Thomas Livelye18b5c62019-05-23 18:09:26 +000088 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
89 SelectionDAG &DAG) const override;
90
JF Bastienaf111db2015-08-24 22:16:48 +000091 // Custom lowering hooks.
92 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Derek Schuff9769deb2015-12-11 23:49:46 +000093 SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively1a3cbe72019-05-23 01:24:01 +000094 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman94c65662016-02-16 23:48:04 +000095 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
JF Bastienaf111db2015-08-24 22:16:48 +000096 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman81719f82015-11-25 16:55:01 +000097 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman950a13c2015-09-16 16:51:30 +000098 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
99 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman35bfb242015-12-04 23:22:35 +0000100 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Derek Schuffaadc89c2016-02-16 18:18:36 +0000101 SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
Heejin Ahnd6f48782019-01-30 03:21:57 +0000102 SDValue LowerIntrinsic(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively64a39a12019-01-10 22:32:11 +0000103 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively079816e2019-01-30 02:23:29 +0000104 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelya0d25812018-09-07 21:54:46 +0000105 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelyfb84fd72018-11-02 00:06:56 +0000106 SDValue LowerAccessVectorElement(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively55735d52018-10-20 01:31:18 +0000107 SDValue LowerShift(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman10e730a2015-06-29 23:51:55 +0000108};
109
Dan Gohman7b634842015-08-24 18:44:37 +0000110namespace WebAssembly {
111FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
112 const TargetLibraryInfo *libInfo);
Heejin Ahnf208f632018-09-05 01:27:38 +0000113} // end namespace WebAssembly
Dan Gohman7b634842015-08-24 18:44:37 +0000114
Heejin Ahnf208f632018-09-05 01:27:38 +0000115} // end namespace llvm
Dan Gohman10e730a2015-06-29 23:51:55 +0000116
117#endif