Skip to content

Commit

Permalink
Merge pull request #5045 from pow2clk/cp-release-1.7.2212
Browse files Browse the repository at this point in the history
Merge relevant changes into release 1.7.2212

7ce4986 Fix opt.exe external lib loading (#5049)
8f4d1f4 PIX: DxcPixDxilInstructionOffsets should operate on libs (#5046)
0795b94 Fix AppVeyor Linux tests failing loading dxil.so (#5024)
6d3574a Remove SO version from unix binaries (#5010)
6d480fd Allow libdxcompiler.so and dxc to find libdxil.so (#5004)
d751bd8 Correct WinAdapter path assumptions in public headers (#5003)
484f1b0 Fix instruction order issue in scalarizer (#5001)
d9d83d0 Fix two issues found in our internal build (#5002)
c8603e4 Added a workaround for PDBs with empty defines. (#4945)
073d860 [bug] Fix memory leak in dxil validator (#4966)
87fc5b5 PIX: Symbol manager: don't allow static members to contribute to member offsets (#4952)
8588ecb Turn off structurize-returns when cleanup blocks are present. (#4927)
bac7aa7 build: disable LLVM_ENABLE_TERMINFO by default. (#4908)
  • Loading branch information
pow2clk authored Feb 27, 2023
2 parents e8c4673 + 7ce4986 commit f949bca
Show file tree
Hide file tree
Showing 38 changed files with 886 additions and 96 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ endif()

include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})

include_directories( ${LLVM_MAIN_INCLUDE_DIR}/dxc/Support) # HLSL Change
include_directories( ${LLVM_INCLUDE_DIR}/dxc/Tracing) # HLSL Change

# when crosscompiling import the executable targets from a file
Expand Down
27 changes: 14 additions & 13 deletions cmake/caches/PredefinedParams.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ set(LLVM_INCLUDE_TESTS ${LLVM_TEST_VALUE} CACHE BOOL "")
set(CLANG_INCLUDE_TESTS ${LLVM_TEST_VALUE} CACHE BOOL "")

set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "")
set(LLVM_APPEND_VC_REV ON CACHE BOOL "")
set(LLVM_APPEND_VC_REV ON CACHE BOOL "")
set(LLVM_DEFAULT_TARGET_TRIPLE "dxil-ms-dx" CACHE STRING "")
set(LLVM_ENABLE_EH ON CACHE BOOL "")
set(LLVM_ENABLE_RTTI ON CACHE BOOL "")
set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
set(LLVM_OPTIMIZED_TABLEGEN OFF CACHE BOOL "")
set(LLVM_ENABLE_EH ON CACHE BOOL "")
set(LLVM_ENABLE_RTTI ON CACHE BOOL "")
set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
set(LLVM_OPTIMIZED_TABLEGEN OFF CACHE BOOL "")
set(LLVM_TARGETS_TO_BUILD "None" CACHE STRING "")
set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
set(CLANG_BUILD_EXAMPLES OFF CACHE BOOL "")
set(CLANG_CL OFF CACHE BOOL "")
set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
set(HLSL_INCLUDE_TESTS ON CACHE BOOL "")
set(ENABLE_SPIRV_CODEGEN ON CACHE BOOL "")
set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
set(CLANG_BUILD_EXAMPLES OFF CACHE BOOL "")
set(CLANG_CL OFF CACHE BOOL "")
set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
set(HLSL_INCLUDE_TESTS ON CACHE BOOL "")
set(ENABLE_SPIRV_CODEGEN ON CACHE BOOL "")
set(SPIRV_BUILD_TESTS ON CACHE BOOL "")
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
12 changes: 11 additions & 1 deletion cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,20 @@ function(llvm_add_library name)
)
endif()

# HLSL Change Begin - Don't generate so versioned files.
set_target_properties(${name}
PROPERTIES
SOVERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}
NO_SONAME On)
if (APPLE)
set_property(TARGET ${name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-install_name,@rpath/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
elseif(UNIX)
set_property(TARGET ${name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-soname,${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()
# HLSL Change End - Don't generate so versioned files.
endif()

if(ARG_MODULE OR ARG_SHARED)
Expand Down
43 changes: 18 additions & 25 deletions include/dxc/Support/dxcapi.use.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,41 @@

namespace dxc {

extern const char* kDxCompilerLib;
extern const char* kDxilLib;

// Helper class to dynamically load the dxcompiler or a compatible libraries.
class DxcDllSupport {
protected:
HMODULE m_dll;
DxcCreateInstanceProc m_createFn;
DxcCreateInstance2Proc m_createFn2;

HRESULT InitializeInternal(LPCWSTR dllName, LPCSTR fnName) {
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) {
if (m_dll != nullptr) return S_OK;

#ifdef _WIN32
m_dll = LoadLibraryW(dllName);
#else
char nameStr[256];
std::wcstombs(nameStr, dllName, 256);
m_dll = ::dlopen(nameStr, RTLD_LAZY);
#endif

m_dll = LoadLibraryA(dllName);
if (m_dll == nullptr) return HRESULT_FROM_WIN32(GetLastError());

#ifdef _WIN32
m_createFn = (DxcCreateInstanceProc)GetProcAddress(m_dll, fnName);
#else
m_createFn = (DxcCreateInstanceProc)::dlsym(m_dll, fnName);
#endif


if (m_createFn == nullptr) {
HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
#ifdef _WIN32
FreeLibrary(m_dll);
m_dll = nullptr;
return hr;
}
#else
m_dll = ::dlopen(dllName, RTLD_LAZY);
if (m_dll == nullptr) return E_FAIL;
m_createFn = (DxcCreateInstanceProc)::dlsym(m_dll, fnName);

if (m_createFn == nullptr) {
::dlclose(m_dll);
#endif
m_dll = nullptr;
return hr;
return E_FAIL;
}
#endif

// Only basic functions used to avoid requiring additional headers.
m_createFn2 = nullptr;
Expand Down Expand Up @@ -86,16 +85,10 @@ class DxcDllSupport {
}

HRESULT Initialize() {
#ifdef _WIN32
return InitializeInternal(L"dxcompiler.dll", "DxcCreateInstance");
#elif __APPLE__
return InitializeInternal(L"libdxcompiler.dylib", "DxcCreateInstance");
#else
return InitializeInternal(L"libdxcompiler.so", "DxcCreateInstance");
#endif
return InitializeInternal(kDxCompilerLib, "DxcCreateInstance");
}

HRESULT InitializeForDll(_In_z_ const wchar_t* dll, _In_z_ const char* entryPoint) {
HRESULT InitializeForDll(_In_z_ LPCSTR dll, _In_z_ LPCSTR entryPoint) {
return InitializeInternal(dll, entryPoint);
}

Expand Down
2 changes: 1 addition & 1 deletion include/dxc/dxcapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#else

#include <dlfcn.h>
#include "dxc/Support/WinAdapter.h"
#include "WinAdapter.h"
#endif

struct IMalloc;
Expand Down
2 changes: 1 addition & 1 deletion include/dxc/dxcisense.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "dxcapi.h"
#ifndef _WIN32
#include "Support/WinAdapter.h"
#include "WinAdapter.h"
#endif

typedef enum DxcGlobalOptions
Expand Down
8 changes: 8 additions & 0 deletions lib/DxcSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ add_llvm_library(LLVMDxcSupport
WinFunctions.cpp
)

#generate header with platform-specific library name
configure_file(
${LLVM_MAIN_SRC_DIR}/lib/DxcSupport/SharedLibAffix.inc
SharedLibAffix.h
)

include_directories( ${LLVM_INCLUDE_DIR}/DxcSupport) #needed to find the generated header

add_dependencies(LLVMDxcSupport TablegenHLSLOptions)
3 changes: 1 addition & 2 deletions lib/DxcSupport/HLSLOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,9 +1183,8 @@ int SetupDxcDllSupport(const DxcOpts &opts, dxc::DxcDllSupport &dxcSupport,
llvm::raw_ostream &errors) {
if (!opts.ExternalLib.empty()) {
DXASSERT(!opts.ExternalFn.empty(), "else ReadDxcOpts should have failed");
StringRefWide externalLib(opts.ExternalLib);
HRESULT hrLoad =
dxcSupport.InitializeForDll(externalLib, opts.ExternalFn.data());
dxcSupport.InitializeForDll(opts.ExternalLib.data(), opts.ExternalFn.data());
if (DXC_FAILED(hrLoad)) {
errors << "Unable to load support for external DLL " << opts.ExternalLib
<< " with function " << opts.ExternalFn << " - error 0x";
Expand Down
24 changes: 24 additions & 0 deletions lib/DxcSupport/SharedLibAffix.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
///////////////////////////////////////////////////////////////////////////////
// //
// SharedLibAffix.inc //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Defines shared library prefixes and suffixes for the build platform. //
// //
///////////////////////////////////////////////////////////////////////////////


#pragma once

#cmakedefine CMAKE_SHARED_LIBRARY_PREFIX "@CMAKE_SHARED_LIBRARY_PREFIX@"
#cmakedefine CMAKE_SHARED_LIBRARY_SUFFIX "@CMAKE_SHARED_LIBRARY_SUFFIX@"

#ifndef CMAKE_SHARED_LIBRARY_PREFIX
#define CMAKE_SHARED_LIBRARY_PREFIX
#endif

#ifndef CMAKE_SHARED_LIBRARY_SUFFIX
#define CMAKE_SHARED_LIBRARY_SUFFIX
#endif
4 changes: 4 additions & 0 deletions lib/DxcSupport/dxcapi.use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
#include "dxc/Support/Unicode.h"
#include "dxc/Support/FileIOHelper.h"
#include "dxc/Support/WinFunctions.h"
#include "SharedLibAffix.h"

namespace dxc {

const char* kDxCompilerLib = CMAKE_SHARED_LIBRARY_PREFIX "dxcompiler" CMAKE_SHARED_LIBRARY_SUFFIX;
const char* kDxilLib = CMAKE_SHARED_LIBRARY_PREFIX "dxil" CMAKE_SHARED_LIBRARY_SUFFIX;

#ifdef _WIN32
static void TrimEOL(_Inout_z_ char *pMsg) {
char *pEnd = pMsg + strlen(pMsg);
Expand Down
40 changes: 22 additions & 18 deletions lib/DxilDia/DxcPixDxilDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
// //
///////////////////////////////////////////////////////////////////////////////

#include "dxc/DXIL/DxilOperations.h"

#include "dxc/Support/WinIncludes.h"

#include "dxc/Support/exception.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Module.h"

#include "DxcPixLiveVariables.h"
#include "DxcPixDxilDebugInfo.h"
Expand Down Expand Up @@ -172,24 +175,25 @@ dxil_debug_info::DxcPixDxilInstructionOffsets::DxcPixDxilInstructionOffsets(
{
assert(SourceColumn == 0);
(void)SourceColumn;
auto Fn = pSession->DxilModuleRef().GetEntryFunction();
auto &Blocks = Fn->getBasicBlockList();
for (auto& CurrentBlock : Blocks) {
auto& Is = CurrentBlock.getInstList();
for (auto& Inst : Is) {
auto & debugLoc = Inst.getDebugLoc();
if (debugLoc)
{
unsigned line = debugLoc.getLine();
if (line == SourceLine)
{
auto file = debugLoc.get()->getFilename();
if (CompareFilenames(FileName, file.str().c_str()))
{
std::uint32_t InstructionNumber;
if (pix_dxil::PixDxilInstNum::FromInst(&Inst, &InstructionNumber))
{
m_offsets.push_back(InstructionNumber);
for (llvm::Function &Fn :
pSession->DxilModuleRef().GetModule()->functions()) {
if (Fn.isDeclaration() || Fn.isIntrinsic() || hlsl::OP::IsDxilOpFunc(&Fn))
continue;
auto &Blocks = Fn.getBasicBlockList();
for (auto &CurrentBlock : Blocks) {
auto &Is = CurrentBlock.getInstList();
for (auto &Inst : Is) {
auto &debugLoc = Inst.getDebugLoc();
if (debugLoc) {
unsigned line = debugLoc.getLine();
if (line == SourceLine) {
auto file = debugLoc.get()->getFilename();
if (CompareFilenames(FileName, file.str().c_str())) {
std::uint32_t InstructionNumber;
if (pix_dxil::PixDxilInstNum::FromInst(&Inst,
&InstructionNumber)) {
m_offsets.push_back(InstructionNumber);
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions lib/DxilDia/DxilDiaSymbolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,11 @@ HRESULT dxil_dia::hlsl_symbols::SymbolManagerInit::CreateCompositeType(DWORD dwP
} else {
for (llvm::DINode *N : CT->getElements()) {
if (auto *Field = llvm::dyn_cast<llvm::DIType>(N)) {
std::unique_ptr<UDTScope> UDTScopeOverride;
if (Field->isStaticMember()) {
// Static members do not contribute to sizes or offsets.
UDTScopeOverride.reset(new UDTScope(&m_pCurUDT, nullptr));
}
DWORD dwUnusedFieldID;
IFR(CreateType(Field, &dwUnusedFieldID));
if (Field->getTag() == llvm::dwarf::DW_TAG_inheritance) {
Expand Down
2 changes: 1 addition & 1 deletion lib/HLSL/DxilValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5563,7 +5563,7 @@ static void VerifyRDATMatches(_In_ ValidationContext &ValCtx,
VerifyBlobPartMatches(ValCtx, PartName, pWriter.get(), pRDATData, RDATSize);

// Verify no errors when runtime reflection from RDAT:
RDAT::DxilRuntimeReflection *pReflection = RDAT::CreateDxilRuntimeReflection();
unique_ptr<RDAT::DxilRuntimeReflection> pReflection(RDAT::CreateDxilRuntimeReflection());
if (!pReflection->InitFromRDAT(pRDATData, RDATSize)) {
ValCtx.EmitFormatError(ValidationRule::ContainerPartMatches, { PartName });
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/Transforms/Scalar/Scalarizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ bool Scalarizer::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
// instruction is processed, it will be replaced without updating our
// Gather entry. This dead instruction will be accessed by finish(),
// causing assert or crash.
Res[I] = IRBuilder<>(SVI.getNextNode()).Insert(EA->clone());
Res[I] = IRBuilder<>(&SVI).Insert(EA->clone());
}
// HLSL Change Ends
}
Expand Down
2 changes: 1 addition & 1 deletion projects/dxilconv/unittests/DxilConvTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class DxilConvTest {

bool DxilConvTest::InitSupport() {
if (!m_dllSupport.IsEnabled()) {
VERIFY_SUCCEEDED(m_dllSupport.InitializeForDll(L"dxilconv.dll", "DxcCreateInstance"));
VERIFY_SUCCEEDED(m_dllSupport.InitializeForDll("dxilconv.dll", "DxcCreateInstance"));
}

if (!FindToolInBinDir("%dxbc2dxil", "dxbc2dxil.exe")) {
Expand Down
1 change: 1 addition & 0 deletions tools/clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -798,4 +798,5 @@ def HLSLPayloadAccessQualifer: DiagGroup<"payload-access-qualifier", [
HLSLPayloadAccessQualiferCall
]>;
def HLSLSemanticIdentifierCollision : DiagGroup<"semantic-identifier-collision">;
def HLSLStructurizeExitsLifetimeMarkersConflict: DiagGroup<"structurize-exits-lifetime-markers-conflict">;
// HLSL Change Ends
3 changes: 3 additions & 0 deletions tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -7754,6 +7754,9 @@ def err_hlsl_logical_binop_scalar : Error<
"operands for short-circuiting logical binary operator must be scalar, for non-scalar types use '%select{and|or}0'">;
def err_hlsl_ternary_scalar : Error<
"condition for short-circuiting ternary operator must be scalar, for non-scalar types use 'select'">;
def warn_hlsl_structurize_exits_lifetime_markers_conflict : Warning <
"structurize-returns skipped function '%0' due to incompatibility with lifetime markers. Use -disable-lifetime-markers to enable structurize-exits on this function.">,
InGroup< HLSLStructurizeExitsLifetimeMarkersConflict >;
// HLSL Change Ends

// SPIRV Change Starts
Expand Down
6 changes: 3 additions & 3 deletions tools/clang/include/clang/SPIRV/SpirvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace spirv {
struct StringMapInfo {
static inline std::string getEmptyKey() { return ""; }
static inline std::string getTombstoneKey() { return ""; }
static unsigned getHashValue(const std::string Val) {
static unsigned getHashValue(const std::string& Val) {
return llvm::hash_combine(Val);
}
static bool isEqual(const std::string LHS, const std::string RHS) {
static bool isEqual(const std::string& LHS, const std::string& RHS) {
// Either both are null, or both should have the same underlying type.
return LHS == RHS;
}
Expand Down Expand Up @@ -851,7 +851,7 @@ class SpirvBuilder {
// kept track of separately. This is because the empty string is used
// as the EmptyKey and TombstoneKey for the map, prohibiting insertion
// of the empty string as a contained value.
llvm::DenseMap<llvm::StringRef, SpirvString *, StringMapInfo> stringLiterals;
llvm::DenseMap<std::string, SpirvString *, StringMapInfo> stringLiterals;
SpirvString *emptyString;

/// Mapping of CTBuffers including matrix 1xN with FXC memory layout to their
Expand Down
2 changes: 2 additions & 0 deletions tools/clang/lib/CodeGen/CGCleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "CGCleanup.h"
#include "CodeGenFunction.h"
#include "CGHLSLRuntime.h" // HLSL Change

using namespace clang;
using namespace CodeGen;
Expand Down Expand Up @@ -435,6 +436,7 @@ static llvm::BasicBlock *CreateNormalEntry(CodeGenFunction &CGF,
if (!Entry) {
Entry = CGF.createBasicBlock("cleanup");
Scope.setNormalBlock(Entry);
CGF.CGM.getHLSLRuntime().MarkCleanupBlock(CGF, Entry); // HLSL Change
}
return Entry;
}
Expand Down
Loading

0 comments on commit f949bca

Please sign in to comment.