blob: b8e61237752927853b38c15c9dcbd1a8852007cd [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;
Dan Gohman10e730a2015-06-29 23:51:55 +000042
43class WebAssemblyTargetLowering final : public TargetLowering {
Heejin Ahnf208f632018-09-05 01:27:38 +000044public:
Dan Gohman10e730a2015-06-29 23:51:55 +000045 WebAssemblyTargetLowering(const TargetMachine &TM,
46 const WebAssemblySubtarget &STI);
47
Heejin Ahnf208f632018-09-05 01:27:38 +000048private:
Dan Gohman10e730a2015-06-29 23:51:55 +000049 /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
50 /// right decision when generating code for different targets.
51 const WebAssemblySubtarget *Subtarget;
JF Bastienb9073fb2015-07-22 21:28:15 +000052
Heejin Ahne8653bb2018-08-07 00:22:22 +000053 AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override;
Dan Gohman7b634842015-08-24 18:44:37 +000054 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
55 const TargetLibraryInfo *LibInfo) const override;
JF Bastienfda53372015-08-03 00:00:11 +000056 MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
Dan Gohmancdd48b82017-11-28 01:13:40 +000057 MachineBasicBlock *
58 EmitInstrWithCustomInserter(MachineInstr &MI,
59 MachineBasicBlock *MBB) const override;
JF Bastien480c8402015-08-11 20:13:18 +000060 const char *getTargetNodeName(unsigned Opcode) const override;
Heejin Ahnf208f632018-09-05 01:27:38 +000061 std::pair<unsigned, const TargetRegisterClass *>
62 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
63 StringRef Constraint, MVT VT) const override;
Dan Gohman3192ddf2015-11-19 23:04:59 +000064 bool isCheapToSpeculateCttz() const override;
65 bool isCheapToSpeculateCtlz() const override;
Dan Gohman4b9d7912015-12-15 22:01:29 +000066 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
Jonas Paulsson024e3192017-07-21 11:59:37 +000067 unsigned AS,
68 Instruction *I = nullptr) const override;
Dan Gohmanbb372242016-01-26 03:39:31 +000069 bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, unsigned Align,
Simon Pilgrim4e0648a2019-06-12 17:14:03 +000070 MachineMemOperand::Flags Flags,
Dan Gohmanbb372242016-01-26 03:39:31 +000071 bool *Fast) const override;
Reid Klecknerb5180542017-03-21 16:57:19 +000072 bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
Thomas Lively81125f72019-09-27 02:06:50 +000073 bool isVectorLoadExtDesirable(SDValue ExtVal) const override;
Simon Pilgrim99f70162018-06-28 17:27:09 +000074 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
75 EVT VT) const override;
Heejin Ahn4128cb02018-08-02 21:44:24 +000076 bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
77 MachineFunction &MF,
78 unsigned Intrinsic) const override;
Simon Pilgrim99f70162018-06-28 17:27:09 +000079
JF Bastienaf111db2015-08-24 22:16:48 +000080 SDValue LowerCall(CallLoweringInfo &CLI,
81 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000082 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
83 bool isVarArg,
84 const SmallVectorImpl<ISD::OutputArg> &Outs,
85 LLVMContext &Context) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000086 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
87 const SmallVectorImpl<ISD::OutputArg> &Outs,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000088 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
JF Bastienb9073fb2015-07-22 21:28:15 +000089 SelectionDAG &DAG) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000090 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
91 bool IsVarArg,
92 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000093 const SDLoc &DL, SelectionDAG &DAG,
JF Bastienb9073fb2015-07-22 21:28:15 +000094 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienaf111db2015-08-24 22:16:48 +000095
Thomas Livelye18b5c62019-05-23 18:09:26 +000096 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
97 SelectionDAG &DAG) const override;
98
Heejin Ahn54c136b2019-07-11 05:55:47 +000099 const char *getClearCacheBuiltinName() const override {
100 report_fatal_error("llvm.clear_cache is not supported on wasm");
101 }
102
JF Bastienaf111db2015-08-24 22:16:48 +0000103 // Custom lowering hooks.
104 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Derek Schuff9769deb2015-12-11 23:49:46 +0000105 SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively1a3cbe72019-05-23 01:24:01 +0000106 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman94c65662016-02-16 23:48:04 +0000107 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
JF Bastienaf111db2015-08-24 22:16:48 +0000108 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman81719f82015-11-25 16:55:01 +0000109 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman950a13c2015-09-16 16:51:30 +0000110 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
111 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman35bfb242015-12-04 23:22:35 +0000112 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Derek Schuffaadc89c2016-02-16 18:18:36 +0000113 SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
Heejin Ahnd6f48782019-01-30 03:21:57 +0000114 SDValue LowerIntrinsic(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively64a39a12019-01-10 22:32:11 +0000115 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively079816e2019-01-30 02:23:29 +0000116 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelya0d25812018-09-07 21:54:46 +0000117 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelyecb7daf2019-11-01 10:21:00 -0700118 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
Thomas Livelyfb84fd72018-11-02 00:06:56 +0000119 SDValue LowerAccessVectorElement(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively55735d52018-10-20 01:31:18 +0000120 SDValue LowerShift(SDValue Op, SelectionDAG &DAG) const;
Thomas Lively40af4812020-05-15 12:12:20 -0700121
122 // Custom DAG combine hooks
123 SDValue
124 PerformDAGCombine(SDNode *N,
125 TargetLowering::DAGCombinerInfo &DCI) const override;
Dan Gohman10e730a2015-06-29 23:51:55 +0000126};
127
Dan Gohman7b634842015-08-24 18:44:37 +0000128namespace WebAssembly {
129FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
130 const TargetLibraryInfo *libInfo);
Heejin Ahnf208f632018-09-05 01:27:38 +0000131} // end namespace WebAssembly
Dan Gohman7b634842015-08-24 18:44:37 +0000132
Heejin Ahnf208f632018-09-05 01:27:38 +0000133} // end namespace llvm
Dan Gohman10e730a2015-06-29 23:51:55 +0000134
135#endif