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