2015-01-31 19:17:59 +08:00
|
|
|
//===-- X86TargetTransformInfo.h - X86 specific TTI -------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-01-31 19:17:59 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// This file a TargetTransformInfo::Concept conforming object specific to the
|
|
|
|
/// X86 target machine. It uses the target's detailed information to
|
|
|
|
/// provide more precise answers to certain TTI queries, while letting the
|
|
|
|
/// target independent and default TTI implementations handle the rest.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_TARGET_X86_X86TARGETTRANSFORMINFO_H
|
|
|
|
#define LLVM_LIB_TARGET_X86_X86TARGETTRANSFORMINFO_H
|
|
|
|
|
|
|
|
#include "X86.h"
|
|
|
|
#include "X86TargetMachine.h"
|
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
|
|
|
#include "llvm/CodeGen/BasicTTIImpl.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
2015-01-31 19:17:59 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> {
|
|
|
|
typedef BasicTTIImplBase<X86TTIImpl> BaseT;
|
|
|
|
typedef TargetTransformInfo TTI;
|
2015-02-01 22:01:15 +08:00
|
|
|
friend BaseT;
|
2015-01-31 19:17:59 +08:00
|
|
|
|
|
|
|
const X86Subtarget *ST;
|
|
|
|
const X86TargetLowering *TLI;
|
|
|
|
|
2015-02-01 22:22:17 +08:00
|
|
|
const X86Subtarget *getST() const { return ST; }
|
2015-02-01 22:01:15 +08:00
|
|
|
const X86TargetLowering *getTLI() const { return TLI; }
|
|
|
|
|
2019-02-20 01:05:11 +08:00
|
|
|
const FeatureBitset InlineFeatureIgnoreList = {
|
2019-03-28 21:38:58 +08:00
|
|
|
// This indicates the CPU is 64 bit capable not that we are in 64-bit
|
|
|
|
// mode.
|
|
|
|
X86::Feature64Bit,
|
|
|
|
|
|
|
|
// These features don't have any intrinsics or ABI effect.
|
|
|
|
X86::FeatureNOPL,
|
|
|
|
X86::FeatureCMPXCHG16B,
|
|
|
|
X86::FeatureLAHFSAHF,
|
|
|
|
|
|
|
|
// Codegen control options.
|
|
|
|
X86::FeatureFast11ByteNOP,
|
|
|
|
X86::FeatureFast15ByteNOP,
|
|
|
|
X86::FeatureFastBEXTR,
|
|
|
|
X86::FeatureFastHorizontalOps,
|
|
|
|
X86::FeatureFastLZCNT,
|
|
|
|
X86::FeatureFastPartialYMMorZMMWrite,
|
|
|
|
X86::FeatureFastScalarFSQRT,
|
|
|
|
X86::FeatureFastSHLDRotate,
|
|
|
|
X86::FeatureFastVariableShuffle,
|
|
|
|
X86::FeatureFastVectorFSQRT,
|
|
|
|
X86::FeatureLEAForSP,
|
|
|
|
X86::FeatureLEAUsesAG,
|
|
|
|
X86::FeatureLZCNTFalseDeps,
|
2019-03-28 22:12:46 +08:00
|
|
|
X86::FeatureBranchFusion,
|
2019-03-28 21:38:58 +08:00
|
|
|
X86::FeatureMacroFusion,
|
|
|
|
X86::FeatureMergeToThreeWayBranch,
|
|
|
|
X86::FeaturePadShortFunctions,
|
|
|
|
X86::FeaturePOPCNTFalseDeps,
|
|
|
|
X86::FeatureSSEUnalignedMem,
|
|
|
|
X86::FeatureSlow3OpsLEA,
|
|
|
|
X86::FeatureSlowDivide32,
|
|
|
|
X86::FeatureSlowDivide64,
|
|
|
|
X86::FeatureSlowIncDec,
|
|
|
|
X86::FeatureSlowLEA,
|
|
|
|
X86::FeatureSlowPMADDWD,
|
|
|
|
X86::FeatureSlowPMULLD,
|
|
|
|
X86::FeatureSlowSHLD,
|
|
|
|
X86::FeatureSlowTwoMemOps,
|
|
|
|
X86::FeatureSlowUAMem16,
|
|
|
|
|
|
|
|
// Perf-tuning flags.
|
|
|
|
X86::FeatureHasFastGather,
|
|
|
|
X86::FeatureSlowUAMem32,
|
|
|
|
|
|
|
|
// Based on whether user set the -mprefer-vector-width command line.
|
|
|
|
X86::FeaturePrefer256Bit,
|
|
|
|
|
|
|
|
// CPU name enums. These just follow CPU string.
|
|
|
|
X86::ProcIntelAtom,
|
|
|
|
X86::ProcIntelGLM,
|
|
|
|
X86::ProcIntelGLP,
|
|
|
|
X86::ProcIntelSLM,
|
|
|
|
X86::ProcIntelTRM,
|
2019-02-20 01:05:11 +08:00
|
|
|
};
|
|
|
|
|
2015-01-31 19:17:59 +08:00
|
|
|
public:
|
2015-09-17 07:38:13 +08:00
|
|
|
explicit X86TTIImpl(const X86TargetMachine *TM, const Function &F)
|
2015-07-09 10:08:42 +08:00
|
|
|
: BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
|
|
|
|
TLI(ST->getTargetLowering()) {}
|
2015-01-31 19:17:59 +08:00
|
|
|
|
|
|
|
/// \name Scalar TTI Implementations
|
|
|
|
/// @{
|
|
|
|
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth);
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
|
Model cache size and associativity in TargetTransformInfo
Summary:
We add the precise cache sizes and associativity for the following Intel
architectures:
- Penry
- Nehalem
- Westmere
- Sandy Bridge
- Ivy Bridge
- Haswell
- Broadwell
- Skylake
- Kabylake
Polly uses since several months a performance model for BLAS computations that
derives optimal cache and register tile sizes from cache and latency
information (based on ideas from "Analytical Modeling Is Enough for High-Performance BLIS", by Tze Meng Low published at TOMS 2016).
While bootstrapping this model, these target values have been kept in Polly.
However, as our implementation is now rather mature, it seems time to teach
LLVM itself about cache sizes.
Interestingly, L1 and L2 cache sizes are pretty constant across
micro-architectures, hence a set of architecture specific default values
seems like a good start. They can be expanded to more target specific values,
in case certain newer architectures require different values. For now a set
of Intel architectures are provided.
Just as a little teaser, for a simple gemm kernel this model allows us to
improve performance from 1.2s to 0.27s. For gemm kernels with less optimal
memory layouts even larger speedups can be reported.
Reviewers: Meinersbur, bollu, singam-sanjay, hfinkel, gareevroman, fhahn, sebpop, efriedma, asb
Reviewed By: fhahn, asb
Subscribers: lsaba, asb, pollydev, llvm-commits
Differential Revision: https://reviews.llvm.org/D37051
llvm-svn: 311647
2017-08-24 17:46:25 +08:00
|
|
|
/// \name Cache TTI Implementation
|
|
|
|
/// @{
|
|
|
|
llvm::Optional<unsigned> getCacheSize(
|
|
|
|
TargetTransformInfo::CacheLevel Level) const;
|
|
|
|
llvm::Optional<unsigned> getCacheAssociativity(
|
|
|
|
TargetTransformInfo::CacheLevel Level) const;
|
|
|
|
/// @}
|
|
|
|
|
2015-01-31 19:17:59 +08:00
|
|
|
/// \name Vector TTI Implementations
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
unsigned getNumberOfRegisters(bool Vector);
|
2017-04-06 04:51:38 +08:00
|
|
|
unsigned getRegisterBitWidth(bool Vector) const;
|
|
|
|
unsigned getLoadStoreVecRegBitWidth(unsigned AS) const;
|
2015-05-07 01:12:25 +08:00
|
|
|
unsigned getMaxInterleaveFactor(unsigned VF);
|
2015-08-06 02:08:10 +08:00
|
|
|
int getArithmeticInstrCost(
|
2015-01-31 19:17:59 +08:00
|
|
|
unsigned Opcode, Type *Ty,
|
|
|
|
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,
|
|
|
|
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue,
|
|
|
|
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
|
[X86] updating TTI costs for arithmetic instructions on X86\SLM arch.
updated instructions:
pmulld, pmullw, pmulhw, mulsd, mulps, mulpd, divss, divps, divsd, divpd, addpd and subpd.
special optimization case which replaces pmulld with pmullw\pmulhw\pshuf seq.
In case if the real operands bitwidth <= 16.
Differential Revision: https://reviews.llvm.org/D28104
llvm-svn: 291657
2017-01-11 16:23:37 +08:00
|
|
|
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
|
|
|
|
ArrayRef<const Value *> Args = ArrayRef<const Value *>());
|
2015-08-06 02:08:10 +08:00
|
|
|
int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp);
|
2017-04-12 19:49:08 +08:00
|
|
|
int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
|
|
|
|
const Instruction *I = nullptr);
|
|
|
|
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
|
|
|
|
const Instruction *I = nullptr);
|
2015-08-06 02:08:10 +08:00
|
|
|
int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
|
|
|
|
int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
|
2017-04-12 19:49:08 +08:00
|
|
|
unsigned AddressSpace, const Instruction *I = nullptr);
|
2015-08-06 02:08:10 +08:00
|
|
|
int getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
|
|
|
|
unsigned AddressSpace);
|
2015-12-29 04:10:59 +08:00
|
|
|
int getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr,
|
|
|
|
bool VariableMask, unsigned Alignment);
|
2017-01-05 22:03:41 +08:00
|
|
|
int getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE,
|
|
|
|
const SCEV *Ptr);
|
2015-01-31 19:17:59 +08:00
|
|
|
|
2017-06-07 00:45:25 +08:00
|
|
|
unsigned getAtomicMemIntrinsicMaxElementSize() const;
|
|
|
|
|
2016-05-24 16:17:50 +08:00
|
|
|
int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
|
2017-03-14 14:35:36 +08:00
|
|
|
ArrayRef<Type *> Tys, FastMathFlags FMF,
|
|
|
|
unsigned ScalarizationCostPassed = UINT_MAX);
|
2016-05-24 16:17:50 +08:00
|
|
|
int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
|
2017-03-14 14:35:36 +08:00
|
|
|
ArrayRef<Value *> Args, FastMathFlags FMF,
|
|
|
|
unsigned VF = 1);
|
2016-05-24 16:17:50 +08:00
|
|
|
|
2017-07-31 22:19:32 +08:00
|
|
|
int getArithmeticReductionCost(unsigned Opcode, Type *Ty,
|
|
|
|
bool IsPairwiseForm);
|
2015-01-31 19:17:59 +08:00
|
|
|
|
2017-09-08 21:49:36 +08:00
|
|
|
int getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwiseForm,
|
|
|
|
bool IsUnsigned);
|
|
|
|
|
2017-01-02 18:37:52 +08:00
|
|
|
int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy,
|
|
|
|
unsigned Factor, ArrayRef<unsigned> Indices,
|
2018-10-14 16:50:06 +08:00
|
|
|
unsigned Alignment, unsigned AddressSpace,
|
2018-10-31 17:57:56 +08:00
|
|
|
bool UseMaskForCond = false,
|
|
|
|
bool UseMaskForGaps = false);
|
2017-01-02 18:37:52 +08:00
|
|
|
int getInterleavedMemoryOpCostAVX512(unsigned Opcode, Type *VecTy,
|
|
|
|
unsigned Factor, ArrayRef<unsigned> Indices,
|
2018-10-14 16:50:06 +08:00
|
|
|
unsigned Alignment, unsigned AddressSpace,
|
2018-10-31 17:57:56 +08:00
|
|
|
bool UseMaskForCond = false,
|
|
|
|
bool UseMaskForGaps = false);
|
2017-06-25 16:26:25 +08:00
|
|
|
int getInterleavedMemoryOpCostAVX2(unsigned Opcode, Type *VecTy,
|
|
|
|
unsigned Factor, ArrayRef<unsigned> Indices,
|
2018-10-14 16:50:06 +08:00
|
|
|
unsigned Alignment, unsigned AddressSpace,
|
2018-10-31 17:57:56 +08:00
|
|
|
bool UseMaskForCond = false,
|
|
|
|
bool UseMaskForGaps = false);
|
2017-01-02 18:37:52 +08:00
|
|
|
|
2015-08-06 02:08:10 +08:00
|
|
|
int getIntImmCost(int64_t);
|
2015-01-31 19:17:59 +08:00
|
|
|
|
2015-08-06 02:08:10 +08:00
|
|
|
int getIntImmCost(const APInt &Imm, Type *Ty);
|
2015-01-31 19:17:59 +08:00
|
|
|
|
2017-08-20 20:34:29 +08:00
|
|
|
unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands);
|
|
|
|
|
2015-08-06 02:08:10 +08:00
|
|
|
int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty);
|
|
|
|
int getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
|
|
|
|
Type *Ty);
|
2017-08-08 03:56:34 +08:00
|
|
|
bool isLSRCostLess(TargetTransformInfo::LSRCost &C1,
|
|
|
|
TargetTransformInfo::LSRCost &C2);
|
2018-02-06 07:43:05 +08:00
|
|
|
bool canMacroFuseCmp();
|
2015-10-19 15:43:38 +08:00
|
|
|
bool isLegalMaskedLoad(Type *DataType);
|
|
|
|
bool isLegalMaskedStore(Type *DataType);
|
2015-10-25 23:37:55 +08:00
|
|
|
bool isLegalMaskedGather(Type *DataType);
|
|
|
|
bool isLegalMaskedScatter(Type *DataType);
|
2019-03-22 01:38:52 +08:00
|
|
|
bool isLegalMaskedExpandLoad(Type *DataType);
|
|
|
|
bool isLegalMaskedCompressStore(Type *DataType);
|
2017-09-09 21:38:18 +08:00
|
|
|
bool hasDivRemOp(Type *DataType, bool IsSigned);
|
2017-11-28 05:15:43 +08:00
|
|
|
bool isFCmpOrdCheaperThanFCmpZero(Type *Ty);
|
2015-07-30 06:09:48 +08:00
|
|
|
bool areInlineCompatible(const Function *Caller,
|
|
|
|
const Function *Callee) const;
|
2019-02-20 04:12:20 +08:00
|
|
|
bool areFunctionArgsABICompatible(const Function *Caller,
|
|
|
|
const Function *Callee,
|
|
|
|
SmallPtrSetImpl<Argument *> &Args) const;
|
2017-10-30 22:19:33 +08:00
|
|
|
const TTI::MemCmpExpansionOptions *enableMemCmpExpansion(
|
|
|
|
bool IsZeroCmp) const;
|
2016-10-21 05:04:31 +08:00
|
|
|
bool enableInterleavedAccessVectorization();
|
2015-12-29 04:10:59 +08:00
|
|
|
private:
|
|
|
|
int getGSScalarCost(unsigned Opcode, Type *DataTy, bool VariableMask,
|
|
|
|
unsigned Alignment, unsigned AddressSpace);
|
|
|
|
int getGSVectorCost(unsigned Opcode, Type *DataTy, Value *Ptr,
|
|
|
|
unsigned Alignment, unsigned AddressSpace);
|
2015-01-31 19:17:59 +08:00
|
|
|
|
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|