BPFTargetTransformInfo.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file uses the target's specific information to
  10. // provide more precise answers to certain TTI queries, while letting the
  11. // target independent and default TTI implementations handle the rest.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
  15. #define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
  16. #include "BPFTargetMachine.h"
  17. #include "llvm/Analysis/TargetTransformInfo.h"
  18. #include "llvm/CodeGen/BasicTTIImpl.h"
  19. #include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
  20. namespace llvm {
  21. class BPFTTIImpl : public BasicTTIImplBase<BPFTTIImpl> {
  22. typedef BasicTTIImplBase<BPFTTIImpl> BaseT;
  23. typedef TargetTransformInfo TTI;
  24. friend BaseT;
  25. const BPFSubtarget *ST;
  26. const BPFTargetLowering *TLI;
  27. const BPFSubtarget *getST() const { return ST; }
  28. const BPFTargetLowering *getTLI() const { return TLI; }
  29. public:
  30. explicit BPFTTIImpl(const BPFTargetMachine *TM, const Function &F)
  31. : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
  32. TLI(ST->getTargetLowering()) {}
  33. int getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) {
  34. if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))
  35. return TTI::TCC_Free;
  36. return TTI::TCC_Basic;
  37. }
  38. InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
  39. CmpInst::Predicate VecPred,
  40. TTI::TargetCostKind CostKind,
  41. const llvm::Instruction *I = nullptr) {
  42. if (Opcode == Instruction::Select)
  43. return SCEVCheapExpansionBudget.getValue();
  44. return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
  45. I);
  46. }
  47. InstructionCost getArithmeticInstrCost(
  48. unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
  49. TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
  50. TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
  51. ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
  52. const Instruction *CxtI = nullptr) {
  53. int ISD = TLI->InstructionOpcodeToISD(Opcode);
  54. if (ISD == ISD::ADD && CostKind == TTI::TCK_RecipThroughput)
  55. return SCEVCheapExpansionBudget.getValue() + 1;
  56. return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
  57. Op2Info);
  58. }
  59. TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize,
  60. bool IsZeroCmp) const {
  61. TTI::MemCmpExpansionOptions Options;
  62. Options.LoadSizes = {8, 4, 2, 1};
  63. Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);
  64. return Options;
  65. }
  66. };
  67. } // end namespace llvm
  68. #endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H