Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.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"
21#include "llvm/ADT/ArrayRef.h"
24#include "llvm/IR/Function.h"
25
26namespace llvm {
27
28class Loop;
29class ScalarEvolution;
30class User;
31class Value;
32
33class HexagonTTIImpl final : 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
53public:
54 explicit HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F)
55 : BaseT(TM, F.getDataLayout()),
56 ST(*TM->getSubtargetImpl(F)), TLI(*ST.getTargetLowering()) {}
57
58 /// \name Scalar TTI Implementations
59 /// @{
60
62 getPopcntSupport(unsigned IntTyWidthInBit) const override;
63
64 // The Hexagon target can unroll loops with run-time trip counts.
67 OptimizationRemarkEmitter *ORE) const override;
68
70 TTI::PeelingPreferences &PP) const override;
71
72 /// Bias LSR towards creating post-increment opportunities.
74 getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const override;
75
76 // L1 cache prefetch.
77 unsigned getPrefetchDistance() const override;
78 unsigned getCacheLineSize() const override;
79
80 /// @}
81
82 /// \name Vector TTI Implementations
83 /// @{
84
85 unsigned getNumberOfRegisters(unsigned ClassID) const override;
86 unsigned getMaxInterleaveFactor(ElementCount VF) const override;
89 unsigned getMinVectorRegisterBitWidth() const override;
90 ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const override;
91
93 TargetTransformInfo::RegisterKind K) const override {
94 return true;
95 }
97 return false;
98 }
99 bool hasBranchDivergence(const Function *F = nullptr) const override {
100 return false;
101 }
102 bool enableAggressiveInterleaving(bool LoopHasReductions) const override {
103 return false;
104 }
105 bool prefersVectorizedAddressing() const override { return false; }
106 bool enableInterleavedAccessVectorization() const override { return true; }
107
110 TTI::TargetCostKind CostKind) const override;
113 TTI::TargetCostKind CostKind) const override;
116 TTI::TargetCostKind CostKind) const override;
118 unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
121 const Instruction *I = nullptr) const override;
123 getMaskedMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
124 unsigned AddressSpace,
125 TTI::TargetCostKind CostKind) const override;
128 ArrayRef<int> Mask, TTI::TargetCostKind CostKind, int Index,
129 VectorType *SubTp, ArrayRef<const Value *> Args = {},
130 const Instruction *CxtI = nullptr) const override;
131 InstructionCost getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
132 const Value *Ptr, bool VariableMask,
133 Align Alignment,
135 const Instruction *I) const override;
137 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
138 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
139 bool UseMaskForCond = false, bool UseMaskForGaps = false) const override;
141 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
145 const Instruction *I = nullptr) const override;
147 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
151 const Instruction *CxtI = nullptr) const override;
153 getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
155 const Instruction *I = nullptr) const override;
157 InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
159 unsigned Index, const Value *Op0,
160 const Value *Op1) const override;
161
164 const Instruction *I = nullptr) const override {
165 return 1;
166 }
167
168 bool isLegalMaskedStore(Type *DataType, Align Alignment,
169 unsigned AddressSpace) const override;
170 bool isLegalMaskedLoad(Type *DataType, Align Alignment,
171 unsigned AddressSpace) const override;
172
173 /// @}
174
177 TTI::TargetCostKind CostKind) const override;
178
179 // Hexagon specific decision to generate a lookup table.
180 bool shouldBuildLookupTables() const override;
181};
182
183} // end namespace llvm
184#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
mir Rename Register Operands
This pass exposes codegen information to IR-level passes.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1) const override
BasicTTIImplBase(const TargetMachine *TM, const DataLayout &DL)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:678
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
bool isLegalMaskedStore(Type *DataType, Align Alignment, unsigned AddressSpace) const override
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const override
bool isLegalMaskedLoad(Type *DataType, Align Alignment, unsigned AddressSpace) const override
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
bool shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const override
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const override
unsigned getNumberOfRegisters(unsigned ClassID) const override
— Vector TTI begin —
InstructionCost getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE, const SCEV *S, TTI::TargetCostKind CostKind) const override
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={}, const Instruction *CxtI=nullptr) const override
TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const override
unsigned getMinVectorRegisterBitWidth() const override
bool enableAggressiveInterleaving(bool LoopHasReductions) const override
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override
InstructionCost getGatherScatterOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask, Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I) const override
bool supportsEfficientVectorElementLoadStore() const override
InstructionCost getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind) const override
Compute a cost of the given call instruction.
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, TTI::PeelingPreferences &PP) const override
HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F)
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1) const override
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
Get intrinsic cost based on arguments.
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, ArrayRef< int > Mask, TTI::TargetCostKind CostKind, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CxtI=nullptr) const override
bool prefersVectorizedAddressing() const override
TTI::AddressingModeKind getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const override
Bias LSR towards creating post-increment opportunities.
bool shouldBuildLookupTables() const override
InstructionCost getMaskedMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind) const override
bool enableInterleavedAccessVectorization() const override
unsigned getMaxInterleaveFactor(ElementCount VF) const override
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TTI::TargetCostKind CostKind) const override
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE) const override
unsigned getCacheLineSize() const override
unsigned getPrefetchDistance() const override
— Vector TTI end —
bool hasBranchDivergence(const Function *F=nullptr) const override
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
The optimization diagnostic interface.
This class represents an analyzed expression in the program.
The main scalar evolution driver.
virtual const DataLayout & getDataLayout() const
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
TargetCostKind
The kind of cost model.
PopcntSupportKind
Flags indicating the kind of support for population count.
AddressingModeKind
Which addressing mode Loop Strength Reduction will try to generate.
ShuffleKind
The various kinds of shuffle patterns for vector queries.
CastContextHint
Represents a hint about the context in which a cast is used.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
LLVM Value Representation.
Definition Value.h:75
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
ArrayRef(const T &OneElt) -> ArrayRef< T >
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Parameters that control the generic loop unrolling transformation.