1 //===-- X86TargetTransformInfo.h - X86 specific TTI -------------*- 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 //===----------------------------------------------------------------------===// 8 /// \file 9 /// This file a TargetTransformInfo::Concept conforming object specific to the 10 /// X86 target machine. It uses the target's detailed information to 11 /// provide more precise answers to certain TTI queries, while letting the 12 /// target independent and default TTI implementations handle the rest. 13 /// 14 //===----------------------------------------------------------------------===// 15 16 #ifndef LLVM_LIB_TARGET_X86_X86TARGETTRANSFORMINFO_H 17 #define LLVM_LIB_TARGET_X86_X86TARGETTRANSFORMINFO_H 18 19 #include "X86TargetMachine.h" 20 #include "llvm/Analysis/TargetTransformInfo.h" 21 #include "llvm/CodeGen/BasicTTIImpl.h" 22 23 namespace llvm { 24 25 class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> { 26 typedef BasicTTIImplBase<X86TTIImpl> BaseT; 27 typedef TargetTransformInfo TTI; 28 friend BaseT; 29 30 const X86Subtarget *ST; 31 const X86TargetLowering *TLI; 32 33 const X86Subtarget *getST() const { return ST; } 34 const X86TargetLowering *getTLI() const { return TLI; } 35 36 const FeatureBitset InlineFeatureIgnoreList = { 37 // This indicates the CPU is 64 bit capable not that we are in 64-bit 38 // mode. 39 X86::Feature64Bit, 40 41 // These features don't have any intrinsics or ABI effect. 42 X86::FeatureNOPL, 43 X86::FeatureCMPXCHG16B, 44 X86::FeatureLAHFSAHF, 45 46 // Codegen control options. 47 X86::FeatureFast11ByteNOP, 48 X86::FeatureFast15ByteNOP, 49 X86::FeatureFastBEXTR, 50 X86::FeatureFastHorizontalOps, 51 X86::FeatureFastLZCNT, 52 X86::FeatureFastScalarFSQRT, 53 X86::FeatureFastSHLDRotate, 54 X86::FeatureFastScalarShiftMasks, 55 X86::FeatureFastVectorShiftMasks, 56 X86::FeatureFastVariableShuffle, 57 X86::FeatureFastVectorFSQRT, 58 X86::FeatureLEAForSP, 59 X86::FeatureLEAUsesAG, 60 X86::FeatureLZCNTFalseDeps, 61 X86::FeatureBranchFusion, 62 X86::FeatureMacroFusion, 63 X86::FeatureMergeToThreeWayBranch, 64 X86::FeaturePadShortFunctions, 65 X86::FeaturePOPCNTFalseDeps, 66 X86::FeatureSSEUnalignedMem, 67 X86::FeatureSlow3OpsLEA, 68 X86::FeatureSlowDivide32, 69 X86::FeatureSlowDivide64, 70 X86::FeatureSlowIncDec, 71 X86::FeatureSlowLEA, 72 X86::FeatureSlowPMADDWD, 73 X86::FeatureSlowPMULLD, 74 X86::FeatureSlowSHLD, 75 X86::FeatureSlowTwoMemOps, 76 X86::FeatureSlowUAMem16, 77 X86::FeaturePreferMaskRegisters, 78 X86::FeatureInsertVZEROUPPER, 79 X86::FeatureUseGLMDivSqrtCosts, 80 81 // Perf-tuning flags. 82 X86::FeatureHasFastGather, 83 X86::FeatureSlowUAMem32, 84 85 // Based on whether user set the -mprefer-vector-width command line. 86 X86::FeaturePrefer128Bit, 87 X86::FeaturePrefer256Bit, 88 89 // CPU name enums. These just follow CPU string. 90 X86::ProcIntelAtom, 91 X86::ProcIntelSLM, 92 }; 93 94 public: 95 explicit X86TTIImpl(const X86TargetMachine *TM, const Function &F) 96 : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), 97 TLI(ST->getTargetLowering()) {} 98 99 /// \name Scalar TTI Implementations 100 /// @{ 101 TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth); 102 103 /// @} 104 105 /// \name Cache TTI Implementation 106 /// @{ 107 llvm::Optional<unsigned> getCacheSize( 108 TargetTransformInfo::CacheLevel Level) const; 109 llvm::Optional<unsigned> getCacheAssociativity( 110 TargetTransformInfo::CacheLevel Level) const; 111 /// @} 112 113 /// \name Vector TTI Implementations 114 /// @{ 115 116 unsigned getNumberOfRegisters(unsigned ClassID) const; 117 unsigned getRegisterBitWidth(bool Vector) const; 118 unsigned getLoadStoreVecRegBitWidth(unsigned AS) const; 119 unsigned getMaxInterleaveFactor(unsigned VF); 120 int getArithmeticInstrCost( 121 unsigned Opcode, Type *Ty, 122 TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, 123 TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, 124 TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None, 125 TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None, 126 ArrayRef<const Value *> Args = ArrayRef<const Value *>(), 127 const Instruction *CxtI = nullptr); 128 int getShuffleCost(TTI::ShuffleKind Kind, VectorType *Tp, int Index, 129 VectorType *SubTp); 130 int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, 131 const Instruction *I = nullptr); 132 int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, 133 const Instruction *I = nullptr); 134 int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index); 135 unsigned getScalarizationOverhead(Type *Ty, const APInt &DemandedElts, 136 bool Insert, bool Extract); 137 int getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, 138 unsigned AddressSpace, const Instruction *I = nullptr); 139 int getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, 140 unsigned AddressSpace); 141 int getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr, 142 bool VariableMask, unsigned Alignment, 143 const Instruction *I); 144 int getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE, 145 const SCEV *Ptr); 146 147 unsigned getAtomicMemIntrinsicMaxElementSize() const; 148 149 int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, 150 ArrayRef<Type *> Tys, FastMathFlags FMF, 151 unsigned ScalarizationCostPassed = UINT_MAX, 152 const Instruction *I = nullptr); 153 int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, 154 ArrayRef<Value *> Args, FastMathFlags FMF, 155 unsigned VF = 1, const Instruction *I = nullptr); 156 157 int getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, 158 bool IsPairwiseForm); 159 160 int getMinMaxCost(Type *Ty, Type *CondTy, bool IsUnsigned); 161 162 int getMinMaxReductionCost(VectorType *Ty, VectorType *CondTy, 163 bool IsPairwiseForm, bool IsUnsigned); 164 165 int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, 166 unsigned Factor, ArrayRef<unsigned> Indices, 167 unsigned Alignment, unsigned AddressSpace, 168 bool UseMaskForCond = false, 169 bool UseMaskForGaps = false); 170 int getInterleavedMemoryOpCostAVX512(unsigned Opcode, Type *VecTy, 171 unsigned Factor, ArrayRef<unsigned> Indices, 172 unsigned Alignment, unsigned AddressSpace, 173 bool UseMaskForCond = false, 174 bool UseMaskForGaps = false); 175 int getInterleavedMemoryOpCostAVX2(unsigned Opcode, Type *VecTy, 176 unsigned Factor, ArrayRef<unsigned> Indices, 177 unsigned Alignment, unsigned AddressSpace, 178 bool UseMaskForCond = false, 179 bool UseMaskForGaps = false); 180 181 int getIntImmCost(int64_t); 182 183 int getIntImmCost(const APInt &Imm, Type *Ty); 184 185 unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands, 186 TTI::TargetCostKind); 187 188 int getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty); 189 int getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, 190 Type *Ty); 191 bool isLSRCostLess(TargetTransformInfo::LSRCost &C1, 192 TargetTransformInfo::LSRCost &C2); 193 bool canMacroFuseCmp(); 194 bool isLegalMaskedLoad(Type *DataType, MaybeAlign Alignment); 195 bool isLegalMaskedStore(Type *DataType, MaybeAlign Alignment); 196 bool isLegalNTLoad(Type *DataType, Align Alignment); 197 bool isLegalNTStore(Type *DataType, Align Alignment); 198 bool isLegalMaskedGather(Type *DataType, MaybeAlign Alignment); 199 bool isLegalMaskedScatter(Type *DataType, MaybeAlign Alignment); 200 bool isLegalMaskedExpandLoad(Type *DataType); 201 bool isLegalMaskedCompressStore(Type *DataType); 202 bool hasDivRemOp(Type *DataType, bool IsSigned); 203 bool isFCmpOrdCheaperThanFCmpZero(Type *Ty); 204 bool areInlineCompatible(const Function *Caller, 205 const Function *Callee) const; 206 bool areFunctionArgsABICompatible(const Function *Caller, 207 const Function *Callee, 208 SmallPtrSetImpl<Argument *> &Args) const; 209 TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, 210 bool IsZeroCmp) const; 211 bool enableInterleavedAccessVectorization(); 212 private: 213 int getGSScalarCost(unsigned Opcode, Type *DataTy, bool VariableMask, 214 unsigned Alignment, unsigned AddressSpace); 215 int getGSVectorCost(unsigned Opcode, Type *DataTy, Value *Ptr, 216 unsigned Alignment, unsigned AddressSpace); 217 218 /// @} 219 }; 220 221 } // end namespace llvm 222 223 #endif 224