Clean up and rework DXIL library depencencies (#4877) (#4919)

* 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.

(cherry picked from commit 2168dcb4fb)

Co-authored-by: Chris B <cbieneman@microsoft.com>
This commit is contained in:
Helena Kotas 2023-01-06 17:27:52 -08:00 коммит произвёл GitHub
Родитель 8c9d92be79
Коммит 83f8c6c5b7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
24 изменённых файлов: 36 добавлений и 53 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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

Просмотреть файл

@ -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; }

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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)

Просмотреть файл

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

Просмотреть файл

@ -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

Просмотреть файл

@ -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); }

Просмотреть файл

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

Просмотреть файл

@ -5,6 +5,7 @@ add_llvm_library(LLVMDxilContainer
DxilContainerAssembler.cpp
DxilContainerReader.cpp
DxcContainerBuilder.cpp
DxilRDATBuilder.cpp
DxilRuntimeReflection.cpp
RDATDxilSubobjects.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,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"

Просмотреть файл

@ -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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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)

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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