| 1 | /*========================== begin_copyright_notice ============================ |
| 2 | |
| 3 | Copyright (C) 2017-2021 Intel Corporation |
| 4 | |
| 5 | SPDX-License-Identifier: MIT |
| 6 | |
| 7 | ============================= end_copyright_notice ===========================*/ |
| 8 | |
| 9 | #include "../headers/clang_debug.h" |
| 10 | |
| 11 | #if defined _WIN32 |
| 12 | |
| 13 | #if defined(_DEBUG) || defined(_INTERNAL) |
| 14 | |
| 15 | namespace clang { |
| 16 | |
| 17 | /*****************************************************************************\ |
| 18 | Declaring all registry values for CLANG component: |
| 19 | \*****************************************************************************/ |
| 20 | |
| 21 | const SDebugVariableEnumValue g_cl_intel_simd_operations_placeholder[] = { |
| 22 | {"cl_intel_simd_operations_placeholder functionality is disabled (default)", 0x0}, |
| 23 | {"cl_intel_simd_operations_placeholder functionality is enabled", 0x1}, |
| 24 | }; |
| 25 | |
| 26 | const SDebugVariableEnumValue g_cl_khr_fp16[] = { |
| 27 | {"cl_khr_fp16 forced disabled on unsupported products (default)", 0x0}, |
| 28 | {"cl_khr_fp16 is enabled", 0x1}, |
| 29 | }; |
| 30 | |
| 31 | const SDebugVariableEnumValue g_cl_khr_fp64[] = { |
| 32 | {"cl_khr_fp64 forced disabled on unsupported products (default)", 0x0}, |
| 33 | {"cl_khr_fp64 is enabled", 0x1}, |
| 34 | }; |
| 35 | |
| 36 | const SDebugVariableEnumValue g_cl_khr_subgroups[] = { |
| 37 | {"cl_khr_subgroups stays disabled on unsupported products (default)", 0x0}, |
| 38 | {"cl_khr_subgroups is enabled", 0x1}, |
| 39 | }; |
| 40 | |
| 41 | struct DEBUG_VARIABLES_REGKEY { |
| 42 | /////////////////////////////////////////////////////////////////////////////// |
| 43 | // CLANG_Debug |
| 44 | /////////////////////////////////////////////////////////////////////////////// |
| 45 | OCL_CLANG_DeclareEnum( |
| 46 | cl_intel_simd_operations_placeholder, "CLANG_Debug", |
| 47 | "Enables the prototype SIMD built-in functions. You probably don't want to set this if you're writing new code " |
| 48 | "- use the cl_intel_subgroups functionality instead. See: SIMD Shuffles for more information.", |
| 49 | g_cl_intel_simd_operations_placeholder); |
| 50 | |
| 51 | OCL_CLANG_DeclareEnum( |
| 52 | cl_khr_fp16_, // cl_khr_fp16 actual ask ??? |
| 53 | "CLANG_Debug", |
| 54 | "Force enables the cl_khr_fp16 (half precision) extension through the compiler, even on products that do not " |
| 55 | "support the extension by default. Currently, this only applies to Broadwell (Gen8). This includes: defining " |
| 56 | "cl_khr_fp16, allowing the pragma for cl_khr_fp16, and enabling fp16 code generation in the IGIL backend.", |
| 57 | g_cl_khr_fp16); |
| 58 | |
| 59 | OCL_CLANG_DeclareEnum(cl_khr_fp64_, "CLANG_Debug", |
| 60 | "Enables the cl_khr_fp64 (double precision) extension through the compiler. This includes: " |
| 61 | "defining cl_khr_fp64, allowing the pragma for cl_khr_fp64, and enabling fp64 code generation " |
| 62 | "in the IGIL backend. This is mostly intended to aid performance evaluation of fp64 features " |
| 63 | "and is not a conformant fp64 implementation. Be very careful drawing performance conclusions " |
| 64 | "using this registry key if your workload uses a non-conformant fp64 built-in function", |
| 65 | g_cl_khr_fp64); |
| 66 | |
| 67 | OCL_CLANG_DeclareEnum( |
| 68 | cl_khr_subgroups, "CLANG_Debug", |
| 69 | "Force enables the cl_khr_subgroups extension through the compiler. This includes: defining cl_khr_subgroups " |
| 70 | "and allowing the pragma for cl_khr_subgroups. This was primarily added to get additional test coverage for the " |
| 71 | "cl_intel_subgroups functionality via the Khronos cl_khr_subroups conformance tests, though this hasn't been " |
| 72 | "tried to see how useful it is in practice.", |
| 73 | g_cl_khr_subgroups); |
| 74 | |
| 75 | OCL_CLANG_DeclareString( |
| 76 | LLVMOptionsString, "CLANG_Debug", |
| 77 | "Pass compile options to LLVM (for debug builds). Any valid LLVM options can be listed here. A good place to " |
| 78 | "start may be something like: -debug -debug-only=isel -print-machineinstrs -print-after-all"); |
| 79 | |
| 80 | OCL_CLANG_DeclareString(CLANGOptionsString, "CLANG_Debug", |
| 81 | "Pass compile options to CLANG (for debug builds)."); // Get description info later |
| 82 | }; |
| 83 | |
| 84 | DEBUG_VARIABLES_REGKEY g_DebugVariables; |
| 85 | |
| 86 | const DWORD NUM_DEBUG_VARIABLES = sizeof(DEBUG_VARIABLES_REGKEY) / sizeof(SDebugVariableMetaData); |
| 87 | |
| 88 | /*****************************************************************************\ |
| 89 | Function:LoadDebugVariables |
| 90 | |
| 91 | Description:Loads debug variables from the registry |
| 92 | |
| 93 | Input: None |
| 94 | |
| 95 | Output:None |
| 96 | \*****************************************************************************/ |
| 97 | |
| 98 | void __cdecl LoadDebugVariables(void) { |
| 99 | #if defined(WIN32) && defined(ENABLE_REGISTRY_READ) |
| 100 | |
| 101 | SDebugVariableMetaData *pDebugVariable = (SDebugVariableMetaData *)&g_DebugVariables; |
| 102 | |
| 103 | for (DWORD i = 0; i < NUM_DEBUG_VARIABLES; i++) { |
| 104 | DWORD value = 0; |
| 105 | |
| 106 | const char *name = pDebugVariable[i].GetName(); |
| 107 | |
| 108 | value = llvm::ReadRegistry(name, value); |
| 109 | |
| 110 | pDebugVariable[i].m_IsSet = TRUE; |
| 111 | |
| 112 | pDebugVariable[i].m_Value = value; |
| 113 | } |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | PFNLOADDEBUGVARIABLES pfnLoadDebugVariables = LoadDebugVariables; |
| 118 | |
| 119 | void __cdecl DumpRegistryKeyDefinitions(void) { |
| 120 | // Create the directory path |
| 121 | CreateDirectoryA("C:\\Intel", NULL); |
| 122 | CreateDirectoryA("C:\\Intel\\IGfx", NULL); |
| 123 | CreateDirectoryA("C:\\Intel\\IGfx\\GfxRegistryManager", NULL); |
| 124 | CreateDirectoryA("C:\\Intel\\IGfx\\GfxRegistryManager\\Keys", NULL); |
| 125 | |
| 126 | // Create the XML file to hold the debug variable definitions |
| 127 | FILE *fp = NULL; |
| 128 | errno_t result = fopen_s(&fp, "C:\\Intel\\IGfx\\GfxRegistryManager\\Keys\\OCL.CLANG.xml", "w"); |
| 129 | if (fp == NULL || result != 0) { |
| 130 | printf_s("Unsuccessful OCL registry dump"); |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | SDebugVariableMetaData *pDebugVariable = (SDebugVariableMetaData *)&g_DebugVariables; |
| 135 | |
| 136 | const char *currentGroup = "Generic"; |
| 137 | |
| 138 | // Generate the XML |
| 139 | fprintf(fp, "<RegistryKeys>\n"); |
| 140 | |
| 141 | // Dump the DEBUG_VARIABLES entries |
| 142 | for (DWORD i = 0; i < NUM_DEBUG_VARIABLES; i++) { |
| 143 | if (strcmp(currentGroup, pDebugVariable[i].GetGroup()) != 0) { |
| 144 | // Create new group tag |
| 145 | currentGroup = pDebugVariable[i].GetGroup(); |
| 146 | fprintf(fp, " <Group name=\"%s\">\n", currentGroup); |
| 147 | } |
| 148 | pDebugVariable[i].DumpDefinition(fp); |
| 149 | } |
| 150 | |
| 151 | fprintf(fp, " </Group>\n"); |
| 152 | fprintf(fp, "</RegistryKeys>\n"); |
| 153 | |
| 154 | fclose(fp); |
| 155 | fp = NULL; |
| 156 | } |
| 157 | |
| 158 | } // namespace clang |
| 159 | |
| 160 | #endif |
| 161 | |
| 162 | #endif |