25 : Entry(M.getOrInsertNamedMetadata(
"dx.valver")) {}
46 auto *ValVerMD = cast<MDNode>(Entry->
getOperand(0));
47 auto *MajorMD = mdconst::extract<ConstantInt>(ValVerMD->getOperand(0));
48 auto *MinorMD = mdconst::extract<ConstantInt>(ValVerMD->getOperand(1));
49 return VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue());
80 NamedMDNode *Entry = M.getOrInsertNamedMetadata(
"dx.shaderModel");
81 Triple TT(M.getTargetTriple());
98 NamedMDNode *Entry = M.getOrInsertNamedMetadata(
"dx.version");
116 unsigned NumThreads[3];
120 : ShaderKind(ModuleShaderKind) {
122 if (ShaderKind == Triple::EnvironmentType::Library) {
123 Attribute EntryAttr =
F.getFnAttribute(
"hlsl.shader");
125 Triple T(
"",
"",
"", EntryProfile);
126 ShaderKind =
T.getEnvironment();
129 if (ShaderKind == Triple::EnvironmentType::Compute) {
131 F.getFnAttribute(
"hlsl.numthreads").getValueAsString();
133 NumThreadsStr.split(NumThreads,
',');
134 assert(NumThreads.
size() == 3 &&
"invalid numthreads");
137 for (
auto It : Zip) {
140 [[maybe_unused]]
bool Result = Str.getAsInteger(10, V);
141 assert(!Result &&
"Failed to parse numthreads");
143 unsigned &Num = std::get<1>(It);
144 Num =
V.getLimitedValue();
151 std::vector<Metadata *> MDVals;
153 if (RawShaderFlag != 0)
154 appendShaderFlags(MDVals, RawShaderFlag, Ctx);
157 if (IsLib && ShaderKind != Triple::EnvironmentType::Library)
158 appendShaderKind(MDVals, Ctx);
160 if (ShaderKind == Triple::EnvironmentType::Compute)
161 appendNumThreads(MDVals, Ctx);
169 if (RawShaderFlag == 0)
172 std::vector<Metadata *> MDVals;
174 appendShaderFlags(MDVals, RawShaderFlag, Ctx);
197 void appendNumThreads(std::vector<Metadata *> &MDVals,
LLVMContext &Ctx) {
201 std::vector<Metadata *> NumThreadVals;
205 MDVals.emplace_back(
MDNode::get(Ctx, NumThreadVals));
208 static void appendShaderFlags(std::vector<Metadata *> &MDVals,
216 void appendShaderKind(std::vector<Metadata *> &MDVals,
LLVMContext &Ctx) {
231 :
F(
F), Ctx(
F.getContext()), Props(
F, ModuleShaderKind) {}
237 return emitDXILEntryPointTuple(
239 Props.emitDXILEntryProps(RawShaderFlag, Ctx,
false), Ctx);
246 return emitDXILEntryPointTuple(
249 Props.emitDXILEntryProps(RawShaderFlag, Ctx,
true), Ctx);
257 return emitDXILEntryPointTuple(
259 EntryProps::emitEntryPropsForEmptyEntry(RawShaderFlag, Ctx), Ctx);
273 MDVals[4] = Properties;
281 for (
auto &
F : M.functions()) {
282 if (!
F.hasFnAttribute(
"hlsl.shader"))
287 auto &Ctx = M.getContext();
290 MDTuple *MDResources =
nullptr;
291 if (
auto *NamedResources = M.getNamedMetadata(
"dx.resources"))
292 MDResources = dyn_cast<MDTuple>(NamedResources->getOperand(0));
294 std::vector<MDNode *> Entries;
296 switch (
T.getEnvironment()) {
300 EntryMD::emitEmptyEntryForLib(MDResources, ShaderFlags, Ctx);
301 Entries.emplace_back(EmptyEntry);
304 EntryMD MD(*Entry,
T.getEnvironment());
305 Entries.emplace_back(MD.emitEntryTupleForLib(0));
317 "non-lib profiles should only have one entry");
318 EntryMD MD(*EntryList.
front(),
T.getEnvironment());
319 Entries.emplace_back(MD.emitEntryTuple(MDResources, ShaderFlags));
322 assert(0 &&
"invalid profile");
327 M.getOrInsertNamedMetadata(
"dx.entryPoints");
328 for (
auto *Entry : Entries)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const FuncProtoTy Signatures[]
Defines the llvm::VersionTuple class, which represents a version in the form major[....
Class for arbitrary precision integers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
StringRef getValueAsString() const
Return the attribute's value as a string.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
This is an important class for using LLVM in a threaded context.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDString * get(LLVMContext &Context, StringRef Str)
A Module instance is used to store all the information related to an LLVM module.
LLVMContext & getContext() const
Get the global data context.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
void setOperand(unsigned I, MDNode *New)
MDNode * getOperand(unsigned i) const
unsigned getNumOperands() const
Module * getParent()
Get the module that holds this named metadata collection.
void addOperand(MDNode *M)
reference emplace_back(ArgTypes &&... Args)
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.
Triple - Helper class for working with autoconf configuration names.
std::string normalize() const
Return the normalized form of this triple's string.
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
Represents a version number in the form major[.minor[.subminor[.build]]].
unsigned getMajor() const
Retrieve the major version number.
std::optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
void update(VersionTuple ValidatorVer)
VersionTuple getAsVersionTuple()
ValidatorVersionMD(Module &M)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void createShaderModelMD(Module &M)
void createDXILVersionMD(Module &M)
void createEntryMD(Module &M, const uint64_t ShaderFlags)
This is an optimization pass for GlobalISel generic memory operations.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.