1285163Sdim//- WebAssemblyISelLowering.h - WebAssembly DAG Lowering Interface -*- C++ -*-//
2285163Sdim//
3285163Sdim//                     The LLVM Compiler Infrastructure
4285163Sdim//
5285163Sdim// This file is distributed under the University of Illinois Open Source
6285163Sdim// License. See LICENSE.TXT for details.
7285163Sdim//
8285163Sdim//===----------------------------------------------------------------------===//
9285163Sdim///
10285163Sdim/// \file
11285163Sdim/// \brief This file defines the interfaces that WebAssembly uses to lower LLVM
12285163Sdim/// code into a selection DAG.
13285163Sdim///
14285163Sdim//===----------------------------------------------------------------------===//
15285163Sdim
16285163Sdim#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
17285163Sdim#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
18285163Sdim
19285163Sdim#include "llvm/Target/TargetLowering.h"
20285163Sdim
21285163Sdimnamespace llvm {
22285163Sdim
23285163Sdimnamespace WebAssemblyISD {
24285163Sdim
25296417Sdimenum NodeType : unsigned {
26285163Sdim  FIRST_NUMBER = ISD::BUILTIN_OP_END,
27296417Sdim#define HANDLE_NODETYPE(NODE) NODE,
28296417Sdim#include "WebAssemblyISD.def"
29296417Sdim#undef HANDLE_NODETYPE
30285163Sdim};
31285163Sdim
32285163Sdim} // end namespace WebAssemblyISD
33285163Sdim
34285163Sdimclass WebAssemblySubtarget;
35285163Sdimclass WebAssemblyTargetMachine;
36285163Sdim
37285163Sdimclass WebAssemblyTargetLowering final : public TargetLowering {
38285163Sdimpublic:
39285163Sdim  WebAssemblyTargetLowering(const TargetMachine &TM,
40285163Sdim                            const WebAssemblySubtarget &STI);
41285163Sdim
42285163Sdimprivate:
43285163Sdim  /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
44285163Sdim  /// right decision when generating code for different targets.
45285163Sdim  const WebAssemblySubtarget *Subtarget;
46296417Sdim
47296417Sdim  FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
48296417Sdim                           const TargetLibraryInfo *LibInfo) const override;
49296417Sdim  bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
50296417Sdim  MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
51296417Sdim  const char *getTargetNodeName(unsigned Opcode) const override;
52296417Sdim  std::pair<unsigned, const TargetRegisterClass *>
53296417Sdim  getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
54296417Sdim                               StringRef Constraint, MVT VT) const override;
55296417Sdim  bool isCheapToSpeculateCttz() const override;
56296417Sdim  bool isCheapToSpeculateCtlz() const override;
57296417Sdim  bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
58296417Sdim                             unsigned AS) const override;
59296417Sdim
60296417Sdim  SDValue LowerCall(CallLoweringInfo &CLI,
61296417Sdim                    SmallVectorImpl<SDValue> &InVals) const override;
62296417Sdim  bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
63296417Sdim                      bool isVarArg,
64296417Sdim                      const SmallVectorImpl<ISD::OutputArg> &Outs,
65296417Sdim                      LLVMContext &Context) const override;
66296417Sdim  SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
67296417Sdim                      const SmallVectorImpl<ISD::OutputArg> &Outs,
68296417Sdim                      const SmallVectorImpl<SDValue> &OutVals, SDLoc dl,
69296417Sdim                      SelectionDAG &DAG) const override;
70296417Sdim  SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
71296417Sdim                               bool IsVarArg,
72296417Sdim                               const SmallVectorImpl<ISD::InputArg> &Ins,
73296417Sdim                               SDLoc DL, SelectionDAG &DAG,
74296417Sdim                               SmallVectorImpl<SDValue> &InVals) const override;
75296417Sdim
76296417Sdim  // Custom lowering hooks.
77296417Sdim  SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
78296417Sdim  SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
79296417Sdim  SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
80296417Sdim  SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
81296417Sdim  SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
82296417Sdim  SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
83296417Sdim  SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
84285163Sdim};
85285163Sdim
86296417Sdimnamespace WebAssembly {
87296417SdimFastISel *createFastISel(FunctionLoweringInfo &funcInfo,
88296417Sdim                         const TargetLibraryInfo *libInfo);
89296417Sdim} // end namespace WebAssembly
90296417Sdim
91285163Sdim} // end namespace llvm
92285163Sdim
93285163Sdim#endif
94