2
0
Эх сурвалжийг харах

Fix dependency on HL/DxilModule from llvm::Module (#1651)

- use function pointers for HL/DxilModule remove function callbacks
- move ReducibilityAnalysis to llvm/Analysis
Tex Riddell 6 жил өмнө
parent
commit
254b8853be

+ 0 - 0
include/dxc/HLSL/ReducibilityAnalysis.h → include/llvm/Analysis/ReducibilityAnalysis.h


+ 7 - 0
include/llvm/IR/Module.h

@@ -690,6 +690,13 @@ public:
 /// @}
 
   // HLSL Change start
+  typedef void (*RemoveFunctionCallback)(llvm::Module*, llvm::Function*);
+  RemoveFunctionCallback   pHLModuleRemoveFunction = nullptr;
+  RemoveFunctionCallback pDxilModuleRemoveFunction = nullptr;
+  void RemoveFunctionHook(llvm::Function* F) {
+    if   (pHLModuleRemoveFunction)   (*pHLModuleRemoveFunction)(this, F);
+    if (pDxilModuleRemoveFunction) (*pDxilModuleRemoveFunction)(this, F);
+  }
   bool HasHLModule() const { return TheHLModule != nullptr; }
   void SetHLModule(hlsl::HLModule *pValue) { TheHLModule = pValue; }
   hlsl::HLModule &GetHLModule() { return *TheHLModule; }

+ 1 - 0
lib/Analysis/CMakeLists.txt

@@ -53,6 +53,7 @@ add_llvm_library(LLVMAnalysis
   PHITransAddr.cpp
   PostDominators.cpp
   PtrUseVisitor.cpp
+  ReducibilityAnalysis.cpp
   regioninfo.cpp
   RegionPass.cpp
   regionprinter.cpp

+ 1 - 1
lib/HLSL/ReducibilityAnalysis.cpp → lib/Analysis/ReducibilityAnalysis.cpp

@@ -7,7 +7,7 @@
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include "dxc/HLSL/ReducibilityAnalysis.h"
+#include "llvm/Analysis/ReducibilityAnalysis.h"
 #include "dxc/Support/Global.h"
 
 #include "llvm/IR/LLVMContext.h"

+ 8 - 0
lib/DXIL/DxilModule.cpp

@@ -75,6 +75,12 @@ const char* kFP32DenormValuePreserveString = "preserve";
 const char* kFP32DenormValueFtzString      = "ftz";
 }
 
+// Avoid dependency on DxilModule from llvm::Module using this:
+void DxilModule_RemoveFunction(llvm::Module* M, llvm::Function* F) {
+  if (M && F && M->HasDxilModule())
+    M->GetDxilModule().RemoveFunction(F);
+}
+
 //------------------------------------------------------------------------------
 //
 //  DxilModule methods.
@@ -103,6 +109,7 @@ DxilModule::DxilModule(Module *pModule)
 {
 
   DXASSERT_NOMSG(m_pModule != nullptr);
+  m_pModule->pDxilModuleRemoveFunction = &DxilModule_RemoveFunction;
 
 #if defined(_DEBUG) || defined(DBG)
   // Pin LLVM dump methods.
@@ -115,6 +122,7 @@ DxilModule::DxilModule(Module *pModule)
 }
 
 DxilModule::~DxilModule() {
+  m_pModule->pDxilModuleRemoveFunction = nullptr;
 }
 
 LLVMContext &DxilModule::GetCtx() const { return m_Ctx; }

+ 0 - 1
lib/HLSL/CMakeLists.txt

@@ -31,7 +31,6 @@ add_llvm_library(LLVMHLSL
   HLResource.cpp
   HLSignatureLower.cpp
   PauseResumePasses.cpp
-  ReducibilityAnalysis.cpp
   WaveSensitivityAnalysis.cpp
 
   ADDITIONAL_HEADER_DIRS

+ 1 - 1
lib/HLSL/DxcOptimizer.cpp

@@ -16,7 +16,7 @@
 #include "dxc/DxilContainer/DxilContainer.h"
 #include "dxc/Support/FileIOHelper.h"
 #include "dxc/DXIL/DxilModule.h"
-#include "dxc/HLSL/ReducibilityAnalysis.h"
+#include "llvm/Analysis/ReducibilityAnalysis.h"
 #include "dxc/HLSL/HLMatrixLowerPass.h"
 #include "dxc/HLSL/DxilGenerationPass.h"
 #include "dxc/HLSL/ComputeViewIdState.h"

+ 1 - 1
lib/HLSL/DxilValidation.cpp

@@ -20,7 +20,7 @@
 #include "dxc/Support/Global.h"
 #include "dxc/DXIL/DxilUtil.h"
 #include "dxc/DXIL/DxilInstructions.h"
-#include "dxc/HLSL/ReducibilityAnalysis.h"
+#include "llvm/Analysis/ReducibilityAnalysis.h"
 #include "dxc/Support/WinIncludes.h"
 #include "dxc/Support/FileIOHelper.h"
 #include "dxc/DXIL/DxilEntryProps.h"

+ 8 - 0
lib/HLSL/HLModule.cpp

@@ -35,6 +35,12 @@ using std::unique_ptr;
 
 namespace hlsl {
 
+// Avoid dependency on HLModule from llvm::Module using this:
+void HLModule_RemoveFunction(llvm::Module* M, llvm::Function* F) {
+  if (M && F && M->HasHLModule())
+    M->GetHLModule().RemoveFunction(F);
+}
+
 //------------------------------------------------------------------------------
 //
 //  HLModule methods.
@@ -58,6 +64,7 @@ HLModule::HLModule(Module *pModule)
     , m_DefaultLinkage(DXIL::DefaultLinkage::Default)
     , m_pTypeSystem(llvm::make_unique<DxilTypeSystem>(pModule)) {
   DXASSERT_NOMSG(m_pModule != nullptr);
+  m_pModule->pHLModuleRemoveFunction = &HLModule_RemoveFunction;
 
   // Pin LLVM dump methods. TODO: make debug-only.
   void (__thiscall Module::*pfnModuleDump)() const = &Module::dump;
@@ -66,6 +73,7 @@ HLModule::HLModule(Module *pModule)
 }
 
 HLModule::~HLModule() {
+  m_pModule->pHLModuleRemoveFunction = nullptr;
 }
 
 LLVMContext &HLModule::GetCtx() const { return m_Ctx; }

+ 2 - 6
lib/IR/Function.cpp

@@ -27,8 +27,6 @@
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
-#include "dxc/HLSL/HLModule.h" // HLSL Change
-#include "dxc/DXIL/DxilModule.h" // HLSL Change
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/RWMutex.h"
 #include "llvm/Support/StringPool.h"
@@ -237,14 +235,12 @@ Type *Function::getReturnType() const {
 }
 
 void Function::removeFromParent() {
-  if (getParent()->HasHLModule()) getParent()->GetHLModule().RemoveFunction(this); // HLSL Change
-  if (getParent()->HasDxilModule()) getParent()->GetDxilModule().RemoveFunction(this); // HLSL Change
+  getParent()->RemoveFunctionHook(this); // HLSL Change
   getParent()->getFunctionList().remove(this);
 }
 
 void Function::eraseFromParent() {
-  if (getParent()->HasHLModule()) getParent()->GetHLModule().RemoveFunction(this); // HLSL Change
-  if (getParent()->HasDxilModule()) getParent()->GetDxilModule().RemoveFunction(this); // HLSL Change
+  getParent()->RemoveFunctionHook(this); // HLSL Change
   getParent()->getFunctionList().erase(this);
 }