LLVM 24.0.0git
DXILTranslateMetadata.cpp
Go to the documentation of this file.
1//===- DXILTranslateMetadata.cpp - Pass to emit DXIL metadata -------------===//
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
10#include "DXILRootSignature.h"
11#include "DXILShaderFlags.h"
13#include "DirectX.h"
14#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/Twine.h"
19#include "llvm/IR/BasicBlock.h"
20#include "llvm/IR/Constants.h"
23#include "llvm/IR/Function.h"
24#include "llvm/IR/IRBuilder.h"
25#include "llvm/IR/LLVMContext.h"
26#include "llvm/IR/MDBuilder.h"
27#include "llvm/IR/Metadata.h"
28#include "llvm/IR/Module.h"
30#include "llvm/Pass.h"
34#include <cstdint>
35
36using namespace llvm;
37using namespace llvm::dxil;
38
39namespace {
40
41/// A simple wrapper of DiagnosticInfo that generates module-level diagnostic
42/// for the DXILValidateMetadata pass
43class DiagnosticInfoValidateMD : public DiagnosticInfo {
44private:
45 const Twine &Msg;
46 const Module &Mod;
47
48public:
49 /// \p M is the module for which the diagnostic is being emitted. \p Msg is
50 /// the message to show. Note that this class does not copy this message, so
51 /// this reference must be valid for the whole life time of the diagnostic.
52 DiagnosticInfoValidateMD(const Module &M,
53 const Twine &Msg LLVM_LIFETIME_BOUND,
55 : DiagnosticInfo(DK_Unsupported, Severity), Msg(Msg), Mod(M) {}
56
57 void print(DiagnosticPrinter &DP) const override {
58 DP << Mod.getName() << ": " << Msg << '\n';
59 }
60};
61
62static void reportError(Module &M, Twine Message,
63 DiagnosticSeverity Severity = DS_Error) {
64 M.getContext().diagnose(DiagnosticInfoValidateMD(M, Message, Severity));
65}
66
67static void reportLoopError(Module &M, Twine Message,
68 DiagnosticSeverity Severity = DS_Error) {
69 reportError(M, Twine("Invalid \"llvm.loop\" metadata: ") + Message, Severity);
70}
71
72enum class EntryPropsTag {
73 ShaderFlags = 0,
74 GSState,
75 DSState,
76 HSState,
77 NumThreads,
78 AutoBindingSpace,
79 RayPayloadSize,
80 RayAttribSize,
81 ShaderKind,
82 MSState,
83 ASStateTag,
84 WaveSize,
85 EntryRootSig,
86 WaveRange = 23,
87};
88
89} // namespace
90
92 DXILResourceTypeMap &DRTM) {
93 LLVMContext &Context = M.getContext();
94
95 for (ResourceInfo &RI : DRM)
96 if (RI.hasBinding() && !RI.hasSymbol())
97 RI.createSymbol(M,
98 DRTM[RI.getHandleTy()].createElementStruct(RI.getName()));
99
100 SmallVector<Metadata *> SRVs, UAVs, CBufs, Smps;
101 for (const ResourceInfo &RI : DRM.srvs())
102 if (RI.hasBinding())
103 SRVs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
104 for (const ResourceInfo &RI : DRM.uavs())
105 if (RI.hasBinding())
106 UAVs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
107 for (const ResourceInfo &RI : DRM.cbuffers())
108 if (RI.hasBinding())
109 CBufs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
110 for (const ResourceInfo &RI : DRM.samplers())
111 if (RI.hasBinding())
112 Smps.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
113
114 Metadata *SRVMD = SRVs.empty() ? nullptr : MDNode::get(Context, SRVs);
115 Metadata *UAVMD = UAVs.empty() ? nullptr : MDNode::get(Context, UAVs);
116 Metadata *CBufMD = CBufs.empty() ? nullptr : MDNode::get(Context, CBufs);
117 Metadata *SmpMD = Smps.empty() ? nullptr : MDNode::get(Context, Smps);
118
119 if (DRM.empty())
120 return nullptr;
121
122 NamedMDNode *ResourceMD = M.getOrInsertNamedMetadata("dx.resources");
123 ResourceMD->addOperand(
124 MDNode::get(M.getContext(), {SRVMD, UAVMD, CBufMD, SmpMD}));
125
126 return ResourceMD;
127}
128
130 switch (Env) {
131 case Triple::Pixel:
132 return "ps";
133 case Triple::Vertex:
134 return "vs";
135 case Triple::Geometry:
136 return "gs";
137 case Triple::Hull:
138 return "hs";
139 case Triple::Domain:
140 return "ds";
141 case Triple::Compute:
142 return "cs";
143 case Triple::Library:
144 return "lib";
145 case Triple::Mesh:
146 return "ms";
148 return "as";
150 return "rootsig";
151 default:
152 break;
153 }
154 llvm_unreachable("Unsupported environment for DXIL generation.");
155}
156
160
165 ConstantInt::get(Type::getInt32Ty(Ctx), static_cast<int>(Tag))));
166 switch (Tag) {
167 case EntryPropsTag::ShaderFlags:
169 ConstantInt::get(Type::getInt64Ty(Ctx), Value)));
170 break;
171 case EntryPropsTag::ShaderKind:
173 ConstantInt::get(Type::getInt32Ty(Ctx), Value)));
174 break;
175 case EntryPropsTag::GSState:
176 case EntryPropsTag::DSState:
177 case EntryPropsTag::HSState:
178 case EntryPropsTag::NumThreads:
179 case EntryPropsTag::AutoBindingSpace:
180 case EntryPropsTag::RayPayloadSize:
181 case EntryPropsTag::RayAttribSize:
182 case EntryPropsTag::MSState:
183 case EntryPropsTag::ASStateTag:
184 case EntryPropsTag::WaveSize:
185 case EntryPropsTag::EntryRootSig:
186 case EntryPropsTag::WaveRange:
187 llvm_unreachable("NYI: Unhandled entry property tag");
188 }
189 return MDVals;
190}
191
193 uint64_t EntryShaderFlags,
194 const ModuleMetadataInfo &MMDI) {
196 LLVMContext &Ctx = EP.Entry->getContext();
197 if (EntryShaderFlags != 0)
198 MDVals.append(getTagValueAsMetadata(EntryPropsTag::ShaderFlags,
199 EntryShaderFlags, Ctx));
200
201 if (EP.Entry != nullptr) {
202 // FIXME: support more props.
203 // See https://github.com/llvm/llvm-project/issues/57948.
204 // Add shader kind for lib entries.
207 MDVals.append(getTagValueAsMetadata(EntryPropsTag::ShaderKind,
208 getShaderStage(EP.ShaderStage), Ctx));
209
211 // Handle mandatory "hlsl.numthreads"
212 MDVals.emplace_back(ConstantAsMetadata::get(ConstantInt::get(
213 Type::getInt32Ty(Ctx), static_cast<int>(EntryPropsTag::NumThreads))));
214 Metadata *NumThreadVals[] = {ConstantAsMetadata::get(ConstantInt::get(
215 Type::getInt32Ty(Ctx), EP.NumThreadsX)),
216 ConstantAsMetadata::get(ConstantInt::get(
217 Type::getInt32Ty(Ctx), EP.NumThreadsY)),
218 ConstantAsMetadata::get(ConstantInt::get(
219 Type::getInt32Ty(Ctx), EP.NumThreadsZ))};
220 MDVals.emplace_back(MDNode::get(Ctx, NumThreadVals));
221
222 // Handle optional "hlsl.wavesize". The fields are optionally represented
223 // if they are non-zero.
224 if (EP.WaveSizeMin != 0) {
225 bool IsWaveRange = VersionTuple(6, 8) <= MMDI.ShaderModelVersion;
226 bool IsWaveSize =
227 !IsWaveRange && VersionTuple(6, 6) <= MMDI.ShaderModelVersion;
228
229 if (!IsWaveRange && !IsWaveSize) {
230 reportError(M, "Shader model 6.6 or greater is required to specify "
231 "the \"hlsl.wavesize\" function attribute");
232 return nullptr;
233 }
234
235 // A range is being specified if EP.WaveSizeMax != 0
236 if (EP.WaveSizeMax && !IsWaveRange) {
238 M, "Shader model 6.8 or greater is required to specify "
239 "wave size range values of the \"hlsl.wavesize\" function "
240 "attribute");
241 return nullptr;
242 }
243
244 EntryPropsTag Tag =
245 IsWaveSize ? EntryPropsTag::WaveSize : EntryPropsTag::WaveRange;
247 ConstantInt::get(Type::getInt32Ty(Ctx), static_cast<int>(Tag))));
248
250 ConstantInt::get(Type::getInt32Ty(Ctx), EP.WaveSizeMin))};
251 if (IsWaveRange) {
253 ConstantInt::get(Type::getInt32Ty(Ctx), EP.WaveSizeMax)));
255 ConstantInt::get(Type::getInt32Ty(Ctx), EP.WaveSizePref)));
256 }
257
258 MDVals.emplace_back(MDNode::get(Ctx, WaveSizeVals));
259 }
260 }
261 }
262
263 if (MDVals.empty())
264 return nullptr;
265 return MDNode::get(Ctx, MDVals);
266}
267
269 MDTuple *Signatures, MDNode *Resources,
270 MDTuple *Properties, LLVMContext &Ctx) {
271 // Each entry point metadata record specifies:
272 // * reference to the entry point function global symbol
273 // * unmangled name
274 // * list of signatures
275 // * list of resources
276 // * list of tag-value pairs of shader capabilities and other properties
277 Metadata *MDVals[5];
278 MDVals[0] =
279 EntryFn ? ValueAsMetadata::get(const_cast<Function *>(EntryFn)) : nullptr;
280 MDVals[1] = MDString::get(Ctx, EntryFn ? EntryFn->getName() : "");
281 MDVals[2] = Signatures;
282 MDVals[3] = Resources;
283 MDVals[4] = Properties;
284 return MDNode::get(Ctx, MDVals);
285}
286
288 MDTuple *Signatures, MDNode *MDResources,
289 const uint64_t EntryShaderFlags,
290 const ModuleMetadataInfo &MMDI) {
291 MDTuple *Properties = getEntryPropAsMetadata(M, EP, EntryShaderFlags, MMDI);
292 return constructEntryMetadata(EP.Entry, Signatures, MDResources, Properties,
293 EP.Entry->getContext());
294}
295
297 if (MMDI.ValidatorVersion.empty())
298 return;
299
300 LLVMContext &Ctx = M.getContext();
301 IRBuilder<> IRB(M);
302 Metadata *MDVals[2];
303 MDVals[0] =
305 MDVals[1] = ConstantAsMetadata::get(
306 IRB.getInt32(MMDI.ValidatorVersion.getMinor().value_or(0)));
307 NamedMDNode *ValVerNode = M.getOrInsertNamedMetadata("dx.valver");
308 // Set validator version obtained from DXIL Metadata Analysis pass
309 ValVerNode->clearOperands();
310 ValVerNode->addOperand(MDNode::get(Ctx, MDVals));
311}
312
314 const ModuleMetadataInfo &MMDI) {
315 LLVMContext &Ctx = M.getContext();
316 IRBuilder<> IRB(M);
317 Metadata *SMVals[3];
319 SMVals[0] = MDString::get(Ctx, getShortShaderStage(MMDI.ShaderProfile));
320 SMVals[1] = ConstantAsMetadata::get(IRB.getInt32(SM.getMajor()));
321 SMVals[2] = ConstantAsMetadata::get(IRB.getInt32(SM.getMinor().value_or(0)));
322 NamedMDNode *SMMDNode = M.getOrInsertNamedMetadata("dx.shaderModel");
323 SMMDNode->addOperand(MDNode::get(Ctx, SMVals));
324}
325
327 LLVMContext &Ctx = M.getContext();
328 IRBuilder<> IRB(M);
329 VersionTuple DXILVer = MMDI.DXILVersion;
330 Metadata *DXILVals[2];
331 DXILVals[0] = ConstantAsMetadata::get(IRB.getInt32(DXILVer.getMajor()));
332 DXILVals[1] =
333 ConstantAsMetadata::get(IRB.getInt32(DXILVer.getMinor().value_or(0)));
334 NamedMDNode *DXILVerMDNode = M.getOrInsertNamedMetadata("dx.version");
335 DXILVerMDNode->addOperand(MDNode::get(Ctx, DXILVals));
336}
337
339 uint64_t ShaderFlags) {
340 LLVMContext &Ctx = M.getContext();
341 MDTuple *Properties = nullptr;
342 if (ShaderFlags != 0) {
344 MDVals.append(
345 getTagValueAsMetadata(EntryPropsTag::ShaderFlags, ShaderFlags, Ctx));
346 Properties = MDNode::get(Ctx, MDVals);
347 }
348 // Library has an entry metadata with resource table metadata and all other
349 // MDNodes as null.
350 return constructEntryMetadata(nullptr, nullptr, RMD, Properties, Ctx);
351}
352
353static void translateBranchMetadata(Module &M, Instruction *BBTerminatorInst) {
354 MDNode *HlslControlFlowMD =
355 BBTerminatorInst->getMetadata("hlsl.controlflow.hint");
356
357 if (!HlslControlFlowMD)
358 return;
359
360 assert(HlslControlFlowMD->getNumOperands() == 2 &&
361 "invalid operands for hlsl.controlflow.hint");
362
363 MDBuilder MDHelper(M.getContext());
364
365 llvm::Metadata *HintsStr = MDHelper.createString("dx.controlflow.hints");
366 llvm::Metadata *HintsValue = MDHelper.createConstant(
367 mdconst::extract<ConstantInt>(HlslControlFlowMD->getOperand(1)));
368
369 MDNode *MDNode = llvm::MDNode::get(M.getContext(), {HintsStr, HintsValue});
370
371 BBTerminatorInst->setMetadata("dx.controlflow.hints", MDNode);
372 BBTerminatorInst->setMetadata("hlsl.controlflow.hint", nullptr);
373}
374
375// Determines if the metadata node will be compatible with DXIL's loop metadata
376// representation.
377//
378// Reports an error for compatible metadata that is ill-formed.
379static bool isLoopMDCompatible(Module &M, Metadata *MD) {
380 // DXIL only accepts the following loop hints:
381 std::array<StringLiteral, 3> ValidHintNames = {"llvm.loop.unroll.count",
382 "llvm.loop.unroll.disable",
383 "llvm.loop.unroll.full"};
384
385 MDNode *HintMD = dyn_cast<MDNode>(MD);
386 if (!HintMD || HintMD->getNumOperands() == 0)
387 return false;
388
389 auto *HintStr = dyn_cast<MDString>(HintMD->getOperand(0));
390 if (!HintStr)
391 return false;
392
393 if (!llvm::is_contained(ValidHintNames, HintStr->getString()))
394 return false;
395
396 auto ValidCountNode = [](MDNode *CountMD) -> bool {
397 if (CountMD->getNumOperands() == 2)
398 if (auto *Count = dyn_cast<ConstantAsMetadata>(CountMD->getOperand(1)))
399 if (isa<ConstantInt>(Count->getValue()))
400 return true;
401 return false;
402 };
403
404 if (HintStr->getString() == "llvm.loop.unroll.count") {
405 if (!ValidCountNode(HintMD)) {
406 reportLoopError(M, "\"llvm.loop.unroll.count\" must have 2 operands and "
407 "the second must be a constant integer");
408 return false;
409 }
410 } else if (HintMD->getNumOperands() != 1) {
411 reportLoopError(
412 M, "\"llvm.loop.unroll.disable\" and \"llvm.loop.unroll.full\" "
413 "must be provided as a single operand");
414 return false;
415 }
416
417 return true;
418}
419
420static void translateLoopMetadata(Module &M, Instruction *I, MDNode *BaseMD) {
421 // A distinct node has the self-referential form: !0 = !{ !0, ... }
422 auto IsDistinctNode = [](MDNode *Node) -> bool {
423 return Node && Node->getNumOperands() != 0 && Node == Node->getOperand(0);
424 };
425
426 // Set metadata to null to remove empty/ill-formed metadata from instruction
427 if (BaseMD->getNumOperands() == 0 || !IsDistinctNode(BaseMD))
428 return I->setMetadata("llvm.loop", nullptr);
429
430 // It is valid to have a chain of self-refential loop metadata nodes, as
431 // below. We will collapse these into just one when we reconstruct the
432 // metadata.
433 //
434 // Eg:
435 // !0 = !{!0, !1}
436 // !1 = !{!1, !2}
437 // !2 = !{!"llvm.loop.unroll.disable"}
438 //
439 // So, traverse down a potential self-referential chain
440 while (1 < BaseMD->getNumOperands() &&
441 IsDistinctNode(dyn_cast<MDNode>(BaseMD->getOperand(1))))
442 BaseMD = dyn_cast<MDNode>(BaseMD->getOperand(1));
443
444 // To reconstruct a distinct node we create a temporary node that we will
445 // then update to create a self-reference.
446 llvm::TempMDTuple TempNode = llvm::MDNode::getTemporary(M.getContext(), {});
447 SmallVector<Metadata *> CompatibleOperands = {TempNode.get()};
448
449 // Iterate and reconstruct the metadata nodes that contains any hints,
450 // stripping any unrecognized metadata.
452 for (auto &Op : Operands.drop_front())
453 if (isLoopMDCompatible(M, Op.get()))
454 CompatibleOperands.push_back(Op.get());
455
456 if (2 < CompatibleOperands.size())
457 reportLoopError(M, "Provided conflicting hints");
458
459 MDNode *CompatibleLoopMD = MDNode::get(M.getContext(), CompatibleOperands);
460 TempNode->replaceAllUsesWith(CompatibleLoopMD);
461
462 I->setMetadata("llvm.loop", CompatibleLoopMD);
463}
464
465using InstructionMDList = std::array<unsigned, 7>;
466
468 return {
469 M.getMDKindID("dx.nonuniform"), M.getMDKindID("dx.controlflow.hints"),
470 M.getMDKindID("dx.precise"), llvm::LLVMContext::MD_range,
471 llvm::LLVMContext::MD_alias_scope, llvm::LLVMContext::MD_noalias,
472 M.getMDKindID("llvm.loop")};
473}
474
476 // construct allowlist of valid metadata node kinds
477 InstructionMDList DXILCompatibleMDs = getCompatibleInstructionMDs(M);
478 unsigned char MDLoopKind = M.getContext().getMDKindID("llvm.loop");
479
480 for (Function &F : M) {
481 for (BasicBlock &BB : F) {
482 // This needs to be done first so that "hlsl.controlflow.hints" isn't
483 // removed in the allow-list below
484 translateBranchMetadata(M, BB.getTerminator());
485
486 for (auto &I : make_early_inc_range(BB)) {
488 if (MDNode *LoopMD = I.getMetadata(MDLoopKind))
489 translateLoopMetadata(M, &I, LoopMD);
490 I.dropUnknownNonDebugMetadata(DXILCompatibleMDs);
491 }
492 }
493 }
494}
495
496static void cleanModuleFlags(Module &M) {
497 NamedMDNode *MDFlags = M.getModuleFlagsMetadata();
498 if (!MDFlags)
499 return;
500
502 M.getModuleFlagsMetadata(FlagEntries);
503 bool Updated = false;
504 for (auto &Flag : FlagEntries) {
505 // llvm 3.7 only supports behavior up to AppendUnique.
506 if (Flag.Behavior <= Module::ModFlagBehavior::AppendUnique)
507 continue;
508 Flag.Behavior = Module::ModFlagBehavior::Warning;
509 Updated = true;
510 }
511
512 if (!Updated)
513 return;
514
515 MDFlags->eraseFromParent();
516
517 for (auto &Flag : FlagEntries)
518 M.addModuleFlag(Flag.Behavior, Flag.Key->getString(), Flag.Val);
519}
520
521using GlobalMDList = std::array<StringLiteral, 12>;
522
523// The following are compatible with DXIL but not emit with clang, they can
524// be added when applicable:
525// dx.typeAnnotations, dx.dxrPayloadAnnotations
527 "llvm.ident", "llvm.module.flags",
528 "dx.resources", "dx.valver",
529 "dx.shaderModel", "dx.version",
530 "dx.entryPoints", "dx.source.contents",
531 "dx.source.defines", "dx.source.mainFileName",
532 "dx.source.args", "dx.viewIdState"};
533
536 const ModuleShaderFlags &ShaderFlags,
537 const ModuleMetadataInfo &MMDI,
538 const ModuleSignatureInfo &SignatureInfo) {
539 LLVMContext &Ctx = M.getContext();
540 IRBuilder<> IRB(M);
541 SmallVector<MDNode *> EntryFnMDNodes;
542
543 emitValidatorVersionMD(M, MMDI);
545 emitDXILVersionTupleMD(M, MMDI);
546 NamedMDNode *NamedResourceMD = emitResourceMetadata(M, DRM, DRTM);
547 auto *ResourceMD =
548 (NamedResourceMD != nullptr) ? NamedResourceMD->getOperand(0) : nullptr;
549
551 // Get the combined shader flag mask of all functions in the library to be
552 // used as shader flags mask value associated with top-level library entry
553 // metadata.
554 uint64_t CombinedMask = ShaderFlags.getCombinedFlags();
555 EntryFnMDNodes.emplace_back(
556 emitTopLevelLibraryNode(M, ResourceMD, CombinedMask));
557 } else if (1 < MMDI.EntryPropertyVec.size())
558 reportError(M, "Non-library shader: One and only one entry expected");
559
560 for (const EntryProperties &EntryProp : MMDI.EntryPropertyVec) {
561 uint64_t EntryShaderFlags = 0;
563 EntryShaderFlags = ShaderFlags.getFunctionFlags(EntryProp.Entry);
564 if (EntryProp.ShaderStage != MMDI.ShaderProfile)
566 M, "Shader stage '" +
568 "' for entry '" + Twine(EntryProp.Entry->getName()) +
569 "' different from specified target profile '" +
571 "'"));
572 }
573 MDTuple *Signatures = nullptr;
574 if (const EntrySignature *Sig = SignatureInfo.get(EntryProp.Entry)) {
575 Signatures = Sig->getAsMetadata(Ctx, MMDI.ValidatorVersion);
576 // This module-level dependency state describes a single shader, not a
577 // concatenation of the independent signatures in a library.
578 if (MMDI.ShaderProfile != Triple::Library &&
579 (MMDI.ValidatorVersion.empty() ||
580 MMDI.ValidatorVersion == VersionTuple(0, 0) ||
581 MMDI.ValidatorVersion >= VersionTuple(1, 1)) &&
582 (Sig->InputVectors || Sig->OutputVectors)) {
583 auto State = Sig->getDependencyState();
584 auto *StateMD = M.getOrInsertNamedMetadata("dx.viewIdState");
585 StateMD->clearOperands();
586 StateMD->addOperand(MDNode::get(
588 }
589 }
590 EntryFnMDNodes.emplace_back(emitEntryMD(
591 M, EntryProp, Signatures, ResourceMD, EntryShaderFlags, MMDI));
592 }
593
594 NamedMDNode *EntryPointsNamedMD =
595 M.getOrInsertNamedMetadata("dx.entryPoints");
596 for (auto *Entry : EntryFnMDNodes)
597 EntryPointsNamedMD->addOperand(Entry);
598
600
601 // Finally, strip all module metadata that is not explicitly specified in the
602 // allow-list
604
605 for (NamedMDNode &NamedMD : M.named_metadata())
606 if (!NamedMD.getName().starts_with("llvm.dbg.") &&
607 !llvm::is_contained(CompatibleNamedModuleMDs, NamedMD.getName()))
608 ToStrip.push_back(&NamedMD);
609
610 for (NamedMDNode *NamedMD : ToStrip)
611 NamedMD->eraseFromParent();
612}
613
616 DXILResourceMap &DRM = MAM.getResult<DXILResourceAnalysis>(M);
618 const ModuleShaderFlags &ShaderFlags = MAM.getResult<ShaderFlagsAnalysis>(M);
619 const dxil::ModuleMetadataInfo MMDI = MAM.getResult<DXILMetadataAnalysis>(M);
620
621 const auto &SignatureInfo = MAM.getResult<SignatureAnalysis>(M);
622 translateGlobalMetadata(M, DRM, DRTM, ShaderFlags, MMDI, SignatureInfo);
624
625 return PreservedAnalyses::all();
626}
627
643
645 DXILResourceMap &DRM =
646 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
647 DXILResourceTypeMap &DRTM =
648 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
649 const ModuleShaderFlags &ShaderFlags =
653
654 const auto &SignatureInfo =
655 getAnalysis<SignatureAnalysisWrapper>().getSignatureInfo();
656 translateGlobalMetadata(M, DRM, DRTM, ShaderFlags, MMDI, SignatureInfo);
658 return true;
659}
660
662
666
668 "DXIL Translate Metadata", false, false)
675 "DXIL Translate Metadata", false, false)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
static Error reportError(StringRef Message)
#define LLVM_LIFETIME_BOUND
Definition Compiler.h:456
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DXIL Remove Unused Resources
static void translateLoopMetadata(Module &M, Instruction *I, MDNode *BaseMD)
static InstructionMDList getCompatibleInstructionMDs(llvm::Module &M)
static bool isLoopMDCompatible(Module &M, Metadata *MD)
static void emitDXILVersionTupleMD(Module &M, const ModuleMetadataInfo &MMDI)
static void emitValidatorVersionMD(Module &M, const ModuleMetadataInfo &MMDI)
static MDTuple * emitTopLevelLibraryNode(Module &M, MDNode *RMD, uint64_t ShaderFlags)
static MDTuple * getEntryPropAsMetadata(Module &M, const EntryProperties &EP, uint64_t EntryShaderFlags, const ModuleMetadataInfo &MMDI)
static void translateBranchMetadata(Module &M, Instruction *BBTerminatorInst)
static void translateGlobalMetadata(Module &M, DXILResourceMap &DRM, DXILResourceTypeMap &DRTM, const ModuleShaderFlags &ShaderFlags, const ModuleMetadataInfo &MMDI, const ModuleSignatureInfo &SignatureInfo)
static MDTuple * constructEntryMetadata(const Function *EntryFn, MDTuple *Signatures, MDNode *Resources, MDTuple *Properties, LLVMContext &Ctx)
static SmallVector< Metadata * > getTagValueAsMetadata(EntryPropsTag Tag, uint64_t Value, LLVMContext &Ctx)
static void translateInstructionMetadata(Module &M)
static GlobalMDList CompatibleNamedModuleMDs
static void cleanModuleFlags(Module &M)
static StringRef getShortShaderStage(Triple::EnvironmentType Env)
std::array< StringLiteral, 12 > GlobalMDList
static NamedMDNode * emitResourceMetadata(Module &M, DXILResourceMap &DRM, DXILResourceTypeMap &DRTM)
static uint32_t getShaderStage(Triple::EnvironmentType Env)
static MDTuple * emitEntryMD(Module &M, const EntryProperties &EP, MDTuple *Signatures, MDNode *MDResources, const uint64_t EntryShaderFlags, const ModuleMetadataInfo &MMDI)
std::array< unsigned, 7 > InstructionMDList
static void emitShaderModelVersionMD(Module &M, const ModuleMetadataInfo &MMDI)
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
ModuleAnalysisManager MAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
SI Fold Operands
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
Defines the llvm::VersionTuple class, which represents a version in the form major[....
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:548
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Definition Constants.h:878
iterator_range< iterator > samplers()
iterator_range< iterator > srvs()
iterator_range< iterator > cbuffers()
iterator_range< iterator > uavs()
Wrapper pass for the legacy pass manager.
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
This is the base abstract class for diagnostic reporting in the backend.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:352
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition IRBuilder.h:465
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2909
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
LLVM_ABI ConstantAsMetadata * createConstant(Constant *C)
Return the given constant as metadata.
Definition MDBuilder.cpp:25
LLVM_ABI MDString * createString(StringRef Str)
Return the given string as metadata.
Definition MDBuilder.cpp:21
Metadata node.
Definition Metadata.h:1081
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1437
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1591
ArrayRef< MDOperand > operands() const
Definition Metadata.h:1435
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1579
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1443
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:597
Tuple of metadata.
Definition Metadata.h:1496
Root of the metadata hierarchy.
Definition Metadata.h:64
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:253
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
Definition Module.h:147
@ Warning
Emits a warning if two values disagree.
Definition Module.h:125
A tuple of MDNodes.
Definition Metadata.h:1797
LLVM_ABI void eraseFromParent()
Drop all references and remove the node from parent module.
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI void clearOperands()
Drop all references to this node's operands.
LLVM_ABI void addOperand(MDNode *M)
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.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
reference emplace_back(ArgTypes &&... Args)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
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.
Definition StringRef.h:56
@ RootSignature
Definition Triple.h:413
@ Amplification
Definition Triple.h:412
static LLVM_ABI StringRef getEnvironmentTypeName(EnvironmentType Kind)
Get the canonical name for the Kind environment.
Definition Triple.cpp:405
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:300
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:299
static LLVM_ABI ValueAsMetadata * get(Value *V)
Definition Metadata.cpp:514
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:315
Represents a version number in the form major[.minor[.subminor[.build]]].
unsigned getMajor() const
Retrieve the major version number.
bool empty() const
Determine whether this version information is empty (e.g., all version components are zero).
std::optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
const EntrySignature * get(const Function *F) const
Wrapper pass for the legacy pass manager.
Wrapper pass for the legacy pass manager.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:679
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
ModulePass * createDXILTranslateMetadataLegacyPass()
Pass to emit metadata for DXIL.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:649
@ DK_Unsupported
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...
Definition Casting.h:547
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
DWARFExpression::Operation Op
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
Triple::EnvironmentType ShaderStage
Triple::EnvironmentType ShaderProfile
SmallVector< EntryProperties > EntryPropertyVec