LLVM  9.0.0svn
X86TargetTransformInfo.h
Go to the documentation of this file.
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 "X86.h"
20 #include "X86TargetMachine.h"
24 
25 namespace llvm {
26 
27 class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> {
29  typedef TargetTransformInfo TTI;
30  friend BaseT;
31 
32  const X86Subtarget *ST;
33  const X86TargetLowering *TLI;
34 
35  const X86Subtarget *getST() const { return ST; }
36  const X86TargetLowering *getTLI() const { return TLI; }
37 
38  const FeatureBitset InlineFeatureIgnoreList = {
39  // This indicates the CPU is 64 bit capable not that we are in 64-bit mode.
40  X86::Feature64Bit,
41 
42  // These features don't have any intrinsics or ABI effect.
43  X86::FeatureNOPL,
44  X86::FeatureCMPXCHG16B,
45  X86::FeatureLAHFSAHF,
46 
47  // Codegen control options.
48  X86::FeatureFast11ByteNOP,
49  X86::FeatureFast15ByteNOP,
50  X86::FeatureFastBEXTR,
51  X86::FeatureFastHorizontalOps,
52  X86::FeatureFastLZCNT,
53  X86::FeatureFastPartialYMMorZMMWrite,
54  X86::FeatureFastScalarFSQRT,
55  X86::FeatureFastSHLDRotate,
56  X86::FeatureFastVariableShuffle,
57  X86::FeatureFastVectorFSQRT,
58  X86::FeatureLEAForSP,
59  X86::FeatureLEAUsesAG,
60  X86::FeatureLZCNTFalseDeps,
61  X86::FeatureMacroFusion,
62  X86::FeatureMergeToThreeWayBranch,
63  X86::FeaturePadShortFunctions,
64  X86::FeaturePOPCNTFalseDeps,
65  X86::FeatureSSEUnalignedMem,
66  X86::FeatureSlow3OpsLEA,
67  X86::FeatureSlowDivide32,
68  X86::FeatureSlowDivide64,
69  X86::FeatureSlowIncDec,
70  X86::FeatureSlowLEA,
71  X86::FeatureSlowPMADDWD,
72  X86::FeatureSlowPMULLD,
73  X86::FeatureSlowSHLD,
74  X86::FeatureSlowTwoMemOps,
75  X86::FeatureSlowUAMem16,
76 
77  // Perf-tuning flags.
78  X86::FeatureHasFastGather,
79  X86::FeatureSlowUAMem32,
80 
81  // Based on whether user set the -mprefer-vector-width command line.
82  X86::FeaturePrefer256Bit,
83 
84  // CPU name enums. These just follow CPU string.
85  X86::ProcIntelAtom,
86  X86::ProcIntelGLM,
87  X86::ProcIntelGLP,
88  X86::ProcIntelSLM,
89  X86::ProcIntelTRM,
90  };
91 
92 public:
93  explicit X86TTIImpl(const X86TargetMachine *TM, const Function &F)
94  : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
95  TLI(ST->getTargetLowering()) {}
96 
97  /// \name Scalar TTI Implementations
98  /// @{
99  TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth);
100 
101  /// @}
102 
103  /// \name Cache TTI Implementation
104  /// @{
108  TargetTransformInfo::CacheLevel Level) const;
109  /// @}
110 
111  /// \name Vector TTI Implementations
112  /// @{
113 
114  unsigned getNumberOfRegisters(bool Vector);
115  unsigned getRegisterBitWidth(bool Vector) const;
116  unsigned getLoadStoreVecRegBitWidth(unsigned AS) const;
117  unsigned getMaxInterleaveFactor(unsigned VF);
119  unsigned Opcode, Type *Ty,
125  int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp);
126  int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
127  const Instruction *I = nullptr);
128  int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
129  const Instruction *I = nullptr);
130  int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
131  int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
132  unsigned AddressSpace, const Instruction *I = nullptr);
133  int getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
134  unsigned AddressSpace);
135  int getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr,
136  bool VariableMask, unsigned Alignment);
138  const SCEV *Ptr);
139 
140  unsigned getAtomicMemIntrinsicMaxElementSize() const;
141 
142  int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
144  unsigned ScalarizationCostPassed = UINT_MAX);
145  int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
147  unsigned VF = 1);
148 
149  int getArithmeticReductionCost(unsigned Opcode, Type *Ty,
150  bool IsPairwiseForm);
151 
152  int getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwiseForm,
153  bool IsUnsigned);
154 
155  int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy,
156  unsigned Factor, ArrayRef<unsigned> Indices,
157  unsigned Alignment, unsigned AddressSpace,
158  bool UseMaskForCond = false,
159  bool UseMaskForGaps = false);
160  int getInterleavedMemoryOpCostAVX512(unsigned Opcode, Type *VecTy,
161  unsigned Factor, ArrayRef<unsigned> Indices,
162  unsigned Alignment, unsigned AddressSpace,
163  bool UseMaskForCond = false,
164  bool UseMaskForGaps = false);
165  int getInterleavedMemoryOpCostAVX2(unsigned Opcode, Type *VecTy,
166  unsigned Factor, ArrayRef<unsigned> Indices,
167  unsigned Alignment, unsigned AddressSpace,
168  bool UseMaskForCond = false,
169  bool UseMaskForGaps = false);
170 
171  int getIntImmCost(int64_t);
172 
173  int getIntImmCost(const APInt &Imm, Type *Ty);
174 
175  unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands);
176 
177  int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty);
178  int getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
179  Type *Ty);
182  bool canMacroFuseCmp();
184  bool isLegalMaskedStore(Type *DataType);
185  bool isLegalMaskedGather(Type *DataType);
186  bool isLegalMaskedScatter(Type *DataType);
187  bool hasDivRemOp(Type *DataType, bool IsSigned);
189  bool areInlineCompatible(const Function *Caller,
190  const Function *Callee) const;
191  bool areFunctionArgsABICompatible(const Function *Caller,
192  const Function *Callee,
193  SmallPtrSetImpl<Argument *> &Args) const;
195  bool IsZeroCmp) const;
197 private:
198  int getGSScalarCost(unsigned Opcode, Type *DataTy, bool VariableMask,
199  unsigned Alignment, unsigned AddressSpace);
200  int getGSVectorCost(unsigned Opcode, Type *DataTy, Value *Ptr,
201  unsigned Alignment, unsigned AddressSpace);
202 
203  /// @}
204 };
205 
206 } // end namespace llvm
207 
208 #endif
llvm::Optional< unsigned > getCacheSize(TargetTransformInfo::CacheLevel Level) const
This class represents lattice values for constants.
Definition: AllocatorList.h:23
int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
bool isFCmpOrdCheaperThanFCmpZero(Type *Ty)
int getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr, bool VariableMask, unsigned Alignment)
Calculate the cost of Gather / Scatter operation.
The main scalar evolution driver.
unsigned getRegisterBitWidth(bool Vector) const
bool isLegalMaskedScatter(Type *DataType)
F(f)
Base class which can be used to help build a TTI implementation.
Definition: BasicTTIImpl.h:77
unsigned getAtomicMemIntrinsicMaxElementSize() const
unsigned getNumberOfRegisters(bool Vector)
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:343
unsigned getMaxInterleaveFactor(unsigned VF)
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
bool isLegalMaskedStore(Type *DataType)
int getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>())
int getInterleavedMemoryOpCostAVX2(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
bool isLSRCostLess(TargetTransformInfo::LSRCost &C1, TargetTransformInfo::LSRCost &C2)
PopcntSupportKind
Flags indicating the kind of support for population count.
llvm::Optional< unsigned > getCacheAssociativity(TargetTransformInfo::CacheLevel Level) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
int getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE, const SCEV *Ptr)
If not nullptr, enable inline expansion of memcmp.
Container class for subtarget features.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
bool isLegalMaskedGather(Type *DataType)
int getInterleavedMemoryOpCostAVX512(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
bool isLegalMaskedLoad(Type *DataType)
const TTI::MemCmpExpansionOptions * enableMemCmpExpansion(bool IsZeroCmp) const
int getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace)
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
int getArithmeticReductionCost(unsigned Opcode, Type *Ty, bool IsPairwiseForm)
unsigned getUserCost(const User *U, ArrayRef< const Value *> Operands)
int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth)
OperandValueProperties
Additional properties of an operand&#39;s values.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
bool areFunctionArgsABICompatible(const Function *Caller, const Function *Callee, SmallPtrSetImpl< Argument *> &Args) const
AddressSpace
Definition: NVPTXBaseInfo.h:21
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I=nullptr)
int getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwiseForm, bool IsUnsigned)
Class for arbitrary precision integers.
Definition: APInt.h:69
amdgpu Simplify well known AMD library false FunctionCallee Callee
unsigned getLoadStoreVecRegBitWidth(unsigned AS) const
This class represents an analyzed expression in the program.
int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
#define I(x, y, z)
Definition: MD5.cpp:58
const unsigned Kind
LLVM Value Representation.
Definition: Value.h:72
bool hasDivRemOp(Type *DataType, bool IsSigned)
static const Function * getParent(const Value *V)
const DataLayout & getDataLayout() const
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:159
OperandValueKind
Additional information about an operand&#39;s possible values.
This pass exposes codegen information to IR-level passes.
CacheLevel
The possible cache levels.
X86TTIImpl(const X86TargetMachine *TM, const Function &F)
int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Type *> Tys, FastMathFlags FMF, unsigned ScalarizationCostPassed=UINT_MAX)
int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
int getIntImmCost(int64_t)
Calculate the cost of materializing a 64-bit value.
This file describes how to lower LLVM code to machine code.
ShuffleKind
The various kinds of shuffle patterns for vector queries.