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

via llvm-commits llvm-commits at lists.llvm.org
Thu May 29 10:12:12 PDT 2025


Author: Helena Kotas
Date: 2025-05-29T10:12:09-07:00
New Revision: 74ad4baef07336bcb3b01570e21b560339fad2c3

URL: https://github.com/llvm/llvm-project/commit/74ad4baef07336bcb3b01570e21b560339fad2c3
DIFF: https://github.com/llvm/llvm-project/commit/74ad4baef07336bcb3b01570e21b560339fad2c3.diff

LOG: [HLSL] Move DXILResourceImplicitBinding pass closer to DXIL Resource Analysis (#140981)

Moving `DXILResourceImplicitBinding` pass and the associated `DXILResourceBindingAnalysis` lower in the llc pipeline to just before the DXIL Resource Analysis, which is where its results are first needed, and adjusting the set of analyses it preserves.

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.

Added: 
    

Modified: 
    llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
    llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
    llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
    llvm/test/CodeGen/DirectX/llc-pipeline.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp b/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
index 72d410b55c7e5..6e69c5ac1d633 100644
--- a/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
+++ b/llvm/lib/Target/DirectX/DXILResourceImplicitBinding.cpp
@@ -136,10 +136,17 @@ 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();
-  return PreservedAnalyses::all();
+
+  if (!DRBI.hasImplicitBinding())
+    return PreservedAnalyses::all();
+
+  if (!assignBindings(M, DRBI, DRTM))
+    return PreservedAnalyses::all();
+
+  PreservedAnalyses PA;
+  PA.preserve<DXILResourceBindingAnalysis>();
+  PA.preserve<DXILResourceTypeAnalysis>();
+  return PA;
 }
 
 namespace {
@@ -163,6 +170,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 625de759eb831..1a36809658498 100644
--- a/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
+++ b/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
@@ -409,6 +409,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