69 lines · c
1//===- SPIRVTargetTransformInfo.h - SPIR-V specific TTI ---------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8// \file9// This file contains a TargetTransformInfoImplBase conforming object specific10// to the SPIRV target machine. It uses the target's detailed information to11// provide more precise answers to certain TTI queries, while letting the12// target independent and default TTI implementations handle the rest.13//14//===----------------------------------------------------------------------===//15 16#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVTARGETTRANSFORMINFO_H17#define LLVM_LIB_TARGET_SPIRV_SPIRVTARGETTRANSFORMINFO_H18 19#include "SPIRV.h"20#include "SPIRVTargetMachine.h"21#include "llvm/Analysis/TargetTransformInfo.h"22#include "llvm/CodeGen/BasicTTIImpl.h"23 24namespace llvm {25class SPIRVTTIImpl final : public BasicTTIImplBase<SPIRVTTIImpl> {26 using BaseT = BasicTTIImplBase<SPIRVTTIImpl>;27 using TTI = TargetTransformInfo;28 29 friend BaseT;30 31 const SPIRVSubtarget *ST;32 const SPIRVTargetLowering *TLI;33 34 const TargetSubtargetInfo *getST() const { return ST; }35 const SPIRVTargetLowering *getTLI() const { return TLI; }36 37public:38 explicit SPIRVTTIImpl(const SPIRVTargetMachine *TM, const Function &F)39 : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),40 TLI(ST->getTargetLowering()) {}41 42 TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override {43 // SPIR-V natively supports OpBitcount, per 3.53.14 in the spec, as such it44 // is reasonable to assume the Op is fast / preferable to the expanded loop.45 // Furthermore, this prevents information being lost if transforms are46 // applied to SPIR-V before lowering to a concrete target.47 if (!isPowerOf2_32(TyWidth) || TyWidth > 64)48 return TTI::PSK_Software; // Arbitrary bit-width INT is not core SPIR-V.49 return TTI::PSK_FastHardware;50 }51 52 unsigned getFlatAddressSpace() const override {53 // Clang has 2 distinct address space maps. One where54 // default=4=Generic, and one with default=0=Function. This depends on the55 // environment.56 return ST->isShader() ? 0 : 4;57 }58 bool collectFlatAddressOperands(SmallVectorImpl<int> &OpIndexes,59 Intrinsic::ID IID) const override;60 Value *rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV,61 Value *NewV) const override;62 63 bool allowVectorElementIndexingUsingGEP() const override { return false; }64};65 66} // namespace llvm67 68#endif // LLVM_LIB_TARGET_SPIRV_SPIRVTARGETTRANSFORMINFO_H69