LLVM 24.0.0git
BPFISelLowering.h
Go to the documentation of this file.
1//===-- BPFISelLowering.h - BPF DAG Lowering Interface ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the interfaces that BPF uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_BPF_BPFISELLOWERING_H
15#define LLVM_LIB_TARGET_BPF_BPFISELLOWERING_H
16
17#include "BPF.h"
20
21namespace llvm {
22class BPFSubtarget;
23
25public:
26 explicit BPFTargetLowering(const TargetMachine &TM, const BPFSubtarget &STI);
27
28 // Provide custom lowering hooks for some operations.
29 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
30
31 // This method decides whether folding a constant offset
32 // with the given GlobalAddress is legal.
33 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
34
35 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned, Align,
37 unsigned *) const override;
38
40 getConstraintType(StringRef Constraint) const override;
41
42 std::pair<unsigned, const TargetRegisterClass *>
44 StringRef Constraint, MVT VT) const override;
45
48 MachineBasicBlock *BB) const override;
49
51 shouldExpandAtomicRMWInIR(const AtomicRMWInst *AI) const override;
53 shouldExpandAtomicStoreInIR(const StoreInst *SI) const override;
54
55 bool getHasAlu32() const { return HasAlu32; }
56 bool getHasJmp32() const { return HasJmp32; }
57 bool getHasJmpExt() const { return HasJmpExt; }
58
60 EVT VT) const override;
61
62 // Exception handling support.
64 const Constant *) const override {
65 return BPF::R0;
66 }
68 const Constant *) const override {
69 return BPF::R0;
70 }
71
72 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override;
73
74 unsigned getJumpTableEncoding() const override;
75
76 /// The entries are addresses of blocks, also in position independent code.
77 bool isJumpTableRelative() const override { return false; }
78
79private:
80 // Control Instruction Selection Features
81 bool HasAlu32;
82 bool HasJmp32;
83 bool HasJmpExt;
84 bool HasMovsx;
85 bool HasLoadAcqStoreRel;
86
87 // Allows Misalignment
88 bool AllowsMisalignedMemAccess;
89
90 SDValue LowerSDIVSREM(SDValue Op, SelectionDAG &DAG) const;
97 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
98 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
99 SDValue LowerTRAP(SDValue Op, SelectionDAG &DAG) const;
100 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
101 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
102 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
103
104 template <class NodeTy>
105 SDValue getAddr(NodeTy *N, SelectionDAG &DAG, unsigned Flags = 0) const;
106
107 // Lower the result values of a call, copying them out of physregs into vregs
109 CallingConv::ID CallConv, bool IsVarArg,
111 const SDLoc &DL, SelectionDAG &DAG,
112 SmallVectorImpl<SDValue> &InVals) const;
113
114 // Lower a call into CALLSEQ_START - BPFISD:CALL - CALLSEQ_END chain
116 SmallVectorImpl<SDValue> &InVals) const override;
117
118 // Lower incoming arguments, copy physregs into vregs
119 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
120 bool IsVarArg,
122 const SDLoc &DL, SelectionDAG &DAG,
123 SmallVectorImpl<SDValue> &InVals) const override;
124
125 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
127 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
128 SelectionDAG &DAG) const override;
129
130 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
131 SelectionDAG &DAG) const override;
132
133 bool isIntDivCheap(EVT VT, AttributeList Attr) const override {
134 return false;
135 }
136
137 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
138 Type *Ty) const override {
139 return true;
140 }
141
142 // Prevent reducing load width during SelectionDag phase.
143 // Otherwise, we may transform the following
144 // ctx = ctx + reloc_offset
145 // ... (*(u32 *)ctx) & 0x8000...
146 // to
147 // ctx = ctx + reloc_offset
148 // ... (*(u8 *)(ctx + 1)) & 0x80 ...
149 // which will be rejected by the verifier.
150 bool
151 shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy, EVT NewVT,
152 std::optional<unsigned> ByteOffset) const override {
153 return false;
154 }
155
156 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
157 Type *Ty, unsigned AS,
158 Instruction *I = nullptr) const override;
159
160 // isTruncateFree - Return true if it's free to truncate a value of
161 // type Ty1 to type Ty2. e.g. On BPF at alu32 mode, it's free to truncate
162 // a i64 value in register R1 to i32 by referencing its sub-register W1.
163 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
164 bool isTruncateFree(EVT VT1, EVT VT2) const override;
165
166 // For 32bit ALU result zext to 64bit is free.
167 bool isZExtFree(Type *Ty1, Type *Ty2) const override;
168 bool isZExtFree(EVT VT1, EVT VT2) const override;
169 bool isZExtFree(SDValue Val, EVT VT2) const override;
170
171 unsigned EmitSubregExt(MachineInstr &MI, MachineBasicBlock *BB, unsigned Reg,
172 bool isSigned) const;
173
174 MachineBasicBlock * EmitInstrWithCustomInserterMemcpy(MachineInstr &MI,
175 MachineBasicBlock *BB)
176 const;
177 MachineBasicBlock *
178 EmitInstrWithCustomInserterLDimm64(MachineInstr &MI,
179 MachineBasicBlock *BB) const;
180
181 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
182 bool IsVarArg,
183 const SmallVectorImpl<ISD::OutputArg> &Outs,
184 LLVMContext &Context, const Type *RetTy) const override;
185};
186}
187
188#endif
return SDValue()
uint64_t Imm
static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, const ARMSubtarget *Subtarget)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
static bool isSigned(unsigned Opcode)
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
static SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG, const SparcSubtarget *Subtarget)
static SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad, bool isV9, bool is64Bit)
static SDValue LowerATOMIC_LOAD_STORE(SDValue Op, SelectionDAG &DAG)
static SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad, bool isV9, bool is64Bit)
This file describes how to lower LLVM code to machine code.
static SDValue LowerShiftParts(SDValue Op, SelectionDAG &DAG)
Lower SRA_PARTS and friends, which return two i32 values and take a 2 x i32 value to shift plus a shi...
static SDValue LowerCallResult(SDValue Chain, SDValue InGlue, const SmallVectorImpl< CCValAssign > &RVLocs, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals)
LowerCallResult - Lower the result values of a call into the appropriate copies out of appropriate ph...
an instruction that atomically reads a memory location, combines it with another value,...
BPFTargetLowering::ConstraintType getConstraintType(StringRef Constraint) const override
Given a constraint, return the type of constraint it is for this target.
unsigned getJumpTableEncoding() const override
Return the entry encoding for a jump table in the current function.
bool isJumpTableRelative() const override
The entries are addresses of blocks, also in position independent code.
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override
Return true if folding a constant offset with the given GlobalAddress is legal.
AtomicExpansionKind shouldExpandAtomicRMWInIR(const AtomicRMWInst *AI) const override
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all.
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned, Align, MachineMemOperand::Flags, unsigned *) const override
Determine if the target supports unaligned memory accesses.
Register getExceptionPointerRegister(ExceptionHandling EH, const Constant *) const override
If a physical register, this returns the register that receives the exception address on entry to an ...
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
Return the ValueType of the result of SETCC operations.
BPFTargetLowering(const TargetMachine &TM, const BPFSubtarget &STI)
AtomicExpansionKind shouldExpandAtomicStoreInIR(const StoreInst *SI) const override
Returns how the given (atomic) store should be expanded by the IR-level AtomicExpand pass into.
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *BB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override
Return the type to use for a scalar shift opcode, given the shifted amount type.
Register getExceptionSelectorRegister(ExceptionHandling EH, const Constant *) const override
If a physical register, this returns the register that receives the exception typeid on entry to a la...
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
This is an important base class in LLVM.
Definition Constant.h:44
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Machine Value Type.
Representation of each machine instruction.
Flags
Flags values. These may be or'd together.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
TargetLowering(const TargetLowering &)=delete
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
This is an optimization pass for GlobalISel generic memory operations.
@ Load
The value being inserted comes from a load (InsertElement only).
DWARFExpression::Operation Op
ExceptionHandling
Definition CodeGen.h:54
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Extended Value Type.
Definition ValueTypes.h:35
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*...
This structure contains all information that is necessary for lowering calls.