26#include "llvm/IR/IntrinsicsDirectX.h"
86 case Intrinsic::dx_wave_is_first_lane:
87 case Intrinsic::dx_wave_getlaneindex:
88 case Intrinsic::dx_wave_any:
89 case Intrinsic::dx_wave_all:
90 case Intrinsic::dx_wave_readlane:
91 case Intrinsic::dx_wave_active_countbits:
93 case Intrinsic::dx_wave_reduce_sum:
94 case Intrinsic::dx_wave_reduce_usum:
95 case Intrinsic::dx_wave_reduce_max:
96 case Intrinsic::dx_wave_reduce_umax:
97 case Intrinsic::dx_wave_reduce_min:
98 case Intrinsic::dx_wave_reduce_umin:
111 CSF.Doubles =
I.getType()->getScalarType()->isDoubleTy();
114 for (
const Value *
Op :
I.operands()) {
115 if (
Op->getType()->getScalarType()->isDoubleTy()) {
123 switch (
I.getOpcode()) {
124 case Instruction::FDiv:
125 case Instruction::UIToFP:
126 case Instruction::SIToFP:
127 case Instruction::FPToUI:
128 case Instruction::FPToSI:
129 CSF.DX11_1_DoubleExtensions =
true;
134 if (!CSF.LowPrecisionPresent)
135 CSF.LowPrecisionPresent =
I.getType()->getScalarType()->isIntegerTy(16) ||
136 I.getType()->getScalarType()->isHalfTy();
138 if (!CSF.LowPrecisionPresent) {
139 for (
const Value *
Op :
I.operands()) {
140 if (
Op->getType()->getScalarType()->isIntegerTy(16) ||
141 Op->getType()->getScalarType()->isHalfTy()) {
142 CSF.LowPrecisionPresent =
true;
148 if (CSF.LowPrecisionPresent) {
149 if (CSF.NativeLowPrecisionMode)
150 CSF.NativeLowPrecision =
true;
152 CSF.MinimumPrecision =
true;
156 CSF.Int64Ops =
I.getType()->getScalarType()->isIntegerTy(64);
159 for (
const Value *
Op :
I.operands()) {
160 if (
Op->getType()->getScalarType()->isIntegerTy(64)) {
168 switch (
II->getIntrinsicID()) {
171 case Intrinsic::dx_resource_handlefrombinding: {
176 if (!CSF.ResMayNotAlias && CanSetResMayNotAlias &&
178 CSF.ResMayNotAlias =
true;
183 CSF.EnableRawAndStructuredBuffers =
true;
190 case Intrinsic::dx_resource_load_typedbuffer: {
191 dxil::ResourceTypeInfo &RTI =
201 const Function *CF = CI->getCalledFunction();
203 if (FunctionFlags.contains(CF))
204 CSF.
merge(FunctionFlags[CF]);
215ModuleShaderFlags::gatherGlobalModuleFlags(
const Module &M,
216 const DXILResourceMap &DRM,
219 ComputedShaderFlags CSF;
225 llvm::Attribute::OptimizeNone);
228 if (CSF.DisableOptimizations !=
229 EntryFunProps.Entry->hasFnAttribute(llvm::Attribute::OptimizeNone))
230 EntryFunProps.Entry->getContext().diagnose(DiagnosticInfoUnsupported(
231 *(EntryFunProps.Entry),
"Inconsistent optnone attribute "));
237 uint32_t NumUAVs = 0;
242 NumUAVs +=
UAV.getBinding().Size;
244 CSF.Max64UAVs =
true;
254 M.getModuleFlag(
"dx.nativelowprec")))
256 CSF.NativeLowPrecisionMode = NativeLowPrec->getValue().getBoolValue();
261 CSF.ResMayNotAlias = !DRM.
uavs().
empty();
275 M.getModuleFlag(
"dx.resmayalias")))
276 if (ResMayAlias->getValue().getBoolValue())
277 CanSetResMayNotAlias =
false;
287 const std::vector<CallGraphNode *> &CurSCC = *SCCI;
299 if (
F->isDeclaration()) {
300 assert(!
F->getName().starts_with(
"dx.op.") &&
301 "DXIL Shader Flag analysis should not be run post-lowering.");
306 for (
const auto &BB : *
F)
307 for (
const auto &
I : BB)
308 updateFunctionFlags(CSF,
I, DRTM, MMDI);
316 CombinedSFMask.merge(SCCSF);
324 FunctionFlags[
F].merge(SCCSF);
330 OS <<
formatv(
"; Shader Flags Value: {0:x8}\n;\n", FlagVal);
333 OS <<
"; Note: shader requires additional functionality:\n";
334#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleNum, FlagName, Str) \
336 (OS << ";").indent(7) << Str << "\n";
337#include "llvm/BinaryFormat/DXContainerConstants.def"
338 OS <<
"; Note: extra DXIL module flags:\n";
339#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) \
341 (OS << ";").indent(7) << Str << "\n";
342#include "llvm/BinaryFormat/DXContainerConstants.def"
349 auto Iter = FunctionFlags.find(Func);
350 assert((Iter != FunctionFlags.end() && Iter->first == Func) &&
351 "Get Shader Flags : No Shader Flags Mask exists for function");
377 OS <<
"; Combined Shader Flags for Module\n";
380 OS <<
"; Shader Flags for Module Functions\n";
381 for (
const auto &
F : M.getFunctionList()) {
382 if (
F.isDeclaration())
385 OS <<
formatv(
"; Function {0} : {1:x8}\n;\n",
F.getName(),
403 MSFI.initialize(M, DRTM, DRM, MMDI);
417 "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 ...
static bool hasUAVsAtEveryStage(const DXILResourceMap &DRM, const ModuleMetadataInfo &MMDI)
static bool checkWaveOps(Intrinsic::ID IID)
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
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 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.
Represents a version number in the form major[.minor[.subminor[.build]]].
LLVM_ABI bool isUAV() 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.
FunctionAddr VTableAddr Value
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.
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...
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