2015-01-31 19:17:59 +08:00
|
|
|
//===-- X86TargetTransformInfo.h - X86 specific TTI -------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \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; }
|
|
|
|
|
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,
|
|
|
|
unsigned Alignment, unsigned AddressSpace);
|
|
|
|
int getInterleavedMemoryOpCostAVX512(unsigned Opcode, Type *VecTy,
|
|
|
|
unsigned Factor, ArrayRef<unsigned> Indices,
|
|
|
|
unsigned Alignment, unsigned AddressSpace);
|
2017-06-25 16:26:25 +08:00
|
|
|
int getInterleavedMemoryOpCostAVX2(unsigned Opcode, Type *VecTy,
|
|
|
|
unsigned Factor, ArrayRef<unsigned> Indices,
|
|
|
|
unsigned Alignment, unsigned AddressSpace);
|
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);
|
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);
|
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;
|
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
|