Skip to content

Commit 3734fa8

Browse files
authored
[DXIL] Consume Metadata Analysis information in passes (#108034)
- Changed `DXILTranslateMetadata::translateMetadata()` to consume DXIL Metadata Analysis information. Subsumed into `DXILTranslateMetedata.cpp` the functionality in `DXILMetadata.*` files - that are hence deleted. - Changed `DXILPrepare` pass to consume DXIL Metadata Analysis information. - Renamed `ModuleMetadataInfo::ShaderStage` to `ModuleMetadataInfo::ShaderProfile` to better convey what it represents. - Updated `unknown` target shader stage specification in triples of a couple of tests. - Added new tests for additional verification of `DXILTranslateMetadata` pass functionality.
1 parent 8dbb739 commit 3734fa8

15 files changed

+395
-416
lines changed

llvm/include/llvm/Analysis/DXILMetadataAnalysis.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ class Function;
2121
namespace dxil {
2222

2323
struct EntryProperties {
24-
const Function *Entry;
24+
const Function *Entry{nullptr};
2525
// Specific target shader stage may be specified for entry functions
26-
Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
26+
Triple::EnvironmentType ShaderStage{Triple::UnknownEnvironment};
2727
unsigned NumThreadsX{0}; // X component
2828
unsigned NumThreadsY{0}; // Y component
2929
unsigned NumThreadsZ{0}; // Z component
3030

31-
EntryProperties(const Function &Fn) : Entry(&Fn) {};
31+
EntryProperties(const Function *Fn = nullptr) : Entry(Fn) {};
3232
};
3333

3434
struct ModuleMetadataInfo {
3535
VersionTuple DXILVersion{};
3636
VersionTuple ShaderModelVersion{};
37-
Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
37+
Triple::EnvironmentType ShaderProfile{Triple::UnknownEnvironment};
3838
VersionTuple ValidatorVersion{};
3939
SmallVector<EntryProperties> EntryPropertyVec{};
4040
void print(raw_ostream &OS) const;

llvm/lib/Analysis/DXILMetadataAnalysis.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
2727
Triple TT(Triple(M.getTargetTriple()));
2828
MMDAI.DXILVersion = TT.getDXILVersion();
2929
MMDAI.ShaderModelVersion = TT.getOSVersion();
30-
MMDAI.ShaderStage = TT.getEnvironment();
30+
MMDAI.ShaderProfile = TT.getEnvironment();
3131
NamedMDNode *ValidatorVerNode = M.getNamedMetadata("dx.valver");
3232
if (ValidatorVerNode) {
3333
auto *ValVerMD = cast<MDNode>(ValidatorVerNode->getOperand(0));
@@ -42,7 +42,7 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
4242
if (!F.hasFnAttribute("hlsl.shader"))
4343
continue;
4444

45-
EntryProperties EFP(F);
45+
EntryProperties EFP(&F);
4646
// Get "hlsl.shader" attribute
4747
Attribute EntryAttr = F.getFnAttribute("hlsl.shader");
4848
assert(EntryAttr.isValid() &&
@@ -74,8 +74,8 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
7474
void ModuleMetadataInfo::print(raw_ostream &OS) const {
7575
OS << "Shader Model Version : " << ShaderModelVersion.getAsString() << "\n";
7676
OS << "DXIL Version : " << DXILVersion.getAsString() << "\n";
77-
OS << "Target Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
78-
<< "\n";
77+
OS << "Target Shader Stage : "
78+
<< Triple::getEnvironmentTypeName(ShaderProfile) << "\n";
7979
OS << "Validator Version : " << ValidatorVersion.getAsString() << "\n";
8080
for (const auto &EP : EntryPropertyVec) {
8181
OS << " " << EP.Entry->getName() << "\n";

llvm/lib/Target/DirectX/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ add_llvm_target(DirectXCodeGen
2222
DXContainerGlobals.cpp
2323
DXILFinalizeLinkage.cpp
2424
DXILIntrinsicExpansion.cpp
25-
DXILMetadata.cpp
2625
DXILOpBuilder.cpp
2726
DXILOpLowering.cpp
2827
DXILPrepare.cpp

llvm/lib/Target/DirectX/DXContainerGlobals.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ void DXContainerGlobals::addPipelineStateValidationInfo(
204204
dxil::ModuleMetadataInfo &MMI =
205205
getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
206206
assert(MMI.EntryPropertyVec.size() == 1 ||
207-
MMI.ShaderStage == Triple::Library);
207+
MMI.ShaderProfile == Triple::Library);
208208
PSV.BaseData.ShaderStage =
209-
static_cast<uint8_t>(MMI.ShaderStage - Triple::Pixel);
209+
static_cast<uint8_t>(MMI.ShaderProfile - Triple::Pixel);
210210

211211
addResourcesForPSV(M, PSV);
212212

@@ -215,7 +215,7 @@ void DXContainerGlobals::addPipelineStateValidationInfo(
215215
// TODO: Lots more stuff to do here!
216216
//
217217
// See issue https://github.com/llvm/llvm-project/issues/96674.
218-
switch (MMI.ShaderStage) {
218+
switch (MMI.ShaderProfile) {
219219
case Triple::Compute:
220220
PSV.BaseData.NumThreadsX = MMI.EntryPropertyVec[0].NumThreadsX;
221221
PSV.BaseData.NumThreadsY = MMI.EntryPropertyVec[0].NumThreadsY;
@@ -225,10 +225,10 @@ void DXContainerGlobals::addPipelineStateValidationInfo(
225225
break;
226226
}
227227

228-
if (MMI.ShaderStage != Triple::Library)
228+
if (MMI.ShaderProfile != Triple::Library)
229229
PSV.EntryName = MMI.EntryPropertyVec[0].Entry->getName();
230230

231-
PSV.finalize(MMI.ShaderStage);
231+
PSV.finalize(MMI.ShaderProfile);
232232
PSV.write(OS);
233233
Constant *Constant =
234234
ConstantDataArray::getString(M.getContext(), Data, /*AddNull*/ false);

0 commit comments

Comments
 (0)