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"),
38 cl::desc(
"Specify list of enabled SPIR-V extensions"));
43 const std::set<SPIRV::Extension::Extension> &AllowList) {
44 Extensions.insert(AllowList.begin(), AllowList.end());
53 const std::string &FS,
56 PointerSize(TM.getPointerSizeInBits( 0)),
58 TLInfo(TM, *this), TargetTriple(TT) {
59 switch (TT.getSubArch()) {
60 case Triple::SPIRVSubArch_v10:
61 SPIRVVersion = VersionTuple(1, 0);
63 case Triple::SPIRVSubArch_v11:
64 SPIRVVersion = VersionTuple(1, 1);
66 case Triple::SPIRVSubArch_v12:
67 SPIRVVersion = VersionTuple(1, 2);
69 case Triple::SPIRVSubArch_v13:
70 SPIRVVersion = VersionTuple(1, 3);
72 case Triple::SPIRVSubArch_v14:
73 SPIRVVersion = VersionTuple(1, 4);
75 case Triple::SPIRVSubArch_v15:
76 SPIRVVersion = VersionTuple(1, 5);
78 case Triple::SPIRVSubArch_v16:
79 SPIRVVersion = VersionTuple(1, 6);
82 if (TT.getVendor() == Triple::AMD)
83 SPIRVVersion = VersionTuple(1, 6);
85 SPIRVVersion = VersionTuple(1, 4);
100 Extensions.insert(SPIRV::Extension::SPV_INTEL_function_pointers);
102 SPIRV::Extension::SPV_EXT_relaxed_printf_string_address_space);
109 initAvailableExtInstSets();
111 GR = std::make_unique<SPIRVGlobalRegistry>(PointerSize);
112 CallLoweringInfo = std::make_unique<SPIRVCallLowering>(TLInfo, GR.get());
113 InlineAsmInfo = std::make_unique<SPIRVInlineAsmLowering>(TLInfo);
114 Legalizer = std::make_unique<SPIRVLegalizerInfo>(*
this);
115 RegBankInfo = std::make_unique<SPIRVRegisterBankInfo>();
126 return AvailableExtensions.contains(E);
130 SPIRV::InstructionSet::InstructionSet E)
const {
131 return AvailableExtInstSets.contains(E);
134SPIRV::InstructionSet::InstructionSet
137 return SPIRV::InstructionSet::GLSL_std_450;
139 return SPIRV::InstructionSet::OpenCL_std;
158void SPIRVSubtarget::accountForAMDShaderTrinaryMinmax() {
160 SPIRV::Extension::SPV_AMD_shader_trinary_minmax_extension)) {
161 AvailableExtInstSets.
insert(
162 SPIRV::InstructionSet::SPV_AMD_shader_trinary_minmax);
168void SPIRVSubtarget::initAvailableExtInstSets() {
169 AvailableExtInstSets.clear();
171 AvailableExtInstSets.insert(SPIRV::InstructionSet::GLSL_std_450);
173 AvailableExtInstSets.insert(SPIRV::InstructionSet::OpenCL_std);
176 accountForAMDShaderTrinaryMinmax();
182 if (Env !=
Unknown && Env != E)
190 initAvailableExtInstSets();
191 Legalizer = std::make_unique<SPIRVLegalizerInfo>(*
this);
198 return F.hasFnAttribute(
"hlsl.shader");
200 "Module has hlsl.shader attributes but environment is Kernel");
204 bool HasShaderAttr =
false;
206 if (
F.hasFnAttribute(
"hlsl.shader")) {
207 HasShaderAttr =
true;
217 const std::set<SPIRV::Extension::Extension> &AllowedExtIds) {
218 AvailableExtensions.clear();
219 const std::set<SPIRV::Extension::Extension> &ValidExtensions =
222 for (
const auto &Ext : AllowedExtIds) {
223 if (ValidExtensions.count(Ext))
224 AvailableExtensions.insert(Ext);
227 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< std::set< SPIRV::Extension::Extension >, 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)
static void addExtensionsToClOpt(const std::set< SPIRV::Extension::Extension > &AllowList)
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
void initAvailableExtensions(const std::set< SPIRV::Extension::Extension > &AllowedExtIds)
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 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]]].
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
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)
Command line parser for toggling SPIR-V extensions.
static std::set< SPIRV::Extension::Extension > getValidExtensions(const Triple &TT)
Returns the list of extensions that are valid for a particular target environment (i....