Path: blob/main/contrib/llvm-project/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.h
35271 views
//===-- NVPTXTargetTransformInfo.h - NVPTX specific TTI ---------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7/// \file8/// This file a TargetTransformInfo::Concept conforming object specific to the9/// NVPTX target machine. It uses the target's detailed information to10/// provide more precise answers to certain TTI queries, while letting the11/// target independent and default TTI implementations handle the rest.12///13//===----------------------------------------------------------------------===//1415#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXTARGETTRANSFORMINFO_H16#define LLVM_LIB_TARGET_NVPTX_NVPTXTARGETTRANSFORMINFO_H1718#include "NVPTXTargetMachine.h"19#include "MCTargetDesc/NVPTXBaseInfo.h"20#include "llvm/Analysis/TargetTransformInfo.h"21#include "llvm/CodeGen/BasicTTIImpl.h"22#include "llvm/CodeGen/TargetLowering.h"23#include <optional>2425namespace llvm {2627class NVPTXTTIImpl : public BasicTTIImplBase<NVPTXTTIImpl> {28typedef BasicTTIImplBase<NVPTXTTIImpl> BaseT;29typedef TargetTransformInfo TTI;30friend BaseT;3132const NVPTXSubtarget *ST;33const NVPTXTargetLowering *TLI;3435const NVPTXSubtarget *getST() const { return ST; };36const NVPTXTargetLowering *getTLI() const { return TLI; };3738public:39explicit NVPTXTTIImpl(const NVPTXTargetMachine *TM, const Function &F)40: BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl()),41TLI(ST->getTargetLowering()) {}4243bool hasBranchDivergence(const Function *F = nullptr) { return true; }4445bool isSourceOfDivergence(const Value *V);4647unsigned getFlatAddressSpace() const {48return AddressSpace::ADDRESS_SPACE_GENERIC;49}5051bool canHaveNonUndefGlobalInitializerInAddressSpace(unsigned AS) const {52return AS != AddressSpace::ADDRESS_SPACE_SHARED &&53AS != AddressSpace::ADDRESS_SPACE_LOCAL && AS != ADDRESS_SPACE_PARAM;54}5556std::optional<Instruction *> instCombineIntrinsic(InstCombiner &IC,57IntrinsicInst &II) const;5859// Loads and stores can be vectorized if the alignment is at least as big as60// the load/store we want to vectorize.61bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment,62unsigned AddrSpace) const {63return Alignment >= ChainSizeInBytes;64}65bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment,66unsigned AddrSpace) const {67return isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment, AddrSpace);68}6970// NVPTX has infinite registers of all kinds, but the actual machine doesn't.71// We conservatively return 1 here which is just enough to enable the72// vectorizers but disables heuristics based on the number of registers.73// FIXME: Return a more reasonable number, while keeping an eye on74// LoopVectorizer's unrolling heuristics.75unsigned getNumberOfRegisters(bool Vector) const { return 1; }7677// Only <2 x half> should be vectorized, so always return 32 for the vector78// register size.79TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const {80return TypeSize::getFixed(32);81}82unsigned getMinVectorRegisterBitWidth() const { return 32; }8384// We don't want to prevent inlining because of target-cpu and -features85// attributes that were added to newer versions of LLVM/Clang: There are86// no incompatible functions in PTX, ptxas will throw errors in such cases.87bool areInlineCompatible(const Function *Caller,88const Function *Callee) const {89return true;90}9192// Increase the inlining cost threshold by a factor of 11, reflecting that93// calls are particularly expensive in NVPTX.94unsigned getInliningThresholdMultiplier() const { return 11; }9596InstructionCost getArithmeticInstrCost(97unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,98TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},99TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},100ArrayRef<const Value *> Args = std::nullopt,101const Instruction *CxtI = nullptr);102103void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,104TTI::UnrollingPreferences &UP,105OptimizationRemarkEmitter *ORE);106107void getPeelingPreferences(Loop *L, ScalarEvolution &SE,108TTI::PeelingPreferences &PP);109110bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) {111// Volatile loads/stores are only supported for shared and global address112// spaces, or for generic AS that maps to them.113if (!(AddrSpace == llvm::ADDRESS_SPACE_GENERIC ||114AddrSpace == llvm::ADDRESS_SPACE_GLOBAL ||115AddrSpace == llvm::ADDRESS_SPACE_SHARED))116return false;117118switch(I->getOpcode()){119default:120return false;121case Instruction::Load:122case Instruction::Store:123return true;124}125}126};127128} // end namespace llvm129130#endif131132133