2015-01-31 19:17:59 +08:00
|
|
|
//===-- NVPTXTargetTransformInfo.h - NVPTX 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
|
|
|
|
/// NVPTX 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_NVPTX_NVPTXTARGETTRANSFORMINFO_H
|
|
|
|
#define LLVM_LIB_TARGET_NVPTX_NVPTXTARGETTRANSFORMINFO_H
|
|
|
|
|
|
|
|
#include "NVPTX.h"
|
|
|
|
#include "NVPTXTargetMachine.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 NVPTXTTIImpl : public BasicTTIImplBase<NVPTXTTIImpl> {
|
|
|
|
typedef BasicTTIImplBase<NVPTXTTIImpl> BaseT;
|
|
|
|
typedef TargetTransformInfo TTI;
|
2015-02-01 22:01:15 +08:00
|
|
|
friend BaseT;
|
2015-01-31 19:17:59 +08:00
|
|
|
|
2015-02-01 22:22:17 +08:00
|
|
|
const NVPTXSubtarget *ST;
|
2015-01-31 19:17:59 +08:00
|
|
|
const NVPTXTargetLowering *TLI;
|
|
|
|
|
2015-02-01 22:22:17 +08:00
|
|
|
const NVPTXSubtarget *getST() const { return ST; };
|
2015-02-01 22:01:15 +08:00
|
|
|
const NVPTXTargetLowering *getTLI() const { return TLI; };
|
|
|
|
|
2015-01-31 19:17:59 +08:00
|
|
|
public:
|
2015-07-09 10:08:42 +08:00
|
|
|
explicit NVPTXTTIImpl(const NVPTXTargetMachine *TM, const Function &F)
|
|
|
|
: BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl()),
|
|
|
|
TLI(ST->getTargetLowering()) {}
|
2015-01-31 19:17:59 +08:00
|
|
|
|
|
|
|
bool hasBranchDivergence() { return true; }
|
|
|
|
|
Divergence analysis for GPU programs
Summary:
Some optimizations such as jump threading and loop unswitching can negatively
affect performance when applied to divergent branches. The divergence analysis
added in this patch conservatively estimates which branches in a GPU program
can diverge. This information can then help LLVM to run certain optimizations
selectively.
Test Plan: test/Analysis/DivergenceAnalysis/NVPTX/diverge.ll
Reviewers: resistor, hfinkel, eliben, meheff, jholewinski
Subscribers: broune, bjarke.roune, madhur13490, tstellarAMD, dberlin, echristo, jholewinski, llvm-commits
Differential Revision: http://reviews.llvm.org/D8576
llvm-svn: 234567
2015-04-10 13:03:50 +08:00
|
|
|
bool isSourceOfDivergence(const Value *V);
|
|
|
|
|
2017-01-31 07:02:12 +08:00
|
|
|
unsigned getFlatAddressSpace() const {
|
|
|
|
return AddressSpace::ADDRESS_SPACE_GENERIC;
|
|
|
|
}
|
|
|
|
|
2018-08-28 01:29:43 +08:00
|
|
|
// Loads and stores can be vectorized if the alignment is at least as big as
|
|
|
|
// the load/store we want to vectorize.
|
|
|
|
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
|
|
|
|
unsigned Alignment,
|
|
|
|
unsigned AddrSpace) const {
|
|
|
|
return Alignment >= ChainSizeInBytes;
|
|
|
|
}
|
|
|
|
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
|
|
|
|
unsigned Alignment,
|
|
|
|
unsigned AddrSpace) const {
|
|
|
|
return isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment, AddrSpace);
|
|
|
|
}
|
|
|
|
|
2018-04-27 21:36:05 +08:00
|
|
|
// NVPTX has infinite registers of all kinds, but the actual machine doesn't.
|
|
|
|
// We conservatively return 1 here which is just enough to enable the
|
|
|
|
// vectorizers but disables heuristics based on the number of registers.
|
|
|
|
// FIXME: Return a more reasonable number, while keeping an eye on
|
|
|
|
// LoopVectorizer's unrolling heuristics.
|
|
|
|
unsigned getNumberOfRegisters(bool Vector) const { return 1; }
|
|
|
|
|
|
|
|
// Only <2 x half> should be vectorized, so always return 32 for the vector
|
|
|
|
// register size.
|
|
|
|
unsigned getRegisterBitWidth(bool Vector) const { return 32; }
|
|
|
|
unsigned getMinVectorRegisterBitWidth() const { return 32; }
|
|
|
|
|
2018-06-17 17:55:20 +08:00
|
|
|
// We don't want to prevent inlining because of target-cpu and -features
|
|
|
|
// attributes that were added to newer versions of LLVM/Clang: There are
|
|
|
|
// no incompatible functions in PTX, ptxas will throw errors in such cases.
|
|
|
|
bool areInlineCompatible(const Function *Caller,
|
|
|
|
const Function *Callee) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-15 09:38:50 +08:00
|
|
|
// Increase the inlining cost threshold by a factor of 5, reflecting that
|
|
|
|
// calls are particularly expensive in NVPTX.
|
|
|
|
unsigned getInliningThresholdMultiplier() { return 5; }
|
|
|
|
|
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-07-14 02:33:21 +08:00
|
|
|
|
[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);
|
2017-10-25 04:31:44 +08:00
|
|
|
bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) {
|
|
|
|
// Volatile loads/stores are only supported for shared and global address
|
|
|
|
// spaces, or for generic AS that maps to them.
|
|
|
|
if (!(AddrSpace == llvm::ADDRESS_SPACE_GENERIC ||
|
|
|
|
AddrSpace == llvm::ADDRESS_SPACE_GLOBAL ||
|
|
|
|
AddrSpace == llvm::ADDRESS_SPACE_SHARED))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch(I->getOpcode()){
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case Instruction::Load:
|
|
|
|
case Instruction::Store:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-01-31 19:17:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|