Home | History | Annotate | Download | only in WebAssembly
      1 //- 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 
     21 namespace llvm {
     22 
     23 namespace WebAssemblyISD {
     24 
     25 enum NodeType : unsigned {
     26   FIRST_NUMBER = ISD::BUILTIN_OP_END,
     27 #define HANDLE_NODETYPE(NODE) NODE,
     28 #include "WebAssemblyISD.def"
     29 #undef HANDLE_NODETYPE
     30 };
     31 
     32 }  // end namespace WebAssemblyISD
     33 
     34 class WebAssemblySubtarget;
     35 class WebAssemblyTargetMachine;
     36 
     37 class WebAssemblyTargetLowering final : public TargetLowering {
     38  public:
     39   WebAssemblyTargetLowering(const TargetMachine &TM,
     40                             const WebAssemblySubtarget &STI);
     41 
     42  private:
     43   /// 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;
     46 
     47   FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
     48                            const TargetLibraryInfo *LibInfo) const override;
     49   bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
     50   MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override;
     51   const char *getTargetNodeName(unsigned Opcode) const override;
     52   std::pair<unsigned, const TargetRegisterClass *> getRegForInlineAsmConstraint(
     53       const TargetRegisterInfo *TRI, StringRef Constraint,
     54       MVT VT) const override;
     55   bool isCheapToSpeculateCttz() const override;
     56   bool isCheapToSpeculateCtlz() const override;
     57   bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
     58                              unsigned AS) const override;
     59   bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace, unsigned Align,
     60                                       bool *Fast) const override;
     61   bool isIntDivCheap(EVT VT, AttributeSet Attr) const override;
     62 
     63   SDValue LowerCall(CallLoweringInfo &CLI,
     64                     SmallVectorImpl<SDValue> &InVals) const override;
     65   bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
     66                       bool isVarArg,
     67                       const SmallVectorImpl<ISD::OutputArg> &Outs,
     68                       LLVMContext &Context) const override;
     69   SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
     70                       const SmallVectorImpl<ISD::OutputArg> &Outs,
     71                       const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
     72                       SelectionDAG &DAG) const override;
     73   SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
     74                                bool IsVarArg,
     75                                const SmallVectorImpl<ISD::InputArg> &Ins,
     76                                const SDLoc &DL, SelectionDAG &DAG,
     77                                SmallVectorImpl<SDValue> &InVals) const override;
     78 
     79   // Custom lowering hooks.
     80   SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
     81   SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
     82   SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
     83   SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
     84   SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
     85   SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
     86   SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
     87   SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
     88   SDValue LowerCopyToReg(SDValue Op, SelectionDAG &DAG) const;
     89 };
     90 
     91 namespace WebAssembly {
     92 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
     93                          const TargetLibraryInfo *libInfo);
     94 }  // end namespace WebAssembly
     95 
     96 }  // end namespace llvm
     97 
     98 #endif
     99