浏览代码

Clean up and rework DXIL library depencencies (#4877)

* Clean up and rework DXIL library depencencies

This change reworks the dependency specifications for the DXIL*
libraries. Many of these libraries had over and under specified
dependencies.

This also collapses the DxilRDATBuidlder into the DxilContainer library
to remove the cyclic dependency between the two libraries.

* Break assert dependency between DXIL and Analysis

In assert builds the DXILModule constructor was creating forced bindings
to debugging methods that are often used from the debugger. This forced
binding is useful, but doesn't need to live in the DXIL library.

To break the dependency I've moved the code into Analysis. I've also
made that code only included when building with MSVC. When using other
compilers `__attribute__((used))` can be applied to the function via the
`LLVM_DUMP_METHOD` annotation to have the same effect.
Chris B 2 年之前
父节点
当前提交
2168dcb4fb

+ 0 - 1
include/dxc/DXIL/DxilModule.h

@@ -354,7 +354,6 @@ private:
   bool m_ForceZeroStoreLifetimes = false;
 
   std::unique_ptr<OP> m_pOP;
-  size_t m_pUnused = 0;
 
   // LLVM used.
   std::vector<llvm::GlobalVariable*> m_LLVMUsed;

+ 0 - 0
include/dxc/DxilRDATBuilder/DxilRDATBuilder.h → include/dxc/DxilContainer/DxilRDATBuilder.h


+ 0 - 0
include/dxc/DxilRDATBuilder/DxilRDATParts.h → include/dxc/DxilContainer/DxilRDATParts.h


+ 3 - 2
include/llvm/IR/Function.h

@@ -523,14 +523,15 @@ public:
   /// basic block inside.  This depends on there being a 'dot' and 'gv' program
   /// in your path.
   ///
-  void viewCFG() const;
+  LLVM_DUMP_METHOD void viewCFG() const; // HLSL Change - Add LLVM_DUMP_METHOD
 
   /// viewCFGOnly - This function is meant for use from the debugger.  It works
   /// just like viewCFG, but it does not include the contents of basic blocks
   /// into the nodes, just the label.  If you are only interested in the CFG
   /// this can make the graph smaller.
   ///
-  void viewCFGOnly() const;
+  // HLSL Change - Add LLVM_DUMP_METHOD
+  LLVM_DUMP_METHOD void viewCFGOnly() const;
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const Value *V) {

+ 1 - 1
include/llvm/IR/Module.h

@@ -662,7 +662,7 @@ public:
              bool ShouldPreserveUseListOrder = false) const;
 
   /// Dump the module to stderr (for debugging).
-  void dump() const;
+  LLVM_DUMP_METHOD void dump() const; // HLSL Change - Add LLVM_DUMP_METHOD
   
   /// This function causes all the subinstructions to "let go" of all references
   /// that they are maintaining.  This allows one to 'delete' a whole class at

+ 1 - 1
include/llvm/IR/Type.h

@@ -119,7 +119,7 @@ protected:
 
 public:
   void print(raw_ostream &O) const;
-  void dump() const;
+  LLVM_DUMP_METHOD void dump() const; // HLSL Change - Add LLVM_DUMP_METHOD
 
   /// getContext - Return the LLVMContext in which this type was uniqued.
   LLVMContext &getContext() const { return Context; }

+ 22 - 0
lib/Analysis/Analysis.cpp

@@ -18,6 +18,26 @@
 
 using namespace llvm;
 
