24#define DEBUG_TYPE "spirv-subtarget"
26#define GET_SUBTARGETINFO_TARGET_DESC
27#define GET_SUBTARGETINFO_CTOR
28#include "SPIRVGenSubtargetInfo.inc"
32 cl::desc(
"SPIR-V Translator compatibility mode"),
37 cl::desc(
"Specify list of enabled SPIR-V extensions"));
51 const std::string &FS,
54 PointerSize(TM.getPointerSizeInBits( 0)),
56 TLInfo(TM, *this), TargetTriple(TT) {
57 switch (TT.getSubArch()) {
58 case Triple::SPIRVSubArch_v10:
59 SPIRVVersion = VersionTuple(1, 0);
61 case Triple::SPIRVSubArch_v11:
62 SPIRVVersion = VersionTuple(1, 1);
64 case Triple::SPIRVSubArch_v12:
65 SPIRVVersion = VersionTuple(1, 2);
67 case Triple::SPIRVSubArch_v13:
68 SPIRVVersion = VersionTuple(1, 3);
70 case Triple::SPIRVSubArch_v14:
71 SPIRVVersion = VersionTuple(1, 4);
73 case Triple::SPIRVSubArch_v15:
74 SPIRVVersion = VersionTuple(1, 5);
76 case Triple::SPIRVSubArch_v16:
77 SPIRVVersion = VersionTuple(1, 6);
80 if (TT.getVendor() == Triple::AMD)
81 SPIRVVersion = VersionTuple(1, 6);
83 SPIRVVersion = VersionTuple(1, 4);
98 Extensions.insert(SPIRV::Extension::SPV_INTEL_function_pointers);
100 SPIRV::Extension::SPV_EXT_relaxed_printf_string_address_space);
107 initAvailableExtInstSets();
109 GR = std::make_unique<SPIRVGlobalRegistry>(PointerSize);
110 CallLoweringInfo = std::make_unique<SPIRVCallLowering>(TLInfo, GR.get());
111 InlineAsmInfo = std::make_unique<SPIRVInlineAsmLowering>(TLInfo);
112 Legalizer = std::make_unique<SPIRVLegalizerInfo>(*
this);
113 RegBankInfo = std::make_unique<SPIRVRegisterBankInfo>();
124 return AvailableExtensions.contains(E);
128 SPIRV::InstructionSet::InstructionSet E)
const {
129 return AvailableExtInstSets.contains(E);
132SPIRV::InstructionSet::InstructionSet
135 return SPIRV::InstructionSet::GLSL_std_450;
137 return SPIRV::InstructionSet::OpenCL_std;
156void SPIRVSubtarget::accountForAMDShaderTrinaryMinmax() {
158 SPIRV::Extension::SPV_AMD_shader_trinary_minmax_extension)) {
159 AvailableExtInstSets.
insert(
160 SPIRV::InstructionSet::SPV_AMD_shader_trinary_minmax);
166void SPIRVSubtarget::initAvailableExtInstSets() {
167 AvailableExtInstSets.clear();
169 AvailableExtInstSets.insert(SPIRV::InstructionSet::GLSL_std_450);
171 AvailableExtInstSets.insert(SPIRV::InstructionSet::OpenCL_std);
174 accountForAMDShaderTrinaryMinmax();
180 if (Env !=
Unknown && Env != E)
188 initAvailableExtInstSets();
189 Legalizer = std::make_unique<SPIRVLegalizerInfo>(*
this);
196 return F.hasFnAttribute(
"hlsl.shader");
198 "Module has hlsl.shader attributes but environment is Kernel");
202 bool HasShaderAttr =
false;
204 if (
F.hasFnAttribute(
"hlsl.shader")) {
205 HasShaderAttr =
true;
216 AvailableExtensions.clear();
220 for (
const auto &Ext : AllowedExtIds) {
221 if (ValidExtensions.
count(Ext))
222 AvailableExtensions.insert(Ext);
225 accountForAMDShaderTrinaryMinmax();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isAtLeastVer(VersionTuple Target, VersionTuple VerToCompareTo)
static cl::opt< bool > SPVTranslatorCompat("translator-compatibility-mode", cl::desc("SPIR-V Translator compatibility mode"), cl::Optional, cl::init(false))
static cl::opt< ExtensionSet, false, SPIRVExtensionsParser > Extensions("spirv-ext", cl::desc("Specify list of enabled SPIR-V extensions"))
A Module instance is used to store all the information related to an LLVM module.
SPIRVSubtarget & initSubtargetDependencies(StringRef CPU, StringRef FS)
bool canDirectlyComparePointers() const
bool isAtLeastSPIRVVer(VersionTuple VerToCompareTo) const
void resolveEnvFromModule(const Module &M)
bool isAtLeastOpenCLVer(VersionTuple VerToCompareTo) const
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
bool canUseExtInstSet(SPIRV::InstructionSet::InstructionSet E) const
static void addExtensionsToClOpt(const ExtensionSet &AllowList)
SPIRVSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const SPIRVTargetMachine &TM)
SPIRV::InstructionSet::InstructionSet getPreferredInstructionSet() const
bool canUseExtension(SPIRV::Extension::Extension E) const
void initAvailableExtensions(const ExtensionSet &AllowedExtIds)
void setEnv(SPIRVEnvType E)
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Represents a version number in the form major[.minor[.subminor[.build]]].
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
DenseSet< SPIRV::Extension::Extension > ExtensionSet
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
InstructionSelector * createSPIRVInstructionSelector(const SPIRVTargetMachine &TM, const SPIRVSubtarget &Subtarget, const RegisterBankInfo &RBI)
static ExtensionSet getValidExtensions(const Triple &TT)
Returns the list of extensions that are valid for a particular target environment (i....