| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 1 | //===-- X86TargetTransformInfo.h - X86 specific TTI -------------*- C++ -*-===// | 
|  | 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 | //===----------------------------------------------------------------------===// | 
|  | 9 | /// \file | 
|  | 10 | /// This file a TargetTransformInfo::Concept conforming object specific to the | 
|  | 11 | /// X86 target machine. It uses the target's detailed information to | 
|  | 12 | /// provide more precise answers to certain TTI queries, while letting the | 
|  | 13 | /// target independent and default TTI implementations handle the rest. | 
|  | 14 | /// | 
|  | 15 | //===----------------------------------------------------------------------===// | 
|  | 16 |  | 
|  | 17 | #ifndef LLVM_LIB_TARGET_X86_X86TARGETTRANSFORMINFO_H | 
|  | 18 | #define LLVM_LIB_TARGET_X86_X86TARGETTRANSFORMINFO_H | 
|  | 19 |  | 
|  | 20 | #include "X86.h" | 
|  | 21 | #include "X86TargetMachine.h" | 
|  | 22 | #include "llvm/Analysis/TargetTransformInfo.h" | 
|  | 23 | #include "llvm/CodeGen/BasicTTIImpl.h" | 
| David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/TargetLowering.h" | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 25 |  | 
|  | 26 | namespace llvm { | 
|  | 27 |  | 
|  | 28 | class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> { | 
|  | 29 | typedef BasicTTIImplBase<X86TTIImpl> BaseT; | 
|  | 30 | typedef TargetTransformInfo TTI; | 
| Chandler Carruth | c340ca8 | 2015-02-01 14:01:15 +0000 | [diff] [blame] | 31 | friend BaseT; | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 32 |  | 
|  | 33 | const X86Subtarget *ST; | 
|  | 34 | const X86TargetLowering *TLI; | 
|  | 35 |  | 
| Chandler Carruth | c956ab66 | 2015-02-01 14:22:17 +0000 | [diff] [blame] | 36 | const X86Subtarget *getST() const { return ST; } | 
| Chandler Carruth | c340ca8 | 2015-02-01 14:01:15 +0000 | [diff] [blame] | 37 | const X86TargetLowering *getTLI() const { return TLI; } | 
|  | 38 |  | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 39 | public: | 
| Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 40 | explicit X86TTIImpl(const X86TargetMachine *TM, const Function &F) | 
| Mehdi Amini | 5010ebf | 2015-07-09 02:08:42 +0000 | [diff] [blame] | 41 | : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), | 
|  | 42 | TLI(ST->getTargetLowering()) {} | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 43 |  | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 44 | /// \name Scalar TTI Implementations | 
|  | 45 | /// @{ | 
|  | 46 | TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth); | 
|  | 47 |  | 
|  | 48 | /// @} | 
|  | 49 |  | 
| Tobias Grosser | d7eb619 | 2017-08-24 09:46:25 +0000 | [diff] [blame] | 50 | /// \name Cache TTI Implementation | 
|  | 51 | /// @{ | 
|  | 52 | llvm::Optional<unsigned> getCacheSize( | 
|  | 53 | TargetTransformInfo::CacheLevel Level) const; | 
|  | 54 | llvm::Optional<unsigned> getCacheAssociativity( | 
|  | 55 | TargetTransformInfo::CacheLevel Level) const; | 
|  | 56 | /// @} | 
|  | 57 |  | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 58 | /// \name Vector TTI Implementations | 
|  | 59 | /// @{ | 
|  | 60 |  | 
|  | 61 | unsigned getNumberOfRegisters(bool Vector); | 
| Keno Fischer | 1ec5dd8 | 2017-04-05 20:51:38 +0000 | [diff] [blame] | 62 | unsigned getRegisterBitWidth(bool Vector) const; | 
|  | 63 | unsigned getLoadStoreVecRegBitWidth(unsigned AS) const; | 
| Wei Mi | 062c744 | 2015-05-06 17:12:25 +0000 | [diff] [blame] | 64 | unsigned getMaxInterleaveFactor(unsigned VF); | 
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 65 | int getArithmeticInstrCost( | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 66 | unsigned Opcode, Type *Ty, | 
|  | 67 | TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, | 
|  | 68 | TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, | 
|  | 69 | TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None, | 
| Mohammed Agabaria | 2c96c43 | 2017-01-11 08:23:37 +0000 | [diff] [blame] | 70 | TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None, | 
|  | 71 | ArrayRef<const Value *> Args = ArrayRef<const Value *>()); | 
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 72 | int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp); | 
| Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 73 | int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, | 
|  | 74 | const Instruction *I = nullptr); | 
|  | 75 | int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, | 
|  | 76 | const Instruction *I = nullptr); | 
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 77 | int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index); | 
|  | 78 | int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, | 
| Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 79 | unsigned AddressSpace, const Instruction *I = nullptr); | 
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 80 | int getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, | 
|  | 81 | unsigned AddressSpace); | 
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 82 | int getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr, | 
|  | 83 | bool VariableMask, unsigned Alignment); | 
| Mohammed Agabaria | 23599ba | 2017-01-05 14:03:41 +0000 | [diff] [blame] | 84 | int getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE, | 
|  | 85 | const SCEV *Ptr); | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 86 |  | 
| Anna Thomas | b2a212c | 2017-06-06 16:45:25 +0000 | [diff] [blame] | 87 | unsigned getAtomicMemIntrinsicMaxElementSize() const; | 
|  | 88 |  | 
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 89 | int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, | 
| Jonas Paulsson | a48ea23 | 2017-03-14 06:35:36 +0000 | [diff] [blame] | 90 | ArrayRef<Type *> Tys, FastMathFlags FMF, | 
|  | 91 | unsigned ScalarizationCostPassed = UINT_MAX); | 
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 92 | int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, | 
| Jonas Paulsson | a48ea23 | 2017-03-14 06:35:36 +0000 | [diff] [blame] | 93 | ArrayRef<Value *> Args, FastMathFlags FMF, | 
|  | 94 | unsigned VF = 1); | 
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 95 |  | 
| Alexey Bataev | 3e9b3eb | 2017-07-31 14:19:32 +0000 | [diff] [blame] | 96 | int getArithmeticReductionCost(unsigned Opcode, Type *Ty, | 
|  | 97 | bool IsPairwiseForm); | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 98 |  | 
| Alexey Bataev | 6dd29fc | 2017-09-08 13:49:36 +0000 | [diff] [blame] | 99 | int getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwiseForm, | 
|  | 100 | bool IsUnsigned); | 
|  | 101 |  | 
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 102 | int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, | 
|  | 103 | unsigned Factor, ArrayRef<unsigned> Indices, | 
| Dorit Nuzman | 38bbf81 | 2018-10-14 08:50:06 +0000 | [diff] [blame] | 104 | unsigned Alignment, unsigned AddressSpace, | 
| Dorit Nuzman | 34da6dd | 2018-10-31 09:57:56 +0000 | [diff] [blame] | 105 | bool UseMaskForCond = false, | 
|  | 106 | bool UseMaskForGaps = false); | 
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 107 | int getInterleavedMemoryOpCostAVX512(unsigned Opcode, Type *VecTy, | 
|  | 108 | unsigned Factor, ArrayRef<unsigned> Indices, | 
| Dorit Nuzman | 38bbf81 | 2018-10-14 08:50:06 +0000 | [diff] [blame] | 109 | unsigned Alignment, unsigned AddressSpace, | 
| Dorit Nuzman | 34da6dd | 2018-10-31 09:57:56 +0000 | [diff] [blame] | 110 | bool UseMaskForCond = false, | 
|  | 111 | bool UseMaskForGaps = false); | 
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 112 | int getInterleavedMemoryOpCostAVX2(unsigned Opcode, Type *VecTy, | 
|  | 113 | unsigned Factor, ArrayRef<unsigned> Indices, | 
| Dorit Nuzman | 38bbf81 | 2018-10-14 08:50:06 +0000 | [diff] [blame] | 114 | unsigned Alignment, unsigned AddressSpace, | 
| Dorit Nuzman | 34da6dd | 2018-10-31 09:57:56 +0000 | [diff] [blame] | 115 | bool UseMaskForCond = false, | 
|  | 116 | bool UseMaskForGaps = false); | 
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 117 |  | 
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 118 | int getIntImmCost(int64_t); | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 119 |  | 
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 120 | int getIntImmCost(const APInt &Imm, Type *Ty); | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 121 |  | 
| Elena Demikhovsky | f58f838 | 2017-08-20 12:34:29 +0000 | [diff] [blame] | 122 | unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands); | 
|  | 123 |  | 
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 124 | int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty); | 
|  | 125 | int getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, | 
|  | 126 | Type *Ty); | 
| Evgeny Stupachenko | c675290 | 2017-08-07 19:56:34 +0000 | [diff] [blame] | 127 | bool isLSRCostLess(TargetTransformInfo::LSRCost &C1, | 
|  | 128 | TargetTransformInfo::LSRCost &C2); | 
| Sanjay Patel | d7c702b | 2018-02-05 23:43:05 +0000 | [diff] [blame] | 129 | bool canMacroFuseCmp(); | 
| Elena Demikhovsky | 20662e3 | 2015-10-19 07:43:38 +0000 | [diff] [blame] | 130 | bool isLegalMaskedLoad(Type *DataType); | 
|  | 131 | bool isLegalMaskedStore(Type *DataType); | 
| Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 132 | bool isLegalMaskedGather(Type *DataType); | 
|  | 133 | bool isLegalMaskedScatter(Type *DataType); | 
| Sanjay Patel | 6fd4391 | 2017-09-09 13:38:18 +0000 | [diff] [blame] | 134 | bool hasDivRemOp(Type *DataType, bool IsSigned); | 
| Sanjay Patel | 0de1a4b | 2017-11-27 21:15:43 +0000 | [diff] [blame] | 135 | bool isFCmpOrdCheaperThanFCmpZero(Type *Ty); | 
| Eric Christopher | d566fb1 | 2015-07-29 22:09:48 +0000 | [diff] [blame] | 136 | bool areInlineCompatible(const Function *Caller, | 
|  | 137 | const Function *Callee) const; | 
| Clement Courbet | b2c3eb8 | 2017-10-30 14:19:33 +0000 | [diff] [blame] | 138 | const TTI::MemCmpExpansionOptions *enableMemCmpExpansion( | 
|  | 139 | bool IsZeroCmp) const; | 
| Michael Kuperstein | b2443ed | 2016-10-20 21:04:31 +0000 | [diff] [blame] | 140 | bool enableInterleavedAccessVectorization(); | 
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 141 | private: | 
|  | 142 | int getGSScalarCost(unsigned Opcode, Type *DataTy, bool VariableMask, | 
|  | 143 | unsigned Alignment, unsigned AddressSpace); | 
|  | 144 | int getGSVectorCost(unsigned Opcode, Type *DataTy, Value *Ptr, | 
|  | 145 | unsigned Alignment, unsigned AddressSpace); | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 146 |  | 
|  | 147 | /// @} | 
|  | 148 | }; | 
| Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 149 |  | 
|  | 150 | } // end namespace llvm | 
|  | 151 |  | 
|  | 152 | #endif |