LLVM 22.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"
12#include "DirectX.h"
13#include "llvm/ADT/STLExtras.h"
15#include "llvm/ADT/Twine.h"
18#include "llvm/IR/BasicBlock.h"
19#include "llvm/IR/Constants.h"
22#include "llvm/IR/Function.h"
23#include "llvm/IR/IRBuilder.h"
24#include "llvm/IR/LLVMContext.h"
25#include "llvm/IR/MDBuilder.h"
26#include "llvm/IR/Metadata.h"
27#include "llvm/IR/Module.h"
29#include "llvm/Pass.h"
33#include <cstdint>
34
35using namespace llvm;
36using namespace llvm::dxil;
37
38namespace {
39
40/// A simple wrapper of DiagnosticInfo that generates module-level diagnostic
41/// for the DXILValidateMetadata pass
42class DiagnosticInfoValidateMD : public DiagnosticInfo {
43private:
44 const Twine &Msg;
45 const Module &Mod;
46
47public:
48 /// \p M is the module for which the diagnostic is being emitted. \p Msg is
49 /// the message to show. Note that this class does not copy this message, so
50 /// this reference must be valid for the whole life time of the diagnostic.
51 DiagnosticInfoValidateMD(const Module &M,
52 const Twine &Msg LLVM_LIFETIME_BOUND,
54 : DiagnosticInfo(DK_Unsupported, Severity), Msg(Msg), Mod(M) {}
55
56 void print(DiagnosticPrinter &DP) const override {
57 DP << Mod.getName() << ": " << Msg << '\n';
58 }
59};
60
61static void reportError(Module &M, Twine Message,
62 DiagnosticSeverity Severity = DS_Error) {
63 M.getContext().diagnose(DiagnosticInfoValidateMD(M, Message, Severity));
64}
65
66static void reportLoopError(Module &M, Twine Message,
67 DiagnosticSeverity Severity = DS_Error) {
68 reportError(M, Twine("Invalid \"llvm.loop\" metadata: ") + Message, Severity);
69}
70
71enum class EntryPropsTag {
72 ShaderFlags = 0,
73 GSState,
74 DSState,
75 HSState,
76 NumThreads,
77 AutoBindingSpace,
78 RayPayloadSize,
79 RayAttribSize,
80 ShaderKind,
81 MSState,
82 ASStateTag,
83 WaveSize,
84 EntryRootSig,
85 WaveRange = 23,
86};
87
88} // namespace
89
91 DXILResourceTypeMap &DRTM) {
92 LLVMContext &Context = M.getContext();
93
94 for (ResourceInfo &RI : DRM)
95 if (!RI.hasSymbol())
96 RI.createSymbol(M,
97 DRTM[RI.getHandleTy()].createElementStruct(RI.getName()));
98
99 SmallVector<Metadata *> SRVs, UAVs, CBufs, Smps;
100 for (const ResourceInfo &RI : DRM.srvs())
101 SRVs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
102 for (const ResourceInfo &RI : DRM.uavs())
103 UAVs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
104 for (const ResourceInfo &RI : DRM.cbuffers())
105 CBufs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
106 for (const ResourceInfo &RI : DRM.samplers())
107 Smps.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
108
109 Metadata *SRVMD = SRVs.empty() ? nullptr : MDNode::get(Context, SRVs);
110 Metadata *UAVMD = UAVs.empty() ? nullptr : MDNode::get(Context, UAVs);
111 Metadata *CBufMD = CBufs.empty() ? nullptr : MDNode::get(Context, CBufs);
112 Metadata *SmpMD = Smps.empty() ? nullptr : MDNode::get(Context, Smps);
113
114 if (DRM.empty())
115 return nullptr;
116
117 NamedMDNode *ResourceMD = M.getOrInsertNamedMetadata("dx.resources");
118 ResourceMD->addOperand(
119 MDNode::get(M.getContext(), {SRVMD, UAVMD, CBufMD, SmpMD}));
120
121 return ResourceMD;
122}
123
125 switch (Env) {
126 case Triple::Pixel:
127 return "ps";
128 case Triple::Vertex:
129 return "vs";
130 case Triple::Geometry:
131 return "gs";
132 case Triple::Hull:
133 return "hs";
134 case Triple::Domain:
135 return "ds";
136 case Triple::Compute:
137 return "cs";
138 case Triple::Library:
139 return "lib";
140 case Triple::Mesh:
141 return "ms";
143 return "as";
145 return "rootsig";
146 default:
147 break;
148 }
149 llvm_unreachable("Unsupported environment for DXIL generation.");
150}
151
155
160 ConstantInt::get(Type::getInt32Ty(Ctx), static_cast<int>(Tag))));
161 switch (Tag) {
162 case EntryPropsTag::ShaderFlags:
164 ConstantInt::get(Type::getInt64Ty(Ctx), Value)));
165 break;
166 case EntryPropsTag::ShaderKind:
168 ConstantInt::get(Type::getInt32Ty(Ctx), Value)));
169 break;
170 case EntryPropsTag::GSState:
171 case EntryPropsTag::DSState:
172 case EntryPropsTag::HSState:
173 case EntryPropsTag::NumThreads:
174 case EntryPropsTag::AutoBindingSpace:
175 case EntryPropsTag::RayPayloadSize:
176 case EntryPropsTag::RayAttribSize:
177 case EntryPropsTag::MSState:
178 case EntryPropsTag::ASStateTag:
179 case EntryPropsTag::WaveSize:
180 case EntryPropsTag::EntryRootSig:
181 case EntryPropsTag::WaveRange:
182 llvm_unreachable("NYI: Unhandled entry property tag");
183 }
184 return MDVals;
185}
186
188 uint64_t EntryShaderFlags,
189 const ModuleMetadataInfo &MMDI) {
191 LLVMContext &Ctx = EP.Entry->getContext();
192 if (EntryShaderFlags != 0)
193 MDVals.append(getTagValueAsMetadata(EntryPropsTag::ShaderFlags,
194 EntryShaderFlags, Ctx));
195
196 if (EP.Entry != nullptr) {
197 // FIXME: support more props.
198 // See https://github.com/llvm/llvm-project/issues/57948.
199 // Add shader kind for lib entries.
202 MDVals.append(getTagValueAsMetadata(EntryPropsTag::ShaderKind,
203 getShaderStage(EP.ShaderStage), Ctx));
204
206 // Handle mandatory "hlsl.numthreads"
207 MDVals.emplace_back(ConstantAsMetadata::get(ConstantInt::get(
208 Type::getInt32Ty(Ctx), static_cast<int>(EntryPropsTag::NumThreads))));
209 Metadata *NumThreadVals[] = {ConstantAsMetadata::get(ConstantInt::get(
210 Type::getInt32Ty(Ctx), EP.NumThreadsX)),
211 ConstantAsMetadata::get(ConstantInt::get(
212 Type::getInt32Ty(Ctx), EP.NumThreadsY)),
213 ConstantAsMetadata::get(ConstantInt::get(
214 Type::getInt32Ty(Ctx), EP.NumThreadsZ))};
215 MDVals.emplace_back(MDNode::get(Ctx, NumThreadVals));
216
217 // Handle optional "hlsl.wavesize". The fields are optionally represented
218 // if they are non-zero.
219 if (EP.WaveSizeMin != 0) {
220 bool IsWaveRange = VersionTuple(6, 8) <= MMDI.ShaderModelVersion;
221 bool IsWaveSize =
222 !IsWaveRange && VersionTuple(6, 6) <= MMDI.ShaderModelVersion;
223
224 if (!IsWaveRange && !IsWaveSize) {
225 reportError(M, "Shader model 6.6 or greater is required to specify "
226 "the \"hlsl.wavesize\" function attribute");
227 return nullptr;
228 }
229
230 // A range is being specified if EP.WaveSizeMax != 0
231 if (EP.WaveSizeMax && !IsWaveRange) {
233 M, "Shader model 6.8 or greater is required to specify "
234 "wave size range values of the \"hlsl.wavesize\" function "
235 "attribute");
236 return nullptr;
237 }
238
239 EntryPropsTag Tag =
240 IsWaveSize ? EntryPropsTag::WaveSize : EntryPropsTag::WaveRange;
242 ConstantInt::get(Type::getInt32Ty(Ctx), static_cast<int>(Tag))));
243
245 ConstantInt::get(Type::getInt32Ty(Ctx), EP.WaveSizeMin))};
246 if (IsWaveRange) {
248 ConstantInt::get(Type::getInt32Ty(Ctx), EP.WaveSizeMax)));
250 ConstantInt::get(Type::getInt32Ty(Ctx), EP.WaveSizePref)));
251 }
252
253 MDVals.emplace_back(MDNode::get(Ctx, WaveSizeVals));
254 }
255 }
256 }
257
258 if (MDVals.empty())
259 return nullptr;
260 return MDNode::get(Ctx, MDVals);
261}
262
264 MDTuple *Signatures, MDNode *Resources,
265 MDTuple *Properties, LLVMContext &Ctx) {
266 // Each entry point metadata record specifies:
267 // * reference to the entry point function global symbol
268 // * unmangled name
269 // * list of signatures
270 // * list of resources
271 // * list of tag-value pairs of shader capabilities and other properties
272 Metadata *MDVals[5];
273 MDVals[0] =
274 EntryFn ? ValueAsMetadata::get(const_cast<Function *>(EntryFn)) : nullptr;
275 MDVals[1] = MDString::get(Ctx, EntryFn ? EntryFn->getName() : "");
276 MDVals[2] = Signatures;
277 MDVals[3] = Resources;
278 MDVals[4] = Properties;
279 return MDNode::get(Ctx, MDVals);
280}
281
283 MDTuple *Signatures, MDNode *MDResources,
284 const uint64_t EntryShaderFlags,
285 const ModuleMetadataInfo &MMDI) {
286 MDTuple *Properties = getEntryPropAsMetadata(M, EP, EntryShaderFlags, MMDI);
287 return constructEntryMetadata(EP.Entry, Signatures, MDResources, Properties,
288 EP.Entry->getContext());
289}
290
292 if (MMDI.ValidatorVersion.empty())
293 return;
294
295 LLVMContext &Ctx = M.getContext();
296 IRBuilder<> IRB(Ctx);
297 Metadata *MDVals[2];
298 MDVals[0] =
300 MDVals[1] = ConstantAsMetadata::get(
301 IRB.getInt32(MMDI.ValidatorVersion.getMinor().value_or(0)));
302 NamedMDNode *ValVerNode = M.getOrInsertNamedMetadata("dx.valver");
303 // Set validator version obtained from DXIL Metadata Analysis pass
304 ValVerNode->clearOperands();
305 ValVerNode->addOperand(MDNode::get(Ctx, MDVals));
306}
307
309 const ModuleMetadataInfo &MMDI) {
310 LLVMContext &Ctx = M.getContext();
311 IRBuilder<> IRB(Ctx);
312 Metadata *SMVals[3];
314 SMVals[0] = MDString::get(Ctx, getShortShaderStage(MMDI.ShaderProfile));
315 SMVals[1] = ConstantAsMetadata::get(IRB.getInt32(SM.getMajor()));
316 SMVals[2] = ConstantAsMetadata::get(IRB.getInt32(SM.getMinor().value_or(0)));
317 NamedMDNode *SMMDNode = M.getOrInsertNamedMetadata("dx.shaderModel");
318 SMMDNode->addOperand(MDNode::get(Ctx, SMVals));
319}
320
322 LLVMContext &Ctx = M.getContext();
323 IRBuilder<> IRB(Ctx);
324 VersionTuple DXILVer = MMDI.DXILVersion;
325 Metadata *DXILVals[2];
326 DXILVals[0] = ConstantAsMetadata::get(IRB.getInt32(DXILVer.getMajor()));
327 DXILVals[1] =
328 ConstantAsMetadata::get(IRB.getInt32(DXILVer.getMinor().value_or(0)));
329 NamedMDNode *DXILVerMDNode = M.getOrInsertNamedMetadata("dx.version");
330 DXILVerMDNode->addOperand(MDNode::get(Ctx, DXILVals));
331}
332
334 uint64_t ShaderFlags) {
335 LLVMContext &Ctx = M.getContext();
336 MDTuple *Properties = nullptr;
337 if (ShaderFlags != 0) {
339 MDVals.append(
340 getTagValueAsMetadata(EntryPropsTag::ShaderFlags, ShaderFlags, Ctx));
341 Properties = MDNode::get(Ctx, MDVals);
342 }
343 // Library has an entry metadata with resource table metadata and all other
344 // MDNodes as null.
345 return constructEntryMetadata(nullptr, nullptr, RMD, Properties, Ctx);
346}
347
348static void translateBranchMetadata(Module &M, Instruction *BBTerminatorInst) {
349 MDNode *HlslControlFlowMD =
350 BBTerminatorInst->getMetadata("hlsl.controlflow.hint");
351
352 if (!HlslControlFlowMD)
353 return;
354
355 assert(HlslControlFlowMD->getNumOperands() == 2 &&
356 "invalid operands for hlsl.controlflow.hint");
357
358 MDBuilder MDHelper(M.getContext());
359
360 llvm::Metadata *HintsStr = MDHelper.createString("dx.controlflow.hints");
361 llvm::Metadata *HintsValue = MDHelper.createConstant(
362 mdconst::extract<ConstantInt>(HlslControlFlowMD->getOperand(1)));
363
364 MDNode *MDNode = llvm::MDNode::get(M.getContext(), {HintsStr, HintsValue});
365
366 BBTerminatorInst->setMetadata("dx.controlflow.hints", MDNode);
367 BBTerminatorInst->setMetadata("hlsl.controlflow.hint", nullptr);
368}
369
370// Determines if the metadata node will be compatible with DXIL's loop metadata
371// representation.
372//
373// Reports an error for compatible metadata that is ill-formed.
374static bool isLoopMDCompatible(Module &M, Metadata *MD) {
375 // DXIL only accepts the following loop hints:
376 std::array<StringLiteral, 3> ValidHintNames = {"llvm.loop.unroll.count",
377 "llvm.loop.unroll.disable",
378 "llvm.loop.unroll.full"};
379
380 MDNode *HintMD = dyn_cast<MDNode>(MD);
381 if (!HintMD || HintMD->getNumOperands() == 0)
382 return false;
383
384 auto *HintStr = dyn_cast<MDString>(HintMD->getOperand(0));
385 if (!HintStr)
386 return false;
387
388 if (!llvm::is_contained(ValidHintNames, HintStr->getString()))
389 return false;
390
391 auto ValidCountNode = [](MDNode *CountMD) -> bool {
392 if (CountMD->getNumOperands() == 2)
393 if (auto *Count = dyn_cast<ConstantAsMetadata>(CountMD->getOperand(1)))
394 if (isa<ConstantInt>(Count->getValue()))
395 return true;
396 return false;
397 };
398
399 if (HintStr->getString() == "llvm.loop.unroll.count") {
400 if (!ValidCountNode(HintMD)) {
401 reportLoopError(M, "\"llvm.loop.unroll.count\" must have 2 operands and "
402 "the second must be a constant integer");
403 return false;
404 }
405 } else if (HintMD->getNumOperands() != 1) {
406 reportLoopError(
407 M, "\"llvm.loop.unroll.disable\" and \"llvm.loop.unroll.full\" "
408 "must be provided as a single operand");
409 return false;
410 }
411
412 return true;
413}
414
415static void translateLoopMetadata(Module &M, Instruction *I, MDNode *BaseMD) {
416 // A distinct node has the self-referential form: !0 = !{ !0, ... }
417 auto IsDistinctNode = [](MDNode *Node) -> bool {
418 return Node && Node->getNumOperands() != 0 && Node == Node->getOperand(0);
419 };
420
421 // Set metadata to null to remove empty/ill-formed metadata from instruction
422 if (BaseMD->getNumOperands() == 0 || !IsDistinctNode(BaseMD))
423 return I->setMetadata("llvm.loop", nullptr);
424
425 // It is valid to have a chain of self-refential loop metadata nodes, as
426 // below. We will collapse these into just one when we reconstruct the
427 // metadata.
428 //
429 // Eg:
430 // !0 = !{!0, !1}
431 // !1 = !{!1, !2}
432 // !2 = !{!"llvm.loop.unroll.disable"}
433 //
434 // So, traverse down a potential self-referential chain
435 while (1 < BaseMD->getNumOperands() &&
436 IsDistinctNode(dyn_cast<MDNode>(BaseMD->getOperand(1))))
437 BaseMD = dyn_cast<MDNode>(BaseMD->getOperand(1));
438
439 // To reconstruct a distinct node we create a temporary node that we will
440 // then update to create a self-reference.
441 llvm::TempMDTuple TempNode = llvm::MDNode::getTemporary(M.getContext(), {});
442 SmallVector<Metadata *> CompatibleOperands = {TempNode.get()};
443
444 // Iterate and reconstruct the metadata nodes that contains any hints,
445 // stripping any unrecognized metadata.
446 ArrayRef<MDOperand> Operands = BaseMD->operands();
447 for (auto &Op : Operands.drop_front())
448 if (isLoopMDCompatible(M, Op.get()))
449 CompatibleOperands.push_back(Op.get());
450
451 if (2 < CompatibleOperands.size())
452 reportLoopError(M, "Provided conflicting hints");
453
454 MDNode *CompatibleLoopMD = MDNode::get(M.getContext(), CompatibleOperands);
455 TempNode->replaceAllUsesWith(CompatibleLoopMD);
456
457 I->setMetadata("llvm.loop", CompatibleLoopMD);
458}
459
460using InstructionMDList = std::array<unsigned, 7>;
461
463 return {
464 M.getMDKindID("dx.nonuniform"), M.getMDKindID("dx.controlflow.hints"),
465 M.getMDKindID("dx.precise"), llvm::LLVMContext::MD_range,
466 llvm::LLVMContext::MD_alias_scope, llvm::LLVMContext::MD_noalias,
467 M.getMDKindID("llvm.loop")};
468}
469
471 // construct allowlist of valid metadata node kinds
472 InstructionMDList DXILCompatibleMDs = getCompatibleInstructionMDs(M);
473 unsigned char MDLoopKind = M.getContext().getMDKindID("llvm.loop");
474
475 for (Function &F : M) {
476 for (BasicBlock &BB : F) {
477 // This needs to be done first so that "hlsl.controlflow.hints" isn't
478 // removed in the allow-list below
479 if (auto *I = BB.getTerminator())
481
482 for (auto &I : make_early_inc_range(BB)) {
483 if (isa<BranchInst>(I))
484 if (MDNode *LoopMD = I.getMetadata(MDLoopKind))
485 translateLoopMetadata(M, &I, LoopMD);
486 I.dropUnknownNonDebugMetadata(DXILCompatibleMDs);
487 }
488 }
489 }
490}
491
492static void cleanModuleFlags(Module &M) {
493 NamedMDNode *MDFlags = M.getModuleFlagsMetadata();
494 if (!MDFlags)
495 return;
496
498 M.getModuleFlagsMetadata(FlagEntries);
499 bool Updated = false;
500 for (auto &Flag : FlagEntries) {
501 // llvm 3.7 only supports behavior up to AppendUnique.
502 if (Flag.Behavior <= Module::ModFlagBehavior::AppendUnique)
503 continue;
504 Flag.Behavior = Module::ModFlagBehavior::Warning;
505 Updated = true;
506 }
507
508 if (!Updated)
509 return;
510
511 MDFlags->eraseFromParent();
512
513 for (auto &Flag : FlagEntries)
514 M.addModuleFlag(Flag.Behavior, Flag.Key->getString(), Flag.Val);
515}
516
517using GlobalMDList = std::array<StringLiteral, 7>;
518
519// The following are compatible with DXIL but not emit with clang, they can
520// be added when applicable:
521// dx.typeAnnotations, dx.viewIDState, dx.dxrPayloadAnnotations
523 "llvm.ident", "llvm.module.flags", "dx.resources", "dx.valver",
524 "dx.shaderModel", "dx.version", "dx.entryPoints",
525};
526
529 const ModuleShaderFlags &ShaderFlags,
530 const ModuleMetadataInfo &MMDI) {
531 LLVMContext &Ctx = M.getContext();
532 IRBuilder<> IRB(Ctx);
533 SmallVector<MDNode *> EntryFnMDNodes;
534
535 emitValidatorVersionMD(M, MMDI);
537 emitDXILVersionTupleMD(M, MMDI);
538 NamedMDNode *NamedResourceMD = emitResourceMetadata(M, DRM, DRTM);
539 auto *ResourceMD =
540 (NamedResourceMD != nullptr) ? NamedResourceMD->getOperand(0) : nullptr;
541 // FIXME: Add support to construct Signatures
542 // See https://github.com/llvm/llvm-project/issues/57928
543 MDTuple *Signatures = nullptr;
544
546 // Get the combined shader flag mask of all functions in the library to be
547 // used as shader flags mask value associated with top-level library entry
548 // metadata.
549 uint64_t CombinedMask = ShaderFlags.getCombinedFlags();
550 EntryFnMDNodes.emplace_back(
551 emitTopLevelLibraryNode(M, ResourceMD, CombinedMask));
552 } else if (1 < MMDI.EntryPropertyVec.size())
553 reportError(M, "Non-library shader: One and only one entry expected");
554
555 for (const EntryProperties &EntryProp : MMDI.EntryPropertyVec) {
556 uint64_t EntryShaderFlags = 0;
558 EntryShaderFlags = ShaderFlags.getFunctionFlags(EntryProp.Entry);
559 if (EntryProp.ShaderStage != MMDI.ShaderProfile)
561 M, "Shader stage '" +
563 "' for entry '" + Twine(EntryProp.Entry->getName()) +
564 "' different from specified target profile '" +
566 "'"));
567 }
568 EntryFnMDNodes.emplace_back(emitEntryMD(
569 M, EntryProp, Signatures, ResourceMD, EntryShaderFlags, MMDI));
570 }
571
572 NamedMDNode *EntryPointsNamedMD =
573 M.getOrInsertNamedMetadata("dx.entryPoints");
574 for (auto *Entry : EntryFnMDNodes)
575 EntryPointsNamedMD->addOperand(Entry);
576
578
579 // Finally, strip all module metadata that is not explicitly specified in the
580 // allow-list
582
583 for (NamedMDNode &NamedMD : M.named_metadata())
584 if (!NamedMD.getName().starts_with("llvm.dbg.") &&
585 !llvm::is_contained(CompatibleNamedModuleMDs, NamedMD.getName()))
586 ToStrip.push_back(&NamedMD);
587
588 for (NamedMDNode *NamedMD : ToStrip)
589 NamedMD->eraseFromParent();
590}
591
594 DXILResourceMap &DRM = MAM.getResult<DXILResourceAnalysis>(M);
596 const ModuleShaderFlags &ShaderFlags = MAM.getResult<ShaderFlagsAnalysis>(M);
597 const dxil::ModuleMetadataInfo MMDI = MAM.getResult<DXILMetadataAnalysis>(M);
598
599 translateGlobalMetadata(M, DRM, DRTM, ShaderFlags, MMDI);
601
602 return PreservedAnalyses::all();
603}
604
618
620 DXILResourceMap &DRM =
621 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
622 DXILResourceTypeMap &DRTM =
623 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
624 const ModuleShaderFlags &ShaderFlags =
628
629 translateGlobalMetadata(M, DRM, DRTM, ShaderFlags, MMDI);
631 return true;
632}
633
635
639
641 "DXIL Translate Metadata", false, false)
647 "DXIL Translate Metadata", false, false)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Error reportError(StringRef Message)
#define LLVM_LIFETIME_BOUND
Definition Compiler.h:435
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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)
std::array< StringLiteral, 7 > GlobalMDList
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 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)
static void translateGlobalMetadata(Module &M, DXILResourceMap &DRM, DXILResourceTypeMap &DRTM, const ModuleShaderFlags &ShaderFlags, const ModuleMetadataInfo &MMDI)
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:55
#define I(x, y, z)
Definition MD5.cpp:58
Machine Check Debug Module
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
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
static const FuncProtoTy Signatures[]
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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition ArrayRef.h:196
LLVM Basic Block Representation.
Definition BasicBlock.h:62
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:536
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:359
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition IRBuilder.h:522
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2788
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:68
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:1078
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1442
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1581
ArrayRef< MDOperand > operands() const
Definition Metadata.h:1440
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1569
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1448
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:608
Tuple of metadata.
Definition Metadata.h:1497
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:255
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
Definition Module.h:146
@ Warning
Emits a warning if two values disagree.
Definition Module.h:124
A tuple of MDNodes.
Definition Metadata.h:1757
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
@ RootSignature
Definition Triple.h:310
@ Amplification
Definition Triple.h:309
static LLVM_ABI StringRef getEnvironmentTypeName(EnvironmentType Kind)
Get the canonical name for the Kind environment.
Definition Triple.cpp:341
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:298
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI ValueAsMetadata * get(Value *V)
Definition Metadata.cpp:503
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:322
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.
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:667
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:632
@ DK_Unsupported
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
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
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:1897
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
Triple::EnvironmentType ShaderStage
Triple::EnvironmentType ShaderProfile
SmallVector< EntryProperties > EntryPropertyVec