1//- WebAssemblyISelLowering.h - WebAssembly DAG Lowering Interface -*- C++ -*-//
2//
3// 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
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file defines the interfaces that WebAssembly uses to lower LLVM
11/// 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
18#include "llvm/CodeGen/TargetLowering.h"
19
20namespace llvm {
21
22namespace WebAssemblyISD {
23
24enum NodeType : unsigned {
25  FIRST_NUMBER = ISD::BUILTIN_OP_END,
26#define HANDLE_NODETYPE(NODE) NODE,
27#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,
34#include "WebAssemblyISD.def"
35#undef HANDLE_NODETYPE
36#undef HANDLE_MEM_NODETYPE
37};
38
39} // end namespace WebAssemblyISD
40
41class WebAssemblySubtarget;
42class WebAssemblyTargetMachine;
43
44class WebAssemblyTargetLowering final : public TargetLowering {
45public:
46  WebAssemblyTargetLowering(const TargetMachine &TM,
47                            const WebAssemblySubtarget &STI);
48
49private:
50  /// 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;
53
54  AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override;
55  FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
56                           const TargetLibraryInfo *LibInfo) const override;
57  MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
58  MachineBasicBlock *
59  EmitInstrWithCustomInserter(MachineInstr &MI,
60                              MachineBasicBlock *MBB) const override;
61  const char *getTargetNodeName(unsigned Opcode) const override;
62  std::pair<unsigned, const TargetRegisterClass *>
63  getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
64                               StringRef Constraint, MVT VT) const override;
65  bool isCheapToSpeculateCttz() const override;
66  bool isCheapToSpeculateCtlz() const override;
67  bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
68                             unsigned AS,
69                             Instruction *I = nullptr) const override;
70  bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, unsigned Align,
71                                      MachineMemOperand::Flags Flags,
72                                      bool *Fast) const override;
73  bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
74  bool isVectorLoadExtDesirable(SDValue ExtVal) const override;
75  EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
76                         EVT VT) const override;
77  bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
78                          MachineFunction &MF,
79                          unsigned Intrinsic) const override;
80
81  SDValue LowerCall(CallLoweringInfo &CLI,
82                    SmallVectorImpl<SDValue> &InVals) const override;
83  bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
84                      bool isVarArg,
85                      const SmallVectorImpl<ISD::OutputArg> &Outs,
86                      LLVMContext &Context) const override;
87  SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
88                      const SmallVectorImpl<ISD::OutputArg> &Outs,
89                      const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
90                      SelectionDAG &DAG) const override;
91  SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
92                               bool IsVarArg,
93                               const SmallVectorImpl<ISD::InputArg> &Ins,
94                               const SDLoc &DL, SelectionDAG &DAG,
95                               SmallVectorImpl<SDValue> &InVals) const override;
96
97  void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
98                          SelectionDAG &DAG) const override;
99
100  const char *getClearCacheBuiltinName() const override {
101    report_fatal_error("llvm.clear_cache is not supported on wasm");
102  }
103
104  // Custom lowering hooks.
105  SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
106  SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
107  SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
108  SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
109  SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
110  SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
111  SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
112  SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
113  SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
114  SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
115  SDValue LowerIntrinsic(SDValue Op, SelectionDAG &DAG) const;
116  SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
117  SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
118  SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
119  SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
120  SDValue LowerAccessVectorElement(SDValue Op, SelectionDAG &DAG) const;
121  SDValue LowerShift(SDValue Op, SelectionDAG &DAG) const;
122};
123
124namespace WebAssembly {
125FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
126                         const TargetLibraryInfo *libInfo);
127} // end namespace WebAssembly
128
129} // end namespace llvm
130
131#endif
132