-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DXIL][Analysis] Add DXILMetadataAnalysis pass #102079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-analysis @llvm/pr-subscribers-backend-directx Author: S. Bharadwaj Yadavalli (bharadwajy) ChangesThree peices of information viz., Shader Model, DXIL version and Shader Stage information are collected in a structure. Additional metadata information is planned to be added in subsequent PRs along with changes to consume the information in passes such as DXILTranslateMetadata. Full diff: https://github.com/llvm/llvm-project/pull/102079.diff 7 Files Affected:
diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
new file mode 100644
index 0000000000000..1424f2209ebe7
--- /dev/null
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -0,0 +1,83 @@
+//=- DXILMetadataAnalysis.h - 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ANALYSIS_DXILMETADATA_H
+#define LLVM_ANALYSIS_DXILMETADATA_H
+
+#include "llvm/ADT/MapVector.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/DXILABI.h"
+#include "llvm/Support/VersionTuple.h"
+#include "llvm/TargetParser/Triple.h"
+
+namespace llvm {
+
+namespace dxil {
+
+struct ModuleMetadataInfo {
+ VersionTuple DXILVersion;
+ Triple::OSType ShaderModel;
+ Triple::EnvironmentType ShaderStage;
+
+ void dump(raw_ostream &OS = errs());
+};
+
+} // namespace dxil
+
+class DXILMetadataAnalysis : public AnalysisInfoMixin<DXILMetadataAnalysis> {
+ friend AnalysisInfoMixin<DXILMetadataAnalysis>;
+
+ static AnalysisKey Key;
+
+public:
+ using Result = dxil::ModuleMetadataInfo;
+ /// Gather module metadata info for the module \c M.
+ dxil::ModuleMetadataInfo run(Module &M, ModuleAnalysisManager &AM);
+};
+
+/// Printer pass for the \c DXILMetadataAnalysis results.
+class DXILMetadataAnalysisPrinterPass
+ : public PassInfoMixin<DXILMetadataAnalysisPrinterPass> {
+ raw_ostream &OS;
+
+public:
+ explicit DXILMetadataAnalysisPrinterPass(raw_ostream &OS) : OS(OS) {}
+
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+
+ static bool isRequired() { return true; }
+};
+
+/// Wrapper pass to be used by other passes using legacy pass manager
+class DXILMetadataAnalysisWrapperPass : public ModulePass {
+ std::unique_ptr<dxil::ModuleMetadataInfo> ModuleMetadata;
+
+public:
+ static char ID; // Class identification, replacement for typeinfo
+
+ DXILMetadataAnalysisWrapperPass();
+ ~DXILMetadataAnalysisWrapperPass() override;
+
+ const dxil::ModuleMetadataInfo &getModuleMetadata() const {
+ return *ModuleMetadata;
+ }
+ dxil::ModuleMetadataInfo &getModuleMetadata() { return *ModuleMetadata; }
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override;
+ bool runOnModule(Module &M) override;
+ void releaseMemory() override;
+
+ void print(raw_ostream &OS, const Module *M) const override;
+ void dump() const;
+};
+
+} // namespace llvm
+
+#endif // LLVM_ANALYSIS_DXILMETADATA_H
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 13be9c11f0107..4e9f083f16826 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -82,6 +82,7 @@ void initializeCycleInfoWrapperPassPass(PassRegistry &);
void initializeDAEPass(PassRegistry&);
void initializeDAHPass(PassRegistry&);
void initializeDCELegacyPassPass(PassRegistry&);
+void initializeDXILMetadataAnalysisWrapperPassPass(PassRegistry &);
void initializeDeadMachineInstructionElimPass(PassRegistry&);
void initializeDebugifyMachineModulePass(PassRegistry &);
void initializeDependenceAnalysisWrapperPassPass(PassRegistry&);
diff --git a/llvm/lib/Analysis/CMakeLists.txt b/llvm/lib/Analysis/CMakeLists.txt
index 997bb7a0bb178..910e00ca022d1 100644
--- a/llvm/lib/Analysis/CMakeLists.txt
+++ b/llvm/lib/Analysis/CMakeLists.txt
@@ -60,6 +60,7 @@ add_llvm_component_library(LLVMAnalysis
DomTreeUpdater.cpp
DominanceFrontier.cpp
DXILResource.cpp
+ DXILMetadataAnalysis.cpp
FunctionPropertiesAnalysis.cpp
GlobalsModRef.cpp
GuardUtils.cpp
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
new file mode 100644
index 0000000000000..020579527b9b8
--- /dev/null
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -0,0 +1,93 @@
+//=- 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/DerivedTypes.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"
+
+using namespace llvm;
+using namespace dxil;
+
+void ModuleMetadataInfo::dump(raw_ostream &OS) {
+ OS << "Shader Model : " << Triple::getOSTypeName(ShaderModel) << "\n";
+ OS << "DXIL Version : " << DXILVersion.getAsString() << "\n";
+ OS << "Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
+ << "\n";
+}
+//===----------------------------------------------------------------------===//
+// DXILMetadataAnalysis and DXILMetadataAnalysisPrinterPass
+
+// Provide an explicit template instantiation for the static ID.
+AnalysisKey DXILMetadataAnalysis::Key;
+
+llvm::dxil::ModuleMetadataInfo
+DXILMetadataAnalysis::run(Module &M, ModuleAnalysisManager &AM) {
+ ModuleMetadataInfo Data;
+ return Data;
+}
+
+PreservedAnalyses
+DXILMetadataAnalysisPrinterPass::run(Module &M, ModuleAnalysisManager &AM) {
+ llvm::dxil::ModuleMetadataInfo &Data = AM.getResult<DXILMetadataAnalysis>(M);
+
+ Data.dump(OS);
+ return PreservedAnalyses::all();
+}
+
+//===----------------------------------------------------------------------===//
+// DXILMetadataAnalysisWrapperPass
+
+DXILMetadataAnalysisWrapperPass::DXILMetadataAnalysisWrapperPass()
+ : ModulePass(ID) {
+ initializeDXILMetadataAnalysisWrapperPassPass(
+ *PassRegistry::getPassRegistry());
+}
+
+DXILMetadataAnalysisWrapperPass::~DXILMetadataAnalysisWrapperPass() = default;
+
+void DXILMetadataAnalysisWrapperPass::getAnalysisUsage(
+ AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+}
+
+bool DXILMetadataAnalysisWrapperPass::runOnModule(Module &M) {
+ ModuleMetadata.reset(new llvm::dxil::ModuleMetadataInfo());
+ Triple TT(Triple(M.getTargetTriple()));
+ ModuleMetadata->DXILVersion = TT.getDXILVersion();
+ ModuleMetadata->ShaderModel = TT.getOS();
+ ModuleMetadata->ShaderStage = TT.getEnvironment();
+ return false;
+}
+
+void DXILMetadataAnalysisWrapperPass::releaseMemory() {
+ ModuleMetadata.reset();
+}
+
+void DXILMetadataAnalysisWrapperPass::print(raw_ostream &OS,
+ const Module *) const {
+ if (!ModuleMetadata) {
+ OS << "No module metadata info has been built!\n";
+ return;
+ }
+ ModuleMetadata->dump();
+}
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
+void DXILMetadataAnalysisWrapperPass::dump() const { print(dbgs(), nullptr); }
+#endif
+
+INITIALIZE_PASS(DXILMetadataAnalysisWrapperPass, DEBUG_TYPE,
+ "DXIL Module Metadata analysis", false, true)
+char DXILMetadataAnalysisWrapperPass::ID = 0;
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 5dbb1e2f49871..af21602f07483 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -31,6 +31,7 @@
#include "llvm/Analysis/CycleAnalysis.h"
#include "llvm/Analysis/DDG.h"
#include "llvm/Analysis/DDGPrinter.h"
+#include "llvm/Analysis/DXILMetadataAnalysis.h"
#include "llvm/Analysis/Delinearization.h"
#include "llvm/Analysis/DemandedBits.h"
#include "llvm/Analysis/DependenceAnalysis.h"
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 3b92823cd283b..5b753eeac7d65 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -20,6 +20,7 @@
#endif
MODULE_ANALYSIS("callgraph", CallGraphAnalysis())
MODULE_ANALYSIS("collector-metadata", CollectorMetadataAnalysis())
+MODULE_ANALYSIS("dxil-metadata", DXILMetadataAnalysis())
MODULE_ANALYSIS("inline-advisor", InlineAdvisorAnalysis())
MODULE_ANALYSIS("ir-similarity", IRSimilarityAnalysis())
MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis())
@@ -115,6 +116,7 @@ MODULE_PASS("print-must-be-executed-contexts",
MustBeExecutedContextPrinterPass(dbgs()))
MODULE_PASS("print-profile-summary", ProfileSummaryPrinterPass(dbgs()))
MODULE_PASS("print-stack-safety", StackSafetyGlobalPrinterPass(dbgs()))
+MODULE_PASS("print<dxil-metadata>", DXILMetadataAnalysisPrinterPass(dbgs()))
MODULE_PASS("print<inline-advisor>", InlineAdvisorAnalysisPrinterPass(dbgs()))
MODULE_PASS("print<module-debuginfo>", ModuleDebugInfoPrinterPass(dbgs()))
MODULE_PASS("pseudo-probe", SampleProfileProbePass(TM))
diff --git a/llvm/lib/Target/DirectX/DirectX.h b/llvm/lib/Target/DirectX/DirectX.h
index d056ae2bc488e..f50e0e00700aa 100644
--- a/llvm/lib/Target/DirectX/DirectX.h
+++ b/llvm/lib/Target/DirectX/DirectX.h
@@ -58,6 +58,9 @@ void initializeDXILPrettyPrinterPass(PassRegistry &);
/// Initializer for dxil::ShaderFlagsAnalysisWrapper pass.
void initializeShaderFlagsAnalysisWrapperPass(PassRegistry &);
+/// Initializer for dxil::DXILMetadataAnalysisWrapper pass.
+void initializeDXILMetadataAnalysisWrapperPassPass(PassRegistry &);
+
/// Initializer for DXContainerGlobals pass.
void initializeDXContainerGlobalsPass(PassRegistry &);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The title calls this boilerplate, but it does actually partially implement the actual logic. We should drop "boilerplate" from the title and add tests for this please.
Updated title and description. Added tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still missing changes in llvm/lib/Passes/PassRegistry.def
to add the newpm style passes to the pass manager. Take a look at #100700 if you want some code to follow for the pattern.
Three peices of information viz., Shader Model, DXIL version and Shader Stage information are collected in a structure. Additional metadata information is planned to be added in subsequent PRs along with changes to consume the information in passes such as DXILTranslateMetadata.
e922b6a
to
250872e
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/146/builds/427 Here is the relevant piece of the build log for the reference:
|
DXIL Metadata Analysis passes (one for legacy PM and one for new PM) that collect following DXIL module metadata information in a structure are added.
Information collected using the legacy pass is verified by adding additional test commands to existing metadata test sources.