1 //===------ BPFTargetTransformInfo.h - BPF specific TTI ---------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
16 #define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
18 #include "BPFTargetMachine.h"
19 #include "llvm/Analysis/TargetTransformInfo.h"
20 #include "llvm/CodeGen/BasicTTIImpl.h"
21 #include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
24 class BPFTTIImpl
: public BasicTTIImplBase
<BPFTTIImpl
> {
25 typedef BasicTTIImplBase
<BPFTTIImpl
> BaseT
;
26 typedef TargetTransformInfo TTI
;
29 const BPFSubtarget
*ST
;
30 const BPFTargetLowering
*TLI
;
32 const BPFSubtarget
*getST() const { return ST
; }
33 const BPFTargetLowering
*getTLI() const { return TLI
; }
36 explicit BPFTTIImpl(const BPFTargetMachine
*TM
, const Function
&F
)
37 : BaseT(TM
, F
.getParent()->getDataLayout()), ST(TM
->getSubtargetImpl(F
)),
38 TLI(ST
->getTargetLowering()) {}
40 int getIntImmCost(const APInt
&Imm
, Type
*Ty
, TTI::TargetCostKind CostKind
) {
41 if (Imm
.getBitWidth() <= 64 && isInt
<32>(Imm
.getSExtValue()))
44 return TTI::TCC_Basic
;
47 InstructionCost
getCmpSelInstrCost(unsigned Opcode
, Type
*ValTy
, Type
*CondTy
,
48 CmpInst::Predicate VecPred
,
49 TTI::TargetCostKind CostKind
,
50 const llvm::Instruction
*I
= nullptr) {
51 if (Opcode
== Instruction::Select
)
52 return SCEVCheapExpansionBudget
.getValue();
54 return BaseT::getCmpSelInstrCost(Opcode
, ValTy
, CondTy
, VecPred
, CostKind
,
58 InstructionCost
getArithmeticInstrCost(
59 unsigned Opcode
, Type
*Ty
,
60 TTI::TargetCostKind CostKind
= TTI::TCK_RecipThroughput
,
61 TTI::OperandValueKind Opd1Info
= TTI::OK_AnyValue
,
62 TTI::OperandValueKind Opd2Info
= TTI::OK_AnyValue
,
63 TTI::OperandValueProperties Opd1PropInfo
= TTI::OP_None
,
64 TTI::OperandValueProperties Opd2PropInfo
= TTI::OP_None
,
65 ArrayRef
<const Value
*> Args
= ArrayRef
<const Value
*>(),
66 const Instruction
*CxtI
= nullptr) {
67 int ISD
= TLI
->InstructionOpcodeToISD(Opcode
);
68 if (ISD
== ISD::ADD
&& CostKind
== TTI::TCK_RecipThroughput
)
69 return SCEVCheapExpansionBudget
.getValue() + 1;
71 return BaseT::getArithmeticInstrCost(Opcode
, Ty
, CostKind
, Opd1Info
,
72 Opd2Info
, Opd1PropInfo
,
77 } // end namespace llvm
79 #endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H