26#include "llvm/IR/IntrinsicsDirectX.h"
38 bool HasUAVWithBinding =
any_of(
40 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_active_countbits:
93 case Intrinsic::dx_wave_ballot:
94 case Intrinsic::dx_wave_prefix_bit_count:
96 case Intrinsic::dx_wave_reduce_or:
97 case Intrinsic::dx_wave_reduce_xor:
98 case Intrinsic::dx_wave_reduce_and:
99 case Intrinsic::dx_wave_reduce_sum:
100 case Intrinsic::dx_wave_reduce_usum:
101 case Intrinsic::dx_wave_product:
102 case Intrinsic::dx_wave_uproduct:
103 case Intrinsic::dx_wave_reduce_max:
104 case Intrinsic::dx_wave_reduce_umax:
105 case Intrinsic::dx_wave_reduce_min:
106 case Intrinsic::dx_wave_reduce_umin:
108 case Intrinsic::dx_wave_prefix_sum:
109 case Intrinsic::dx_wave_prefix_usum:
110 case Intrinsic::dx_wave_prefix_product:
111 case Intrinsic::dx_wave_prefix_uproduct:
113 case Intrinsic::dx_quad_read_across_x:
114 case Intrinsic::dx_quad_read_across_y:
115 case Intrinsic::dx_quad_read_across_diagonal:
143 switch (
II.getIntrinsicID()) {
146 case Intrinsic::dx_resource_load_level:
147 case Intrinsic::dx_resource_sample:
148 case Intrinsic::dx_resource_sample_clamp:
151 case Intrinsic::dx_resource_samplebias:
152 case Intrinsic::dx_resource_samplebias_clamp:
153 case Intrinsic::dx_resource_samplelevel:
156 case Intrinsic::dx_resource_samplegrad:
157 case Intrinsic::dx_resource_samplegrad_clamp:
167 return Flag->getValue().getBoolValue();
176 assert(IID == Intrinsic::dx_resource_load_typedbuffer ||
177 IID == Intrinsic::dx_resource_load_rawbuffer &&
178 "unexpected intrinsic ID");
179 for (
const User *U :
II.users()) {
183 if (EVI->getNumIndices() == 1 && EVI->getIndices()[0] == 1)
199 CSF.Doubles =
I.getType()->getScalarType()->isDoubleTy();
202 for (
const Value *
Op :
I.operands()) {
203 if (
Op->getType()->getScalarType()->isDoubleTy()) {
211 switch (
I.getOpcode()) {
212 case Instruction::FDiv:
213 case Instruction::UIToFP:
214 case Instruction::SIToFP:
215 case Instruction::FPToUI:
216 case Instruction::FPToSI:
217 CSF.DX11_1_DoubleExtensions =
true;
222 if (!CSF.LowPrecisionPresent)
223 CSF.LowPrecisionPresent =
I.getType()->getScalarType()->isIntegerTy(16) ||
224 I.getType()->getScalarType()->isHalfTy();
226 if (!CSF.LowPrecisionPresent) {
227 for (
const Value *
Op :
I.operands()) {
228 if (
Op->getType()->getScalarType()->isIntegerTy(16) ||
229 Op->getType()->getScalarType()->isHalfTy()) {
230 CSF.LowPrecisionPresent =
true;
236 if (CSF.LowPrecisionPresent) {
237 if (CSF.NativeLowPrecisionMode)
238 CSF.NativeLowPrecision =
true;
240 CSF.MinimumPrecision =
true;
244 CSF.Int64Ops =
I.getType()->getScalarType()->isIntegerTy(64);
247 for (
const Value *
Op :
I.operands()) {
248 if (
Op->getType()->getScalarType()->isIntegerTy(64)) {
258 switch (
II->getIntrinsicID()) {
261 case Intrinsic::dx_resource_handlefrombinding: {
266 if (!CSF.ResMayNotAlias && CanSetResMayNotAlias &&
268 CSF.ResMayNotAlias =
true;
273 CSF.EnableRawAndStructuredBuffers =
true;
280 case Intrinsic::dx_resource_handlefromheap: {
283 CSF.SamplerDescriptorHeapIndexing |= IsSamplerHeap;
284 CSF.ResourceDescriptorHeapIndexing |= !IsSamplerHeap;
286 if (!CSF.ResMayNotAlias && CanSetResMayNotAlias && RTI.
isUAV() &&
288 CSF.ResMayNotAlias =
true;
292 case Intrinsic::dx_resource_load_typedbuffer: {
293 dxil::ResourceTypeInfo &RTI =
298 CSF.TiledResources =
true;
301 case Intrinsic::dx_resource_load_rawbuffer: {
303 CSF.TiledResources =
true;
306 case Intrinsic::dx_resource_atomic_binop: {
307 if (
II->getType()->isIntegerTy(64)) {
308 dxil::ResourceTypeInfo &RTI =
311 CSF.AtomicInt64OnTypedResource =
true;
321 if (ARMW->getValOperand()->getType()->isIntegerTy(64) &&
322 ARMW->getPointerAddressSpace() == 3)
323 CSF.AtomicInt64OnGroupShared =
true;
325 if (AXCG->getNewValOperand()->getType()->isIntegerTy(64) &&
326 AXCG->getPointerAddressSpace() == 3)
327 CSF.AtomicInt64OnGroupShared =
true;
331 const Function *CF = CI->getCalledFunction();
333 if (FunctionFlags.contains(CF))
334 CSF.
merge(FunctionFlags[CF]);
336 CSF.DX11_1_DoubleExtensions |=
344ModuleShaderFlags::gatherGlobalModuleFlags(
const Module &M,
345 const DXILResourceMap &DRM,
348 ComputedShaderFlags CSF;
355 uint32_t NumUAVs = 0;
358 if (!
UAV.hasBinding())
364 uint32_t NewNum = NumUAVs + (
Size == 0 ? ~0
U :
Size);
365 if (NewNum < NumUAVs)
371 CSF.Max64UAVs =
true;
381 M.getModuleFlag(
"dx.nativelowprec")))
383 CSF.NativeLowPrecisionMode = NativeLowPrec->getValue().getBoolValue();
388 CSF.ResMayNotAlias = !DRM.
uavs().
empty();
393 M.getModuleFlag(
"dx.allresourcesbound")))
394 if (AllResourcesBound->getValue().getBoolValue())
395 CSF.AllResourcesBound =
true;
409 M.getModuleFlag(
"dx.resmayalias")))
410 if (ResMayAlias->getValue().getBoolValue())
411 CanSetResMayNotAlias =
false;
421 const std::vector<CallGraphNode *> &CurSCC = *SCCI;
433 if (
F->isDeclaration()) {
434 assert(!
F->getName().starts_with(
"dx.op.") &&
435 "DXIL Shader Flag analysis should not be run post-lowering.");
440 for (
const auto &BB : *
F)
441 for (
const auto &
I : BB)
442 updateFunctionFlags(CSF,
I, DRTM, MMDI);
450 CombinedSFMask.merge(SCCSF);
458 FunctionFlags[
F].merge(SCCSF);
463 uint64_t FlagVal = (uint64_t) *
this;
464 OS <<
formatv(
"; Shader Flags Value: {0:x8}\n;\n", FlagVal);
467 OS <<
"; Note: shader requires additional functionality:\n";
468#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleNum, FlagName, Str) \
470 (OS << ";").indent(7) << Str << "\n";
471#include "llvm/BinaryFormat/DXContainerConstants.def"
472 OS <<
"; Note: extra DXIL module flags:\n";
473#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) \
475 (OS << ";").indent(7) << Str << "\n";
476#include "llvm/BinaryFormat/DXContainerConstants.def"
483 auto Iter = FunctionFlags.find(Func);
484 assert((Iter != FunctionFlags.end() && Iter->first == Func) &&
485 "Get Shader Flags : No Shader Flags Mask exists for function");
511 OS <<
"; Combined Shader Flags for Module\n";
514 OS <<
"; Shader Flags for Module Functions\n";
515 for (
const auto &
F : M.getFunctionList()) {
516 if (
F.isDeclaration())
519 OS <<
formatv(
"; Function {0} : {1:x8}\n;\n",
F.getName(),
537 MSFI.initialize(M, DRTM, DRM, MMDI);
551 "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...
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 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.
Represents a version number in the form major[.minor[.subminor[.build]]].
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)
Construct ModuleShaderFlags for module Module M.
const ComputedShaderFlags & getCombinedFlags() const