27#include "llvm/IR/IntrinsicsDirectX.h"
39 bool HasUAVWithBinding =
any_of(
41 if (!HasUAVWithBinding)
85 case Intrinsic::dx_wave_is_first_lane:
86 case Intrinsic::dx_wave_getlaneindex:
87 case Intrinsic::dx_wave_get_lane_count:
88 case Intrinsic::dx_wave_any:
89 case Intrinsic::dx_wave_all_equal:
90 case Intrinsic::dx_wave_all:
91 case Intrinsic::dx_wave_readlane:
92 case Intrinsic::dx_wave_readlane_first:
93 case Intrinsic::dx_wave_active_countbits:
94 case Intrinsic::dx_wave_ballot:
95 case Intrinsic::dx_wave_prefix_bit_count:
97 case Intrinsic::dx_wave_reduce_or:
98 case Intrinsic::dx_wave_reduce_xor:
99 case Intrinsic::dx_wave_reduce_and:
100 case Intrinsic::dx_wave_reduce_sum:
101 case Intrinsic::dx_wave_reduce_usum:
102 case Intrinsic::dx_wave_product:
103 case Intrinsic::dx_wave_uproduct:
104 case Intrinsic::dx_wave_reduce_max:
105 case Intrinsic::dx_wave_reduce_umax:
106 case Intrinsic::dx_wave_reduce_min:
107 case Intrinsic::dx_wave_reduce_umin:
109 case Intrinsic::dx_wave_prefix_sum:
110 case Intrinsic::dx_wave_prefix_usum:
111 case Intrinsic::dx_wave_prefix_product:
112 case Intrinsic::dx_wave_prefix_uproduct:
113 case Intrinsic::dx_wave_multi_prefix_bit_and:
114 case Intrinsic::dx_wave_multi_prefix_bit_or:
115 case Intrinsic::dx_wave_multi_prefix_bit_xor:
116 case Intrinsic::dx_wave_multi_prefix_bit_count:
117 case Intrinsic::dx_wave_multi_prefix_product:
118 case Intrinsic::dx_wave_multi_prefix_uproduct:
119 case Intrinsic::dx_wave_multi_prefix_sum:
120 case Intrinsic::dx_wave_multi_prefix_usum:
122 case Intrinsic::dx_quad_all:
123 case Intrinsic::dx_quad_read_across_x:
124 case Intrinsic::dx_quad_read_across_y:
125 case Intrinsic::dx_quad_read_across_diagonal:
153 switch (
II.getIntrinsicID()) {
156 case Intrinsic::dx_resource_load_level:
157 case Intrinsic::dx_resource_sample:
158 case Intrinsic::dx_resource_sample_clamp:
161 case Intrinsic::dx_resource_samplebias:
162 case Intrinsic::dx_resource_samplebias_clamp:
163 case Intrinsic::dx_resource_samplelevel:
166 case Intrinsic::dx_resource_samplegrad:
167 case Intrinsic::dx_resource_samplegrad_clamp:
177 return Flag->getValue().getBoolValue();
186 assert(IID == Intrinsic::dx_resource_load_typedbuffer ||
187 IID == Intrinsic::dx_resource_load_rawbuffer &&
188 "unexpected intrinsic ID");
189 for (
const User *U :
II.users()) {
193 if (EVI->getNumIndices() == 1 && EVI->getIndices()[0] == 1)
204 const Value *Clamp =
II.getArgOperand(
II.arg_size() - 1);
218 CSF.Doubles =
I.getType()->getScalarType()->isDoubleTy();
221 for (
const Value *
Op :
I.operands()) {
222 if (
Op->getType()->getScalarType()->isDoubleTy()) {
230 switch (
I.getOpcode()) {
231 case Instruction::FDiv:
232 case Instruction::UIToFP:
233 case Instruction::SIToFP:
234 case Instruction::FPToUI:
235 case Instruction::FPToSI:
236 CSF.DX11_1_DoubleExtensions =
true;
241 if (!CSF.LowPrecisionPresent)
242 CSF.LowPrecisionPresent =
I.getType()->getScalarType()->isIntegerTy(16) ||
243 I.getType()->getScalarType()->isHalfTy();
245 if (!CSF.LowPrecisionPresent) {
246 for (
const Value *
Op :
I.operands()) {
247 if (
Op->getType()->getScalarType()->isIntegerTy(16) ||
248 Op->getType()->getScalarType()->isHalfTy()) {
249 CSF.LowPrecisionPresent =
true;
255 if (CSF.LowPrecisionPresent) {
256 if (CSF.NativeLowPrecisionMode)
257 CSF.NativeLowPrecision =
true;
259 CSF.MinimumPrecision =
true;
263 CSF.Int64Ops =
I.getType()->getScalarType()->isIntegerTy(64);
266 for (
const Value *
Op :
I.operands()) {
267 if (
Op->getType()->getScalarType()->isIntegerTy(64)) {
277 switch (
II->getIntrinsicID()) {
280 case Intrinsic::dx_start_vertex_location:
281 case Intrinsic::dx_start_instance_location:
282 CSF.ExtendedCommandInfo =
true;
284 case Intrinsic::dx_view_id:
287 case Intrinsic::dx_resource_handlefrombinding: {
292 if (!CSF.ResMayNotAlias && CanSetResMayNotAlias &&
294 CSF.ResMayNotAlias =
true;
299 CSF.EnableRawAndStructuredBuffers =
true;
306 case Intrinsic::dx_resource_handlefromheap: {
309 CSF.SamplerDescriptorHeapIndexing |= IsSamplerHeap;
310 CSF.ResourceDescriptorHeapIndexing |= !IsSamplerHeap;
312 if (!CSF.ResMayNotAlias && CanSetResMayNotAlias && RTI.
isUAV() &&
314 CSF.ResMayNotAlias =
true;
318 case Intrinsic::dx_resource_load_level:
319 case Intrinsic::dx_resource_load_typedbuffer: {
320 dxil::ResourceTypeInfo &RTI =
324 if (
II->getIntrinsicID() == Intrinsic::dx_resource_load_typedbuffer &&
326 CSF.TiledResources =
true;
329 case Intrinsic::dx_resource_load_rawbuffer: {
331 CSF.TiledResources =
true;
334 case Intrinsic::dx_resource_sample_clamp:
335 case Intrinsic::dx_resource_samplebias_clamp:
336 case Intrinsic::dx_resource_samplegrad_clamp:
341 case Intrinsic::dx_resource_atomic_binop:
342 case Intrinsic::dx_resource_atomic_compare_exchange: {
343 if (
II->getType()->isIntegerTy(64)) {
344 dxil::ResourceTypeInfo &RTI =
347 CSF.AtomicInt64OnTypedResource =
true;
357 if (ARMW->getValOperand()->getType()->isIntegerTy(64) &&
358 ARMW->getPointerAddressSpace() == 3)
359 CSF.AtomicInt64OnGroupShared =
true;
361 if (AXCG->getNewValOperand()->getType()->isIntegerTy(64) &&
362 AXCG->getPointerAddressSpace() == 3)
363 CSF.AtomicInt64OnGroupShared =
true;
367 const Function *CF = CI->getCalledFunction();
369 if (FunctionFlags.contains(CF))
370 CSF.
merge(FunctionFlags[CF]);
372 CSF.DX11_1_DoubleExtensions |=
380ModuleShaderFlags::gatherGlobalModuleFlags(
const Module &M,
381 const DXILResourceMap &DRM,
384 ComputedShaderFlags CSF;
391 uint32_t NumUAVs = 0;
394 if (!
UAV.hasBinding())
400 uint32_t NewNum = NumUAVs + (
Size == 0 ? ~0
U :
Size);
401 if (NewNum < NumUAVs)
407 CSF.Max64UAVs =
true;
417 M.getModuleFlag(
"dx.nativelowprec")))
419 CSF.NativeLowPrecisionMode = NativeLowPrec->getValue().getBoolValue();
424 CSF.ResMayNotAlias = !DRM.
uavs().
empty();
429 M.getModuleFlag(
"dx.allresourcesbound")))
430 if (AllResourcesBound->getValue().getBoolValue())
431 CSF.AllResourcesBound =
true;
446 M.getModuleFlag(
"dx.resmayalias")))
447 if (ResMayAlias->getValue().getBoolValue())
448 CanSetResMayNotAlias =
false;
458 const std::vector<CallGraphNode *> &CurSCC = *SCCI;
470 if (
F->isDeclaration()) {
471 assert(!
F->getName().starts_with(
"dx.op.") &&
472 "DXIL Shader Flag analysis should not be run post-lowering.");
477 for (
const auto &BB : *
F)
478 for (
const auto &
I : BB)
479 updateFunctionFlags(CSF,
I, DRTM, MMDI);
483 CSF.Barycentrics |=
llvm::any_of(Sig->Inputs, [](
const auto &E) {
484 return E.SemanticKind == dxbc::PSV::SemanticKind::Barycentrics;
488 auto HasLowPrecision = [](
const auto &Elements) {
495 if (HasLowPrecision(Sig->Inputs) || HasLowPrecision(Sig->Outputs)) {
496 CSF.LowPrecisionPresent =
true;
497 if (Sig->UseNative16Bit)
498 CSF.NativeLowPrecision =
true;
500 CSF.MinimumPrecision =
true;
504 auto HasShadingRate = [](
const auto &Elements) {
506 return E.SemanticKind == dxbc::PSV::SemanticKind::ShadingRate;
509 if (HasShadingRate(Sig->Inputs) || HasShadingRate(Sig->Outputs))
510 CSF.ShadingRate =
true;
519 CombinedSFMask.merge(SCCSF);
527 FunctionFlags[
F].merge(SCCSF);
532 uint64_t FlagVal = (uint64_t) *
this;
533 OS <<
formatv(
"; Shader Flags Value: {0:x8}\n;\n", FlagVal);
536 OS <<
"; Note: shader requires additional functionality:\n";
537#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleNum, FlagName, Str) \
539 (OS << ";").indent(7) << Str << "\n";
540#include "llvm/BinaryFormat/DXContainerConstants.def"
541 OS <<
"; Note: extra DXIL module flags:\n";
542#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) \
544 (OS << ";").indent(7) << Str << "\n";
545#include "llvm/BinaryFormat/DXContainerConstants.def"
552 auto Iter = FunctionFlags.find(Func);
553 assert((Iter != FunctionFlags.end() && Iter->first == Func) &&
554 "Get Shader Flags : No Shader Flags Mask exists for function");
580 OS <<
"; Combined Shader Flags for Module\n";
583 OS <<
"; Shader Flags for Module Functions\n";
584 for (
const auto &
F : M.getFunctionList()) {
585 if (
F.isDeclaration())
588 OS <<
formatv(
"; Function {0} : {1:x8}\n;\n",
F.getName(),
606 MSFI.initialize(M, DRTM, DRM, MMDI,
622 "DXIL Shader Flag Analysis",
true,
true)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
bool checkIfStatusIsExtracted(const IntrinsicInst &II)
static bool isOptimizationDisabled(const Module &M)
static bool hasUAVsAtEveryStage(const DXILResourceMap &DRM, const ModuleMetadataInfo &MMDI)
static bool hasLODClamp(const IntrinsicInst &II)
Returns true if the LOD clamp argument of II is neither constant zero nor undef.
static bool checkDoubleExtensionOps(Intrinsic::ID IID)
static bool checkAdvancedTextureOps(const IntrinsicInst &II)
Texture load and sample operations accept "programmable offsets", i.e.
static bool checkWaveOps(Intrinsic::ID IID)
Module.h This file contains the declarations for the Module class.
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
This file defines the SmallVector class.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
AnalysisUsage & addRequiredTransitive()
A node in the call graph for a module.
The basic data container for the call graph of a Module of IR.
iterator_range< iterator > uavs()
A wrapper class for inspecting calls to intrinsic functions.
A Module instance is used to store all the information related to an LLVM module.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
LLVM Value Representation.
Represents a version number in the form major[.minor[.subminor[.build]]].
const EntrySignature * get(const Function *F) const
LLVM_ABI bool isUAV() const
LLVM_ABI bool isSampler() const
LLVM_ABI bool isTyped() const
LLVM_ABI TypedInfo getTyped() const
dxil::ResourceKind getResourceKind() const
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Wrapper pass for the legacy pass manager.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
ModuleShaderFlags run(Module &M, ModuleAnalysisManager &AM)
This class implements an extremely fast bulk output stream that can only output to a stream.
Enumerate the SCCs of a directed graph in reverse topological order of the SCC DAG.
bool isAtEnd() const
Direct loop termination test which is more efficient than comparison with end().
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
A special type used by analysis passes to provide an address that identifies that particular analysis...
void merge(const ComputedShaderFlags CSF)
void print(raw_ostream &OS=dbgs()) const
const ComputedShaderFlags & getFunctionFlags(const Function *) const
Return the shader flags mask of the specified function Func.
void initialize(Module &, DXILResourceTypeMap &DRTM, const DXILResourceMap &DRM, const ModuleMetadataInfo &MMDI, const ModuleSignatureInfo &Signatures)
Construct ModuleShaderFlags for module Module M.
const ComputedShaderFlags & getCombinedFlags() const