LLVM  14.0.0git
BPFTargetTransformInfo.h
Go to the documentation of this file.
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 
15 #ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
16 #define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
17 
18 #include "BPFTargetMachine.h"
22 
23 namespace llvm {
24 class BPFTTIImpl : public BasicTTIImplBase<BPFTTIImpl> {
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 
35 public:
36  explicit BPFTTIImpl(const BPFTargetMachine *TM, const Function &F)
37  : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
38  TLI(ST->getTargetLowering()) {}
39 
41  if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))
42  return TTI::TCC_Free;
43 
44  return TTI::TCC_Basic;
45  }
46 
47  InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
48  CmpInst::Predicate VecPred,
50  const llvm::Instruction *I = nullptr) {
51  if (Opcode == Instruction::Select)
52  return SCEVCheapExpansionBudget.getValue();
53 
54  return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
55  I);
56  }
57 
59  unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
65  const Instruction *CxtI = nullptr) {
66  int ISD = TLI->InstructionOpcodeToISD(Opcode);
68  return SCEVCheapExpansionBudget.getValue() + 1;
69 
70  return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info,
71  Opd2Info, Opd1PropInfo,
72  Opd2PropInfo);
73  }
74 };
75 
76 } // end namespace llvm
77 
78 #endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H
llvm::InstructionCost
Definition: InstructionCost.h:29
llvm::TargetTransformInfo::TargetCostKind
TargetCostKind
The kind of cost model.
Definition: TargetTransformInfo.h:211
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::BPFTTIImpl
Definition: BPFTargetTransformInfo.h:24
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:720
llvm::BPFTTIImpl::getCmpSelInstrCost
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, const llvm::Instruction *I=nullptr)
Definition: BPFTargetTransformInfo.h:47
ScalarEvolutionExpander.h
llvm::Function
Definition: Function.h:62
llvm::APInt::getSExtValue
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1474
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:168
llvm::BasicTTIImplBase< BPFTTIImpl >::getArithmeticInstrCost
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value * > Args=ArrayRef< const Value * >(), const Instruction *CxtI=nullptr)
Definition: BasicTTIImpl.h:751
llvm::BPFTTIImpl::getArithmeticInstrCost
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value * > Args=ArrayRef< const Value * >(), const Instruction *CxtI=nullptr)
Definition: BPFTargetTransformInfo.h:58
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::APInt::getBitWidth
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1410
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::TargetTransformInfoImplBase::getDataLayout
const DataLayout & getDataLayout() const
Definition: TargetTransformInfoImpl.h:48
llvm::BPFTTIImpl::getIntImmCost
int getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind)
Definition: BPFTargetTransformInfo.h:40
llvm::TargetTransformInfo::OP_None
@ OP_None
Definition: TargetTransformInfo.h:886
llvm::Instruction
Definition: Instruction.h:45
llvm::BasicTTIImplBase< BPFTTIImpl >::getCmpSelInstrCost
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, const Instruction *I=nullptr)
Definition: BasicTTIImpl.h:1060
llvm::isInt< 32 >
constexpr bool isInt< 32 >(int64_t x)
Definition: MathExtras.h:373
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::TargetTransformInfo::OperandValueProperties
OperandValueProperties
Additional properties of an operand's values.
Definition: TargetTransformInfo.h:886
llvm::SCEVCheapExpansionBudget
cl::opt< unsigned > SCEVCheapExpansionBudget
llvm::BasicTTIImplBase
Base class which can be used to help build a TTI implementation.
Definition: BasicTTIImpl.h:77
llvm::TargetTransformInfo::OperandValueKind
OperandValueKind
Additional information about an operand's possible values.
Definition: TargetTransformInfo.h:878
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::TargetTransformInfo::TCC_Free
@ TCC_Free
Expected to fold away in lowering.
Definition: TargetTransformInfo.h:262
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
CostKind
static cl::opt< TargetTransformInfo::TargetCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(TargetTransformInfo::TCK_RecipThroughput), cl::values(clEnumValN(TargetTransformInfo::TCK_RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(TargetTransformInfo::TCK_Latency, "latency", "Instruction latency"), clEnumValN(TargetTransformInfo::TCK_CodeSize, "code-size", "Code size"), clEnumValN(TargetTransformInfo::TCK_SizeAndLatency, "size-latency", "Code size and latency")))
getParent
static const Function * getParent(const Value *V)
Definition: BasicAliasAnalysis.cpp:890
llvm::TargetLoweringBase::InstructionOpcodeToISD
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
Definition: TargetLoweringBase.cpp:1767
llvm::BPFTTIImpl::BPFTTIImpl
BPFTTIImpl(const BPFTargetMachine *TM, const Function &F)
Definition: BPFTargetTransformInfo.h:36
llvm::TargetTransformInfo::OK_AnyValue
@ OK_AnyValue
Definition: TargetTransformInfo.h:879
llvm::BPFTargetMachine
Definition: BPFTargetMachine.h:20
llvm::MCID::Select
@ Select
Definition: MCInstrDesc.h:162
llvm::BPFTargetLowering
Definition: BPFISelLowering.h:35
llvm::ISD::ADD
@ ADD
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:239
TargetTransformInfo.h
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::TargetTransformInfo::TCC_Basic
@ TCC_Basic
The cost of a typical 'add' instruction.
Definition: TargetTransformInfo.h:263
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
BasicTTIImpl.h
llvm::TargetTransformInfo::TCK_RecipThroughput
@ TCK_RecipThroughput
Reciprocal throughput.
Definition: TargetTransformInfo.h:212
llvm::BPFSubtarget
Definition: BPFSubtarget.h:31
BPFTargetMachine.h