[llvm] [DXIL][Analysis] Add DXILMetadataAnalysis pass (PR #102079)

S. Bharadwaj Yadavalli via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 9 10:33:45 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");
----------------
bharadwajy wrote:

> Analysis passes must not modify the module, so creating metadata here isn’t allowed. In any case, we should be creating the `dx.valver` metadata node based on the results of this pass, so getting the value from there is circular and doesn’t make sense.

Changed the call to get named metadata `dx.ver` from the `Module` along with a change to set `ValidatorVersion` only if one exists, else retaining its default empty value. Is there a different location to obtain Validator Version?

https://github.com/llvm/llvm-project/pull/102079


More information about the llvm-commits mailing list