2017-08-09 07:53:55 +08:00
|
|
|
//===- AMDGPUTargetTransformInfo.h - AMDGPU specific TTI --------*- C++ -*-===//
|
2015-01-31 19:17:59 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-08-09 07:53:55 +08:00
|
|
|
//
|
2015-01-31 19:17:59 +08:00
|
|
|
/// \file
|
|
|
|
/// This file a TargetTransformInfo::Concept conforming object specific to the
|
|
|
|
/// AMDGPU 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.
|
2017-08-09 07:53:55 +08:00
|
|
|
//
|
2015-01-31 19:17:59 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-11 16:00:27 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETTRANSFORMINFO_H
|
|
|
|
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETTRANSFORMINFO_H
|
2015-01-31 19:17:59 +08:00
|
|
|
|
|
|
|
#include "AMDGPU.h"
|
2017-08-09 07:53:55 +08:00
|
|
|
#include "AMDGPUSubtarget.h"
|
2015-01-31 19:17:59 +08:00
|
|
|
#include "AMDGPUTargetMachine.h"
|
AMDGPU: Remove #include "MCTargetDesc/AMDGPUMCTargetDesc.h" from common headers
Summary:
MCTargetDesc/AMDGPUMCTargetDesc.h contains enums for all the instuction
and register defintions, which are huge so we only want to include
them where needed.
This will also make it easier if we want to split the R600 and GCN
definitions into separate tablegenerated files.
I was unable to remove AMDGPUMCTargetDesc.h from SIMachineFunctionInfo.h
because it uses some enums from the header to initialize default values
for the SIMachineFunction class, so I ended up having to remove includes of
SIMachineFunctionInfo.h from headers too.
Reviewers: arsenm, nhaehnle
Reviewed By: nhaehnle
Subscribers: MatzeB, kzhuravl, wdng, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46272
llvm-svn: 332930
2018-05-22 10:03:23 +08:00
|
|
|
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
|
2017-08-09 07:53:55 +08:00
|
|
|
#include "Utils/AMDGPUBaseInfo.h"
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2015-01-31 19:17:59 +08:00
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
|
|
|
#include "llvm/CodeGen/BasicTTIImpl.h"
|
2017-08-09 07:53:55 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/MC/SubtargetFeature.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include <cassert>
|
2015-01-31 19:17:59 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-08-09 07:53:55 +08:00
|
|
|
|
2016-03-25 09:00:32 +08:00
|
|
|
class AMDGPUTargetLowering;
|
2017-08-09 07:53:55 +08:00
|
|
|
class Loop;
|
|
|
|
class ScalarEvolution;
|
|
|
|
class Type;
|
|
|
|
class Value;
|
2015-01-31 19:17:59 +08:00
|
|
|
|
2016-03-11 16:00:27 +08:00
|
|
|
class AMDGPUTTIImpl final : public BasicTTIImplBase<AMDGPUTTIImpl> {
|
2017-08-09 07:53:55 +08:00
|
|
|
using BaseT = BasicTTIImplBase<AMDGPUTTIImpl>;
|
|
|
|
using TTI = TargetTransformInfo;
|
|
|
|
|
2015-02-01 22:01:15 +08:00
|
|
|
friend BaseT;
|
2015-01-31 19:17:59 +08:00
|
|
|
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
Triple TargetTriple;
|
2018-05-31 06:55:35 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AMDGPUTTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
|
|
|
|
: BaseT(TM, F.getParent()->getDataLayout()),
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
TargetTriple(TM->getTargetTriple()) {}
|
2018-05-31 06:55:35 +08:00
|
|
|
|
|
|
|
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
|
|
|
|
TTI::UnrollingPreferences &UP);
|
|
|
|
};
|
|
|
|
|
|
|
|
class GCNTTIImpl final : public BasicTTIImplBase<GCNTTIImpl> {
|
|
|
|
using BaseT = BasicTTIImplBase<GCNTTIImpl>;
|
|
|
|
using TTI = TargetTransformInfo;
|
|
|
|
|
|
|
|
friend BaseT;
|
|
|
|
|
2018-07-12 04:59:01 +08:00
|
|
|
const GCNSubtarget *ST;
|
2018-05-31 06:55:35 +08:00
|
|
|
const AMDGPUTargetLowering *TLI;
|
|
|
|
AMDGPUTTIImpl CommonTTI;
|
2017-01-31 09:20:54 +08:00
|
|
|
bool IsGraphicsShader;
|
2015-02-01 22:01:15 +08:00
|
|
|
|
2017-08-08 01:08:44 +08:00
|
|
|
const FeatureBitset InlineFeatureIgnoreList = {
|
|
|
|
// Codegen control options which don't matter.
|
|
|
|
AMDGPU::FeatureEnableLoadStoreOpt,
|
|
|
|
AMDGPU::FeatureEnableSIScheduler,
|
|
|
|
AMDGPU::FeatureEnableUnsafeDSOffsetFolding,
|
|
|
|
AMDGPU::FeatureFlatForGlobal,
|
|
|
|
AMDGPU::FeaturePromoteAlloca,
|
|
|
|
AMDGPU::FeatureUnalignedBufferAccess,
|
|
|
|
AMDGPU::FeatureUnalignedScratchAccess,
|
|
|
|
|
|
|
|
AMDGPU::FeatureAutoWaitcntBeforeBarrier,
|
|
|
|
AMDGPU::FeatureDebuggerEmitPrologue,
|
|
|
|
AMDGPU::FeatureDebuggerInsertNops,
|
|
|
|
|
|
|
|
// Property of the kernel/environment which can't actually differ.
|
|
|
|
AMDGPU::FeatureSGPRInitBug,
|
|
|
|
AMDGPU::FeatureXNACK,
|
|
|
|
AMDGPU::FeatureTrapHandler,
|
|
|
|
|
|
|
|
// Perf-tuning features
|
|
|
|
AMDGPU::FeatureFastFMAF32,
|
|
|
|
AMDGPU::HalfRate64Ops
|
|
|
|
};
|
|
|
|
|
2018-07-12 04:59:01 +08:00
|
|
|
const GCNSubtarget *getST() const { return ST; }
|
2015-02-01 22:01:15 +08:00
|
|
|
const AMDGPUTargetLowering *getTLI() const { return TLI; }
|
2015-01-31 19:17:59 +08:00
|
|
|
|
2016-03-25 09:00:32 +08:00
|
|
|
static inline int getFullRateInstrCost() {
|
|
|
|
return TargetTransformInfo::TCC_Basic;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int getHalfRateInstrCost() {
|
|
|
|
return 2 * TargetTransformInfo::TCC_Basic;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: The size is usually 8 bytes, but takes 4x as many cycles. Maybe
|
|
|
|
// should be 2 or 4.
|
|
|
|
static inline int getQuarterRateInstrCost() {
|
|
|
|
return 3 * TargetTransformInfo::TCC_Basic;
|
|
|
|
}
|
|
|
|
|
|
|
|
// On some parts, normal fp64 operations are half rate, and others
|
|
|
|
// quarter. This also applies to some integer operations.
|
|
|
|
inline int get64BitInstrCost() const {
|
|
|
|
return ST->hasHalfRate64Ops() ?
|
|
|
|
getHalfRateInstrCost() : getQuarterRateInstrCost();
|
|
|
|
}
|
|
|
|
|
2015-01-31 19:17:59 +08:00
|
|
|
public:
|
2018-05-31 06:55:35 +08:00
|
|
|
explicit GCNTTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
|
2016-06-28 04:48:03 +08:00
|
|
|
: BaseT(TM, F.getParent()->getDataLayout()),
|
2018-07-12 04:59:01 +08:00
|
|
|
ST(static_cast<const GCNSubtarget*>(TM->getSubtargetImpl(F))),
|
2017-01-31 09:20:54 +08:00
|
|
|
TLI(ST->getTargetLowering()),
|
2018-05-31 06:55:35 +08:00
|
|
|
CommonTTI(TM, F),
|
2017-01-31 09:20:54 +08:00
|
|
|
IsGraphicsShader(AMDGPU::isShader(F.getCallingConv())) {}
|
2015-01-31 19:17:59 +08:00
|
|
|
|
|
|
|
bool hasBranchDivergence() { return true; }
|
|
|
|
|
[LoopUnroll] Pass SCEV to getUnrollingPreferences hook. NFCI.
Reviewers: sanjoy, anna, reames, apilipenko, igor-laevsky, mkuper
Subscribers: jholewinski, arsenm, mzolotukhin, nemanjai, nhaehnle, javed.absar, mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D34531
llvm-svn: 306554
2017-06-28 23:53:17 +08:00
|
|
|
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
|
|
|
|
TTI::UnrollingPreferences &UP);
|
2015-01-31 19:17:59 +08:00
|
|
|
|
|
|
|
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) {
|
|
|
|
assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
|
2016-05-19 00:10:19 +08:00
|
|
|
return TTI::PSK_FastHardware;
|
2015-01-31 19:17:59 +08:00
|
|
|
}
|
|
|
|
|
2017-06-21 04:38:06 +08:00
|
|
|
unsigned getHardwareNumberOfRegisters(bool Vector) const;
|
|
|
|
unsigned getNumberOfRegisters(bool Vector) const;
|
2017-08-09 07:53:55 +08:00
|
|
|
unsigned getRegisterBitWidth(bool Vector) const;
|
2017-06-21 04:38:06 +08:00
|
|
|
unsigned getMinVectorRegisterBitWidth() const;
|
2018-03-08 01:09:18 +08:00
|
|
|
unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
|
|
|
|
unsigned ChainSizeInBytes,
|
|
|
|
VectorType *VecTy) const;
|
|
|
|
unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
|
|
|
|
unsigned ChainSizeInBytes,
|
|
|
|
VectorType *VecTy) const;
|
2016-10-03 18:31:34 +08:00
|
|
|
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const;
|
2017-02-23 11:58:53 +08:00
|
|
|
|
|
|
|
bool isLegalToVectorizeMemChain(unsigned ChainSizeInBytes,
|
|
|
|
unsigned Alignment,
|
|
|
|
unsigned AddrSpace) const;
|
|
|
|
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
|
|
|
|
unsigned Alignment,
|
|
|
|
unsigned AddrSpace) const;
|
|
|
|
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
|
|
|
|
unsigned Alignment,
|
|
|
|
unsigned AddrSpace) const;
|
|
|
|
|
2015-05-07 01:12:25 +08:00
|
|
|
unsigned getMaxInterleaveFactor(unsigned VF);
|
2015-12-02 03:08:39 +08:00
|
|
|
|
2017-12-12 05:38:43 +08:00
|
|
|
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const;
|
|
|
|
|
2016-03-25 09:00:32 +08:00
|
|
|
int getArithmeticInstrCost(
|
|
|
|
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 *>());
|
2016-03-25 09:00:32 +08:00
|
|
|
|
2015-12-17 02:37:19 +08:00
|
|
|
unsigned getCFInstrCost(unsigned Opcode);
|
|
|
|
|
2015-12-02 03:08:39 +08:00
|
|
|
int getVectorInstrCost(unsigned Opcode, Type *ValTy, unsigned Index);
|
2015-12-16 02:04:38 +08:00
|
|
|
bool isSourceOfDivergence(const Value *V) const;
|
2017-06-16 03:33:10 +08:00
|
|
|
bool isAlwaysUniform(const Value *V) const;
|
2016-07-07 01:30:56 +08:00
|
|
|
|
2017-01-31 09:20:54 +08:00
|
|
|
unsigned getFlatAddressSpace() const {
|
|
|
|
// Don't bother running InferAddressSpaces pass on graphics shaders which
|
|
|
|
// don't use flat addressing.
|
|
|
|
if (IsGraphicsShader)
|
|
|
|
return -1;
|
2017-02-01 07:48:37 +08:00
|
|
|
return ST->hasFlatAddressSpace() ?
|
2018-08-31 13:49:54 +08:00
|
|
|
AMDGPUAS::FLAT_ADDRESS : AMDGPUAS::UNKNOWN_ADDRESS_SPACE;
|
2017-01-31 09:20:54 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 01:30:56 +08:00
|
|
|
unsigned getVectorSplitCost() { return 0; }
|
2017-05-11 05:29:33 +08:00
|
|
|
|
|
|
|
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
|
|
|
|
Type *SubTp);
|
2017-08-08 01:08:44 +08:00
|
|
|
|
|
|
|
bool areInlineCompatible(const Function *Caller,
|
|
|
|
const Function *Callee) const;
|
2017-09-20 12:25:58 +08:00
|
|
|
|
|
|
|
unsigned getInliningThresholdMultiplier() { return 9; }
|
2018-05-02 05:41:12 +08:00
|
|
|
|
|
|
|
int getArithmeticReductionCost(unsigned Opcode,
|
|
|
|
Type *Ty,
|
|
|
|
bool IsPairwise);
|
2018-05-10 05:18:34 +08:00
|
|
|
int getMinMaxReductionCost(Type *Ty, Type *CondTy,
|
|
|
|
bool IsPairwiseForm,
|
|
|
|
bool IsUnsigned);
|
2015-01-31 19:17:59 +08:00
|
|
|
};
|
|
|
|
|
2018-05-31 06:55:35 +08:00
|
|
|
class R600TTIImpl final : public BasicTTIImplBase<R600TTIImpl> {
|
|
|
|
using BaseT = BasicTTIImplBase<R600TTIImpl>;
|
|
|
|
using TTI = TargetTransformInfo;
|
|
|
|
|
|
|
|
friend BaseT;
|
|
|
|
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
const R600Subtarget *ST;
|
2018-05-31 06:55:35 +08:00
|
|
|
const AMDGPUTargetLowering *TLI;
|
|
|
|
AMDGPUTTIImpl CommonTTI;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit R600TTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
|
|
|
|
: BaseT(TM, F.getParent()->getDataLayout()),
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
ST(static_cast<const R600Subtarget*>(TM->getSubtargetImpl(F))),
|
2018-05-31 06:55:35 +08:00
|
|
|
TLI(ST->getTargetLowering()),
|
|
|
|
CommonTTI(TM, F) {}
|
|
|
|
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 07:47:12 +08:00
|
|
|
const R600Subtarget *getST() const { return ST; }
|
2018-05-31 06:55:35 +08:00
|
|
|
const AMDGPUTargetLowering *getTLI() const { return TLI; }
|
|
|
|
|
|
|
|
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
|
|
|
|
TTI::UnrollingPreferences &UP);
|
|
|
|
unsigned getHardwareNumberOfRegisters(bool Vec) const;
|
|
|
|
unsigned getNumberOfRegisters(bool Vec) const;
|
|
|
|
unsigned getRegisterBitWidth(bool Vector) const;
|
|
|
|
unsigned getMinVectorRegisterBitWidth() const;
|
|
|
|
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const;
|
|
|
|
bool isLegalToVectorizeMemChain(unsigned ChainSizeInBytes, unsigned Alignment,
|
|
|
|
unsigned AddrSpace) const;
|
|
|
|
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
|
|
|
|
unsigned Alignment,
|
|
|
|
unsigned AddrSpace) const;
|
|
|
|
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
|
|
|
|
unsigned Alignment,
|
|
|
|
unsigned AddrSpace) const;
|
|
|
|
unsigned getMaxInterleaveFactor(unsigned VF);
|
|
|
|
unsigned getCFInstrCost(unsigned Opcode);
|
|
|
|
int getVectorInstrCost(unsigned Opcode, Type *ValTy, unsigned Index);
|
|
|
|
};
|
|
|
|
|
2015-01-31 19:17:59 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
2017-08-09 07:53:55 +08:00
|
|
|
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETTRANSFORMINFO_H
|