123408297SDimitry Andric //===------ BPFTargetTransformInfo.h - BPF specific TTI ---------*- C++ -*-===// 223408297SDimitry Andric // 323408297SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 423408297SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 523408297SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 623408297SDimitry Andric // 723408297SDimitry Andric //===----------------------------------------------------------------------===// 823408297SDimitry Andric // 923408297SDimitry Andric // This file uses the target's specific information to 1023408297SDimitry Andric // provide more precise answers to certain TTI queries, while letting the 1123408297SDimitry Andric // target independent and default TTI implementations handle the rest. 1223408297SDimitry Andric // 1323408297SDimitry Andric //===----------------------------------------------------------------------===// 1423408297SDimitry Andric 1523408297SDimitry Andric #ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H 1623408297SDimitry Andric #define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H 1723408297SDimitry Andric 1823408297SDimitry Andric #include "BPFTargetMachine.h" 1923408297SDimitry Andric #include "llvm/Analysis/TargetTransformInfo.h" 2023408297SDimitry Andric #include "llvm/CodeGen/BasicTTIImpl.h" 2123408297SDimitry Andric #include "llvm/Transforms/Utils/ScalarEvolutionExpander.h" 2223408297SDimitry Andric 2323408297SDimitry Andric namespace llvm { 2423408297SDimitry Andric class BPFTTIImpl : public BasicTTIImplBase<BPFTTIImpl> { 2523408297SDimitry Andric typedef BasicTTIImplBase<BPFTTIImpl> BaseT; 2623408297SDimitry Andric typedef TargetTransformInfo TTI; 2723408297SDimitry Andric friend BaseT; 2823408297SDimitry Andric 2923408297SDimitry Andric const BPFSubtarget *ST; 3023408297SDimitry Andric const BPFTargetLowering *TLI; 3123408297SDimitry Andric getST()3223408297SDimitry Andric const BPFSubtarget *getST() const { return ST; } getTLI()3323408297SDimitry Andric const BPFTargetLowering *getTLI() const { return TLI; } 3423408297SDimitry Andric 3523408297SDimitry Andric public: BPFTTIImpl(const BPFTargetMachine * TM,const Function & F)3623408297SDimitry Andric explicit BPFTTIImpl(const BPFTargetMachine *TM, const Function &F) 37*0fca6ea1SDimitry Andric : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)), 3823408297SDimitry Andric TLI(ST->getTargetLowering()) {} 3923408297SDimitry Andric getIntImmCost(const APInt & Imm,Type * Ty,TTI::TargetCostKind CostKind)4023408297SDimitry Andric int getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) { 4123408297SDimitry Andric if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue())) 4223408297SDimitry Andric return TTI::TCC_Free; 4323408297SDimitry Andric 4423408297SDimitry Andric return TTI::TCC_Basic; 4523408297SDimitry Andric } 4623408297SDimitry Andric 47fe6060f1SDimitry Andric InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, 4823408297SDimitry Andric CmpInst::Predicate VecPred, 4923408297SDimitry Andric TTI::TargetCostKind CostKind, 5023408297SDimitry Andric const llvm::Instruction *I = nullptr) { 5123408297SDimitry Andric if (Opcode == Instruction::Select) 52fe6060f1SDimitry Andric return SCEVCheapExpansionBudget.getValue(); 5323408297SDimitry Andric 5423408297SDimitry Andric return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, 5523408297SDimitry Andric I); 5623408297SDimitry Andric } 576e75b2fbSDimitry Andric 586e75b2fbSDimitry Andric InstructionCost getArithmeticInstrCost( 59349cc55cSDimitry Andric unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, 60bdd1243dSDimitry Andric TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None}, 61bdd1243dSDimitry Andric TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None}, 62*0fca6ea1SDimitry Andric ArrayRef<const Value *> Args = std::nullopt, 636e75b2fbSDimitry Andric const Instruction *CxtI = nullptr) { 646e75b2fbSDimitry Andric int ISD = TLI->InstructionOpcodeToISD(Opcode); 656e75b2fbSDimitry Andric if (ISD == ISD::ADD && CostKind == TTI::TCK_RecipThroughput) 666e75b2fbSDimitry Andric return SCEVCheapExpansionBudget.getValue() + 1; 676e75b2fbSDimitry Andric 68bdd1243dSDimitry Andric return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, 69bdd1243dSDimitry Andric Op2Info); 706e75b2fbSDimitry Andric } 7181ad6265SDimitry Andric enableMemCmpExpansion(bool OptSize,bool IsZeroCmp)7281ad6265SDimitry Andric TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, 7381ad6265SDimitry Andric bool IsZeroCmp) const { 7481ad6265SDimitry Andric TTI::MemCmpExpansionOptions Options; 7581ad6265SDimitry Andric Options.LoadSizes = {8, 4, 2, 1}; 7681ad6265SDimitry Andric Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize); 7781ad6265SDimitry Andric return Options; 7881ad6265SDimitry Andric } 7981ad6265SDimitry Andric getMaxNumArgs()8006c3fb27SDimitry Andric unsigned getMaxNumArgs() const { 8106c3fb27SDimitry Andric return 5; 8206c3fb27SDimitry Andric } 8306c3fb27SDimitry Andric 8423408297SDimitry Andric }; 8523408297SDimitry Andric 8623408297SDimitry Andric } // end namespace llvm 8723408297SDimitry Andric 8823408297SDimitry Andric #endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H 89