1//===- DXILShaderFlags.cpp - DXIL Shader Flags helper objects -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file This file contains helper objects and APIs for working with DXIL
10/// Shader Flags.
11///
12//===----------------------------------------------------------------------===//
13
14#include "DXILShaderFlags.h"
15#include "DXILSignatureAnalysis.h"
16#include "DirectX.h"
17#include "llvm/ADT/SCCIterator.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/Analysis/CallGraph.h"
20#include "llvm/Analysis/DXILResource.h"
21#include "llvm/IR/Attributes.h"
22#include "llvm/IR/DiagnosticInfo.h"
23#include "llvm/IR/Instruction.h"
24#include "llvm/IR/Instructions.h"
25#include "llvm/IR/IntrinsicInst.h"
26#include "llvm/IR/Intrinsics.h"
27#include "llvm/IR/IntrinsicsDirectX.h"
28#include "llvm/IR/Module.h"
29#include "llvm/InitializePasses.h"
30#include "llvm/Support/FormatVariadic.h"
31#include "llvm/Support/raw_ostream.h"
32
33using namespace llvm;
34using namespace llvm::dxil;
35
36static bool hasUAVsAtEveryStage(const DXILResourceMap &DRM,
37 const ModuleMetadataInfo &MMDI) {
38 // Heap resources do not count towards hasUAVsAtEveryStage.
39 bool HasUAVWithBinding = any_of(
40 Range: DRM.uavs(), P: [](const ResourceInfo &RI) { return RI.hasBinding(); });
41 if (!HasUAVWithBinding)
42 return false;
43
44 switch (MMDI.ShaderProfile) {
45 default:
46 return false;
47 case Triple::EnvironmentType::Compute:
48 case Triple::EnvironmentType::Pixel:
49 return false;
50 case Triple::EnvironmentType::Vertex:
51 case Triple::EnvironmentType::Geometry:
52 case Triple::EnvironmentType::Hull:
53 case Triple::EnvironmentType::Domain:
54 return true;
55 case Triple::EnvironmentType::Library:
56 case Triple::EnvironmentType::RayGeneration:
57 case Triple::EnvironmentType::Intersection:
58 case Triple::EnvironmentType::AnyHit:
59 case Triple::EnvironmentType::ClosestHit:
60 case Triple::EnvironmentType::Miss:
61 case Triple::EnvironmentType::Callable:
62 case Triple::EnvironmentType::Mesh:
63 case Triple::EnvironmentType::Amplification:
64 return MMDI.ValidatorVersion < VersionTuple(1, 8);
65 }
66}
67
68static bool checkWaveOps(Intrinsic::ID IID) {
69 // Currently unsupported intrinsics
70 // case Intrinsic::dx_wave_readfirst:
71 // case Intrinsic::dx_wave_reduce.and:
72 // case Intrinsic::dx_wave_reduce.or:
73 // case Intrinsic::dx_wave_reduce.xor:
74 // case Intrinsic::dx_wave_prefixop:
75 // case Intrinsic::dx_quad.readat:
76 // case Intrinsic::dx_quad.readacrossy:
77 // case Intrinsic::dx_quad.readacrossdiagonal:
78 // case Intrinsic::dx_wave_prefixballot:
79 // case Intrinsic::dx_wave_match:
80 // case Intrinsic::dx_wavemulti.*:
81 // case Intrinsic::dx_wavemulti.ballot:
82 // case Intrinsic::dx_quad.vote:
83 switch (IID) {
84 default:
85 return false;
86 case Intrinsic::dx_wave_is_first_lane:
87 case Intrinsic::dx_wave_getlaneindex:
88 case Intrinsic::dx_wave_get_lane_count:
89 case Intrinsic::dx_wave_any:
90 case Intrinsic::dx_wave_all_equal:
91 case Intrinsic::dx_wave_all:
92 case Intrinsic::dx_wave_readlane:
93 case Intrinsic::dx_wave_readlane_first:
94 case Intrinsic::dx_wave_active_countbits:
95 case Intrinsic::dx_wave_ballot:
96 case Intrinsic::dx_wave_prefix_bit_count:
97 // Wave Active Op Variants
98 case Intrinsic::dx_wave_reduce_or:
99 case Intrinsic::dx_wave_reduce_xor:
100 case Intrinsic::dx_wave_reduce_and:
101 case Intrinsic::dx_wave_reduce_sum:
102 case Intrinsic::dx_wave_reduce_usum:
103 case Intrinsic::dx_wave_product:
104 case Intrinsic::dx_wave_uproduct:
105 case Intrinsic::dx_wave_reduce_max:
106 case Intrinsic::dx_wave_reduce_umax:
107 case Intrinsic::dx_wave_reduce_min:
108 case Intrinsic::dx_wave_reduce_umin:
109 // Wave Prefix Op Variants
110 case Intrinsic::dx_wave_prefix_sum:
111 case Intrinsic::dx_wave_prefix_usum:
112 case Intrinsic::dx_wave_prefix_product:
113 case Intrinsic::dx_wave_prefix_uproduct:
114 // Quad Op Variants
115 case Intrinsic::dx_quad_read_across_x:
116 case Intrinsic::dx_quad_read_across_y:
117 case Intrinsic::dx_quad_read_across_diagonal:
118 return true;
119 }
120}
121
122static bool checkDoubleExtensionOps(Intrinsic::ID IID) {
123 switch (IID) {
124 default:
125 return false;
126 case Intrinsic::fma:
127 return true;
128 }
129}
130
131/// Texture load and sample operations accept "programmable offsets", i.e.
132/// offsets that are not compile-time constants. Such offsets require the
133/// AdvancedTextureOps shader feature flag. Returns true if \p II is one of
134/// those operations and its offsets operand is not a constant.
135static bool checkAdvancedTextureOps(const IntrinsicInst &II) {
136 // TODO: (#116137) Several other DXIL ops also require this feature flag, but
137 // none of them can be generated yet:
138 // - SampleCmp, SampleCmpBias, SampleCmpGrad and SampleCmpLevelZero set the
139 // flag for non-constant offsets, exactly like the ops handled below.
140 // - SampleCmpLevel, TextureGatherRaw and TextureStoreSample set the flag
141 // unconditionally, and have no intrinsics yet.
142
143 // The offsets operand index differs between the intrinsics.
144 unsigned OffsetsIdx;
145 switch (II.getIntrinsicID()) {
146 default:
147 return false;
148 case Intrinsic::dx_resource_load_level:
149 case Intrinsic::dx_resource_sample:
150 case Intrinsic::dx_resource_sample_clamp:
151 OffsetsIdx = 3;
152 break;
153 case Intrinsic::dx_resource_samplebias:
154 case Intrinsic::dx_resource_samplebias_clamp:
155 case Intrinsic::dx_resource_samplelevel:
156 OffsetsIdx = 4;
157 break;
158 case Intrinsic::dx_resource_samplegrad:
159 case Intrinsic::dx_resource_samplegrad_clamp:
160 OffsetsIdx = 5;
161 break;
162 }
163 return !isa<Constant>(Val: II.getArgOperand(i: OffsetsIdx));
164}
165
166static bool isOptimizationDisabled(const Module &M) {
167 const StringRef Key = "dx.disable_optimizations";
168 if (auto *Flag = mdconst::extract_or_null<ConstantInt>(MD: M.getModuleFlag(Key)))
169 return Flag->getValue().getBoolValue();
170 return false;
171}
172
173// Checks to see if the status bit from a load with status
174// instruction is ever extracted. If it is, the module needs
175// to have the TiledResources shader flag set.
176bool checkIfStatusIsExtracted(const IntrinsicInst &II) {
177 [[maybe_unused]] Intrinsic::ID IID = II.getIntrinsicID();
178 assert(IID == Intrinsic::dx_resource_load_typedbuffer ||
179 IID == Intrinsic::dx_resource_load_rawbuffer &&
180 "unexpected intrinsic ID");
181 for (const User *U : II.users()) {
182 if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(Val: U)) {
183 // Resource load operations return a {result, status} pair.
184 // Check if we extract the status
185 if (EVI->getNumIndices() == 1 && EVI->getIndices()[0] == 1)
186 return true;
187 }
188 }
189
190 return false;
191}
192
193/// Update the shader flags mask based on the given instruction.
194/// \param CSF Shader flags mask to update.
195/// \param I Instruction to check.
196void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
197 const Instruction &I,
198 DXILResourceTypeMap &DRTM,
199 const ModuleMetadataInfo &MMDI) {
200 if (!CSF.Doubles)
201 CSF.Doubles = I.getType()->getScalarType()->isDoubleTy();
202
203 if (!CSF.Doubles) {
204 for (const Value *Op : I.operands()) {
205 if (Op->getType()->getScalarType()->isDoubleTy()) {
206 CSF.Doubles = true;
207 break;
208 }
209 }
210 }
211
212 if (CSF.Doubles) {
213 switch (I.getOpcode()) {
214 case Instruction::FDiv:
215 case Instruction::UIToFP:
216 case Instruction::SIToFP:
217 case Instruction::FPToUI:
218 case Instruction::FPToSI:
219 CSF.DX11_1_DoubleExtensions = true;
220 break;
221 }
222 }
223
224 if (!CSF.LowPrecisionPresent)
225 CSF.LowPrecisionPresent = I.getType()->getScalarType()->isIntegerTy(BitWidth: 16) ||
226 I.getType()->getScalarType()->isHalfTy();
227
228 if (!CSF.LowPrecisionPresent) {
229 for (const Value *Op : I.operands()) {
230 if (Op->getType()->getScalarType()->isIntegerTy(BitWidth: 16) ||
231 Op->getType()->getScalarType()->isHalfTy()) {
232 CSF.LowPrecisionPresent = true;
233 break;
234 }
235 }
236 }
237
238 if (CSF.LowPrecisionPresent) {
239 if (CSF.NativeLowPrecisionMode)
240 CSF.NativeLowPrecision = true;
241 else
242 CSF.MinimumPrecision = true;
243 }
244
245 if (!CSF.Int64Ops)
246 CSF.Int64Ops = I.getType()->getScalarType()->isIntegerTy(BitWidth: 64);
247
248 if (!CSF.Int64Ops && !isa<LifetimeIntrinsic>(Val: &I)) {
249 for (const Value *Op : I.operands()) {
250 if (Op->getType()->getScalarType()->isIntegerTy(BitWidth: 64)) {
251 CSF.Int64Ops = true;
252 break;
253 }
254 }
255 }
256
257 if (const auto *II = dyn_cast<IntrinsicInst>(Val: &I)) {
258 CSF.AdvancedTextureOps |= checkAdvancedTextureOps(II: *II);
259
260 switch (II->getIntrinsicID()) {
261 default:
262 break;
263 case Intrinsic::dx_resource_handlefrombinding: {
264 dxil::ResourceTypeInfo &RTI = DRTM[cast<TargetExtType>(Val: II->getType())];
265
266 // Set ResMayNotAlias if DXIL validator version >= 1.8 and the function
267 // uses UAVs
268 if (!CSF.ResMayNotAlias && CanSetResMayNotAlias &&
269 MMDI.ValidatorVersion >= VersionTuple(1, 8) && RTI.isUAV())
270 CSF.ResMayNotAlias = true;
271
272 switch (RTI.getResourceKind()) {
273 case dxil::ResourceKind::StructuredBuffer:
274 case dxil::ResourceKind::RawBuffer:
275 CSF.EnableRawAndStructuredBuffers = true;
276 break;
277 default:
278 break;
279 }
280 break;
281 }
282 case Intrinsic::dx_resource_handlefromheap: {
283 dxil::ResourceTypeInfo &RTI = DRTM[cast<TargetExtType>(Val: II->getType())];
284 bool IsSamplerHeap = RTI.isSampler();
285 CSF.SamplerDescriptorHeapIndexing |= IsSamplerHeap;
286 CSF.ResourceDescriptorHeapIndexing |= !IsSamplerHeap;
287
288 if (!CSF.ResMayNotAlias && CanSetResMayNotAlias && RTI.isUAV() &&
289 MMDI.ValidatorVersion >= VersionTuple(1, 8)) {
290 CSF.ResMayNotAlias = true;
291 }
292 break;
293 }
294 case Intrinsic::dx_resource_load_level:
295 case Intrinsic::dx_resource_load_typedbuffer: {
296 dxil::ResourceTypeInfo &RTI =
297 DRTM[cast<TargetExtType>(Val: II->getArgOperand(i: 0)->getType())];
298 if (RTI.isTyped() && RTI.isUAV())
299 CSF.TypedUAVLoadAdditionalFormats |= RTI.getTyped().ElementCount > 1;
300 if (II->getIntrinsicID() == Intrinsic::dx_resource_load_typedbuffer &&
301 !CSF.TiledResources && checkIfStatusIsExtracted(II: *II))
302 CSF.TiledResources = true;
303 break;
304 }
305 case Intrinsic::dx_resource_load_rawbuffer: {
306 if (!CSF.TiledResources && checkIfStatusIsExtracted(II: *II))
307 CSF.TiledResources = true;
308 break;
309 }
310 case Intrinsic::dx_resource_atomic_binop:
311 case Intrinsic::dx_resource_atomic_compare_exchange: {
312 if (II->getType()->isIntegerTy(BitWidth: 64)) {
313 dxil::ResourceTypeInfo &RTI =
314 DRTM[cast<TargetExtType>(Val: II->getArgOperand(i: 0)->getType())];
315 if (RTI.isTyped())
316 CSF.AtomicInt64OnTypedResource = true;
317 // TODO(https://github.com/llvm/llvm-project/issues/116152): Set
318 // AtomicInt64OnHeapResource when heap-resource intrinsics are added.
319 }
320 break;
321 }
322 }
323 }
324 // 64-bit atomics on groupshared memory (address space 3).
325 if (const auto *ARMW = dyn_cast<AtomicRMWInst>(Val: &I)) {
326 if (ARMW->getValOperand()->getType()->isIntegerTy(BitWidth: 64) &&
327 ARMW->getPointerAddressSpace() == 3)
328 CSF.AtomicInt64OnGroupShared = true;
329 } else if (const auto *AXCG = dyn_cast<AtomicCmpXchgInst>(Val: &I)) {
330 if (AXCG->getNewValOperand()->getType()->isIntegerTy(BitWidth: 64) &&
331 AXCG->getPointerAddressSpace() == 3)
332 CSF.AtomicInt64OnGroupShared = true;
333 }
334 // Handle call instructions
335 if (auto *CI = dyn_cast<CallInst>(Val: &I)) {
336 const Function *CF = CI->getCalledFunction();
337 // Merge-in shader flags mask of the called function in the current module
338 if (FunctionFlags.contains(Val: CF))
339 CSF.merge(CSF: FunctionFlags[CF]);
340
341 CSF.DX11_1_DoubleExtensions |=
342 checkDoubleExtensionOps(IID: CI->getIntrinsicID());
343 CSF.WaveOps |= checkWaveOps(IID: CI->getIntrinsicID());
344 }
345}
346
347/// Set shader flags that apply to all functions within the module
348ComputedShaderFlags
349ModuleShaderFlags::gatherGlobalModuleFlags(const Module &M,
350 const DXILResourceMap &DRM,
351 const ModuleMetadataInfo &MMDI) {
352
353 ComputedShaderFlags CSF;
354
355 CSF.DisableOptimizations = isOptimizationDisabled(M);
356
357 CSF.UAVsAtEveryStage = hasUAVsAtEveryStage(DRM, MMDI);
358
359 // Set the Max64UAVs flag if the number of UAVs is > 8
360 uint32_t NumUAVs = 0;
361 for (auto &UAV : DRM.uavs()) {
362 // Heap resources do not count towards Max64UAVs flag.
363 if (!UAV.hasBinding())
364 continue;
365 if (MMDI.ValidatorVersion < VersionTuple(1, 6)) {
366 NumUAVs++;
367 } else { // MMDI.ValidatorVersion >= VersionTuple(1, 6)
368 uint32_t Size = UAV.getSize();
369 uint32_t NewNum = NumUAVs + (Size == 0 ? ~0U : Size);
370 if (NewNum < NumUAVs)
371 NewNum = ~0U;
372 NumUAVs = NewNum;
373 }
374 }
375 if (NumUAVs > 8)
376 CSF.Max64UAVs = true;
377
378 // Set the module flag that enables native low-precision execution mode.
379 // NativeLowPrecisionMode can only be set when the command line option
380 // -enable-16bit-types is provided. This is indicated by the dx.nativelowprec
381 // module flag being set
382 // This flag is needed even if the module does not use 16-bit types because a
383 // corresponding debug module may include 16-bit types, and tools that use the
384 // debug module may expect it to have the same flags as the original
385 if (auto *NativeLowPrec = mdconst::extract_or_null<ConstantInt>(
386 MD: M.getModuleFlag(Key: "dx.nativelowprec")))
387 if (MMDI.ShaderModelVersion >= VersionTuple(6, 2))
388 CSF.NativeLowPrecisionMode = NativeLowPrec->getValue().getBoolValue();
389
390 // Set ResMayNotAlias to true if DXIL validator version < 1.8 and there
391 // are UAVs present globally.
392 if (CanSetResMayNotAlias && MMDI.ValidatorVersion < VersionTuple(1, 8))
393 CSF.ResMayNotAlias = !DRM.uavs().empty();
394
395 // The command line option -all-resources-bound will set the
396 // dx.allresourcesbound module flag to 1
397 if (auto *AllResourcesBound = mdconst::extract_or_null<ConstantInt>(
398 MD: M.getModuleFlag(Key: "dx.allresourcesbound")))
399 if (AllResourcesBound->getValue().getBoolValue())
400 CSF.AllResourcesBound = true;
401
402 return CSF;
403}
404
405/// Construct ModuleShaderFlags for module Module M
406void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
407 const DXILResourceMap &DRM,
408 const ModuleMetadataInfo &MMDI,
409 const ModuleSignatureInfo &Signatures) {
410
411 CanSetResMayNotAlias = MMDI.DXILVersion >= VersionTuple(1, 7);
412 // The command line option -res-may-alias will set the dx.resmayalias module
413 // flag to 1, thereby disabling the ability to set the ResMayNotAlias flag
414 if (auto *ResMayAlias = mdconst::extract_or_null<ConstantInt>(
415 MD: M.getModuleFlag(Key: "dx.resmayalias")))
416 if (ResMayAlias->getValue().getBoolValue())
417 CanSetResMayNotAlias = false;
418
419 ComputedShaderFlags GlobalSFMask = gatherGlobalModuleFlags(M, DRM, MMDI);
420
421 CallGraph CG(M);
422
423 // Compute Shader Flags Mask for all functions using post-order visit of SCC
424 // of the call graph.
425 for (scc_iterator<CallGraph *> SCCI = scc_begin(G: &CG); !SCCI.isAtEnd();
426 ++SCCI) {
427 const std::vector<CallGraphNode *> &CurSCC = *SCCI;
428
429 // Union of shader masks of all functions in CurSCC
430 ComputedShaderFlags SCCSF;
431 // List of functions in CurSCC that are neither external nor declarations
432 // and hence whose flags are collected
433 SmallVector<Function *> CurSCCFuncs;
434 for (CallGraphNode *CGN : CurSCC) {
435 Function *F = CGN->getFunction();
436 if (!F)
437 continue;
438
439 if (F->isDeclaration()) {
440 assert(!F->getName().starts_with("dx.op.") &&
441 "DXIL Shader Flag analysis should not be run post-lowering.");
442 continue;
443 }
444
445 ComputedShaderFlags CSF = GlobalSFMask;
446 for (const auto &BB : *F)
447 for (const auto &I : BB)
448 updateFunctionFlags(CSF, I, DRTM, MMDI);
449 // An unused signature element still contributes to the shader's type
450 // requirements even when no instruction uses that component type.
451 if (const EntrySignature *Sig = Signatures.get(F)) {
452 auto HasLowPrecision = [](const auto &Elements) {
453 return llvm::any_of(Elements, [](const auto &E) {
454 return E.CompType == ElementType::F16 ||
455 E.CompType == ElementType::I16 ||
456 E.CompType == ElementType::U16;
457 });
458 };
459 if (HasLowPrecision(Sig->Inputs) || HasLowPrecision(Sig->Outputs)) {
460 CSF.LowPrecisionPresent = true;
461 if (Sig->UseNative16Bit)
462 CSF.NativeLowPrecision = true;
463 else
464 CSF.MinimumPrecision = true;
465 }
466 }
467 // Update combined shader flags mask for all functions in this SCC
468 SCCSF.merge(CSF);
469
470 CurSCCFuncs.push_back(Elt: F);
471 }
472
473 // Update combined shader flags mask for all functions of the module
474 CombinedSFMask.merge(CSF: SCCSF);
475
476 // Shader flags mask of each of the functions in an SCC of the call graph is
477 // the union of all functions in the SCC. Update shader flags masks of
478 // functions in CurSCC accordingly. This is trivially true if SCC contains
479 // one function.
480 for (Function *F : CurSCCFuncs)
481 // Merge SCCSF with that of F
482 FunctionFlags[F].merge(CSF: SCCSF);
483 }
484}
485
486void ComputedShaderFlags::print(raw_ostream &OS) const {
487 uint64_t FlagVal = (uint64_t) * this;
488 OS << formatv(Fmt: "; Shader Flags Value: {0:x8}\n;\n", Vals&: FlagVal);
489 if (FlagVal == 0)
490 return;
491 OS << "; Note: shader requires additional functionality:\n";
492#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleNum, FlagName, Str) \
493 if (FlagName) \
494 (OS << ";").indent(7) << Str << "\n";
495#include "llvm/BinaryFormat/DXContainerConstants.def"
496 OS << "; Note: extra DXIL module flags:\n";
497#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str) \
498 if (FlagName) \
499 (OS << ";").indent(7) << Str << "\n";
500#include "llvm/BinaryFormat/DXContainerConstants.def"
501 OS << ";\n";
502}
503
504/// Return the shader flags mask of the specified function Func.
505const ComputedShaderFlags &
506ModuleShaderFlags::getFunctionFlags(const Function *Func) const {
507 auto Iter = FunctionFlags.find(Val: Func);
508 assert((Iter != FunctionFlags.end() && Iter->first == Func) &&
509 "Get Shader Flags : No Shader Flags Mask exists for function");
510 return Iter->second;
511}
512
513//===----------------------------------------------------------------------===//
514// ShaderFlagsAnalysis and ShaderFlagsAnalysisPrinterPass
515
516// Provide an explicit template instantiation for the static ID.
517AnalysisKey ShaderFlagsAnalysis::Key;
518
519ModuleShaderFlags ShaderFlagsAnalysis::run(Module &M,
520 ModuleAnalysisManager &AM) {
521 DXILResourceTypeMap &DRTM = AM.getResult<DXILResourceTypeAnalysis>(IR&: M);
522 DXILResourceMap &DRM = AM.getResult<DXILResourceAnalysis>(IR&: M);
523 const ModuleMetadataInfo MMDI = AM.getResult<DXILMetadataAnalysis>(IR&: M);
524
525 ModuleShaderFlags MSFI;
526 MSFI.initialize(M, DRTM, DRM, MMDI, Signatures: AM.getResult<SignatureAnalysis>(IR&: M));
527
528 return MSFI;
529}
530
531PreservedAnalyses ShaderFlagsAnalysisPrinter::run(Module &M,
532 ModuleAnalysisManager &AM) {
533 const ModuleShaderFlags &FlagsInfo = AM.getResult<ShaderFlagsAnalysis>(IR&: M);
534 // Print description of combined shader flags for all module functions
535 OS << "; Combined Shader Flags for Module\n";
536 FlagsInfo.getCombinedFlags().print(OS);
537 // Print shader flags mask for each of the module functions
538 OS << "; Shader Flags for Module Functions\n";
539 for (const auto &F : M.getFunctionList()) {
540 if (F.isDeclaration())
541 continue;
542 const ComputedShaderFlags &SFMask = FlagsInfo.getFunctionFlags(Func: &F);
543 OS << formatv(Fmt: "; Function {0} : {1:x8}\n;\n", Vals: F.getName(),
544 Vals: (uint64_t)(SFMask));
545 }
546
547 return PreservedAnalyses::all();
548}
549
550//===----------------------------------------------------------------------===//
551// ShaderFlagsAnalysis and ShaderFlagsAnalysisPrinterPass
552
553bool ShaderFlagsAnalysisWrapper::runOnModule(Module &M) {
554 DXILResourceTypeMap &DRTM =
555 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
556 DXILResourceMap &DRM =
557 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
558 const ModuleMetadataInfo MMDI =
559 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
560
561 MSFI.initialize(M, DRTM, DRM, MMDI,
562 Signatures: getAnalysis<SignatureAnalysisWrapper>().getSignatureInfo());
563 return false;
564}
565
566void ShaderFlagsAnalysisWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
567 AU.setPreservesAll();
568 AU.addRequiredTransitive<DXILResourceTypeWrapperPass>();
569 AU.addRequiredTransitive<DXILResourceWrapperPass>();
570 AU.addRequired<DXILMetadataAnalysisWrapperPass>();
571 AU.addRequired<SignatureAnalysisWrapper>();
572}
573
574char ShaderFlagsAnalysisWrapper::ID = 0;
575
576INITIALIZE_PASS_BEGIN(ShaderFlagsAnalysisWrapper, "dx-shader-flag-analysis",
577 "DXIL Shader Flag Analysis", true, true)
578INITIALIZE_PASS_DEPENDENCY(DXILResourceTypeWrapperPass)
579INITIALIZE_PASS_DEPENDENCY(DXILMetadataAnalysisWrapperPass)
580INITIALIZE_PASS_DEPENDENCY(SignatureAnalysisWrapper)
581INITIALIZE_PASS_END(ShaderFlagsAnalysisWrapper, "dx-shader-flag-analysis",
582 "DXIL Shader Flag Analysis", true, true)
583