LLVM 24.0.0git
SPIRVSubtarget.h
Go to the documentation of this file.
1//===-- SPIRVSubtarget.h - SPIR-V Subtarget Information --------*- 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//
9// This file declares the SPIR-V specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H
14#define LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H
15
16#include "SPIRVCallLowering.h"
17#include "SPIRVFrameLowering.h"
18#include "SPIRVISelLowering.h"
20#include "SPIRVInstrInfo.h"
21#include "llvm/ADT/SmallSet.h"
27#include "llvm/IR/DataLayout.h"
28#include "llvm/IR/Module.h"
31
32namespace llvm {
33enum class SPIRVFPContractMode { On, Off, Fast };
34} // namespace llvm
35
36#define OPTIONS_STRUCT_DECL
37#include "SPIRVOptions.inc"
38
39#define GET_SUBTARGETINFO_HEADER
40#include "SPIRVGenSubtargetInfo.inc"
41
42namespace llvm {
43class StringRef;
44class SPIRVTargetMachine;
45
47public:
48 // Enum for the SPIR-V environment: Kernel, Shader or Unknown.
50
51private:
52 const SPIRVOptions &CLOpts;
53 const unsigned PointerSize;
54 VersionTuple SPIRVVersion;
55 VersionTuple OpenCLVersion;
56
57 ExtensionSet DisabledExtensions;
60 std::unique_ptr<SPIRVGlobalRegistry> GR;
61
62 SPIRVInstrInfo InstrInfo;
63 SPIRVFrameLowering FrameLowering;
65 Triple TargetTriple;
66 SPIRVEnvType Env;
67
68 // GlobalISel related APIs.
69 std::unique_ptr<CallLowering> CallLoweringInfo;
70 std::unique_ptr<RegisterBankInfo> RegBankInfo;
71 std::unique_ptr<LegalizerInfo> Legalizer;
72 std::unique_ptr<InstructionSelector> InstSelector;
73 std::unique_ptr<InlineAsmLowering> InlineAsmInfo;
74
75 void initAvailableExtInstSets();
76 void accountForAMDShaderTrinaryMinmax();
77 void accountForNonSemanticDebugBreak();
78
79public:
80 // This constructor initializes the data members to match that
81 // of the specified triple.
82 SPIRVSubtarget(const Triple &TT, const std::string &CPU,
83 const std::string &FS, const SPIRVTargetMachine &TM);
85
86 void initAvailableExtensions(const ExtensionSet &AllowedExtIds);
87 void resolveEnvFromModule(const Module &M);
88
89 // Parses features string setting specified subtarget options.
90 // The definition of this function is auto generated by tblgen.
92 const SPIRVOptions &getCLOpts() const { return CLOpts; }
93 unsigned getPointerSize() const { return PointerSize; }
94 unsigned getBound() const { return GR->getBound(); }
95 bool canDirectlyComparePointers() const;
96 void setEnv(SPIRVEnvType E);
97 SPIRVEnvType getEnv() const { return Env; }
98 bool isKernel() const { return getEnv() == Kernel; }
99 bool isShader() const { return getEnv() == Shader; }
100 bool isLogicalSPIRV() const { return TargetTriple.isSPIRVLogical(); }
101 bool isPhysicalSPIRV() const {
102 return TargetTriple.getArch() == Triple::spirv32 ||
103 TargetTriple.getArch() == Triple::spirv64;
104 }
105 const std::string &getTargetTripleAsStr() const { return TargetTriple.str(); }
106 VersionTuple getSPIRVVersion() const { return SPIRVVersion; };
107 bool isAtLeastSPIRVVer(VersionTuple VerToCompareTo) const;
108 bool isAtLeastOpenCLVer(VersionTuple VerToCompareTo) const;
109 // TODO: implement command line args or other ways to determine this.
110 bool hasOpenCLFullProfile() const { return true; }
111 bool hasOpenCLImageSupport() const { return true; }
114 return AvailableExtensions;
115 }
116 bool canUseExtension(SPIRV::Extension::Extension E) const;
117 bool canUseExtInstSet(SPIRV::InstructionSet::InstructionSet E) const;
118 SPIRV::InstructionSet::InstructionSet getPreferredInstructionSet() const;
119
120 SPIRVGlobalRegistry *getSPIRVGlobalRegistry() const { return GR.get(); }
121
122 const CallLowering *getCallLowering() const override {
123 return CallLoweringInfo.get();
124 }
125 const RegisterBankInfo *getRegBankInfo() const override {
126 return RegBankInfo.get();
127 }
128 const LegalizerInfo *getLegalizerInfo() const override {
129 return Legalizer.get();
130 }
132 return InstSelector.get();
133 }
134 const InlineAsmLowering *getInlineAsmLowering() const override {
135 return InlineAsmInfo.get();
136 }
137 const SPIRVInstrInfo *getInstrInfo() const override { return &InstrInfo; }
138 const SPIRVFrameLowering *getFrameLowering() const override {
139 return &FrameLowering;
140 }
141 const SPIRVTargetLowering *getTargetLowering() const override {
142 return &TLInfo;
143 }
144 const SPIRVRegisterInfo *getRegisterInfo() const override {
145 return &InstrInfo.getRegisterInfo();
146 }
147
148 static bool classof(const TargetSubtargetInfo *ST) {
149 return ST->getTargetTriple().isSPIRV();
150 }
151};
152} // namespace llvm
153
154#endif // LLVM_LIB_TARGET_SPIRV_SPIRVSUBTARGET_H
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file describes how to lower LLVM calls to machine code calls.
DXIL Legalizer
Module.h This file contains the declarations for the Module class.
Interface for Targets to specify which operations they can successfully select and how the others sho...
This file defines the SmallSet class.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
Holds all the information related to register banks.
unsigned getPointerSize() const
bool hasOpenCLImageSupport() const
SPIRVSubtarget & initSubtargetDependencies(StringRef CPU, StringRef FS)
bool isPhysicalSPIRV() const
InstructionSelector * getInstructionSelector() const override
const LegalizerInfo * getLegalizerInfo() const override
bool canDirectlyComparePointers() const
const SPIRVInstrInfo * getInstrInfo() const override
const SmallSet< SPIRV::Extension::Extension, 4 > & getAllAvailableExtensions() const
const std::string & getTargetTripleAsStr() const
bool isAtLeastSPIRVVer(VersionTuple VerToCompareTo) const
static bool classof(const TargetSubtargetInfo *ST)
SPIRVGlobalRegistry * getSPIRVGlobalRegistry() const
void resolveEnvFromModule(const Module &M)
const SPIRVRegisterInfo * getRegisterInfo() const override
bool isAtLeastOpenCLVer(VersionTuple VerToCompareTo) const
const SPIRVTargetLowering * getTargetLowering() const override
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
bool canUseExtInstSet(SPIRV::InstructionSet::InstructionSet E) const
const RegisterBankInfo * getRegBankInfo() const override
const CallLowering * getCallLowering() const override
SPIRVSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const SPIRVTargetMachine &TM)
const SPIRVOptions & getCLOpts() const
bool isLogicalSPIRV() const
const InlineAsmLowering * getInlineAsmLowering() const override
SPIRV::InstructionSet::InstructionSet getPreferredInstructionSet() const
VersionTuple getSPIRVVersion() const
unsigned getBound() const
SPIRVEnvType getEnv() const
bool hasOpenCLFullProfile() const
bool canUseExtension(SPIRV::Extension::Extension E) const
void initAvailableExtensions(const ExtensionSet &AllowedExtIds)
void setEnv(SPIRVEnvType E)
const SPIRVFrameLowering * getFrameLowering() const override
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:134
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
TargetSubtargetInfo - Generic base class for all target subtargets.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
Represents a version number in the form major[.minor[.subminor[.build]]].
This is an optimization pass for GlobalISel generic memory operations.
DenseSet< SPIRV::Extension::Extension > ExtensionSet
SPIRVFPContractMode
@ Fast
Assign the register banks as fast as possible (default).