LLVM  16.0.0git
HexagonTargetTransformInfo.h
Go to the documentation of this file.
1 //==- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass -*- 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 /// \file
8 /// This file implements a TargetTransformInfo analysis pass specific to the
9 /// Hexagon target machine. It uses the target's detailed information to provide
10 /// more precise answers to certain TTI queries, while letting the target
11 /// independent and default TTI implementations handle the rest.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
16 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
17 
18 #include "Hexagon.h"
19 #include "HexagonSubtarget.h"
20 #include "HexagonTargetMachine.h"
21 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/IR/Function.h"
25 
26 namespace llvm {
27 
28 class Loop;
29 class ScalarEvolution;
30 class User;
31 class Value;
32 
33 class HexagonTTIImpl : public BasicTTIImplBase<HexagonTTIImpl> {
35  using TTI = TargetTransformInfo;
36 
37  friend BaseT;
38 
39  const HexagonSubtarget &ST;
40  const HexagonTargetLowering &TLI;
41 
42  const HexagonSubtarget *getST() const { return &ST; }
43  const HexagonTargetLowering *getTLI() const { return &TLI; }
44 
45  bool useHVX() const;
46  bool isHVXVectorType(Type *Ty) const;
47 
48  // Returns the number of vector elements of Ty, if Ty is a vector type,
49  // or 1 if Ty is a scalar type. It is incorrect to call this function
50  // with any other type.
51  unsigned getTypeNumElements(Type *Ty) const;
52 
53 public:
54  explicit HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F)
55  : BaseT(TM, F.getParent()->getDataLayout()),
56  ST(*TM->getSubtargetImpl(F)), TLI(*ST.getTargetLowering()) {}
57 
58  /// \name Scalar TTI Implementations
59  /// @{
60 
61  TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
62 
63  // The Hexagon target can unroll loops with run-time trip counts.
67 
70 
71  /// Bias LSR towards creating post-increment opportunities.
73  getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const;
74 
75  // L1 cache prefetch.
76  unsigned getPrefetchDistance() const override;
77  unsigned getCacheLineSize() const override;
78 
79  /// @}
80 
81  /// \name Vector TTI Implementations
82  /// @{
83 
84  unsigned getNumberOfRegisters(bool vector) const;
85  unsigned getMaxInterleaveFactor(unsigned VF);
87  unsigned getMinVectorRegisterBitWidth() const;
88  ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const;
89 
90  bool
92  return true;
93  }
94  bool supportsEfficientVectorElementLoadStore() { return false; }
96  return false;
97  }
98  bool enableAggressiveInterleaving(bool LoopHasReductions) {
99  return false;
100  }
102  return false;
103  }
105  return true;
106  }
107 
109  const APInt &DemandedElts,
110  bool Insert, bool Extract);
112  ArrayRef<Type *> Tys);
114  ArrayRef<Type *> Tys,
119  const SCEV *S);
121  getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment,
124  const Instruction *I = nullptr);
125  InstructionCost getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
126  Align Alignment, unsigned AddressSpace,
128  InstructionCost getShuffleCost(TTI::ShuffleKind Kind, Type *Tp,
129  ArrayRef<int> Mask,
131  Type *SubTp,
132  ArrayRef<const Value *> Args = std::nullopt);
133  InstructionCost getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
134  const Value *Ptr, bool VariableMask,
135  Align Alignment,
137  const Instruction *I);
138  InstructionCost getInterleavedMemoryOpCost(
139  unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
140  Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
141  bool UseMaskForCond = false, bool UseMaskForGaps = false);
142  InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
143  CmpInst::Predicate VecPred,
145  const Instruction *I = nullptr);
146  InstructionCost getArithmeticInstrCost(
147  unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
148  TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
149  TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
150  ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
151  const Instruction *CxtI = nullptr);
152  InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
155  const Instruction *I = nullptr);
157  InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
158  unsigned Index);
159 
161  const Instruction *I = nullptr) {
162  return 1;
163  }
164 
165  bool isLegalMaskedStore(Type *DataType, Align Alignment);
166  bool isLegalMaskedLoad(Type *DataType, Align Alignment);
167 
168  /// @}
169 
173 
174  // Hexagon specific decision to generate a lookup table.
175  bool shouldBuildLookupTables() const;
176 };
177 
178 } // end namespace llvm
179 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
llvm::InstructionCost
Definition: InstructionCost.h:30
llvm::HexagonTTIImpl::getMinVectorRegisterBitWidth
unsigned getMinVectorRegisterBitWidth() const
Definition: HexagonTargetTransformInfo.cpp:131
llvm::objcarc::ARCInstKind::User
@ User
could "use" a pointer
llvm::TargetTransformInfo::TargetCostKind
TargetCostKind
The kind of cost model.
Definition: TargetTransformInfo.h:218
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::HexagonTTIImpl::getArithmeticInstrCost
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args=ArrayRef< const Value * >(), const Instruction *CxtI=nullptr)
Definition: HexagonTargetTransformInfo.cpp:283
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:719
llvm::HexagonTTIImpl::shouldMaximizeVectorBandwidth
bool shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const
Definition: HexagonTargetTransformInfo.h:91
llvm::ElementCount
Definition: TypeSize.h:404
llvm::Function
Definition: Function.h:60
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:547
llvm::TargetTransformInfo::PopcntSupportKind
PopcntSupportKind
Flags indicating the kind of support for population count.
Definition: TargetTransformInfo.h:585
llvm::HexagonTTIImpl::getMemoryOpCost
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr)
Definition: HexagonTargetTransformInfo.cpp:175
HexagonSubtarget.h
llvm::HexagonTargetMachine
Definition: HexagonTargetMachine.h:26
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:173
llvm::ScalarEvolution
The main scalar evolution driver.
Definition: ScalarEvolution.h:449
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::TargetTransformInfo::PeelingPreferences
Definition: TargetTransformInfo.h:529
llvm::HexagonTTIImpl::getMaxInterleaveFactor
unsigned getMaxInterleaveFactor(unsigned VF)
Definition: HexagonTargetTransformInfo.cpp:113
HexagonTargetMachine.h
llvm::TargetTransformInfo::OperandValueInfo
Definition: TargetTransformInfo.h:926
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::HexagonTTIImpl::getGatherScatterOpCost
InstructionCost getGatherScatterOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask, Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I)
Definition: HexagonTargetTransformInfo.cpp:248
llvm::TargetTransformInfoImplBase::getDataLayout
const DataLayout & getDataLayout() const
Definition: TargetTransformInfoImpl.h:47
llvm::BitmaskEnumDetail::Mask
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::HexagonTTIImpl::getVectorInstrCost
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Definition: HexagonTargetTransformInfo.cpp:331
llvm::HexagonTTIImpl::getPopcntSupport
TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const
Definition: HexagonTargetTransformInfo.cpp:74
llvm::BasicTTIImplBase< HexagonTTIImpl >::getVectorInstrCost
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Definition: BasicTTIImpl.h:1187
llvm::TargetTransformInfo::OP_None
@ OP_None
Definition: TargetTransformInfo.h:918
llvm::TargetTransformInfo::ShuffleKind
ShuffleKind
The various kinds of shuffle patterns for vector queries.
Definition: TargetTransformInfo.h:889
llvm::TargetTransformInfo::CastContextHint
CastContextHint
Represents a hint about the context in which a cast is used.
Definition: TargetTransformInfo.h:1142
llvm::User
Definition: User.h:44
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
llvm::Instruction
Definition: Instruction.h:42
llvm::HexagonTTIImpl::shouldBuildLookupTables
bool shouldBuildLookupTables() const
Definition: HexagonTargetTransformInfo.cpp:400
llvm::HexagonTTIImpl::enableAggressiveInterleaving
bool enableAggressiveInterleaving(bool LoopHasReductions)
Definition: HexagonTargetTransformInfo.h:98
Align
uint64_t Align
Definition: ELFObjHandler.cpp:82
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::AddressSpace
AddressSpace
Definition: NVPTXBaseInfo.h:21
llvm::IntrinsicCostAttributes
Definition: TargetTransformInfo.h:120
Hexagon.h
Operands
mir Rename Register Operands
Definition: MIRNamerPass.cpp:74
llvm::HexagonTTIImpl::getShuffleCost
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, ArrayRef< int > Mask, TTI::TargetCostKind CostKind, int Index, Type *SubTp, ArrayRef< const Value * > Args=std::nullopt)
Definition: HexagonTargetTransformInfo.cpp:240
llvm::HexagonTTIImpl::prefersVectorizedAddressing
bool prefersVectorizedAddressing()
Definition: HexagonTargetTransformInfo.h:101
llvm::VectorType
Base class of all SIMD vector types.
Definition: DerivedTypes.h:389
llvm::SCEV
This class represents an analyzed expression in the program.
Definition: ScalarEvolution.h:75
llvm::HexagonTTIImpl::getCFInstrCost
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr)
Definition: HexagonTargetTransformInfo.h:160
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
llvm::HexagonTTIImpl::getInstructionCost
InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TTI::TargetCostKind CostKind)
Definition: HexagonTargetTransformInfo.cpp:373
llvm::TargetTransformInfo::UnrollingPreferences
Parameters that control the generic loop unrolling transformation.
Definition: TargetTransformInfo.h:417
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::BasicTTIImplBase
Base class which can be used to help build a TTI implementation.
Definition: BasicTTIImpl.h:79
ArrayRef.h
llvm::HexagonTTIImpl::getInterleavedMemoryOpCost
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false)
Definition: HexagonTargetTransformInfo.cpp:255
Ptr
@ Ptr
Definition: TargetLibraryInfo.cpp:60
llvm::HexagonTTIImpl::enableInterleavedAccessVectorization
bool enableInterleavedAccessVectorization()
Definition: HexagonTargetTransformInfo.h:104
llvm::HexagonTTIImpl::isLegalMaskedStore
bool isLegalMaskedStore(Type *DataType, Align Alignment)
Definition: HexagonTargetTransformInfo.cpp:350
llvm::HexagonTTIImpl::getCastInstrCost
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I=nullptr)
Definition: HexagonTargetTransformInfo.cpp:304
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::HexagonTTIImpl::getCallInstrCost
InstructionCost getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind)
Definition: HexagonTargetTransformInfo.cpp:152
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: OptimizationRemarkEmitter.h:33
llvm::HexagonTTIImpl::getOperandsScalarizationOverhead
InstructionCost getOperandsScalarizationOverhead(ArrayRef< const Value * > Args, ArrayRef< Type * > Tys)
Definition: HexagonTargetTransformInfo.cpp:147
llvm::HexagonTargetLowering
Definition: HexagonISelLowering.h:126
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:805
llvm::HexagonTTIImpl::getRegisterBitWidth
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const
Definition: HexagonTargetTransformInfo.cpp:118
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::TargetTransformInfo::AddressingModeKind
AddressingModeKind
Definition: TargetTransformInfo.h:632
llvm::TargetTransformInfo::OK_AnyValue
@ OK_AnyValue
Definition: TargetTransformInfo.h:910
llvm::HexagonTTIImpl::getMaskedMemoryOpCost
InstructionCost getMaskedMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind)
Definition: HexagonTargetTransformInfo.cpp:233
llvm::HexagonTTIImpl::getPeelingPreferences
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, TTI::PeelingPreferences &PP)
Definition: HexagonTargetTransformInfo.cpp:87
llvm::TypeSize
Definition: TypeSize.h:435
llvm::HexagonTTIImpl::supportsEfficientVectorElementLoadStore
bool supportsEfficientVectorElementLoadStore()
Definition: HexagonTargetTransformInfo.h:94
Function.h
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::HexagonTTIImpl::getAddressComputationCost
InstructionCost getAddressComputationCost(Type *Tp, ScalarEvolution *SE, const SCEV *S)
Definition: HexagonTargetTransformInfo.cpp:169
llvm::TargetTransformInfo::RegisterKind
RegisterKind
Definition: TargetTransformInfo.h:967
llvm::HexagonTTIImpl::getPrefetchDistance
unsigned getPrefetchDistance() const override
— Vector TTI end —
Definition: HexagonTargetTransformInfo.cpp:364
llvm::HexagonTTIImpl::getIntrinsicInstrCost
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind)
Definition: HexagonTargetTransformInfo.cpp:159
llvm::HexagonTTIImpl::getPreferredAddressingMode
TTI::AddressingModeKind getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const
Bias LSR towards creating post-increment opportunities.
Definition: HexagonTargetTransformInfo.cpp:100
llvm::HexagonTTIImpl::getCmpSelInstrCost
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, const Instruction *I=nullptr)
Definition: HexagonTargetTransformInfo.cpp:268
llvm::HexagonSubtarget
Definition: HexagonSubtarget.h:43
TargetTransformInfo.h
llvm::HexagonTTIImpl::getCacheLineSize
unsigned getCacheLineSize() const override
Definition: HexagonTargetTransformInfo.cpp:368
llvm::HexagonTTIImpl::getScalarizationOverhead
InstructionCost getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract)
Definition: HexagonTargetTransformInfo.cpp:141
llvm::HexagonTTIImpl::hasBranchDivergence
bool hasBranchDivergence()
Definition: HexagonTargetTransformInfo.h:95
llvm::HexagonTTIImpl::HexagonTTIImpl
HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F)
Definition: HexagonTargetTransformInfo.h:54
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
BasicTTIImpl.h
llvm::HexagonTTIImpl::isLegalMaskedLoad
bool isLegalMaskedLoad(Type *DataType, Align Alignment)
Definition: HexagonTargetTransformInfo.cpp:356
llvm::HexagonTTIImpl::getNumberOfRegisters
unsigned getNumberOfRegisters(bool vector) const
— Vector TTI begin —
Definition: HexagonTargetTransformInfo.cpp:107
llvm::HexagonTTIImpl::getUnrollingPreferences
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE)
Definition: HexagonTargetTransformInfo.cpp:81
llvm::HexagonTTIImpl
Definition: HexagonTargetTransformInfo.h:33
llvm::HexagonTTIImpl::getMinimumVF
ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const
Definition: HexagonTargetTransformInfo.cpp:135