Path: blob/main/contrib/llvm-project/llvm/lib/Target/BPF/BPFISelLowering.h
35269 views
//===-- BPFISelLowering.h - BPF DAG Lowering Interface ----------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines the interfaces that BPF uses to lower LLVM code into a9// selection DAG.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_LIB_TARGET_BPF_BPFISELLOWERING_H14#define LLVM_LIB_TARGET_BPF_BPFISELLOWERING_H1516#include "BPF.h"17#include "llvm/CodeGen/SelectionDAG.h"18#include "llvm/CodeGen/TargetLowering.h"1920namespace llvm {21class BPFSubtarget;22namespace BPFISD {23enum NodeType : unsigned {24FIRST_NUMBER = ISD::BUILTIN_OP_END,25RET_GLUE,26CALL,27SELECT_CC,28BR_CC,29Wrapper,30MEMCPY31};32}3334class BPFTargetLowering : public TargetLowering {35public:36explicit BPFTargetLowering(const TargetMachine &TM, const BPFSubtarget &STI);3738// Provide custom lowering hooks for some operations.39SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;4041// This method returns the name of a target specific DAG node.42const char *getTargetNodeName(unsigned Opcode) const override;4344// This method decides whether folding a constant offset45// with the given GlobalAddress is legal.46bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;4748BPFTargetLowering::ConstraintType49getConstraintType(StringRef Constraint) const override;5051std::pair<unsigned, const TargetRegisterClass *>52getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,53StringRef Constraint, MVT VT) const override;5455MachineBasicBlock *56EmitInstrWithCustomInserter(MachineInstr &MI,57MachineBasicBlock *BB) const override;5859bool getHasAlu32() const { return HasAlu32; }60bool getHasJmp32() const { return HasJmp32; }61bool getHasJmpExt() const { return HasJmpExt; }6263EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,64EVT VT) const override;6566MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override;6768private:69// Control Instruction Selection Features70bool HasAlu32;71bool HasJmp32;72bool HasJmpExt;73bool HasMovsx;7475SDValue LowerSDIVSREM(SDValue Op, SelectionDAG &DAG) const;76SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;77SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;78SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;7980SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;81SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;8283template <class NodeTy>84SDValue getAddr(NodeTy *N, SelectionDAG &DAG, unsigned Flags = 0) const;8586// Lower the result values of a call, copying them out of physregs into vregs87SDValue LowerCallResult(SDValue Chain, SDValue InGlue,88CallingConv::ID CallConv, bool IsVarArg,89const SmallVectorImpl<ISD::InputArg> &Ins,90const SDLoc &DL, SelectionDAG &DAG,91SmallVectorImpl<SDValue> &InVals) const;9293// Maximum number of arguments to a call94static const size_t MaxArgs;9596// Lower a call into CALLSEQ_START - BPFISD:CALL - CALLSEQ_END chain97SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,98SmallVectorImpl<SDValue> &InVals) const override;99100// Lower incoming arguments, copy physregs into vregs101SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,102bool IsVarArg,103const SmallVectorImpl<ISD::InputArg> &Ins,104const SDLoc &DL, SelectionDAG &DAG,105SmallVectorImpl<SDValue> &InVals) const override;106107SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,108const SmallVectorImpl<ISD::OutputArg> &Outs,109const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,110SelectionDAG &DAG) const override;111112void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,113SelectionDAG &DAG) const override;114115EVT getOptimalMemOpType(const MemOp &Op,116const AttributeList &FuncAttributes) const override {117return Op.size() >= 8 ? MVT::i64 : MVT::i32;118}119120bool isIntDivCheap(EVT VT, AttributeList Attr) const override { return true; }121122bool shouldConvertConstantLoadToIntImm(const APInt &Imm,123Type *Ty) const override {124return true;125}126127// Prevent reducing load width during SelectionDag phase.128// Otherwise, we may transform the following129// ctx = ctx + reloc_offset130// ... (*(u32 *)ctx) & 0x8000...131// to132// ctx = ctx + reloc_offset133// ... (*(u8 *)(ctx + 1)) & 0x80 ...134// which will be rejected by the verifier.135bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy,136EVT NewVT) const override {137return false;138}139140bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,141Type *Ty, unsigned AS,142Instruction *I = nullptr) const override;143144// isTruncateFree - Return true if it's free to truncate a value of145// type Ty1 to type Ty2. e.g. On BPF at alu32 mode, it's free to truncate146// a i64 value in register R1 to i32 by referencing its sub-register W1.147bool isTruncateFree(Type *Ty1, Type *Ty2) const override;148bool isTruncateFree(EVT VT1, EVT VT2) const override;149150// For 32bit ALU result zext to 64bit is free.151bool isZExtFree(Type *Ty1, Type *Ty2) const override;152bool isZExtFree(EVT VT1, EVT VT2) const override;153bool isZExtFree(SDValue Val, EVT VT2) const override;154155unsigned EmitSubregExt(MachineInstr &MI, MachineBasicBlock *BB, unsigned Reg,156bool isSigned) const;157158MachineBasicBlock * EmitInstrWithCustomInserterMemcpy(MachineInstr &MI,159MachineBasicBlock *BB)160const;161162};163}164165#endif166167168