blob: 5c6f85584ec2f45a1d9d7828cca4f12d29d0473b [file] [log] [blame]
Eugene Zelenko52889212017-08-01 21:20:10 +00001//==- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass -*- C++ -*-==//
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8/// \file
9/// This file implements a TargetTransformInfo analysis pass specific to the
10/// Hexagon target machine. It uses the target's detailed information to provide
11/// more precise answers to certain TTI queries, while letting the target
12/// independent and default TTI implementations handle the rest.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
17#define LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
18
19#include "Hexagon.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000020#include "HexagonSubtarget.h"
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000021#include "HexagonTargetMachine.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000022#include "llvm/ADT/ArrayRef.h"
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000023#include "llvm/Analysis/TargetTransformInfo.h"
24#include "llvm/CodeGen/BasicTTIImpl.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000025#include "llvm/IR/Function.h"
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000026
27namespace llvm {
28
Eugene Zelenko52889212017-08-01 21:20:10 +000029class Loop;
30class ScalarEvolution;
31class User;
32class Value;
33
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000034class HexagonTTIImpl : public BasicTTIImplBase<HexagonTTIImpl> {
Eugene Zelenko52889212017-08-01 21:20:10 +000035 using BaseT = BasicTTIImplBase<HexagonTTIImpl>;
36 using TTI = TargetTransformInfo;
37
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000038 friend BaseT;
39
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +000040 const HexagonSubtarget &ST;
41 const HexagonTargetLowering &TLI;
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000042
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +000043 const HexagonSubtarget *getST() const { return &ST; }
44 const HexagonTargetLowering *getTLI() const { return &TLI; }
45
46 bool useHVX() const;
47 bool isTypeForHVX(Type *VecTy) const;
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000048
Krzysztof Parzyszekbea23d02018-06-12 15:12:50 +000049 // Returns the number of vector elements of Ty, if Ty is a vector type,
50 // or 1 if Ty is a scalar type. It is incorrect to call this function
51 // with any other type.
52 unsigned getTypeNumElements(Type *Ty) const;
53
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000054public:
Eric Christophera4e5d3c2015-09-16 23:38:13 +000055 explicit HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F)
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +000056 : BaseT(TM, F.getParent()->getDataLayout()),
57 ST(*TM->getSubtargetImpl(F)), TLI(*ST.getTargetLowering()) {}
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000058
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000059 /// \name Scalar TTI Implementations
60 /// @{
61
62 TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
63
64 // The Hexagon target can unroll loops with run-time trip counts.
Geoff Berry66d9bdb2017-06-28 15:53:17 +000065 void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
66 TTI::UnrollingPreferences &UP);
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000067
Krzysztof Parzyszek56f0fc42018-03-26 15:32:03 +000068 /// Bias LSR towards creating post-increment opportunities.
69 bool shouldFavorPostInc() const;
70
Krzysztof Parzyszekd3d0a4b2016-07-22 14:22:43 +000071 // L1 cache prefetch.
72 unsigned getPrefetchDistance() const;
73 unsigned getCacheLineSize() const;
74
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000075 /// @}
76
77 /// \name Vector TTI Implementations
78 /// @{
79
80 unsigned getNumberOfRegisters(bool vector) const;
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +000081 unsigned getMaxInterleaveFactor(unsigned VF);
82 unsigned getRegisterBitWidth(bool Vector) const;
83 unsigned getMinVectorRegisterBitWidth() const;
Krzysztof Parzyszekdfed9412018-04-13 20:16:32 +000084 unsigned getMinimumVF(unsigned ElemWidth) const;
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +000085
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +000086 bool shouldMaximizeVectorBandwidth(bool OptSize) const {
87 return true;
88 }
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +000089 bool supportsEfficientVectorElementLoadStore() {
90 return false;
91 }
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +000092 bool hasBranchDivergence() {
93 return false;
94 }
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +000095 bool enableAggressiveInterleaving(bool LoopHasReductions) {
96 return false;
97 }
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +000098 bool prefersVectorizedAddressing() {
99 return false;
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000100 }
Krzysztof Parzyszek2ff9aa12018-08-22 20:15:04 +0000101 bool enableInterleavedAccessVectorization() {
102 return true;
103 }
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000104
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +0000105 unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract);
106 unsigned getOperandsScalarizationOverhead(ArrayRef<const Value*> Args,
107 unsigned VF);
108 unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef<Type*> Tys);
109 unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
110 ArrayRef<Value*> Args, FastMathFlags FMF, unsigned VF);
111 unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
112 ArrayRef<Type*> Tys, FastMathFlags FMF,
113 unsigned ScalarizationCostPassed = UINT_MAX);
114 unsigned getAddressComputationCost(Type *Tp, ScalarEvolution *SE,
115 const SCEV *S);
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000116 unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
117 unsigned AddressSpace, const Instruction *I = nullptr);
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000118 unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +0000119 unsigned AddressSpace);
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000120 unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +0000121 Type *SubTp);
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000122 unsigned getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr,
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +0000123 bool VariableMask, unsigned Alignment);
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000124 unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy,
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +0000125 unsigned Factor, ArrayRef<unsigned> Indices, unsigned Alignment,
Dorit Nuzman34da6dd2018-10-31 09:57:56 +0000126 unsigned AddressSpace, bool UseMaskForCond = false,
127 bool UseMaskForGaps = false);
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000128 unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +0000129 const Instruction *I);
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000130 unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty,
131 TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,
132 TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue,
133 TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
134 TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +0000135 ArrayRef<const Value *> Args = ArrayRef<const Value *>());
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000136 unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +0000137 const Instruction *I = nullptr);
138 unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000139
Krzysztof Parzyszek4bdf1aa2018-04-13 20:46:50 +0000140 unsigned getCFInstrCost(unsigned Opcode) {
Krzysztof Parzyszek0a15d242018-03-27 17:07:52 +0000141 return 1;
142 }
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +0000143
144 /// @}
Krzysztof Parzyszekdb019ae2016-08-19 14:22:07 +0000145
Evgeny Astigeevich70ed78e2017-06-29 13:42:12 +0000146 int getUserCost(const User *U, ArrayRef<const Value *> Operands);
Sumanth Gundapanenid2dd79b2017-06-30 20:54:24 +0000147
148 // Hexagon specific decision to generate a lookup table.
149 bool shouldBuildLookupTables() const;
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +0000150};
151
152} // end namespace llvm
Eugene Zelenko52889212017-08-01 21:20:10 +0000153#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H