[llvm] 372ddcd - [DXIL][Analysis] Boilerplate for DXILResourceAnalysis pass
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 14:11:48 PDT 2024
Author: Justin Bogner
Date: 2024-08-15T00:11:45+03:00
New Revision: 372ddcd1baf2c17fd544e458e15221044df66a5d
URL: https://github.com/llvm/llvm-project/commit/372ddcd1baf2c17fd544e458e15221044df66a5d
DIFF: https://github.com/llvm/llvm-project/commit/372ddcd1baf2c17fd544e458e15221044df66a5d.diff
LOG: [DXIL][Analysis] Boilerplate for DXILResourceAnalysis pass
Broke this out into its own commit to make the next one easier to
review.
Pull Request: https://github.com/llvm/llvm-project/pull/100700
Added:
Modified:
llvm/include/llvm/Analysis/DXILResource.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/lib/Analysis/Analysis.cpp
llvm/lib/Analysis/DXILResource.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/DXILResource.h b/llvm/include/llvm/Analysis/DXILResource.h
index ed9fade3f14f31..7db088df260f30 100644
--- a/llvm/include/llvm/Analysis/DXILResource.h
+++ b/llvm/include/llvm/Analysis/DXILResource.h
@@ -9,10 +9,14 @@
#ifndef LLVM_ANALYSIS_DXILRESOURCE_H
#define LLVM_ANALYSIS_DXILRESOURCE_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"
namespace llvm {
+class CallInst;
class MDTuple;
namespace dxil {
@@ -214,6 +218,55 @@ class ResourceInfo {
};
} // namespace dxil
+
+using DXILResourceMap = MapVector<CallInst *, dxil::ResourceInfo>;
+
+class DXILResourceAnalysis : public AnalysisInfoMixin<DXILResourceAnalysis> {
+ friend AnalysisInfoMixin<DXILResourceAnalysis>;
+
+ static AnalysisKey Key;
+
+public:
+ using Result = DXILResourceMap;
+
+ /// Gather resource info for the module \c M.
+ DXILResourceMap run(Module &M, ModuleAnalysisManager &AM);
+};
+
+/// Printer pass for the \c DXILResourceAnalysis results.
+class DXILResourcePrinterPass : public PassInfoMixin<DXILResourcePrinterPass> {
+ raw_ostream &OS;
+
+public:
+ explicit DXILResourcePrinterPass(raw_ostream &OS) : OS(OS) {}
+
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+
+ static bool isRequired() { return true; }
+};
+
+class DXILResourceWrapperPass : public ModulePass {
+ std::unique_ptr<DXILResourceMap> ResourceMap;
+
+public:
+ static char ID; // Class identification, replacement for typeinfo
+
+ DXILResourceWrapperPass();
+ ~DXILResourceWrapperPass() override;
+
+ const DXILResourceMap &getResourceMap() const { return *ResourceMap; }
+ DXILResourceMap &getResourceMap() { return *ResourceMap; }
+
+ 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;
+};
+
+ModulePass *createDXILResourceWrapperPassPass();
+
} // namespace llvm
#endif // LLVM_ANALYSIS_DXILRESOURCE_H
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 261912aab3076c..0cd0d2edc23668 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -84,6 +84,7 @@ void initializeDAHPass(PassRegistry&);
void initializeDCELegacyPassPass(PassRegistry&);
void initializeDXILMetadataAnalysisWrapperPassPass(PassRegistry &);
void initializeDXILMetadataAnalysisWrapperPrinterPass(PassRegistry &);
+void initializeDXILResourceWrapperPassPass(PassRegistry &);
void initializeDeadMachineInstructionElimPass(PassRegistry&);
void initializeDebugifyMachineModulePass(PassRegistry &);
void initializeDependenceAnalysisWrapperPassPass(PassRegistry&);
diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h
index c00e425b131987..967238e8d03b6e 100644
--- a/llvm/include/llvm/LinkAllPasses.h
+++ b/llvm/include/llvm/LinkAllPasses.h
@@ -19,6 +19,7 @@
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/CallPrinter.h"
+#include "llvm/Analysis/DXILResource.h"
#include "llvm/Analysis/DomPrinter.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/Passes.h"
@@ -69,6 +70,7 @@ namespace {
(void) llvm::createCallGraphViewerPass();
(void) llvm::createCFGSimplificationPass();
(void) llvm::createStructurizeCFGPass();
+ (void) llvm::createDXILResourceWrapperPassPass();
(void) llvm::createDeadArgEliminationPass();
(void) llvm::createDeadCodeEliminationPass();
(void) llvm::createDependenceAnalysisWrapperPass();
diff --git a/llvm/lib/Analysis/Analysis.cpp b/llvm/lib/Analysis/Analysis.cpp
index 11cc6cfccea6af..58723469f21ca8 100644
--- a/llvm/lib/Analysis/Analysis.cpp
+++ b/llvm/lib/Analysis/Analysis.cpp
@@ -25,6 +25,7 @@ void llvm::initializeAnalysis(PassRegistry &Registry) {
initializeCallGraphDOTPrinterPass(Registry);
initializeCallGraphViewerPass(Registry);
initializeCycleInfoWrapperPassPass(Registry);
+ initializeDXILResourceWrapperPassPass(Registry);
initializeDependenceAnalysisWrapperPassPass(Registry);
initializeDominanceFrontierWrapperPassPass(Registry);
initializeDomViewerWrapperPassPass(Registry);
diff --git a/llvm/lib/Analysis/DXILResource.cpp b/llvm/lib/Analysis/DXILResource.cpp
index 5e8350fd2d2516..9941a55d46d645 100644
--- a/llvm/lib/Analysis/DXILResource.cpp
+++ b/llvm/lib/Analysis/DXILResource.cpp
@@ -9,7 +9,11 @@
#include "llvm/Analysis/DXILResource.h"
#include "llvm/ADT/APInt.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/Metadata.h"
+#include "llvm/InitializePasses.h"
+
+#define DEBUG_TYPE "dxil-resource"
using namespace llvm;
using namespace dxil;
@@ -326,4 +330,77 @@ std::pair<uint32_t, uint32_t> ResourceInfo::getAnnotateProps() const {
return {Word0, Word1};
}
-#define DEBUG_TYPE "dxil-resource"
+//===----------------------------------------------------------------------===//
+// DXILResourceAnalysis and DXILResourcePrinterPass
+
+// Provide an explicit template instantiation for the static ID.
+AnalysisKey DXILResourceAnalysis::Key;
+
+DXILResourceMap DXILResourceAnalysis::run(Module &M,
+ ModuleAnalysisManager &AM) {
+ DXILResourceMap Data;
+ return Data;
+}
+
+PreservedAnalyses DXILResourcePrinterPass::run(Module &M,
+ ModuleAnalysisManager &AM) {
+ DXILResourceMap &Data =
+ AM.getResult<DXILResourceAnalysis>(M);
+
+ for (const auto &[Handle, Info] : Data) {
+ OS << "Binding for ";
+ Handle->print(OS);
+ OS << "\n";
+ // TODO: Info.print(OS);
+ OS << "\n";
+ }
+
+ return PreservedAnalyses::all();
+}
+
+//===----------------------------------------------------------------------===//
+// DXILResourceWrapperPass
+
+DXILResourceWrapperPass::DXILResourceWrapperPass() : ModulePass(ID) {
+ initializeDXILResourceWrapperPassPass(*PassRegistry::getPassRegistry());
+}
+
+DXILResourceWrapperPass::~DXILResourceWrapperPass() = default;
+
+void DXILResourceWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+}
+
+bool DXILResourceWrapperPass::runOnModule(Module &M) {
+ ResourceMap.reset(new DXILResourceMap());
+ return false;
+}
+
+void DXILResourceWrapperPass::releaseMemory() { ResourceMap.reset(); }
+
+void DXILResourceWrapperPass::print(raw_ostream &OS, const Module *) const {
+ if (!ResourceMap) {
+ OS << "No resource map has been built!\n";
+ return;
+ }
+ for (const auto &[Handle, Info] : *ResourceMap) {
+ OS << "Binding for ";
+ Handle->print(OS);
+ OS << "\n";
+ // TODO: Info.print(OS);
+ OS << "\n";
+ }
+}
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD
+void DXILResourceWrapperPass::dump() const { print(dbgs(), nullptr); }
+#endif
+
+INITIALIZE_PASS(DXILResourceWrapperPass, DEBUG_TYPE, "DXIL Resource analysis",
+ false, true)
+char DXILResourceWrapperPass::ID = 0;
+
+ModulePass *llvm::createDXILResourceWrapperPassPass() {
+ return new DXILResourceWrapperPass();
+}
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 1859fde279c98d..c528863d1870a4 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -33,6 +33,7 @@
#include "llvm/Analysis/DDG.h"
#include "llvm/Analysis/DDGPrinter.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
+#include "llvm/Analysis/DXILResource.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 5ef8ba30944470..4fdded7b82f36b 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -22,6 +22,7 @@ MODULE_ANALYSIS("callgraph", CallGraphAnalysis())
MODULE_ANALYSIS("collector-metadata", CollectorMetadataAnalysis())
MODULE_ANALYSIS("ctx-prof-analysis", CtxProfAnalysis(UseCtxProfile))
MODULE_ANALYSIS("dxil-metadata", DXILMetadataAnalysis())
+MODULE_ANALYSIS("dxil-resource", DXILResourceAnalysis())
MODULE_ANALYSIS("inline-advisor", InlineAdvisorAnalysis())
MODULE_ANALYSIS("ir-similarity", IRSimilarityAnalysis())
MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis())
@@ -119,6 +120,7 @@ MODULE_PASS("print-must-be-executed-contexts",
MODULE_PASS("print-profile-summary", ProfileSummaryPrinterPass(dbgs()))
MODULE_PASS("print-stack-safety", StackSafetyGlobalPrinterPass(dbgs()))
MODULE_PASS("print<dxil-metadata>", DXILMetadataAnalysisPrinterPass(dbgs()))
+MODULE_PASS("print<dxil-resource>", DXILResourcePrinterPass(dbgs()))
MODULE_PASS("print<inline-advisor>", InlineAdvisorAnalysisPrinterPass(dbgs()))
MODULE_PASS("print<module-debuginfo>", ModuleDebugInfoPrinterPass(dbgs()))
MODULE_PASS("pseudo-probe", SampleProfileProbePass(TM))
More information about the llvm-commits
mailing list