brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · d7b2cef Raw
89 lines · c
1//===------ BPFTargetTransformInfo.h - BPF specific TTI ---------*- 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-exception6//7//===----------------------------------------------------------------------===//8//9// This file uses the target's specific information to10// provide more precise answers to certain TTI queries, while letting the11// target independent and default TTI implementations handle the rest.12//13//===----------------------------------------------------------------------===//14 15#ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H16#define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H17 18#include "BPFTargetMachine.h"19#include "llvm/Analysis/TargetTransformInfo.h"20#include "llvm/CodeGen/BasicTTIImpl.h"21#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"22 23namespace llvm {24class BPFTTIImpl final : public BasicTTIImplBase<BPFTTIImpl> {25  typedef BasicTTIImplBase<BPFTTIImpl> BaseT;26  typedef TargetTransformInfo TTI;27  friend BaseT;28 29  const BPFSubtarget *ST;30  const BPFTargetLowering *TLI;31 32  const BPFSubtarget *getST() const { return ST; }33  const BPFTargetLowering *getTLI() const { return TLI; }34 35public:36  explicit BPFTTIImpl(const BPFTargetMachine *TM, const Function &F)37      : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),38        TLI(ST->getTargetLowering()) {}39 40  InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,41                                TTI::TargetCostKind CostKind) const override {42    if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))43      return TTI::TCC_Free;44 45    return TTI::TCC_Basic;46  }47 48  InstructionCost getCmpSelInstrCost(49      unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,50      TTI::TargetCostKind CostKind,51      TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},52      TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},53      const llvm::Instruction *I = nullptr) const override {54    if (Opcode == Instruction::Select)55      return SCEVCheapExpansionBudget.getValue();56 57    return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,58                                     Op1Info, Op2Info, I);59  }60 61  InstructionCost getArithmeticInstrCost(62      unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,63      TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},64      TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},65      ArrayRef<const Value *> Args = {},66      const Instruction *CxtI = nullptr) const override {67    int ISD = TLI->InstructionOpcodeToISD(Opcode);68    if (ISD == ISD::ADD && CostKind == TTI::TCK_RecipThroughput)69      return SCEVCheapExpansionBudget.getValue() + 1;70 71    return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,72                                         Op2Info);73  }74 75  TTI::MemCmpExpansionOptions76  enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const override {77    TTI::MemCmpExpansionOptions Options;78    Options.LoadSizes = {8, 4, 2, 1};79    Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);80    return Options;81  }82 83  unsigned getMaxNumArgs() const override { return 5; }84};85 86} // end namespace llvm87 88#endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H89