+// HLSL Change Begin - Windows doesn't support __attribute__((used)) so these methods
+// need to be forcibly bound or they could be stripped at build time.
+#if defined(_MSC_VER) && (!defined(NDEBUG) || defined(LLVM_ENABLE_DUMP))
+#pragma optimize("", off)
+void BindDumpMethods() {
+  // Pin LLVM dump methods.
+  void (__thiscall Module::*pfnModuleDump)() const = &Module::dump;
+  (void)pfnModuleDump;
+  void (__thiscall Type::*pfnTypeDump)() const = &Type::dump;
+  (void)pfnTypeDump;
+  void (__thiscall Function::*pfnViewCFGOnly)() const = &Function::viewCFGOnly;
+  (void)pfnViewCFGOnly;
+}
+#pragma optimize("", on)
+#define HLSL_BIND_DUMP_METHODS BindDumpMethods();
+#else
+#define HLSL_BIND_DUMP_METHODS
+#endif
+// HLSL Change End
+
 /// initializeAnalysis - Initialize all passes linked into the Analysis library.
 void llvm::initializeAnalysis(PassRegistry &Registry) {
   initializeAliasAnalysisAnalysisGroup(Registry);
@@ -69,6 +89,8 @@ void llvm::initializeAnalysis(PassRegistry &Registry) {
   initializeTargetTransformInfoWrapperPassPass(Registry);
   initializeTypeBasedAliasAnalysisPass(Registry);
   initializeScopedNoAliasAAPass(Registry);
+
+  HLSL_BIND_DUMP_METHODS // HLSL Change - Force binding dump methods.
 }
 
 void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {

+ 0 - 1
lib/Analysis/CMakeLists.txt

@@ -76,7 +76,6 @@ add_llvm_library(LLVMAnalysis
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Analysis
   )
 
-target_link_libraries(LLVMAnalysis INTERFACE LLVMDXIL) # HLSL Change
 add_dependencies(LLVMAnalysis intrinsics_gen)
 
 add_subdirectory(IPA)

+ 1 - 1
lib/Analysis/LLVMBuild.txt

@@ -22,4 +22,4 @@ subdirectories = IPA
 type = Library
 name = Analysis
 parent = Libraries
-required_libraries = Core Support
+required_libraries = Core DXIL Support

+ 0 - 1
lib/CMakeLists.txt

@@ -25,7 +25,6 @@ add_subdirectory(DxcSupport) # HLSL Change
 add_subdirectory(HLSL) # HLSL Change
 add_subdirectory(DXIL) # HLSL Change
 add_subdirectory(DxilContainer) # HLSL Change
-add_subdirectory(DxilRDATBuilder) # HLSL Change
 add_subdirectory(DxilPdbInfo) # HLSL Change
 add_subdirectory(DxilPIXPasses) # HLSL Change
 if(WIN32) # HLSL Change

+ 0 - 9
lib/DXIL/DxilModule.cpp

@@ -105,15 +105,6 @@ DxilModule::DxilModule(Module *pModule)
 
   DXASSERT_NOMSG(m_pModule != nullptr);
   SetDxilHook(*m_pModule);
-
-#ifndef NDEBUG
-  // Pin LLVM dump methods.
-  void (__thiscall Module::*pfnModuleDump)() const = &Module::dump;
-  void (__thiscall Type::*pfnTypeDump)() const = &Type::dump;
-  void (__thiscall Function::*pfnViewCFGOnly)() const = &Function::viewCFGOnly;
-  m_pUnused = (char *)&pfnModuleDump - (char *)&pfnTypeDump;
-  m_pUnused -= (size_t)&pfnViewCFGOnly;
-#endif
 }
 
 DxilModule::~DxilModule() { ClearDxilHook(*m_pModule); }

+ 1 - 1
lib/DXIL/LLVMBuild.txt

@@ -13,4 +13,4 @@
 type = Library
 name = DXIL
 parent = Libraries
-required_libraries = Analysis BitReader Core DxcSupport Support
+required_libraries = BitReader Core DxcSupport Support

+ 1 - 0
lib/DxilContainer/CMakeLists.txt

@@ -5,6 +5,7 @@ add_llvm_library(LLVMDxilContainer
   DxilContainerAssembler.cpp
   DxilContainerReader.cpp
   DxcContainerBuilder.cpp
+  DxilRDATBuilder.cpp
   DxilRuntimeReflection.cpp
   RDATDxilSubobjects.cpp
 

+ 1 - 1
lib/DxilContainer/DxilContainerAssembler.cpp

@@ -36,9 +36,9 @@
 #include "dxc/Support/dxcapi.impl.h"
 #include <assert.h> // Needed for DxilPipelineStateValidation.h
 #include "dxc/DxilContainer/DxilPipelineStateValidation.h"
+#include "dxc/DxilContainer/DxilRDATBuilder.h"
 #include "dxc/DxilContainer/DxilRuntimeReflection.h"
 #include "dxc/DXIL/DxilCounters.h"
-#include "dxc/DxilRDATBuilder/DxilRDATBuilder.h"
 #include <algorithm>
 #include <functional>
 

+ 1 - 1
lib/DxilRDATBuilder/DxilRDATBuilder.cpp → lib/DxilContainer/DxilRDATBuilder.cpp

@@ -1,5 +1,5 @@
 #include "dxc/Support/Global.h"
-#include "dxc/DxilRDATBuilder/DxilRDATBuilder.h"
+#include "dxc/DxilContainer/DxilRDATBuilder.h"
 #include "dxc/DxilContainer/DxilPipelineStateValidation.h"
 #include "dxc/Support/FileIOHelper.h"
 

+ 1 - 1
lib/DxilContainer/LLVMBuild.txt

@@ -13,4 +13,4 @@
 type = Library
 name = DxilContainer
 parent = Libraries
-required_libraries = BitReader BitWriter Core DxcSupport IPA Support DXIL DxilRDATBuilder
+required_libraries = BitReader BitWriter Core DxcSupport IPA Support DXIL

+ 1 - 1
lib/DxilPIXPasses/LLVMBuild.txt

@@ -13,4 +13,4 @@
 type = Library
 name = DxilPIXPasses
 parent = Libraries
-required_libraries = BitReader Core DxcSupport IPA Support
+required_libraries = BitReader Core DxcSupport TransformUtils Support

+ 1 - 1
lib/DxilPdbInfo/LLVMBuild.txt

@@ -13,5 +13,5 @@
 type = Library
 name = DxilPdbInfo
 parent = Libraries
-required_libraries = DxilRDATBuilder Core Support
+required_libraries = Core Support DxcSupport DxilContainer
 

+ 0 - 10
lib/DxilRDATBuilder/CMakeLists.txt

@@ -1,10 +0,0 @@
-# Copyright (C) Microsoft Corporation. All rights reserved.
-# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
-add_llvm_library(LLVMDxilRDATBuilder
-  DxilRDATBuilder.cpp
-
-  ADDITIONAL_HEADER_DIRS
-  ${LLVM_MAIN_INCLUDE_DIR}/llvm/IR
-)
-
-add_dependencies(LLVMDxilRDATBuilder intrinsics_gen)

+ 0 - 16
lib/DxilRDATBuilder/LLVMBuild.txt

@@ -1,16 +0,0 @@
-; Copyright (C) Microsoft Corporation. All rights reserved.
-; This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
-;
-; This is an LLVMBuild description file for the components in this subdirectory.
-;
-; For more information on the LLVMBuild system, please see:
-;
-;   http://llvm.org/docs/LLVMBuild.html
-;
-;===------------------------------------------------------------------------===;
-
-[component_0]
-type = Library
-name = DxilRDATBuilder
-parent = Libraries
-required_libraries = Support

+ 1 - 1
lib/DxilRootSignature/LLVMBuild.txt

@@ -13,4 +13,4 @@
 type = Library
 name = DxilRootSignature
 parent = Libraries
-required_libraries = BitReader Core DxcSupport IPA Support
+required_libraries = BitReader Core DXIL DxilContainer DxcSupport IPA Support

+ 0 - 1
lib/LLVMBuild.txt

@@ -41,7 +41,6 @@ subdirectories =
  HLSL
  DXIL
  DxilContainer
- DxilRDATBuilder
  DxilPdbInfo
  DxilDia
  DxrFallback

+ 0 - 1
unittests/Analysis/CMakeLists.txt

@@ -1,5 +1,4 @@
 set(LLVM_LINK_COMPONENTS
-  DXIL # HLSL Change
   IPA
   Analysis
   AsmParser

+ 0 - 1
unittests/IR/CMakeLists.txt

@@ -2,7 +2,6 @@ set(LLVM_LINK_COMPONENTS
   Analysis
   AsmParser
   Core
-  DXIL  # HLSL Change
   IPA
   Support
   )