From 5c42a3cbc41122936e72bcf9618dffab8316fea1 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 26 Oct 2015 22:52:16 +0100 Subject: [PATCH] d3d12: Add a unreachable function used as debug/optimisation hint --- rpcs3/Emu/RSX/D3D12/D3D12Utils.cpp | 9 +++++ rpcs3/Emu/RSX/D3D12/D3D12Utils.h | 57 ++++++++++++++++++++++++++++++ rpcs3/stdafx_d3d12.h | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Utils.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Utils.cpp index 582bcfcc3d..5733d47970 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Utils.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Utils.cpp @@ -262,4 +262,13 @@ void D3D12GSRender::initConvertShader() p.first->Release(); p.second->Release(); } + +void unreachable_internal(const char *msg, const char *file, unsigned line) +{ + abort(); + #ifdef LLVM_BUILTIN_UNREACHABLE + LLVM_BUILTIN_UNREACHABLE; + #endif +} + #endif diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Utils.h b/rpcs3/Emu/RSX/D3D12/D3D12Utils.h index b1c7bcc701..85b2fa4ef5 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Utils.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12Utils.h @@ -7,6 +7,63 @@ #include "Emu/Memory/vm.h" #include "Emu/RSX/GCM.h" + +// From llvm Compiler.h + +// Need to be set by define +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + +/// \macro LLVM_GNUC_PREREQ +/// \brief Extend the default __GNUC_PREREQ even if glibc's features.h isn't +/// available. +#ifndef LLVM_GNUC_PREREQ +# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +#define LLVM_GNUC_PREREQ(maj, min, patch) \ + ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \ + ((maj) << 20) + ((min) << 10) + (patch)) +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) +#define LLVM_GNUC_PREREQ(maj, min, patch) \ + ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10)) +#else +#define LLVM_GNUC_PREREQ(maj, min, patch) 0 +#endif +#endif + +#ifdef __GNUC__ +#define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn)) +#elif defined(_MSC_VER) +#define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn) +#else +#define LLVM_ATTRIBUTE_NORETURN +#endif + +#if __has_builtin(__builtin_unreachable) || LLVM_GNUC_PREREQ(4, 5, 0) +# define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable() +#elif defined(_MSC_VER) +# define LLVM_BUILTIN_UNREACHABLE __assume(false) +#endif + +LLVM_ATTRIBUTE_NORETURN void unreachable_internal(const char *msg = nullptr, const char *file = nullptr, unsigned line = 0); + +/// Marks that the current location is not supposed to be reachable. +/// In !NDEBUG builds, prints the message and location info to stderr. +/// In NDEBUG builds, becomes an optimizer hint that the current location +/// is not supposed to be reachable. On compilers that don't support +/// such hints, prints a reduced message instead. +/// +/// Use this instead of assert(0). It conveys intent more clearly and +/// allows compilers to omit some unnecessary code. +#ifndef NDEBUG +#define unreachable(msg) \ + unreachable_internal(msg, __FILE__, __LINE__) +#elif defined(LLVM_BUILTIN_UNREACHABLE) +#define unreachable(msg) LLVM_BUILTIN_UNREACHABLE +#else +#define unreachable(msg) unreachable_internal() +#endif + using namespace Microsoft::WRL; // From DX12 D3D11On12 Sample (MIT Licensed) diff --git a/rpcs3/stdafx_d3d12.h b/rpcs3/stdafx_d3d12.h index 9fb2716b0d..954084813a 100644 --- a/rpcs3/stdafx_d3d12.h +++ b/rpcs3/stdafx_d3d12.h @@ -1,3 +1,3 @@ #pragma once -#include "stdafx.h" +#include "stdafx.h" \ No newline at end of file