1*9880d681SAndroid Build Coastguard Worker //===-- BPFISelLowering.h - BPF DAG Lowering Interface ----------*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file defines the interfaces that BPF uses to lower LLVM code into a 11*9880d681SAndroid Build Coastguard Worker // selection DAG. 12*9880d681SAndroid Build Coastguard Worker // 13*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_BPF_BPFISELLOWERING_H 16*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_BPF_BPFISELLOWERING_H 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker #include "BPF.h" 19*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/SelectionDAG.h" 20*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetLowering.h" 21*9880d681SAndroid Build Coastguard Worker 22*9880d681SAndroid Build Coastguard Worker namespace llvm { 23*9880d681SAndroid Build Coastguard Worker class BPFSubtarget; 24*9880d681SAndroid Build Coastguard Worker namespace BPFISD { 25*9880d681SAndroid Build Coastguard Worker enum NodeType : unsigned { 26*9880d681SAndroid Build Coastguard Worker FIRST_NUMBER = ISD::BUILTIN_OP_END, 27*9880d681SAndroid Build Coastguard Worker RET_FLAG, 28*9880d681SAndroid Build Coastguard Worker CALL, 29*9880d681SAndroid Build Coastguard Worker SELECT_CC, 30*9880d681SAndroid Build Coastguard Worker BR_CC, 31*9880d681SAndroid Build Coastguard Worker Wrapper 32*9880d681SAndroid Build Coastguard Worker }; 33*9880d681SAndroid Build Coastguard Worker } 34*9880d681SAndroid Build Coastguard Worker 35*9880d681SAndroid Build Coastguard Worker class BPFTargetLowering : public TargetLowering { 36*9880d681SAndroid Build Coastguard Worker public: 37*9880d681SAndroid Build Coastguard Worker explicit BPFTargetLowering(const TargetMachine &TM, const BPFSubtarget &STI); 38*9880d681SAndroid Build Coastguard Worker 39*9880d681SAndroid Build Coastguard Worker // Provide custom lowering hooks for some operations. 40*9880d681SAndroid Build Coastguard Worker SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker // This method returns the name of a target specific DAG node. 43*9880d681SAndroid Build Coastguard Worker const char *getTargetNodeName(unsigned Opcode) const override; 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Worker MachineBasicBlock * 46*9880d681SAndroid Build Coastguard Worker EmitInstrWithCustomInserter(MachineInstr &MI, 47*9880d681SAndroid Build Coastguard Worker MachineBasicBlock *BB) const override; 48*9880d681SAndroid Build Coastguard Worker 49*9880d681SAndroid Build Coastguard Worker private: 50*9880d681SAndroid Build Coastguard Worker SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const; 51*9880d681SAndroid Build Coastguard Worker SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const; 52*9880d681SAndroid Build Coastguard Worker SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Worker // Lower the result values of a call, copying them out of physregs into vregs 55*9880d681SAndroid Build Coastguard Worker SDValue LowerCallResult(SDValue Chain, SDValue InFlag, 56*9880d681SAndroid Build Coastguard Worker CallingConv::ID CallConv, bool IsVarArg, 57*9880d681SAndroid Build Coastguard Worker const SmallVectorImpl<ISD::InputArg> &Ins, 58*9880d681SAndroid Build Coastguard Worker const SDLoc &DL, SelectionDAG &DAG, 59*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<SDValue> &InVals) const; 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Worker // Maximum number of arguments to a call 62*9880d681SAndroid Build Coastguard Worker static const unsigned MaxArgs; 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker // Lower a call into CALLSEQ_START - BPFISD:CALL - CALLSEQ_END chain 65*9880d681SAndroid Build Coastguard Worker SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, 66*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<SDValue> &InVals) const override; 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Worker // Lower incoming arguments, copy physregs into vregs 69*9880d681SAndroid Build Coastguard Worker SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, 70*9880d681SAndroid Build Coastguard Worker bool IsVarArg, 71*9880d681SAndroid Build Coastguard Worker const SmallVectorImpl<ISD::InputArg> &Ins, 72*9880d681SAndroid Build Coastguard Worker const SDLoc &DL, SelectionDAG &DAG, 73*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<SDValue> &InVals) const override; 74*9880d681SAndroid Build Coastguard Worker 75*9880d681SAndroid Build Coastguard Worker SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg, 76*9880d681SAndroid Build Coastguard Worker const SmallVectorImpl<ISD::OutputArg> &Outs, 77*9880d681SAndroid Build Coastguard Worker const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL, 78*9880d681SAndroid Build Coastguard Worker SelectionDAG &DAG) const override; 79*9880d681SAndroid Build Coastguard Worker getOptimalMemOpType(uint64_t Size,unsigned DstAlign,unsigned SrcAlign,bool IsMemset,bool ZeroMemset,bool MemcpyStrSrc,MachineFunction & MF)80*9880d681SAndroid Build Coastguard Worker EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign, 81*9880d681SAndroid Build Coastguard Worker bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc, 82*9880d681SAndroid Build Coastguard Worker MachineFunction &MF) const override { 83*9880d681SAndroid Build Coastguard Worker return Size >= 8 ? MVT::i64 : MVT::i32; 84*9880d681SAndroid Build Coastguard Worker } 85*9880d681SAndroid Build Coastguard Worker shouldConvertConstantLoadToIntImm(const APInt & Imm,Type * Ty)86*9880d681SAndroid Build Coastguard Worker bool shouldConvertConstantLoadToIntImm(const APInt &Imm, 87*9880d681SAndroid Build Coastguard Worker Type *Ty) const override { 88*9880d681SAndroid Build Coastguard Worker return true; 89*9880d681SAndroid Build Coastguard Worker } 90*9880d681SAndroid Build Coastguard Worker }; 91*9880d681SAndroid Build Coastguard Worker } 92*9880d681SAndroid Build Coastguard Worker 93*9880d681SAndroid Build Coastguard Worker #endif 94