BPFTargetTransformInfo.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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::OperandValueKind Opd1Info = TTI::OK_AnyValue,
  50. TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue,
  51. TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
  52. TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
  53. ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
  54. const Instruction *CxtI = nullptr) {
  55. int ISD = TLI->InstructionOpcodeToISD(Opcode);
  56. if (ISD == ISD::ADD && CostKind == TTI::TCK_RecipThroughput)
  57. return SCEVCheapExpansionBudget.getValue() + 1;
  58. return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info,
  59. Opd2Info, Opd1PropInfo,
  60. Opd2PropInfo);
  61. }
  62. };
  63. } // end namespace llvm
  64. #endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H