[llvm] [DXIL][Analysis] Add DXILMetadataAnalysis pass (PR #102079)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 12 03:08:34 PDT 2024
================
@@ -0,0 +1,106 @@
+//=- DXILMetadataAnalysis.cpp - Representation of Module metadata -*- C++ -*=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Analysis/DXILMetadataAnalysis.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+
+#define DEBUG_TYPE "dxil-metadata-analysis"
+
+using namespace llvm;
+using namespace dxil;
+
+void ModuleMetadataInfo::print(raw_ostream &OS) const {
+ OS << "Shader Model Version : " << ShaderModelVersion.getAsString() << "\n";
+ OS << "DXIL Version : " << DXILVersion.getAsString() << "\n";
+ OS << "Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
+ << "\n";
+ OS << "Validator Version : " << ValidatorVersion.getAsString() << "\n";
+}
+
+ModuleMetadataInfo::ModuleMetadataInfo(Module &M) {
+ Triple TT(Triple(M.getTargetTriple()));
+ DXILVersion = TT.getDXILVersion();
+ ShaderModelVersion = TT.getOSVersion();
+ ShaderStage = TT.getEnvironment();
+ NamedMDNode *Entry = M.getOrInsertNamedMetadata("dx.valver");
----------------
bogner wrote:
My understanding is that validator version is derived from the shader model / DXIL version, and that the only time that it isn’t is if it’s overridden on the command line. There was some discussion recently about why you would ever want to override it other than specifically for preview versions and what it even means for the validator version to differ significantly from the shader model version. Currently the metadata you’re reading is only ever set by the command line override.
Presumably the “right” thing to do here is to derive the validator version from the other versions. However, if we want to maintain the current behaviour in clang it looks like it just defaults to 1.0 if the command line argument isn’t set (this seems wrong). I think there’s a valid argument to leaving this out of this change and having a discussion about what the correct behaviour here actually is before adding it.
https://github.com/llvm/llvm-project/pull/102079
More information about the llvm-commits
mailing list