Path: blob/main/contrib/llvm-project/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
35269 views
//===------ BPFTargetTransformInfo.h - BPF specific TTI ---------*- 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 uses the target's specific information to9// provide more precise answers to certain TTI queries, while letting the10// target independent and default TTI implementations handle the rest.11//12//===----------------------------------------------------------------------===//1314#ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H15#define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H1617#include "BPFTargetMachine.h"18#include "llvm/Analysis/TargetTransformInfo.h"19#include "llvm/CodeGen/BasicTTIImpl.h"20#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"2122namespace llvm {23class BPFTTIImpl : public BasicTTIImplBase<BPFTTIImpl> {24typedef BasicTTIImplBase<BPFTTIImpl> BaseT;25typedef TargetTransformInfo TTI;26friend BaseT;2728const BPFSubtarget *ST;29const BPFTargetLowering *TLI;3031const BPFSubtarget *getST() const { return ST; }32const BPFTargetLowering *getTLI() const { return TLI; }3334public:35explicit BPFTTIImpl(const BPFTargetMachine *TM, const Function &F)36: BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),37TLI(ST->getTargetLowering()) {}3839int getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) {40if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))41return TTI::TCC_Free;4243return TTI::TCC_Basic;44}4546InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,47CmpInst::Predicate VecPred,48TTI::TargetCostKind CostKind,49const llvm::Instruction *I = nullptr) {50if (Opcode == Instruction::Select)51return SCEVCheapExpansionBudget.getValue();5253return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,54I);55}5657InstructionCost getArithmeticInstrCost(58unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,59TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},60TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},61ArrayRef<const Value *> Args = std::nullopt,62const Instruction *CxtI = nullptr) {63int ISD = TLI->InstructionOpcodeToISD(Opcode);64if (ISD == ISD::ADD && CostKind == TTI::TCK_RecipThroughput)65return SCEVCheapExpansionBudget.getValue() + 1;6667return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,68Op2Info);69}7071TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize,72bool IsZeroCmp) const {73TTI::MemCmpExpansionOptions Options;74Options.LoadSizes = {8, 4, 2, 1};75Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);76return Options;77}7879unsigned getMaxNumArgs() const {80return 5;81}8283};8485} // end namespace llvm8687#endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H888990