LLVM 24.0.0git
SPIRVTargetTransformInfo.h
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8// \file
9// This file contains a TargetTransformInfoImplBase conforming object specific
10// to the SPIRV target machine. It uses the target's detailed information to
11// provide more precise answers to certain TTI queries, while letting the
12// target independent and default TTI implementations handle the rest.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVTARGETTRANSFORMINFO_H
17#define LLVM_LIB_TARGET_SPIRV_SPIRVTARGETTRANSFORMINFO_H
18
19#include "SPIRV.h"
20#include "SPIRVTargetMachine.h"
24
25namespace llvm {
26class SPIRVTTIImpl final : public BasicTTIImplBase<SPIRVTTIImpl> {
28 using TTI = TargetTransformInfo;
29
30 friend BaseT;
31
32 const SPIRVSubtarget *ST;
33 const SPIRVTargetLowering *TLI;
34
35 const TargetSubtargetInfo *getST() const { return ST; }
36 const SPIRVTargetLowering *getTLI() const { return TLI; }
37
38public:
39 explicit SPIRVTTIImpl(const SPIRVTargetMachine *TM, const Function &F)
40 : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
41 TLI(ST->getTargetLowering()) {}
42
43 bool hasBranchDivergence(const Function *F = nullptr) const override {
44 // Shader and OpenCL work-items execute divergently across invocations.
45 return true;
46 }
47
48 ValueUniformity getValueUniformity(const Value *V) const override;
49
50 unsigned getFlatAddressSpace() const override {
51 // Clang has 2 distinct address space maps. One where
52 // default=Generic, and one with default=Function. This depends on the
53 // environment.
54 return ST->isShader() ? SPIRVAS::Function : SPIRVAS::Generic;
55 }
57 Intrinsic::ID IID) const override;
59 Value *NewV) const override;
60
61 bool allowVectorElementIndexingUsingGEP() const override { return false; }
62
63 unsigned getNumberOfRegisters(unsigned ClassID) const override {
64 // Turn off the vectorizer for logical SPIR-V. It cannot express loads that
65 // span several struct members.
66 if (ST->isLogicalSPIRV() &&
67 ClassID == getRegisterClassForType(/*Vector=*/true))
68 return 0;
69 return BaseT::getNumberOfRegisters(ClassID);
70 }
71
74 TTI::TargetCostKind CostKind) const override;
75
76 bool isLegalMaskedGather(Type *DataType, Align Alignment) const override;
77 bool isLegalMaskedScatter(Type *DataType, Align Alignment) const override;
78
80 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
82 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
83 TTI::TargetCostKind CostKind,
84 std::optional<FastMathFlags> FMF) const override {
86 }
87};
88
89} // namespace llvm
90
91#endif // LLVM_LIB_TARGET_SPIRV_SPIRVTARGETTRANSFORMINFO_H
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
#define F(x, y, z)
Definition MD5.cpp:54
uint64_t IntrinsicInst * II
SPIR-V address space definition.
This pass exposes codegen information to IR-level passes.
BasicTTIImplBase(const TargetMachine *TM, const DataLayout &DL)
static InstructionCost getInvalid(CostType Val=0)
A wrapper class for inspecting calls to intrinsic functions.
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
Get intrinsic cost based on arguments.
Value * rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV, Value *NewV) const override
bool isLegalMaskedScatter(Type *DataType, Align Alignment) const override
unsigned getNumberOfRegisters(unsigned ClassID) const override
bool collectFlatAddressOperands(SmallVectorImpl< int > &OpIndexes, Intrinsic::ID IID) const override
SPIRVTTIImpl(const SPIRVTargetMachine *TM, const Function &F)
bool hasBranchDivergence(const Function *F=nullptr) const override
bool isLegalMaskedGather(Type *DataType, Align Alignment) const override
InstructionCost getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, ElementCount VF, TTI::PartialReductionExtendKind OpAExtend, TTI::PartialReductionExtendKind OpBExtend, std::optional< unsigned > BinOp, TTI::TargetCostKind CostKind, std::optional< FastMathFlags > FMF) const override
unsigned getFlatAddressSpace() const override
bool allowVectorElementIndexingUsingGEP() const override
ValueUniformity getValueUniformity(const Value *V) const override
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const DataLayout & getDataLayout() const
virtual unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const
virtual unsigned getNumberOfRegisters(unsigned ClassID) const
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
TargetCostKind
The kind of cost model.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
ValueUniformity
Enum describing how values behave with respect to uniformity and divergence, to answer the question: ...
Definition Uniformity.h:18
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39