[llvm] [HLSL] Move DXILResourceImplicitBinding pass closer to DXIL Resource Analysis (PR #140981)

Helena Kotas via llvm-commits llvm-commits at lists.llvm.org
Tue May 27 09:50:56 PDT 2025


https://github.com/hekota updated https://github.com/llvm/llvm-project/pull/140981

>From a922b551b2fc8c68fd177a7d0657221af1a4704c Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Wed, 21 May 2025 18:52:36 -0700
Subject: [PATCH] [HLSL] Moving DXILResourceImplicitBinding pass right before
 DXIL Resource Analysis

Moving DXILResourceImplicitBinding pass and the associated DXILResourceBindingAnalysis lower in the llc pipeline to just before DXIL Resource Analysis, which is where its results are first needed.

The reason for this change is that I will soon be adding DXILResourceBindingAnalysis dependency to DXILPostOptimizationValidation pass and bringing this closer to where it is needed avoid unnecessary churn to preserved analysis setting in preceding passes.
---
 .../Target/DirectX/DXILResourceImplicitBinding.cpp  | 13 ++++++++++---
 llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp   |  1 +
 llvm/lib/Target/DirectX/DirectXTargetMachine.cpp    |  2 +-
 llvm/test/CodeGen/DirectX/llc-pipeline.ll           |  4 ++--
 4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp b/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
index 92454bea51e31..8caa3b37698fc 100644
--- a/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
+++ b/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
@@ -135,9 +135,14 @@ PreservedAnalyses DXILResourceImplicitBinding::run(Module &M,
 
   DXILResourceBindingInfo &DRBI = AM.getResult<DXILResourceBindingAnalysis>(M);
   DXILResourceTypeMap &DRTM = AM.getResult<DXILResourceTypeAnalysis>(M);
-  if (DRBI.hasImplicitBinding())
-    if (assignBindings(M, DRBI, DRTM))
-      return PreservedAnalyses::none();
+  if (DRBI.hasImplicitBinding()) {
+    if (assignBindings(M, DRBI, DRTM)) {
+      PreservedAnalyses PA;
+      PA.preserve<DXILResourceBindingAnalysis>();
+      PA.preserve<DXILResourceTypeAnalysis>();
+      return PA;
+    }
+  }
   return PreservedAnalyses::all();
 }
 
@@ -162,6 +167,8 @@ class DXILResourceImplicitBindingLegacy : public ModulePass {
   void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
     AU.addRequired<DXILResourceTypeWrapperPass>();
     AU.addRequired<DXILResourceBindingWrapperPass>();
+    AU.addPreserved<DXILResourceTypeWrapperPass>();
+    AU.addPreserved<DXILResourceBindingWrapperPass>();
   }
 };
 
diff --git a/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp b/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
index e0dce3d750ed1..1d496bf0a5656 100644
--- a/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
+++ b/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
@@ -408,6 +408,7 @@ class DXILTranslateMetadataLegacy : public ModulePass {
     AU.addPreserved<DXILResourceWrapperPass>();
     AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
     AU.addPreserved<ShaderFlagsAnalysisWrapper>();
+    AU.addPreserved<DXILResourceBindingWrapperPass>();
   }
 
   bool runOnModule(Module &M) override {
diff --git a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
index 22142484cef3c..40fe6c6e639e4 100644
--- a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
+++ b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
@@ -103,7 +103,6 @@ class DirectXPassConfig : public TargetPassConfig {
   FunctionPass *createTargetRegisterAllocator(bool) override { return nullptr; }
   void addCodeGenPrepare() override {
     addPass(createDXILFinalizeLinkageLegacyPass());
-    addPass(createDXILResourceImplicitBindingLegacyPass());
     addPass(createDXILResourceAccessLegacyPass());
     addPass(createDXILIntrinsicExpansionLegacyPass());
     addPass(createDXILCBufferAccessLegacyPass());
@@ -114,6 +113,7 @@ class DirectXPassConfig : public TargetPassConfig {
     addPass(createScalarizerPass(DxilScalarOptions));
     addPass(createDXILForwardHandleAccessesLegacyPass());
     addPass(createDXILLegalizeLegacyPass());
+    addPass(createDXILResourceImplicitBindingLegacyPass());
     addPass(createDXILTranslateMetadataLegacyPass());
     addPass(createDXILPostOptimizationValidationLegacyPass());
     addPass(createDXILOpLoweringLegacyPass());
diff --git a/llvm/test/CodeGen/DirectX/llc-pipeline.ll b/llvm/test/CodeGen/DirectX/llc-pipeline.ll
index 088040a491bdc..2b29fd30a7a56 100644
--- a/llvm/test/CodeGen/DirectX/llc-pipeline.ll
+++ b/llvm/test/CodeGen/DirectX/llc-pipeline.ll
@@ -14,8 +14,6 @@
 
 ; CHECK-NEXT: ModulePass Manager
 ; CHECK-NEXT:   DXIL Finalize Linkage
-; CHECK-NEXT:   DXIL Resource Binding Analysis
-; CHECK-NEXT:   DXIL Resource Implicit Binding
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT:     DXIL Resource Access
 ; CHECK-NEXT:   DXIL Intrinsic Expansion
@@ -27,6 +25,8 @@
 ; CHECK-NEXT:     Scalarize vector operations
 ; CHECK-NEXT:     DXIL Forward Handle Accesses
 ; CHECK-NEXT:     DXIL Legalizer
+; CHECK-NEXT:   DXIL Resource Binding Analysis
+; CHECK-NEXT:   DXIL Resource Implicit Binding
 ; CHECK-NEXT:   DXIL Resources Analysis
 ; CHECK-NEXT:   DXIL Module Metadata analysis
 ; CHECK-NEXT:   DXIL Shader Flag Analysis



More information about the llvm-commits mailing list