Path: blob/main/contrib/llvm-project/llvm/lib/Target/VE/VETargetTransformInfo.h
35269 views
//===- VETargetTransformInfo.h - VE 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/// VE 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_VE_VETARGETTRANSFORMINFO_H16#define LLVM_LIB_TARGET_VE_VETARGETTRANSFORMINFO_H1718#include "VE.h"19#include "VETargetMachine.h"20#include "llvm/Analysis/TargetTransformInfo.h"21#include "llvm/CodeGen/BasicTTIImpl.h"2223static llvm::Type *getVectorElementType(llvm::Type *Ty) {24return llvm::cast<llvm::FixedVectorType>(Ty)->getElementType();25}2627static llvm::Type *getLaneType(llvm::Type *Ty) {28using namespace llvm;29if (!isa<VectorType>(Ty))30return Ty;31return getVectorElementType(Ty);32}3334static bool isVectorLaneType(llvm::Type &ElemTy) {35// check element sizes for vregs36if (ElemTy.isIntegerTy()) {37unsigned ScaBits = ElemTy.getScalarSizeInBits();38return ScaBits == 1 || ScaBits == 32 || ScaBits == 64;39}40if (ElemTy.isPointerTy()) {41return true;42}43if (ElemTy.isFloatTy() || ElemTy.isDoubleTy()) {44return true;45}46return false;47}4849namespace llvm {5051class VETTIImpl : public BasicTTIImplBase<VETTIImpl> {52using BaseT = BasicTTIImplBase<VETTIImpl>;53friend BaseT;5455const VESubtarget *ST;56const VETargetLowering *TLI;5758const VESubtarget *getST() const { return ST; }59const VETargetLowering *getTLI() const { return TLI; }6061bool enableVPU() const { return getST()->enableVPU(); }6263static bool isSupportedReduction(Intrinsic::ID ReductionID) {64#define VEC_VP_CASE(SUFFIX) \65case Intrinsic::vp_reduce_##SUFFIX: \66case Intrinsic::vector_reduce_##SUFFIX:6768switch (ReductionID) {69VEC_VP_CASE(add)70VEC_VP_CASE(and)71VEC_VP_CASE(or)72VEC_VP_CASE(xor)73VEC_VP_CASE(smax)74return true;7576default:77return false;78}79#undef VEC_VP_CASE80}8182public:83explicit VETTIImpl(const VETargetMachine *TM, const Function &F)84: BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),85TLI(ST->getTargetLowering()) {}8687unsigned getNumberOfRegisters(unsigned ClassID) const {88bool VectorRegs = (ClassID == 1);89if (VectorRegs) {90// TODO report vregs once vector isel is stable.91return 0;92}9394return 64;95}9697TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const {98switch (K) {99case TargetTransformInfo::RGK_Scalar:100return TypeSize::getFixed(64);101case TargetTransformInfo::RGK_FixedWidthVector:102// TODO report vregs once vector isel is stable.103return TypeSize::getFixed(0);104case TargetTransformInfo::RGK_ScalableVector:105return TypeSize::getScalable(0);106}107108llvm_unreachable("Unsupported register kind");109}110111/// \returns How the target needs this vector-predicated operation to be112/// transformed.113TargetTransformInfo::VPLegalization114getVPLegalizationStrategy(const VPIntrinsic &PI) const {115using VPLegalization = TargetTransformInfo::VPLegalization;116return VPLegalization(VPLegalization::Legal, VPLegalization::Legal);117}118119unsigned getMinVectorRegisterBitWidth() const {120// TODO report vregs once vector isel is stable.121return 0;122}123124bool shouldBuildRelLookupTables() const {125// NEC nld doesn't support relative lookup tables. It shows following126// errors. So, we disable it at the moment.127// /opt/nec/ve/bin/nld: src/CMakeFiles/cxxabi_shared.dir/cxa_demangle.cpp128// .o(.rodata+0x17b4): reloc against `.L.str.376': error 2129// /opt/nec/ve/bin/nld: final link failed: Nonrepresentable section on130// output131return false;132}133134// Load & Store {135bool isLegalMaskedLoad(Type *DataType, MaybeAlign Alignment) {136return isVectorLaneType(*getLaneType(DataType));137}138bool isLegalMaskedStore(Type *DataType, MaybeAlign Alignment) {139return isVectorLaneType(*getLaneType(DataType));140}141bool isLegalMaskedGather(Type *DataType, MaybeAlign Alignment) {142return isVectorLaneType(*getLaneType(DataType));143};144bool isLegalMaskedScatter(Type *DataType, MaybeAlign Alignment) {145return isVectorLaneType(*getLaneType(DataType));146}147// } Load & Store148149bool shouldExpandReduction(const IntrinsicInst *II) const {150if (!enableVPU())151return true;152return !isSupportedReduction(II->getIntrinsicID());153}154};155156} // namespace llvm157158#endif // LLVM_LIB_TARGET_VE_VETARGETTRANSFORMINFO_H159160161