diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a253f3915..238bb39d7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,13 @@ mark_as_advanced(DXC_DISABLE_ALLOCATOR_OVERRIDES) option(DXC_CODEGEN_EXCEPTIONS_TRAP "An exception in code generation generates a trap, ending the compiler process" OFF) mark_as_advanced(DXC_CODEGEN_EXCEPTIONS_TRAP) +option(DXC_ENABLE_ETW "Compile with ETW Tracing" ON) +mark_as_advanced(DXC_ENABLE_ETW) + +if(DXC_ENABLE_ETW) + add_compile_definitions(DXC_ENABLE_ETW) +endif() + # adjust link option to enable debugging from kernel mode; not compatible with incremental linking if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND MSVC AND NOT CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "ARM64EC") add_link_options(/DEBUGTYPE:CV,FIXUP,PDATA /INCREMENTAL:NO) @@ -108,7 +115,9 @@ endif() if(MSVC) # use new Standard Conforming Preprocessor # https://learn.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview?view=msvc-170 - add_compile_options(/Zc:preprocessor) + if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") + add_compile_options(/Zc:preprocessor) + endif() endif() # enable control flow guard diff --git a/include/dxc/Support/dxcapi.use.h b/include/dxc/Support/dxcapi.use.h index 44fe23bad6..747a7ca2dd 100644 --- a/include/dxc/Support/dxcapi.use.h +++ b/include/dxc/Support/dxcapi.use.h @@ -34,7 +34,7 @@ class DxcDllSupport { m_dll = LoadLibraryA(dllName); if (m_dll == nullptr) return HRESULT_FROM_WIN32(GetLastError()); - m_createFn = (DxcCreateInstanceProc)GetProcAddress(m_dll, fnName); + m_createFn = reinterpret_cast(reinterpret_cast(GetProcAddress(m_dll, fnName))); if (m_createFn == nullptr) { HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); @@ -64,7 +64,7 @@ class DxcDllSupport { fnName2[s] = '2'; fnName2[s + 1] = '\0'; #ifdef _WIN32 - m_createFn2 = (DxcCreateInstance2Proc)GetProcAddress(m_dll, fnName2); + m_createFn2 = reinterpret_cast(reinterpret_cast(GetProcAddress(m_dll, fnName2))); #else m_createFn2 = (DxcCreateInstance2Proc)::dlsym(m_dll, fnName2); #endif diff --git a/include/dxc/WinAdapter.h b/include/dxc/WinAdapter.h index d02ad1ac38..b034681c22 100644 --- a/include/dxc/WinAdapter.h +++ b/include/dxc/WinAdapter.h @@ -198,19 +198,8 @@ #define OutputDebugStringA(msg) fputs(msg, stderr) #define OutputDebugFormatA(...) fprintf(stderr, __VA_ARGS__) -// Event Tracing for Windows (ETW) provides application programmers the ability -// to start and stop event tracing sessions, instrument an application to -// provide trace events, and consume trace events. -#define DxcEtw_DXCompilerCreateInstance_Start() -#define DxcEtw_DXCompilerCreateInstance_Stop(hr) -#define DxcEtw_DXCompilerCompile_Start() -#define DxcEtw_DXCompilerCompile_Stop(hr) -#define DxcEtw_DXCompilerDisassemble_Start() -#define DxcEtw_DXCompilerDisassemble_Stop(hr) -#define DxcEtw_DXCompilerPreprocess_Start() -#define DxcEtw_DXCompilerPreprocess_Stop(hr) -#define DxcEtw_DxcValidation_Start() -#define DxcEtw_DxcValidation_Stop(hr) +// I have no idea if I don't break something like INSTALL targets, requires CI tests +#include "WinEtwAdapter.h" #define UInt32Add UIntAdd #define Int32ToUInt32 IntToUInt diff --git a/include/dxc/WinEtwAdapter.h b/include/dxc/WinEtwAdapter.h new file mode 100644 index 0000000000..67771d6c6c --- /dev/null +++ b/include/dxc/WinEtwAdapter.h @@ -0,0 +1,33 @@ +//===- WinEtwAdapter.h - Windows ETW Adapter, stub -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_WIN_ETW_ADAPTER_H +#define LLVM_SUPPORT_WIN_ETW_ADAPTER_H + +// Event Tracing for Windows (ETW) provides application programmers the ability +// to start and stop event tracing sessions, instrument an application to +// provide trace events, and consume trace events. +#define EventRegisterMicrosoft_Windows_DXCompiler_API() +#define EventUnregisterMicrosoft_Windows_DXCompiler_API() +#define DxcEtw_DXCompilerCreateInstance_Start() +#define DxcEtw_DXCompilerCreateInstance_Stop(hr) +#define DxcEtw_DXCompilerInitialization_Start() +#define DxcEtw_DXCompilerInitialization_Stop(hr) +#define DxcEtw_DXCompilerShutdown_Start() +#define DxcEtw_DXCompilerShutdown_Stop(hr) +#define DxcEtw_DXCompilerCompile_Start() +#define DxcEtw_DXCompilerCompile_Stop(hr) +#define DxcEtw_DXCompilerDisassemble_Start() +#define DxcEtw_DXCompilerDisassemble_Stop(hr) +#define DxcEtw_DXCompilerPreprocess_Start() +#define DxcEtw_DXCompilerPreprocess_Stop(hr) +#define DxcEtw_DxcValidation_Start() +#define DxcEtw_DxcValidation_Stop(hr) + +#endif // LLVM_SUPPORT_WIN_ETW_ADAPTER_H diff --git a/include/llvm/CodeGen/SchedulerRegistry.h b/include/llvm/CodeGen/SchedulerRegistry.h index e4570a8adc..04d2441259 100644 --- a/include/llvm/CodeGen/SchedulerRegistry.h +++ b/include/llvm/CodeGen/SchedulerRegistry.h @@ -40,7 +40,7 @@ class RegisterScheduler : public MachinePassRegistryNode { static MachinePassRegistry Registry; RegisterScheduler(const char *N, const char *D, FunctionPassCtor C) - : MachinePassRegistryNode(N, D, (MachinePassCtor)C) + : MachinePassRegistryNode(N, D, reinterpret_cast(reinterpret_cast(C))) { Registry.Add(this); } ~RegisterScheduler() { Registry.Remove(this); } @@ -54,10 +54,10 @@ class RegisterScheduler : public MachinePassRegistryNode { return (RegisterScheduler *)Registry.getList(); } static FunctionPassCtor getDefault() { - return (FunctionPassCtor)Registry.getDefault(); + return reinterpret_cast(reinterpret_cast(Registry.getDefault())); } static void setDefault(FunctionPassCtor C) { - Registry.setDefault((MachinePassCtor)C); + Registry.setDefault(reinterpret_cast(reinterpret_cast(C))); } static void setListener(MachinePassRegistryListener *L) { Registry.setListener(L); diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 2c00a2522c..490ef5cc30 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -90,7 +90,8 @@ void LLVMContextSetDiagnosticHandler(LLVMContextRef C, LLVMDiagnosticHandler Handler, void *DiagnosticContext) { unwrap(C)->setDiagnosticHandler( - LLVM_EXTENSION reinterpret_cast(Handler), + reinterpret_cast( + reinterpret_cast(Handler)), DiagnosticContext); } diff --git a/lib/MSSupport/MSFileSystemImpl.cpp b/lib/MSSupport/MSFileSystemImpl.cpp index 38fc105d7a..ca734f7b4d 100644 --- a/lib/MSSupport/MSFileSystemImpl.cpp +++ b/lib/MSSupport/MSFileSystemImpl.cpp @@ -322,8 +322,9 @@ typedef BOOLEAN(WINAPI *PtrCreateSymbolicLinkW)( /*__in*/ DWORD dwFlags); PtrCreateSymbolicLinkW create_symbolic_link_api = - PtrCreateSymbolicLinkW(::GetProcAddress(::GetModuleHandleW(L"Kernel32.dll"), - "CreateSymbolicLinkW")); + PtrCreateSymbolicLinkW(reinterpret_cast(::GetProcAddress( + ::GetModuleHandleW(L"Kernel32.dll"), + "CreateSymbolicLinkW"))); } // namespace #endif diff --git a/lib/Support/Windows/RWMutex.inc b/lib/Support/Windows/RWMutex.inc index d7ab99f45e..4691a56328 100644 --- a/lib/Support/Windows/RWMutex.inc +++ b/lib/Support/Windows/RWMutex.inc @@ -49,21 +49,16 @@ static bool loadSRW() { sChecked = true; if (HMODULE hLib = ::GetModuleHandleW(L"Kernel32.dll")) { - fpInitializeSRWLock = - (VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib, - "InitializeSRWLock"); - fpAcquireSRWLockExclusive = - (VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib, - "AcquireSRWLockExclusive"); - fpAcquireSRWLockShared = - (VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib, - "AcquireSRWLockShared"); - fpReleaseSRWLockExclusive = - (VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib, - "ReleaseSRWLockExclusive"); - fpReleaseSRWLockShared = - (VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib, - "ReleaseSRWLockShared"); + fpInitializeSRWLock = reinterpret_cast( + reinterpret_cast(::GetProcAddress(hLib, "InitializeSRWLock"))); + fpAcquireSRWLockExclusive = reinterpret_cast( + reinterpret_cast(::GetProcAddress(hLib, "AcquireSRWLockExclusive"))); + fpAcquireSRWLockShared = reinterpret_cast( + reinterpret_cast(::GetProcAddress(hLib, "AcquireSRWLockShared"))); + fpReleaseSRWLockExclusive = reinterpret_cast( + reinterpret_cast(::GetProcAddress(hLib, "ReleaseSRWLockExclusive"))); + fpReleaseSRWLockShared = reinterpret_cast( + reinterpret_cast(::GetProcAddress(hLib, "ReleaseSRWLockShared"))); if (fpInitializeSRWLock != NULL) { sHasSRW = true; @@ -73,6 +68,7 @@ static bool loadSRW() { return sHasSRW; } + RWMutexImpl::RWMutexImpl() { // TODO: harden to allocation failures - HLSL Change if (loadSRW()) { diff --git a/projects/dxilconv/tools/dxilconv/dxilconv.cpp b/projects/dxilconv/tools/dxilconv/dxilconv.cpp index 73d7f3df0e..f8dea8aa0e 100644 --- a/projects/dxilconv/tools/dxilconv/dxilconv.cpp +++ b/projects/dxilconv/tools/dxilconv/dxilconv.cpp @@ -23,7 +23,11 @@ #include "dxc/config.h" #include "dxc/dxcisense.h" #include "dxc/dxctools.h" +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #include "DxbcConverter.h" diff --git a/tools/clang/tools/dxcompiler/CMakeLists.txt b/tools/clang/tools/dxcompiler/CMakeLists.txt index c69e276194..513045669c 100644 --- a/tools/clang/tools/dxcompiler/CMakeLists.txt +++ b/tools/clang/tools/dxcompiler/CMakeLists.txt @@ -128,7 +128,8 @@ endif (MSVC) add_clang_library(dxcompiler SHARED ${SOURCES}) add_dependencies(dxcompiler TablegenHLSLOptions) -if (MSVC) + +if (MSVC AND DXC_ENABLE_ETW) # No DxcEtw on non-Windows platforms. add_dependencies(dxcompiler DxcEtw) endif() diff --git a/tools/clang/tools/dxcompiler/DXCompiler.cpp b/tools/clang/tools/dxcompiler/DXCompiler.cpp index c548441449..b502bba398 100644 --- a/tools/clang/tools/dxcompiler/DXCompiler.cpp +++ b/tools/clang/tools/dxcompiler/DXCompiler.cpp @@ -17,7 +17,11 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" #ifdef LLVM_ON_WIN32 +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #endif #include "dxillib.h" diff --git a/tools/clang/tools/dxcompiler/DXCompiler.rc b/tools/clang/tools/dxcompiler/DXCompiler.rc index 4bec9e092e..b79f272e37 100644 --- a/tools/clang/tools/dxcompiler/DXCompiler.rc +++ b/tools/clang/tools/dxcompiler/DXCompiler.rc @@ -11,4 +11,6 @@ #define VER_ORIGINALFILENAME_STR "DXCompiler.dll" // #include +#ifdef DXC_ENABLE_ETW #include "dxcetw.rc" +#endif \ No newline at end of file diff --git a/tools/clang/tools/dxcompiler/dxcapi.cpp b/tools/clang/tools/dxcompiler/dxcapi.cpp index a6a877cba4..a0736633ed 100644 --- a/tools/clang/tools/dxcompiler/dxcapi.cpp +++ b/tools/clang/tools/dxcompiler/dxcapi.cpp @@ -22,7 +22,11 @@ #include "dxc/dxcisense.h" #include "dxc/dxctools.h" #ifdef _WIN32 +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #endif #include "dxc/DxilContainer/DxcContainerBuilder.h" #include "dxillib.h" diff --git a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp index ebeee380ef..6f4c5c0ea7 100644 --- a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp +++ b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp @@ -51,7 +51,11 @@ #include "dxc/Support/microcom.h" #ifdef _WIN32 +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #endif #include "dxcompileradapter.h" #include "dxcshadersourceinfo.h" diff --git a/tools/clang/tools/dxcvalidator/dxcvalidator.cpp b/tools/clang/tools/dxcvalidator/dxcvalidator.cpp index 60ad35036f..ddcbdc357d 100644 --- a/tools/clang/tools/dxcvalidator/dxcvalidator.cpp +++ b/tools/clang/tools/dxcvalidator/dxcvalidator.cpp @@ -27,7 +27,11 @@ #include "dxc/Support/dxcapi.impl.h" #ifdef _WIN32 +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #endif using namespace llvm; diff --git a/tools/clang/tools/dxildll/dxildll.cpp b/tools/clang/tools/dxildll/dxildll.cpp index 12ca2026ca..51c7aa66f6 100644 --- a/tools/clang/tools/dxildll/dxildll.cpp +++ b/tools/clang/tools/dxildll/dxildll.cpp @@ -23,8 +23,12 @@ #include "llvm/Support/ManagedStatic.h" #include #ifdef _WIN32 +#ifdef DXC_ENABLE_ETW #include "Tracing/DxcRuntimeEtw.h" #include "dxc/Tracing/dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #endif #include "dxc/dxcisense.h" diff --git a/tools/clang/tools/dxrfallbackcompiler/DXCompiler.cpp b/tools/clang/tools/dxrfallbackcompiler/DXCompiler.cpp index 018bf1cf4a..bb703489fd 100644 --- a/tools/clang/tools/dxrfallbackcompiler/DXCompiler.cpp +++ b/tools/clang/tools/dxrfallbackcompiler/DXCompiler.cpp @@ -14,7 +14,11 @@ #include "dxc/Support/Global.h" #include "dxc/Support/HLSLOptions.h" #include "dxc/config.h" +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #include "dxillib.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" diff --git a/tools/clang/tools/dxrfallbackcompiler/DXCompiler.rc b/tools/clang/tools/dxrfallbackcompiler/DXCompiler.rc index 5fedc5d4c4..63d45c8214 100644 --- a/tools/clang/tools/dxrfallbackcompiler/DXCompiler.rc +++ b/tools/clang/tools/dxrfallbackcompiler/DXCompiler.rc @@ -11,4 +11,6 @@ #define VER_ORIGINALFILENAME_STR "DxrFallbackCompiler.dll" // #include +#ifdef DXC_ENABLE_ETW #include "dxcetw.rc" +#endif diff --git a/tools/clang/tools/dxrfallbackcompiler/dxcapi.cpp b/tools/clang/tools/dxrfallbackcompiler/dxcapi.cpp index f640ee6f47..9807956f52 100644 --- a/tools/clang/tools/dxrfallbackcompiler/dxcapi.cpp +++ b/tools/clang/tools/dxrfallbackcompiler/dxcapi.cpp @@ -16,7 +16,11 @@ #include "dxc/Support/Global.h" #include "dxc/dxcdxrfallbackcompiler.h" #include "dxc/dxctools.h" +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #include HRESULT CreateDxcDxrFallbackCompiler(REFIID riid, LPVOID *ppv);