blob: 58e088a0ba503d595a4829bac299c86912e691ac [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,
Thomas Lively3479fd22019-10-31 20:01:02 -070027#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 Bastienaf111db2015-08-24 22:16:48 +000034#include "WebAssemblyISD.def"
35#undef HANDLE_NODETYPE
Thomas Lively3479fd22019-10-31 20:01:02 -070036#undef HANDLE_MEM_NODETYPE
Dan Gohman10e730a2015-06-29 23:51:55 +000037};
38
Heejin Ahnf208f632018-09-05 01:27:38 +000039} // end namespace WebAssemblyISD
Dan Gohman10e730a2015-06-29 23:51:55 +000040
41class WebAssemblySubtarget;
42class WebAssemblyTargetMachine;
43
44class WebAssemblyTargetLowering final : public TargetLowering {
Heejin Ahnf208f632018-09-05 01:27:38 +000045public:
Dan Gohman10e730a2015-06-29 23:51:55 +000046 WebAssemblyTargetLowering(const TargetMachine &TM,
47 const WebAssemblySubtarget &STI);
48
Heejin Ahnf208f632018-09-05 01:27:38 +000049private:
Dan Gohman10e730a2015-06-29 23:51:55 +000050 /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
51 /// right decision when generating code for different targets.
52 const WebAssemblySubtarget *Subtarget;
JF Bastienb9073fb2015-07-22 21:28:15 +000053
Heejin Ahne8653bb2018-08-07 00:22:22 +000054 AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override;
Dan Gohman7b634842015-08-24 18:44:37 +000055 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
56 const TargetLibraryInfo *LibInfo) const override;
JF Bastienfda53372015-08-03 00:00:11 +000057 MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
Dan Gohmancdd48b82017-11-28 01:13:40 +000058 MachineBasicBlock *
59 EmitInstrWithCustomInserter(MachineInstr &MI,
60 MachineBasicBlock *MBB) const override;
JF Bastien480c8402015-08-11 20:13:18 +000061 const char *getTargetNodeName(unsigned Opcode) const override;
Heejin Ahnf208f632018-09-05 01:27:38 +000062 std::pair<unsigned, const TargetRegisterClass *>
63 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
64 StringRef Constraint, MVT VT) const override;
Dan Gohman3192ddf2015-11-19 23:04:59 +000065 bool isCheapToSpeculateCttz() const override;
66 bool isCheapToSpeculateCtlz() const override;
Dan Gohman4b9d7912015-12-15 22:01:29 +000067 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
Jonas Paulsson024e3192017-07-21 11:59:37 +000068 unsigned AS,
69 Instruction *I = nullptr) const override;
Dan Gohmanbb372242016-01-26 03:39:31 +000070 bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, unsigned Align,
Simon Pilgrim4e0648a2019-06-12 17:14:03 +000071 MachineMemOperand::Flags Flags,
Dan Gohmanbb372242016-01-26 03:39:31 +000072 bool *Fast) const override;
Reid Klecknerb5180542017-03-21 16:57:19 +000073 bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
Thomas Lively81125f72019-09-27 02:06:50 +000074 bool isVectorLoadExtDesirable(SDValue ExtVal) const override;
Simon Pilgrim99f70162018-06-28 17:27:09 +000075 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
76 EVT VT) const override;
Heejin Ahn4128cb02018-08-02 21:44:24 +000077 bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
78 MachineFunction &MF,
79 unsigned Intrinsic) const override;
Simon Pilgrim99f70162018-06-28 17:27:09 +000080
JF Bastienaf111db2015-08-24 22:16:48 +000081 SDValue LowerCall(CallLoweringInfo &CLI,
82 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000083 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
84 bool isVarArg,
85 const SmallVectorImpl<ISD::OutputArg> &Outs,
86 LLVMContext &Context) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000087 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
88 const SmallVectorImpl<ISD::OutputArg> &Outs,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000089 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
JF Bastienb9073fb2015-07-22 21:28:15 +000090 SelectionDAG &DAG) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000091 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
92 bool IsVarArg,
93 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000094 const SDLoc &DL, SelectionDAG &DAG,
JF Bastienb9073fb2015-07-22 21:28:15 +000095 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienaf111db2015-08-24 22:16:48 +000096
Thomas Livelye18b5c62019-05-23 18:09:26 +000097 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
98 SelectionDAG &DAG) const override;
99
Heejin Ahn54c136b2019-07-11 05:55:47 +0000100 const char *getClearCacheBuiltinName() const override {
101 report_fatal_error("llvm.clear_cache is not supported on wasm");
102 }
103
JF Bastienaf111db2015-08-24 22:16:48 +0000104 // Custom lowering hooks.
105 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Derek Schuff9769deb2015-12-11 23:49:46 +0000106 SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively1a3cbe72019-05-23 01:24:01 +0000107 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman94c65662016-02-16 23:48:04 +0000108 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
JF Bastienaf111db2015-08-24 22:16:48 +0000109 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman81719f82015-11-25 16:55:01 +0000110 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman950a13c2015-09-16 16:51:30 +0000111 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
112 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman35bfb242015-12-04 23:22:35 +0000113 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Derek Schuffaadc89c2016-02-16 18:18:36 +0000114 SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
Heejin Ahnd6f48782019-01-30 03:21:57 +0000115 SDValue LowerIntrinsic(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively64a39a12019-01-10 22:32:11 +0000116 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively079816e2019-01-30 02:23:29 +0000117 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelya0d25812018-09-07 21:54:46 +0000118 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelyecb7daf2019-11-01 10:21:00 -0700119 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelyfb84fd72018-11-02 00:06:56 +0000120 SDValue LowerAccessVectorElement(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively55735d52018-10-20 01:31:18 +0000121 SDValue LowerShift(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman10e730a2015-06-29 23:51:55 +0000122};
123
Dan Gohman7b634842015-08-24 18:44:37 +0000124namespace WebAssembly {
125FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
126 const TargetLibraryInfo *libInfo);
Heejin Ahnf208f632018-09-05 01:27:38 +0000127} // end namespace WebAssembly
Dan Gohman7b634842015-08-24 18:44:37 +0000128
Heejin Ahnf208f632018-09-05 01:27:38 +0000129} // end namespace llvm
Dan Gohman10e730a2015-06-29 23:51:55 +0000130
131#endif