51 DiagnosticInfoValidateMD(
const Module &M,
56 void print(DiagnosticPrinter &DP)
const override {
57 DP << Mod.getName() <<
": " << Msg <<
'\n';
63 M.getContext().diagnose(DiagnosticInfoValidateMD(M, Message, Severity));
66static void reportLoopError(
Module &M,
Twine Message,
68 reportError(M,
Twine(
"Invalid \"llvm.loop\" metadata: ") + Message, Severity);
71enum class EntryPropsTag {
95 if (RI.hasBinding() && !RI.hasSymbol())
97 DRTM[RI.getHandleTy()].createElementStruct(RI.getName()));
102 SRVs.
push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
105 UAVs.
push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
108 CBufs.
push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
111 Smps.
push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
121 NamedMDNode *ResourceMD = M.getOrInsertNamedMetadata(
"dx.resources");
123 MDNode::get(M.getContext(), {SRVMD, UAVMD, CBufMD, SmpMD}));
166 case EntryPropsTag::ShaderFlags:
170 case EntryPropsTag::ShaderKind:
174 case EntryPropsTag::GSState:
175 case EntryPropsTag::DSState:
176 case EntryPropsTag::HSState:
177 case EntryPropsTag::NumThreads:
178 case EntryPropsTag::AutoBindingSpace:
179 case EntryPropsTag::RayPayloadSize:
180 case EntryPropsTag::RayAttribSize:
181 case EntryPropsTag::MSState:
182 case EntryPropsTag::ASStateTag:
183 case EntryPropsTag::WaveSize:
184 case EntryPropsTag::EntryRootSig:
185 case EntryPropsTag::WaveRange:
196 if (EntryShaderFlags != 0)
198 EntryShaderFlags, Ctx));
200 if (EP.
Entry !=
nullptr) {
228 if (!IsWaveRange && !IsWaveSize) {
229 reportError(M,
"Shader model 6.6 or greater is required to specify "
230 "the \"hlsl.wavesize\" function attribute");
237 M,
"Shader model 6.8 or greater is required to specify "
238 "wave size range values of the \"hlsl.wavesize\" function "
244 IsWaveSize ? EntryPropsTag::WaveSize : EntryPropsTag::WaveRange;
280 MDVals[2] = Signatures;
282 MDVals[4] = Properties;
306 NamedMDNode *ValVerNode = M.getOrInsertNamedMetadata(
"dx.valver");
321 NamedMDNode *SMMDNode = M.getOrInsertNamedMetadata(
"dx.shaderModel");
333 NamedMDNode *DXILVerMDNode = M.getOrInsertNamedMetadata(
"dx.version");
341 if (ShaderFlags != 0) {
353 MDNode *HlslControlFlowMD =
354 BBTerminatorInst->
getMetadata(
"hlsl.controlflow.hint");
356 if (!HlslControlFlowMD)
360 "invalid operands for hlsl.controlflow.hint");
371 BBTerminatorInst->
setMetadata(
"hlsl.controlflow.hint",
nullptr);
380 std::array<StringLiteral, 3> ValidHintNames = {
"llvm.loop.unroll.count",
381 "llvm.loop.unroll.disable",
382 "llvm.loop.unroll.full"};
395 auto ValidCountNode = [](
MDNode *CountMD) ->
bool {
396 if (CountMD->getNumOperands() == 2)
403 if (HintStr->getString() ==
"llvm.loop.unroll.count") {
404 if (!ValidCountNode(HintMD)) {
405 reportLoopError(M,
"\"llvm.loop.unroll.count\" must have 2 operands and "
406 "the second must be a constant integer");
411 M,
"\"llvm.loop.unroll.disable\" and \"llvm.loop.unroll.full\" "
412 "must be provided as a single operand");
421 auto IsDistinctNode = [](
MDNode *
Node) ->
bool {
427 return I->setMetadata(
"llvm.loop",
nullptr);
455 if (2 < CompatibleOperands.
size())
456 reportLoopError(M,
"Provided conflicting hints");
459 TempNode->replaceAllUsesWith(CompatibleLoopMD);
461 I->setMetadata(
"llvm.loop", CompatibleLoopMD);
468 M.getMDKindID(
"dx.nonuniform"), M.getMDKindID(
"dx.controlflow.hints"),
469 M.getMDKindID(
"dx.precise"), llvm::LLVMContext::MD_range,
470 llvm::LLVMContext::MD_alias_scope, llvm::LLVMContext::MD_noalias,
471 M.getMDKindID(
"llvm.loop")};
477 unsigned char MDLoopKind = M.getContext().getMDKindID(
"llvm.loop");
483 if (
auto *
I = BB.getTerminator())
488 if (
MDNode *LoopMD =
I.getMetadata(MDLoopKind))
490 I.dropUnknownNonDebugMetadata(DXILCompatibleMDs);
502 M.getModuleFlagsMetadata(FlagEntries);
503 bool Updated =
false;
504 for (
auto &Flag : FlagEntries) {
517 for (
auto &Flag : FlagEntries)
518 M.addModuleFlag(Flag.Behavior, Flag.Key->getString(), Flag.Val);
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",
547 (NamedResourceMD !=
nullptr) ? NamedResourceMD->
getOperand(0) :
nullptr;
556 uint64_t CombinedMask = ShaderFlags.getCombinedFlags();
560 reportError(M,
"Non-library shader: One and only one entry expected");
565 EntryShaderFlags = ShaderFlags.getFunctionFlags(EntryProp.
Entry);
568 M,
"Shader stage '" +
571 "' different from specified target profile '" +
576 M, EntryProp, Signatures, ResourceMD, EntryShaderFlags, MMDI));
580 M.getOrInsertNamedMetadata(
"dx.entryPoints");
581 for (
auto *Entry : EntryFnMDNodes)
591 if (!NamedMD.getName().starts_with(
"llvm.dbg.") &&
596 NamedMD->eraseFromParent();
648 "DXIL Translate Metadata",
false,
false)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Error reportError(StringRef Message)
#define LLVM_LIFETIME_BOUND
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DXIL Remove Unused Resources
Module.h This file contains the declarations for the Module class.
ModuleAnalysisManager MAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
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),...
LLVM Basic Block Representation.
iterator_range< iterator > samplers()
iterator_range< iterator > srvs()
iterator_range< iterator > cbuffers()
iterator_range< iterator > uavs()
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.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
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.
LLVM_ABI ConstantAsMetadata * createConstant(Constant *C)
Return the given constant as metadata.
LLVM_ABI MDString * createString(StringRef Str)
Return the given string as metadata.
const MDOperand & getOperand(unsigned I) const
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
ArrayRef< MDOperand > operands() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
@ Warning
Emits a warning if two values disagree.
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.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
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.
static LLVM_ABI StringRef getEnvironmentTypeName(EnvironmentType Kind)
Get the canonical name for the Kind environment.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
LLVM Value Representation.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
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.
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.
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...
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...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
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.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Triple::EnvironmentType ShaderStage