| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 1 | //==- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass -*- C++ -*-==// | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 2 | // | 
|  | 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 Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 20 | #include "HexagonSubtarget.h" | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 21 | #include "HexagonTargetMachine.h" | 
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/ArrayRef.h" | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/TargetTransformInfo.h" | 
|  | 24 | #include "llvm/CodeGen/BasicTTIImpl.h" | 
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 25 | #include "llvm/IR/Function.h" | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 26 |  | 
|  | 27 | namespace llvm { | 
|  | 28 |  | 
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 29 | class Loop; | 
|  | 30 | class ScalarEvolution; | 
|  | 31 | class User; | 
|  | 32 | class Value; | 
|  | 33 |  | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 34 | class HexagonTTIImpl : public BasicTTIImplBase<HexagonTTIImpl> { | 
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 35 | using BaseT = BasicTTIImplBase<HexagonTTIImpl>; | 
|  | 36 | using TTI = TargetTransformInfo; | 
|  | 37 |  | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 38 | friend BaseT; | 
|  | 39 |  | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 40 | const HexagonSubtarget &ST; | 
|  | 41 | const HexagonTargetLowering &TLI; | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 42 |  | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 43 | 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 Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 48 |  | 
| Krzysztof Parzyszek | bea23d0 | 2018-06-12 15:12:50 +0000 | [diff] [blame] | 49 | // 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 Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 54 | public: | 
| Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 55 | explicit HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F) | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 56 | : BaseT(TM, F.getParent()->getDataLayout()), | 
|  | 57 | ST(*TM->getSubtargetImpl(F)), TLI(*ST.getTargetLowering()) {} | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 58 |  | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 59 | /// \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 Berry | 66d9bdb | 2017-06-28 15:53:17 +0000 | [diff] [blame] | 65 | void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, | 
|  | 66 | TTI::UnrollingPreferences &UP); | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 67 |  | 
| Krzysztof Parzyszek | 56f0fc4 | 2018-03-26 15:32:03 +0000 | [diff] [blame] | 68 | /// Bias LSR towards creating post-increment opportunities. | 
|  | 69 | bool shouldFavorPostInc() const; | 
|  | 70 |  | 
| Krzysztof Parzyszek | d3d0a4b | 2016-07-22 14:22:43 +0000 | [diff] [blame] | 71 | // L1 cache prefetch. | 
|  | 72 | unsigned getPrefetchDistance() const; | 
|  | 73 | unsigned getCacheLineSize() const; | 
|  | 74 |  | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 75 | /// @} | 
|  | 76 |  | 
|  | 77 | /// \name Vector TTI Implementations | 
|  | 78 | /// @{ | 
|  | 79 |  | 
|  | 80 | unsigned getNumberOfRegisters(bool vector) const; | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 81 | unsigned getMaxInterleaveFactor(unsigned VF); | 
|  | 82 | unsigned getRegisterBitWidth(bool Vector) const; | 
|  | 83 | unsigned getMinVectorRegisterBitWidth() const; | 
| Krzysztof Parzyszek | dfed941 | 2018-04-13 20:16:32 +0000 | [diff] [blame] | 84 | unsigned getMinimumVF(unsigned ElemWidth) const; | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 85 |  | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 86 | bool shouldMaximizeVectorBandwidth(bool OptSize) const { | 
|  | 87 | return true; | 
|  | 88 | } | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 89 | bool supportsEfficientVectorElementLoadStore() { | 
|  | 90 | return false; | 
|  | 91 | } | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 92 | bool hasBranchDivergence() { | 
|  | 93 | return false; | 
|  | 94 | } | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 95 | bool enableAggressiveInterleaving(bool LoopHasReductions) { | 
|  | 96 | return false; | 
|  | 97 | } | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 98 | bool prefersVectorizedAddressing() { | 
|  | 99 | return false; | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 100 | } | 
| Krzysztof Parzyszek | 2ff9aa1 | 2018-08-22 20:15:04 +0000 | [diff] [blame] | 101 | bool enableInterleavedAccessVectorization() { | 
|  | 102 | return true; | 
|  | 103 | } | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 104 |  | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 105 | 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 Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 116 | unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, | 
|  | 117 | unsigned AddressSpace, const Instruction *I = nullptr); | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 118 | unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 119 | unsigned AddressSpace); | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 120 | unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 121 | Type *SubTp); | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 122 | unsigned getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr, | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 123 | bool VariableMask, unsigned Alignment); | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 124 | unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 125 | unsigned Factor, ArrayRef<unsigned> Indices, unsigned Alignment, | 
| Dorit Nuzman | 34da6dd | 2018-10-31 09:57:56 +0000 | [diff] [blame] | 126 | unsigned AddressSpace, bool UseMaskForCond = false, | 
|  | 127 | bool UseMaskForGaps = false); | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 128 | unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 129 | const Instruction *I); | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 130 | 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 Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 135 | ArrayRef<const Value *> Args = ArrayRef<const Value *>()); | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 136 | unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 137 | const Instruction *I = nullptr); | 
|  | 138 | unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index); | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 139 |  | 
| Krzysztof Parzyszek | 4bdf1aa | 2018-04-13 20:46:50 +0000 | [diff] [blame] | 140 | unsigned getCFInstrCost(unsigned Opcode) { | 
| Krzysztof Parzyszek | 0a15d24 | 2018-03-27 17:07:52 +0000 | [diff] [blame] | 141 | return 1; | 
|  | 142 | } | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 143 |  | 
|  | 144 | /// @} | 
| Krzysztof Parzyszek | db019ae | 2016-08-19 14:22:07 +0000 | [diff] [blame] | 145 |  | 
| Evgeny Astigeevich | 70ed78e | 2017-06-29 13:42:12 +0000 | [diff] [blame] | 146 | int getUserCost(const User *U, ArrayRef<const Value *> Operands); | 
| Sumanth Gundapaneni | d2dd79b | 2017-06-30 20:54:24 +0000 | [diff] [blame] | 147 |  | 
|  | 148 | // Hexagon specific decision to generate a lookup table. | 
|  | 149 | bool shouldBuildLookupTables() const; | 
| Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 150 | }; | 
|  | 151 |  | 
|  | 152 | } // end namespace llvm | 
| Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 153 | #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H |