blob: 5bc723028e63bf7c2738d0e0d10b2de2c0bed6db [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001//- WebAssemblyISelLowering.h - WebAssembly DAG Lowering Interface -*- C++ -*-//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief This file defines the interfaces that WebAssembly uses to lower LLVM
12/// code into a selection DAG.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
17#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
18
19#include "llvm/Target/TargetLowering.h"
20
21namespace llvm {
22
23namespace WebAssemblyISD {
24
JF Bastien480c8402015-08-11 20:13:18 +000025enum NodeType : unsigned {
Dan Gohman10e730a2015-06-29 23:51:55 +000026 FIRST_NUMBER = ISD::BUILTIN_OP_END,
JF Bastienaf111db2015-08-24 22:16:48 +000027#define HANDLE_NODETYPE(NODE) NODE,
28#include "WebAssemblyISD.def"
29#undef HANDLE_NODETYPE
Dan Gohman10e730a2015-06-29 23:51:55 +000030};
31
Derek Schuff3f063292016-02-11 20:57:09 +000032} // end namespace WebAssemblyISD
Dan Gohman10e730a2015-06-29 23:51:55 +000033
34class WebAssemblySubtarget;
35class WebAssemblyTargetMachine;
36
37class WebAssemblyTargetLowering final : public TargetLowering {
Derek Schuff3f063292016-02-11 20:57:09 +000038 public:
Dan Gohman10e730a2015-06-29 23:51:55 +000039 WebAssemblyTargetLowering(const TargetMachine &TM,
40 const WebAssemblySubtarget &STI);
41
Derek Schuff3f063292016-02-11 20:57:09 +000042 private:
Dan Gohman10e730a2015-06-29 23:51:55 +000043 /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
44 /// right decision when generating code for different targets.
45 const WebAssemblySubtarget *Subtarget;
JF Bastienb9073fb2015-07-22 21:28:15 +000046
Dan Gohman7b634842015-08-24 18:44:37 +000047 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
48 const TargetLibraryInfo *LibInfo) const override;
JF Bastienaf111db2015-08-24 22:16:48 +000049 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
JF Bastienfda53372015-08-03 00:00:11 +000050 MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
JF Bastien480c8402015-08-11 20:13:18 +000051 const char *getTargetNodeName(unsigned Opcode) const override;
Derek Schuff3f063292016-02-11 20:57:09 +000052 std::pair<unsigned, const TargetRegisterClass *> getRegForInlineAsmConstraint(
53 const TargetRegisterInfo *TRI, StringRef Constraint,
54 MVT VT) const override;
Dan Gohman3192ddf2015-11-19 23:04:59 +000055 bool isCheapToSpeculateCttz() const override;
56 bool isCheapToSpeculateCtlz() const override;
Dan Gohman4b9d7912015-12-15 22:01:29 +000057 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
58 unsigned AS) const override;
Dan Gohmanbb372242016-01-26 03:39:31 +000059 bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, unsigned Align,
60 bool *Fast) const override;
Dan Gohmanb4c3c382016-05-18 14:29:42 +000061 bool isIntDivCheap(EVT VT, AttributeSet Attr) const override;
JF Bastien480c8402015-08-11 20:13:18 +000062
JF Bastienaf111db2015-08-24 22:16:48 +000063 SDValue LowerCall(CallLoweringInfo &CLI,
64 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000065 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
66 bool isVarArg,
67 const SmallVectorImpl<ISD::OutputArg> &Outs,
68 LLVMContext &Context) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000069 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
70 const SmallVectorImpl<ISD::OutputArg> &Outs,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000071 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
JF Bastienb9073fb2015-07-22 21:28:15 +000072 SelectionDAG &DAG) const override;
JF Bastienb9073fb2015-07-22 21:28:15 +000073 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
74 bool IsVarArg,
75 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +000076 const SDLoc &DL, SelectionDAG &DAG,
JF Bastienb9073fb2015-07-22 21:28:15 +000077 SmallVectorImpl<SDValue> &InVals) const override;
JF Bastienaf111db2015-08-24 22:16:48 +000078
79 // Custom lowering hooks.
80 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Derek Schuff9769deb2015-12-11 23:49:46 +000081 SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman94c65662016-02-16 23:48:04 +000082 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
JF Bastienaf111db2015-08-24 22:16:48 +000083 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman81719f82015-11-25 16:55:01 +000084 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman950a13c2015-09-16 16:51:30 +000085 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
86 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman35bfb242015-12-04 23:22:35 +000087 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Derek Schuffaadc89c2016-02-16 18:18:36 +000088 SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman10e730a2015-06-29 23:51:55 +000089};
90
Dan Gohman7b634842015-08-24 18:44:37 +000091namespace WebAssembly {
92FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
93 const TargetLibraryInfo *libInfo);
Derek Schuff3f063292016-02-11 20:57:09 +000094} // end namespace WebAssembly
Dan Gohman7b634842015-08-24 18:44:37 +000095
Derek Schuff3f063292016-02-11 20:57:09 +000096} // end namespace llvm
Dan Gohman10e730a2015-06-29 23:51:55 +000097
98#endif