26#include "llvm/IR/IntrinsicsDirectX.h"
37 if (DRM.
uavs().empty())
43 case Triple::EnvironmentType::Compute:
44 case Triple::EnvironmentType::Pixel:
46 case Triple::EnvironmentType::Vertex:
47 case Triple::EnvironmentType::Geometry:
48 case Triple::EnvironmentType::Hull:
49 case Triple::EnvironmentType::Domain:
51 case Triple::EnvironmentType::Library:
52 case Triple::EnvironmentType::RayGeneration:
53 case Triple::EnvironmentType::Intersection:
54 case Triple::EnvironmentType::AnyHit:
55 case Triple::EnvironmentType::ClosestHit:
56 case Triple::EnvironmentType::Miss:
57 case Triple::EnvironmentType::Callable:
58 case Triple::EnvironmentType::Mesh:
59 case Triple::EnvironmentType::Amplification:
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:
109 CSF.Doubles =
I.getType()->getScalarType()->isDoubleTy();
112 for (
const Value *
Op :
I.operands()) {
113 if (
Op->getType()->getScalarType()->isDoubleTy()) {
121 switch (
I.getOpcode()) {
122 case Instruction::FDiv:
123 case Instruction::UIToFP:
124 case Instruction::SIToFP:
125 case Instruction::FPToUI:
126 case Instruction::FPToSI:
127 CSF.DX11_1_DoubleExtensions =
true;
132 if (!CSF.LowPrecisionPresent)
133 CSF.LowPrecisionPresent =
I.getType()->getScalarType()->isIntegerTy(16) ||
134 I.getType()->getScalarType()->isHalfTy();
136 if (!CSF.LowPrecisionPresent) {
137 for (
const Value *
Op :
I.operands()) {
138 if (
Op->getType()->getScalarType()->isIntegerTy(16) ||
139 Op->getType()->getScalarType()->isHalfTy()) {
140 CSF.LowPrecisionPresent =
true;
146 if (CSF.LowPrecisionPresent) {
147 if (CSF.NativeLowPrecisionMode)
148 CSF.NativeLowPrecision =
true;
150 CSF.MinimumPrecision =
true;
154 CSF.Int64Ops =
I.getType()->getScalarType()->isIntegerTy(64);
156 if (!CSF.Int64Ops && !isa<LifetimeIntrinsic>(&
I)) {
157 for (
const Value *
Op :
I.operands()) {
158 if (
Op->getType()->getScalarType()->isIntegerTy(64)) {
165 if (
auto *
II = dyn_cast<IntrinsicInst>(&
I)) {
166 switch (
II->getIntrinsicID()) {
169 case Intrinsic::dx_resource_handlefrombinding: {
174 if (!CSF.ResMayNotAlias && CanSetResMayNotAlias &&
176 CSF.ResMayNotAlias =
true;
181 CSF.EnableRawAndStructuredBuffers =
true;
188 case Intrinsic::dx_resource_load_typedbuffer: {
190 DRTM[cast<TargetExtType>(
II->getArgOperand(0)->getType())];
198 if (
auto *CI = dyn_cast<CallInst>(&
I)) {
199 const Function *CF = CI->getCalledFunction();
201 if (FunctionFlags.contains(CF))
202 CSF.
merge(FunctionFlags[CF]);
213ModuleShaderFlags::gatherGlobalModuleFlags(
const Module &M,
223 llvm::Attribute::OptimizeNone);
226 if (CSF.DisableOptimizations !=
227 EntryFunProps.Entry->hasFnAttribute(llvm::Attribute::OptimizeNone))
229 *(EntryFunProps.Entry),
"Inconsistent optnone attribute "));
240 NumUAVs +=
UAV.getBinding().Size;
242 CSF.Max64UAVs =
true;
251 if (
auto *NativeLowPrec = mdconst::extract_or_null<ConstantInt>(
252 M.getModuleFlag(
"dx.nativelowprec")))
254 CSF.NativeLowPrecisionMode = NativeLowPrec->getValue().getBoolValue();
259 CSF.ResMayNotAlias = !DRM.
uavs().empty();
272 if (
auto *ResMayAlias = mdconst::extract_or_null<ConstantInt>(
273 M.getModuleFlag(
"dx.resmayalias")))
274 if (ResMayAlias->getValue().getBoolValue())
275 CanSetResMayNotAlias =
false;
285 const std::vector<CallGraphNode *> &CurSCC = *SCCI;
297 if (
F->isDeclaration()) {
298 assert(!
F->getName().starts_with(
"dx.op.") &&
299 "DXIL Shader Flag analysis should not be run post-lowering.");
304 for (
const auto &BB : *
F)
305 for (
const auto &
I : BB)
306 updateFunctionFlags(CSF,
I, DRTM, MMDI);
314 CombinedSFMask.
merge(SCCSF);
322 FunctionFlags[
F].merge(SCCSF);
328 OS <<
formatv(
"; Shader Flags Value: {0:x8}\n;\n", FlagVal);
331 OS <<
"; Note: shader requires additional functionality:\n";
332#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleNum, FlagName, Str) \
334 (OS << ";").indent(7) << Str << "\n";
335#include "llvm/BinaryFormat/DXContainerConstants.def"
336 OS <<
"; Note: extra DXIL module flags:\n";
337#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) \
339 (OS << ";").indent(7) << Str << "\n";
340#include "llvm/BinaryFormat/DXContainerConstants.def"
347 auto Iter = FunctionFlags.find(Func);
348 assert((Iter != FunctionFlags.end() && Iter->first == Func) &&
349 "Get Shader Flags : No Shader Flags Mask exists for function");
375 OS <<
"; Combined Shader Flags for Module\n";
378 OS <<
"; Shader Flags for Module Functions\n";
379 for (
const auto &
F : M.getFunctionList()) {
380 if (
F.isDeclaration())
383 OS <<
formatv(
"; Function {0} : {1:x8}\n;\n",
F.getName(),
395 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
397 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
399 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
415 "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...
block Block Frequency Analysis
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.
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.
A container for analyses that lazily runs them and caches their results.
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.
This class represents an Operation in the Expression.
iterator_range< iterator > uavs()
Diagnostic information for unsupported feature in backend.
A Module instance is used to store all the information related to an LLVM module.
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.
LLVM Value Representation.
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.
This is an optimization pass for GlobalISel generic memory operations.
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)
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