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};
86
87} // namespace
88
90 DXILResourceTypeMap &DRTM) {
91 LLVMContext &Context = M.getContext();
92
93 for (ResourceInfo &RI : DRM)
94 if (!RI.hasSymbol())
95 RI.createSymbol(M,
96 DRTM[RI.getHandleTy()].createElementStruct(RI.getName()));
97
98 SmallVector<Metadata *> SRVs, UAVs, CBufs, Smps;
99 for (const ResourceInfo &RI : DRM.srvs())
100 SRVs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
101 for (const ResourceInfo &RI : DRM.uavs())
102 UAVs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
103 for (const ResourceInfo &RI : DRM.cbuffers())
104 CBufs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
105 for (const ResourceInfo &RI : DRM.samplers())
106 Smps.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
107
108 Metadata *SRVMD = SRVs.empty() ? nullptr : MDNode::get(Context, SRVs);
109 Metadata *UAVMD = UAVs.empty() ? nullptr : MDNode::get(Context, UAVs);
110 Metadata *CBufMD = CBufs.empty() ? nullptr : MDNode::get(Context, CBufs);
111 Metadata *SmpMD = Smps.empty() ? nullptr : MDNode::get(Context, Smps);
112
113 if (DRM.empty())
114 return nullptr;
115
116 NamedMDNode *ResourceMD = M.getOrInsertNamedMetadata("dx.resources");
117 ResourceMD->addOperand(
118 MDNode::get(M.getContext(), {SRVMD, UAVMD, CBufMD, SmpMD}));
119
120 return ResourceMD;
121}
122
124 switch (Env) {
125 case Triple::Pixel:
126 return "ps";
127 case Triple::Vertex:
128 return "vs";
129 case Triple::Geometry:
130 return "gs";
131 case Triple::Hull:
132 return "hs";
133 case Triple::Domain:
134 return "ds";
135 case Triple::Compute:
136 return "cs";
137 case Triple::Library:
138 return "lib";
139 case Triple::Mesh:
140 return "ms";
142 return "as";
144 return "rootsig";
145 default:
146 break;
147 }
148 llvm_unreachable("Unsupported environment for DXIL generation.");
149}
150
154
159 ConstantInt::get(Type::getInt32Ty(Ctx), static_cast<int>(Tag))));
160 switch (Tag) {
161 case EntryPropsTag::ShaderFlags:
163 ConstantInt::get(Type::getInt64Ty(Ctx), Value)));
164 break;
165 case EntryPropsTag::ShaderKind:
167 ConstantInt::get(Type::getInt32Ty(Ctx), Value)));
168 break;
169 case EntryPropsTag::GSState:
170 case EntryPropsTag::DSState:
171 case EntryPropsTag::HSState:
172 case EntryPropsTag::NumThreads:
173 case EntryPropsTag::AutoBindingSpace:
174 case EntryPropsTag::RayPayloadSize:
175 case EntryPropsTag::RayAttribSize:
176 case EntryPropsTag::MSState:
177 case EntryPropsTag::ASStateTag:
178 case EntryPropsTag::WaveSize:
179 case EntryPropsTag::EntryRootSig:
180 llvm_unreachable("NYI: Unhandled entry property tag");
181 }
182 return MDVals;
183}
184
185static MDTuple *
187 const Triple::EnvironmentType ShaderProfile) {
189 LLVMContext &Ctx = EP.Entry->getContext();
190 if (EntryShaderFlags != 0)
191 MDVals.append(getTagValueAsMetadata(EntryPropsTag::ShaderFlags,
192 EntryShaderFlags, Ctx));
193
194 if (EP.Entry != nullptr) {
195 // FIXME: support more props.
196 // See https://github.com/llvm/llvm-project/issues/57948.
197 // Add shader kind for lib entries.
198 if (ShaderProfile == Triple::EnvironmentType::Library &&
200 MDVals.append(getTagValueAsMetadata(EntryPropsTag::ShaderKind,
201 getShaderStage(EP.ShaderStage), Ctx));
202
204 MDVals.emplace_back(ConstantAsMetadata::get(ConstantInt::get(
205 Type::getInt32Ty(Ctx), static_cast<int>(EntryPropsTag::NumThreads))));
206 Metadata *NumThreadVals[] = {ConstantAsMetadata::get(ConstantInt::get(
207 Type::getInt32Ty(Ctx), EP.NumThreadsX)),
208 ConstantAsMetadata::get(ConstantInt::get(
209 Type::getInt32Ty(Ctx), EP.NumThreadsY)),
210 ConstantAsMetadata::get(ConstantInt::get(
211 Type::getInt32Ty(Ctx), EP.NumThreadsZ))};
212 MDVals.emplace_back(MDNode::get(Ctx, NumThreadVals));
213 }
214 }
215 if (MDVals.empty())
216 return nullptr;
217 return MDNode::get(Ctx, MDVals);
218}
219
221 MDTuple *Signatures, MDNode *Resources,
222 MDTuple *Properties, LLVMContext &Ctx) {
223 // Each entry point metadata record specifies:
224 // * reference to the entry point function global symbol
225 // * unmangled name
226 // * list of signatures
227 // * list of resources
228 // * list of tag-value pairs of shader capabilities and other properties
229 Metadata *MDVals[5];
230 MDVals[0] =
231 EntryFn ? ValueAsMetadata::get(const_cast<Function *>(EntryFn)) : nullptr;
232 MDVals[1] = MDString::get(Ctx, EntryFn ? EntryFn->getName() : "");
233 MDVals[2] = Signatures;
234 MDVals[3] = Resources;
235 MDVals[4] = Properties;
236 return MDNode::get(Ctx, MDVals);
237}
238
240 MDNode *MDResources,
241 const uint64_t EntryShaderFlags,
242 const Triple::EnvironmentType ShaderProfile) {
243 MDTuple *Properties =
244 getEntryPropAsMetadata(EP, EntryShaderFlags, ShaderProfile);
245 return constructEntryMetadata(EP.Entry, Signatures, MDResources, Properties,
246 EP.Entry->getContext());
247}
248
250 if (MMDI.ValidatorVersion.empty())
251 return;
252
253 LLVMContext &Ctx = M.getContext();
254 IRBuilder<> IRB(Ctx);
255 Metadata *MDVals[2];
256 MDVals[0] =
258 MDVals[1] = ConstantAsMetadata::get(
259 IRB.getInt32(MMDI.ValidatorVersion.getMinor().value_or(0)));
260 NamedMDNode *ValVerNode = M.getOrInsertNamedMetadata("dx.valver");
261 // Set validator version obtained from DXIL Metadata Analysis pass
262 ValVerNode->clearOperands();
263 ValVerNode->addOperand(MDNode::get(Ctx, MDVals));
264}
265
267 const ModuleMetadataInfo &MMDI) {
268 LLVMContext &Ctx = M.getContext();
269 IRBuilder<> IRB(Ctx);
270 Metadata *SMVals[3];
272 SMVals[0] = MDString::get(Ctx, getShortShaderStage(MMDI.ShaderProfile));
273 SMVals[1] = ConstantAsMetadata::get(IRB.getInt32(SM.getMajor()));
274 SMVals[2] = ConstantAsMetadata::get(IRB.getInt32(SM.getMinor().value_or(0)));
275 NamedMDNode *SMMDNode = M.getOrInsertNamedMetadata("dx.shaderModel");
276 SMMDNode->addOperand(MDNode::get(Ctx, SMVals));
277}
278
280 LLVMContext &Ctx = M.getContext();
281 IRBuilder<> IRB(Ctx);
282 VersionTuple DXILVer = MMDI.DXILVersion;
283 Metadata *DXILVals[2];
284 DXILVals[0] = ConstantAsMetadata::get(IRB.getInt32(DXILVer.getMajor()));
285 DXILVals[1] =
286 ConstantAsMetadata::get(IRB.getInt32(DXILVer.getMinor().value_or(0)));
287 NamedMDNode *DXILVerMDNode = M.getOrInsertNamedMetadata("dx.version");
288 DXILVerMDNode->addOperand(MDNode::get(Ctx, DXILVals));
289}
290
292 uint64_t ShaderFlags) {
293 LLVMContext &Ctx = M.getContext();
294 MDTuple *Properties = nullptr;
295 if (ShaderFlags != 0) {
297 MDVals.append(
298 getTagValueAsMetadata(EntryPropsTag::ShaderFlags, ShaderFlags, Ctx));
299 Properties = MDNode::get(Ctx, MDVals);
300 }
301 // Library has an entry metadata with resource table metadata and all other
302 // MDNodes as null.
303 return constructEntryMetadata(nullptr, nullptr, RMD, Properties, Ctx);
304}
305
306static void translateBranchMetadata(Module &M, Instruction *BBTerminatorInst) {
307 MDNode *HlslControlFlowMD =
308 BBTerminatorInst->getMetadata("hlsl.controlflow.hint");
309
310 if (!HlslControlFlowMD)
311 return;
312
313 assert(HlslControlFlowMD->getNumOperands() == 2 &&
314 "invalid operands for hlsl.controlflow.hint");
315
316 MDBuilder MDHelper(M.getContext());
317
318 llvm::Metadata *HintsStr = MDHelper.createString("dx.controlflow.hints");
319 llvm::Metadata *HintsValue = MDHelper.createConstant(
320 mdconst::extract<ConstantInt>(HlslControlFlowMD->getOperand(1)));
321
322 MDNode *MDNode = llvm::MDNode::get(M.getContext(), {HintsStr, HintsValue});
323
324 BBTerminatorInst->setMetadata("dx.controlflow.hints", MDNode);
325 BBTerminatorInst->setMetadata("hlsl.controlflow.hint", nullptr);
326}
327
328// Determines if the metadata node will be compatible with DXIL's loop metadata
329// representation.
330//
331// Reports an error for compatible metadata that is ill-formed.
332static bool isLoopMDCompatible(Module &M, Metadata *MD) {
333 // DXIL only accepts the following loop hints:
334 std::array<StringLiteral, 3> ValidHintNames = {"llvm.loop.unroll.count",
335 "llvm.loop.unroll.disable",
336 "llvm.loop.unroll.full"};
337
338 MDNode *HintMD = dyn_cast<MDNode>(MD);
339 if (!HintMD || HintMD->getNumOperands() == 0)
340 return false;
341
342 auto *HintStr = dyn_cast<MDString>(HintMD->getOperand(0));
343 if (!HintStr)
344 return false;
345
346 if (!llvm::is_contained(ValidHintNames, HintStr->getString()))
347 return false;
348
349 auto ValidCountNode = [](MDNode *CountMD) -> bool {
350 if (CountMD->getNumOperands() == 2)
351 if (auto *Count = dyn_cast<ConstantAsMetadata>(CountMD->getOperand(1)))
352 if (isa<ConstantInt>(Count->getValue()))
353 return true;
354 return false;
355 };
356
357 if (HintStr->getString() == "llvm.loop.unroll.count") {
358 if (!ValidCountNode(HintMD)) {
359 reportLoopError(M, "\"llvm.loop.unroll.count\" must have 2 operands and "
360 "the second must be a constant integer");
361 return false;
362 }
363 } else if (HintMD->getNumOperands() != 1) {
364 reportLoopError(
365 M, "\"llvm.loop.unroll.disable\" and \"llvm.loop.unroll.full\" "
366 "must be provided as a single operand");
367 return false;
368 }
369
370 return true;
371}
372
373static void translateLoopMetadata(Module &M, Instruction *I, MDNode *BaseMD) {
374 // A distinct node has the self-referential form: !0 = !{ !0, ... }
375 auto IsDistinctNode = [](MDNode *Node) -> bool {
376 return Node && Node->getNumOperands() != 0 && Node == Node->getOperand(0);
377 };
378
379 // Set metadata to null to remove empty/ill-formed metadata from instruction
380 if (BaseMD->getNumOperands() == 0 || !IsDistinctNode(BaseMD))
381 return I->setMetadata("llvm.loop", nullptr);
382
383 // It is valid to have a chain of self-refential loop metadata nodes, as
384 // below. We will collapse these into just one when we reconstruct the
385 // metadata.
386 //
387 // Eg:
388 // !0 = !{!0, !1}
389 // !1 = !{!1, !2}
390 // !2 = !{!"llvm.loop.unroll.disable"}
391 //
392 // So, traverse down a potential self-referential chain
393 while (1 < BaseMD->getNumOperands() &&
394 IsDistinctNode(dyn_cast<MDNode>(BaseMD->getOperand(1))))
395 BaseMD = dyn_cast<MDNode>(BaseMD->getOperand(1));
396
397 // To reconstruct a distinct node we create a temporary node that we will
398 // then update to create a self-reference.
399 llvm::TempMDTuple TempNode = llvm::MDNode::getTemporary(M.getContext(), {});
400 SmallVector<Metadata *> CompatibleOperands = {TempNode.get()};
401
402 // Iterate and reconstruct the metadata nodes that contains any hints,
403 // stripping any unrecognized metadata.
404 ArrayRef<MDOperand> Operands = BaseMD->operands();
405 for (auto &Op : Operands.drop_front())
406 if (isLoopMDCompatible(M, Op.get()))
407 CompatibleOperands.push_back(Op.get());
408
409 if (2 < CompatibleOperands.size())
410 reportLoopError(M, "Provided conflicting hints");
411
412 MDNode *CompatibleLoopMD = MDNode::get(M.getContext(), CompatibleOperands);
413 TempNode->replaceAllUsesWith(CompatibleLoopMD);
414
415 I->setMetadata("llvm.loop", CompatibleLoopMD);
416}
417
418using InstructionMDList = std::array<unsigned, 7>;
419
421 return {
422 M.getMDKindID("dx.nonuniform"), M.getMDKindID("dx.controlflow.hints"),
423 M.getMDKindID("dx.precise"), llvm::LLVMContext::MD_range,
424 llvm::LLVMContext::MD_alias_scope, llvm::LLVMContext::MD_noalias,
425 M.getMDKindID("llvm.loop")};
426}
427
429 // construct allowlist of valid metadata node kinds
430 InstructionMDList DXILCompatibleMDs = getCompatibleInstructionMDs(M);
431 unsigned char MDLoopKind = M.getContext().getMDKindID("llvm.loop");
432
433 for (Function &F : M) {
434 for (BasicBlock &BB : F) {
435 // This needs to be done first so that "hlsl.controlflow.hints" isn't
436 // removed in the allow-list below
437 if (auto *I = BB.getTerminator())
439
440 for (auto &I : make_early_inc_range(BB)) {
441 if (isa<BranchInst>(I))
442 if (MDNode *LoopMD = I.getMetadata(MDLoopKind))
443 translateLoopMetadata(M, &I, LoopMD);
444 I.dropUnknownNonDebugMetadata(DXILCompatibleMDs);
445 }
446 }
447 }
448}
449
450static void cleanModuleFlags(Module &M) {
451 NamedMDNode *MDFlags = M.getModuleFlagsMetadata();
452 if (!MDFlags)
453 return;
454
456 M.getModuleFlagsMetadata(FlagEntries);
457 bool Updated = false;
458 for (auto &Flag : FlagEntries) {
459 // llvm 3.7 only supports behavior up to AppendUnique.
460 if (Flag.Behavior <= Module::ModFlagBehavior::AppendUnique)
461 continue;
462 Flag.Behavior = Module::ModFlagBehavior::Warning;
463 Updated = true;
464 }
465
466 if (!Updated)
467 return;
468
469 MDFlags->eraseFromParent();
470
471 for (auto &Flag : FlagEntries)
472 M.addModuleFlag(Flag.Behavior, Flag.Key->getString(), Flag.Val);
473}
474
475using GlobalMDList = std::array<StringLiteral, 7>;
476
477// The following are compatible with DXIL but not emit with clang, they can
478// be added when applicable:
479// dx.typeAnnotations, dx.viewIDState, dx.dxrPayloadAnnotations
481 "llvm.ident", "llvm.module.flags", "dx.resources", "dx.valver",
482 "dx.shaderModel", "dx.version", "dx.entryPoints",
483};
484
487 const ModuleShaderFlags &ShaderFlags,
488 const ModuleMetadataInfo &MMDI) {
489 LLVMContext &Ctx = M.getContext();
490 IRBuilder<> IRB(Ctx);
491 SmallVector<MDNode *> EntryFnMDNodes;
492
493 emitValidatorVersionMD(M, MMDI);
495 emitDXILVersionTupleMD(M, MMDI);
496 NamedMDNode *NamedResourceMD = emitResourceMetadata(M, DRM, DRTM);
497 auto *ResourceMD =
498 (NamedResourceMD != nullptr) ? NamedResourceMD->getOperand(0) : nullptr;
499 // FIXME: Add support to construct Signatures
500 // See https://github.com/llvm/llvm-project/issues/57928
501 MDTuple *Signatures = nullptr;
502
504 // Get the combined shader flag mask of all functions in the library to be
505 // used as shader flags mask value associated with top-level library entry
506 // metadata.
507 uint64_t CombinedMask = ShaderFlags.getCombinedFlags();
508 EntryFnMDNodes.emplace_back(
509 emitTopLevelLibraryNode(M, ResourceMD, CombinedMask));
510 } else if (1 < MMDI.EntryPropertyVec.size())
511 reportError(M, "Non-library shader: One and only one entry expected");
512
513 for (const EntryProperties &EntryProp : MMDI.EntryPropertyVec) {
514 uint64_t EntryShaderFlags = 0;
516 EntryShaderFlags = ShaderFlags.getFunctionFlags(EntryProp.Entry);
517 if (EntryProp.ShaderStage != MMDI.ShaderProfile)
519 M, "Shader stage '" +
521 "' for entry '" + Twine(EntryProp.Entry->getName()) +
522 "' different from specified target profile '" +
524 "'"));
525 }
526
527 EntryFnMDNodes.emplace_back(emitEntryMD(EntryProp, Signatures, ResourceMD,
528 EntryShaderFlags,
529 MMDI.ShaderProfile));
530 }
531
532 NamedMDNode *EntryPointsNamedMD =
533 M.getOrInsertNamedMetadata("dx.entryPoints");
534 for (auto *Entry : EntryFnMDNodes)
535 EntryPointsNamedMD->addOperand(Entry);
536
538
539 // Finally, strip all module metadata that is not explicitly specified in the
540 // allow-list
542
543 for (NamedMDNode &NamedMD : M.named_metadata())
544 if (!NamedMD.getName().starts_with("llvm.dbg.") &&
545 !llvm::is_contained(CompatibleNamedModuleMDs, NamedMD.getName()))
546 ToStrip.push_back(&NamedMD);
547
548 for (NamedMDNode *NamedMD : ToStrip)
549 NamedMD->eraseFromParent();
550}
551
554 DXILResourceMap &DRM = MAM.getResult<DXILResourceAnalysis>(M);
556 const ModuleShaderFlags &ShaderFlags = MAM.getResult<ShaderFlagsAnalysis>(M);
557 const dxil::ModuleMetadataInfo MMDI = MAM.getResult<DXILMetadataAnalysis>(M);
558
559 translateGlobalMetadata(M, DRM, DRTM, ShaderFlags, MMDI);
561
562 return PreservedAnalyses::all();
563}
564
578
580 DXILResourceMap &DRM =
581 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
582 DXILResourceTypeMap &DRTM =
583 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
584 const ModuleShaderFlags &ShaderFlags =
588
589 translateGlobalMetadata(M, DRM, DRTM, ShaderFlags, MMDI);
591 return true;
592}
593
595
599
601 "DXIL Translate Metadata", false, false)
607 "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 MDTuple * getEntryPropAsMetadata(const EntryProperties &EP, uint64_t EntryShaderFlags, const Triple::EnvironmentType ShaderProfile)
static void emitValidatorVersionMD(Module &M, const ModuleMetadataInfo &MMDI)
static MDTuple * emitTopLevelLibraryNode(Module &M, MDNode *RMD, uint64_t ShaderFlags)
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 MDTuple * emitEntryMD(const EntryProperties &EP, MDTuple *Signatures, MDNode *MDResources, const uint64_t EntryShaderFlags, const Triple::EnvironmentType ShaderProfile)
static NamedMDNode * emitResourceMetadata(Module &M, DXILResourceMap &DRM, DXILResourceTypeMap &DRTM)
static uint32_t getShaderStage(Triple::EnvironmentType Env)
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