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