blob: ce4ef1478d592d0bec54da48cc8adcc2828ef873 [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,
Simon Pilgrim4e0648a2019-06-12 17:14:03 +000063 MachineMemOperand::Flags Flags,
Dan Gohmanbb372242016-01-26 03:39:31 +000064 bool *Fast) const override;
Reid Klecknerb5180542017-03-21 16:57:19 +000065 bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
JF Bastien480c8402015-08-11 20:13:18 +000066
Simon Pilgrim99f70162018-06-28 17:27:09 +000067 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
68 EVT VT) const override;
Heejin Ahn4128cb02018-08-02 21:44:24 +000069 bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
70 MachineFunction &MF,
71 unsigned Intrinsic) const override;
Simon Pilgrim99f70162018-06-28 17:27:09 +000072
JF Bastienaf111db2015-08-24 22:16:48 +000073 SDValue LowerCall(CallLoweringInfo &CLI,
74 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000075 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
76 bool isVarArg,
77 const SmallVectorImpl<ISD::OutputArg> &Outs,
78 LLVMContext &Context) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000079 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
80 const SmallVectorImpl<ISD::OutputArg> &Outs,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000081 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
JF Bastienb9073fb2015-07-22 21:28:15 +000082 SelectionDAG &DAG) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000083 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
84 bool IsVarArg,
85 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000086 const SDLoc &DL, SelectionDAG &DAG,
JF Bastienb9073fb2015-07-22 21:28:15 +000087 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienaf111db2015-08-24 22:16:48 +000088
Thomas Livelye18b5c62019-05-23 18:09:26 +000089 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
90 SelectionDAG &DAG) const override;
91
JF Bastienaf111db2015-08-24 22:16:48 +000092 // Custom lowering hooks.
93 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Derek Schuff9769deb2015-12-11 23:49:46 +000094 SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively1a3cbe72019-05-23 01:24:01 +000095 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman94c65662016-02-16 23:48:04 +000096 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
JF Bastienaf111db2015-08-24 22:16:48 +000097 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman81719f82015-11-25 16:55:01 +000098 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman950a13c2015-09-16 16:51:30 +000099 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
100 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman35bfb242015-12-04 23:22:35 +0000101 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Derek Schuffaadc89c2016-02-16 18:18:36 +0000102 SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
Heejin Ahnd6f48782019-01-30 03:21:57 +0000103 SDValue LowerIntrinsic(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively64a39a12019-01-10 22:32:11 +0000104 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively079816e2019-01-30 02:23:29 +0000105 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelya0d25812018-09-07 21:54:46 +0000106 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelyfb84fd72018-11-02 00:06:56 +0000107 SDValue LowerAccessVectorElement(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively55735d52018-10-20 01:31:18 +0000108 SDValue LowerShift(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman10e730a2015-06-29 23:51:55 +0000109};
110
Dan Gohman7b634842015-08-24 18:44:37 +0000111namespace WebAssembly {
112FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
113 const TargetLibraryInfo *libInfo);
Heejin Ahnf208f632018-09-05 01:27:38 +0000114} // end namespace WebAssembly
Dan Gohman7b634842015-08-24 18:44:37 +0000115
Heejin Ahnf208f632018-09-05 01:27:38 +0000116} // end namespace llvm
Dan Gohman10e730a2015-06-29 23:51:55 +0000117
118#endif