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 {
96 DRTM[RI.getHandleTy()].createElementStruct(RI.getName()));
100 SRVs.
push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
102 UAVs.
push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
104 CBufs.
push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
106 Smps.
push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
116 NamedMDNode *ResourceMD = M.getOrInsertNamedMetadata(
"dx.resources");
118 MDNode::get(M.getContext(), {SRVMD, UAVMD, CBufMD, SmpMD}));
161 case EntryPropsTag::ShaderFlags:
165 case EntryPropsTag::ShaderKind:
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:
190 if (EntryShaderFlags != 0)
192 EntryShaderFlags, Ctx));
194 if (EP.
Entry !=
nullptr) {
234 MDVals[3] = Resources;
235 MDVals[4] = Properties;
260 NamedMDNode *ValVerNode = M.getOrInsertNamedMetadata(
"dx.valver");
275 NamedMDNode *SMMDNode = M.getOrInsertNamedMetadata(
"dx.shaderModel");
287 NamedMDNode *DXILVerMDNode = M.getOrInsertNamedMetadata(
"dx.version");
295 if (ShaderFlags != 0) {
307 MDNode *HlslControlFlowMD =
308 BBTerminatorInst->
getMetadata(
"hlsl.controlflow.hint");
310 if (!HlslControlFlowMD)
314 "invalid operands for hlsl.controlflow.hint");
325 BBTerminatorInst->
setMetadata(
"hlsl.controlflow.hint",
nullptr);
334 std::array<StringLiteral, 3> ValidHintNames = {
"llvm.loop.unroll.count",
335 "llvm.loop.unroll.disable",
336 "llvm.loop.unroll.full"};
349 auto ValidCountNode = [](
MDNode *CountMD) ->
bool {
350 if (CountMD->getNumOperands() == 2)
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");
365 M,
"\"llvm.loop.unroll.disable\" and \"llvm.loop.unroll.full\" "
366 "must be provided as a single operand");
375 auto IsDistinctNode = [](
MDNode *
Node) ->
bool {
381 return I->setMetadata(
"llvm.loop",
nullptr);
409 if (2 < CompatibleOperands.
size())
410 reportLoopError(M,
"Provided conflicting hints");
413 TempNode->replaceAllUsesWith(CompatibleLoopMD);
415 I->setMetadata(
"llvm.loop", CompatibleLoopMD);
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")};
431 unsigned char MDLoopKind = M.getContext().getMDKindID(
"llvm.loop");
437 if (
auto *
I = BB.getTerminator())
442 if (
MDNode *LoopMD =
I.getMetadata(MDLoopKind))
444 I.dropUnknownNonDebugMetadata(DXILCompatibleMDs);
456 M.getModuleFlagsMetadata(FlagEntries);
457 bool Updated =
false;
458 for (
auto &Flag : FlagEntries) {
471 for (
auto &Flag : FlagEntries)
472 M.addModuleFlag(Flag.Behavior, Flag.Key->getString(), Flag.Val);
481 "llvm.ident",
"llvm.module.flags",
"dx.resources",
"dx.valver",
482 "dx.shaderModel",
"dx.version",
"dx.entryPoints",
498 (NamedResourceMD !=
nullptr) ? NamedResourceMD->
getOperand(0) :
nullptr;
507 uint64_t CombinedMask = ShaderFlags.getCombinedFlags();
511 reportError(M,
"Non-library shader: One and only one entry expected");
516 EntryShaderFlags = ShaderFlags.getFunctionFlags(EntryProp.
Entry);
519 M,
"Shader stage '" +
522 "' different from specified target profile '" +
533 M.getOrInsertNamedMetadata(
"dx.entryPoints");
534 for (
auto *Entry : EntryFnMDNodes)
544 if (!NamedMD.getName().starts_with(
"llvm.dbg.") &&
549 NamedMD->eraseFromParent();
601 "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...
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
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.
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),...
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
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.
StringRef - 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...
FunctionAddr VTableAddr Count
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...
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