]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/BPF/BPFISelLowering.h
Merge ^/head r326936 through r327149.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / BPF / BPFISelLowering.h
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/CodeGen/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   // This method decides whether folding a constant offset
46   // with the given GlobalAddress is legal.
47   bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
48
49   std::pair<unsigned, const TargetRegisterClass *>
50   getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
51                                StringRef Constraint, MVT VT) const override;
52
53   MachineBasicBlock *
54   EmitInstrWithCustomInserter(MachineInstr &MI,
55                               MachineBasicBlock *BB) const override;
56
57   bool getHasJmpExt() const { return HasJmpExt; }
58
59 private:
60   // Control Instruction Selection Features
61   bool HasJmpExt;
62
63   SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
64   SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
65   SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
66
67   // Lower the result values of a call, copying them out of physregs into vregs
68   SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
69                           CallingConv::ID CallConv, bool IsVarArg,
70                           const SmallVectorImpl<ISD::InputArg> &Ins,
71                           const SDLoc &DL, SelectionDAG &DAG,
72                           SmallVectorImpl<SDValue> &InVals) const;
73
74   // Maximum number of arguments to a call
75   static const unsigned MaxArgs;
76
77   // Lower a call into CALLSEQ_START - BPFISD:CALL - CALLSEQ_END chain
78   SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
79                     SmallVectorImpl<SDValue> &InVals) const override;
80
81   // Lower incoming arguments, copy physregs into vregs
82   SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
83                                bool IsVarArg,
84                                const SmallVectorImpl<ISD::InputArg> &Ins,
85                                const SDLoc &DL, SelectionDAG &DAG,
86                                SmallVectorImpl<SDValue> &InVals) const override;
87
88   SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
89                       const SmallVectorImpl<ISD::OutputArg> &Outs,
90                       const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
91                       SelectionDAG &DAG) const override;
92
93   EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign,
94                           bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
95                           MachineFunction &MF) const override {
96     return Size >= 8 ? MVT::i64 : MVT::i32;
97   }
98
99   bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
100                                          Type *Ty) const override {
101     return true;
102   }
103 };
104 }
105
106 #endif