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"
|
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
|
|
|
|
|
|
|
const AMDGPUSubtarget *ST;
|
2015-02-01 22:01:15 +08:00
|
|
|
const AMDGPUTargetLowering *TLI;
|
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,
|
|
|
|
AMDGPU::FeatureDebuggerReserveRegs,
|
|
|
|
|
|
|
|
// Property of the kernel/environment which can't actually differ.
|
|
|
|
AMDGPU::FeatureSGPRInitBug,
|
|
|
|
AMDGPU::FeatureXNACK,
|
|
|
|
AMDGPU::FeatureTrapHandler,
|
|
|
|
|
|
|
|
// Perf-tuning features
|
|
|
|
AMDGPU::FeatureFastFMAF32,
|
|
|
|
AMDGPU::HalfRate64Ops
|
|
|
|
};
|
|
|
|
|
2015-02-01 22:22:17 +08:00
|
|
|
const AMDGPUSubtarget *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:
|
2016-06-28 04:48:03 +08:00
|
|
|
explicit AMDGPUTTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
|
|
|
|
: BaseT(TM, F.getParent()->getDataLayout()),
|
|
|
|
ST(TM->getSubtargetImpl(F)),
|
2017-01-31 09:20:54 +08:00
|
|
|
TLI(ST->getTargetLowering()),
|
|
|
|
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;
|
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
|
|
|
|
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() ?
|
2017-03-27 22:04:01 +08:00
|
|
|
ST->getAMDGPUAS().FLAT_ADDRESS : ST->getAMDGPUAS().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; }
|
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
|