├── CMakeLists.txt ├── README.md ├── README.txt ├── llvm_prebuilt.cmake ├── llvm_utils.cmake └── releases ├── 10.0.0 └── patches_external │ ├── BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch │ ├── IndVarSimplify-Do-not-use-SCEV-expander-for-IVCount-.patch │ ├── InstCombine-visitBitCast-do-not-crash-on-weird-bitca.patch │ ├── Instruction-Add-dropLocation-and-updateLocationAfter.patch │ ├── fix_for_llvm-as_buildbreak.patch │ ├── fix_for_llvm-link_buildbreak.patch │ └── fix_for_opt_buildbreak.patch ├── 4.0.0 └── patches_external │ ├── 2_1-enable-aggressive-combining.patch │ ├── 2_2-completely-turn-off-code-sinking-in-InstructionCombining.patch │ ├── 3_1-SimplifyCFG-SinkThenElseCodeToEnd-does-not-sink-code.patch │ ├── 4_1-non-recursive-sink-hoist-region.patch │ ├── 4_2-Fix_invariant_fdiv_hoisting_in_LICM.patch │ ├── Add-Reassoc-Contract-ApproxFunc-to-FMF.patch │ ├── Be-conservative-when-splitting-loop.patch │ ├── ConstantFolding-Constant-fold-llvm.sqrt-x-like-other.patch │ ├── Enable-gcc-8-build.patch │ ├── Enabling-test-Offset32-Regression-Fix.patch │ ├── Fix-crash-due-to-bad-bitcast.patch │ ├── Fixed-faulty-PHI-node-update.patch │ ├── Temporarily-disable-the-combination-on-b.patch │ └── add_win_crt_info.patch ├── 7.0.0 └── patches_external │ ├── BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch │ ├── IndVarSimplify-Do-not-use-SCEV-expander-for-IVCount-.patch │ ├── Use-depth-limit-for-trunc-analysis.patch │ ├── add_win_crt_info.patch │ ├── export-utility-to-targets-build-install_1.patch │ ├── export-utility-to-targets-build-install_2.patch │ ├── fix-pointer-for-lifetime-intrinsic.patch │ └── initializaton_order_fiasco-workaround.patch ├── 8.0.0 └── patches_external │ ├── BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch │ ├── IndVarSimplify-Do-not-use-SCEV-expander-for-IVCount-.patch │ ├── Use-depth-limit-for-trunc-analysis.patch │ ├── add_win_crt_info.patch │ ├── export-utility-to-targets-build-install.patch │ └── fix_for_typo_regex.patch └── 9.0.0 └── patches_external ├── BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch ├── IndVarSimplify-Do-not-use-SCEV-expander-for-IVCount-.patch ├── add_win_crt_info.patch └── disable-backtrace-on-Android.patch /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #===================== begin_copyright_notice ================================== 2 | # 3 | # Copyright (c) 2017-2018 Intel Corporation. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a 6 | # copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included 14 | # in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | # 24 | # 25 | # ======================= end_copyright_notice ================================== 26 | 27 | # 28 | # LLVM module 29 | # 30 | 31 | cmake_minimum_required(VERSION 3.4.3) 32 | 33 | if(BS_USE_OSDM_BUILD_SYSTEM) 34 | include(${BUILD_SYS_INC}/utils.cmake) 35 | bs_find_patch() 36 | else() 37 | if (NOT PATCH) 38 | find_program(PATCH NAMES patch patch.exe) 39 | endif() 40 | if (NOT PYTHON) 41 | find_program(PYTHON NAMES python3 python python3.exe python.exe) 42 | endif() 43 | endif() 44 | 45 | 46 | include(llvm_utils.cmake) 47 | 48 | set(LLVM_TARGETS_TO_BUILD "X86" CACHE STRING "desc" FORCE) 49 | set(LLVM_BUILD_TOOLS true CACHE BOOL "desc" FORCE) 50 | set(LLVM_INCLUDE_TOOLS true CACHE BOOL "desc" FORCE) 51 | set(LLVM_INSTALL_UTILS false CACHE BOOL "desc" FORCE) 52 | set(LLVM_INCLUDE_UTILS true CACHE BOOL "desc" FORCE) # required to run LIT tests 53 | set(LLVM_BUILD_UTILS false CACHE BOOL "desc" FORCE) 54 | set(LLVM_BUILD_EXAMPLES false CACHE BOOL "desc" FORCE) 55 | set(LLVM_INCLUDE_EXAMPLES false CACHE BOOL "desc" FORCE) 56 | set(LLVM_BUILD_TESTS false CACHE BOOL "desc" FORCE) 57 | set(LLVM_INCLUDE_TESTS false CACHE BOOL "desc" FORCE) 58 | set(LLVM_APPEND_VC_REV false CACHE BOOL "desc" FORCE) 59 | set(LLVM_ENABLE_THREADS true CACHE BOOL "desc" FORCE) 60 | set(LLVM_ENABLE_CXX1Y false CACHE BOOL "desc" FORCE) 61 | set(LLVM_ENABLE_PIC true CACHE BOOL "desc" FORCE) 62 | set(LLVM_ENABLE_WARNINGS true CACHE BOOL "desc" FORCE) 63 | set(LLVM_ENABLE_PEDANTIC true CACHE BOOL "desc" FORCE) 64 | set(LLVM_ENABLE_WERROR false CACHE BOOL "desc" FORCE) 65 | set(LLVM_ABI_BREAKING_CHECKS FORCE_OFF CACHE BOOL "desc" FORCE) 66 | set(LLVM_BUILD_RUNTIME true CACHE BOOL "desc" FORCE) 67 | set(LLVM_ENABLE_TERMINFO false CACHE BOOL "desc" FORCE) 68 | set(LLVM_ENABLE_DUMP true CACHE BOOL "desc" FORCE) 69 | set(LLVM_BUILD_LLVM_DYLIB false CACHE BOOL "desc" FORCE) 70 | set(LLVM_LINK_LLVM_DYLIB false CACHE BOOL "desc" FORCE) 71 | set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "desc" FORCE) 72 | 73 | if(DEFINED BUILD_PACKAGE) 74 | if(NOT WIN32) 75 | set(LLVM_BUILD_LLVM_DYLIB true CACHE BOOL "desc" FORCE) 76 | set(LLVM_LINK_LLVM_DYLIB true CACHE BOOL "desc" FORCE) 77 | endif() 78 | set(LLVM_INSTALL_UTILS true CACHE BOOL "desc" FORCE) 79 | set(LLVM_BUILD_UTILS true CACHE BOOL "desc" FORCE) 80 | endif() 81 | 82 | 83 | set(LLVM_OPTIONS 84 | "-DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD}" 85 | "-DLLVM_BUILD_TOOLS=${LLVM_BUILD_TOOLS}" 86 | "-DLLVM_INCLUDE_TOOLS=${LLVM_INCLUDE_TOOLS}" 87 | "-DLLVM_INSTALL_UTILS=${LLVM_INSTALL_UTILS}" 88 | "-DLLVM_INCLUDE_UTILS=${LLVM_INCLUDE_UTILS}" 89 | "-DLLVM_BUILD_UTILS=${LLVM_BUILD_UTILS}" 90 | "-DLLVM_BUILD_EXAMPLES=${LLVM_BUILD_EXAMPLES}" 91 | "-DLLVM_INCLUDE_EXAMPLES=${LLVM_INCLUDE_EXAMPLES}" 92 | "-DLLVM_BUILD_TESTS=${LLVM_BUILD_TESTS}" 93 | "-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}" 94 | "-DLLVM_APPEND_VC_REV=${LLVM_APPEND_VC_REV}" 95 | "-DLLVM_ENABLE_THREADS=${LLVM_ENABLE_THREADS}" 96 | "-DLLVM_ENABLE_CXX1Y=${LLVM_ENABLE_CXX1Y}" 97 | "-DLLVM_ENABLE_PIC=${LLVM_ENABLE_PIC}" 98 | "-DLLVM_ENABLE_WARNINGS=${LLVM_ENABLE_WARNINGS}" 99 | "-DLLVM_ENABLE_PEDANTIC=${LLVM_ENABLE_PEDANTIC}" 100 | "-DLLVM_ENABLE_WERROR=${LLVM_ENABLE_WERROR}" 101 | "-DLLVM_ABI_BREAKING_CHECKS=${LLVM_ABI_BREAKING_CHECKS}" 102 | "-DLLVM_BUILD_RUNTIME=${LLVM_BUILD_RUNTIME}" 103 | "-DLLVM_ENABLE_TERMINFO=${LLVM_ENABLE_TERMINFO}" 104 | "-DLLVM_ENABLE_DUMP=${LLVM_ENABLE_DUMP}" 105 | "-DLLVM_BUILD_LLVM_DYLIB=${LLVM_BUILD_LLVM_DYLIB}" 106 | "-DLLVM_LINK_LLVM_DYLIB=${LLVM_LINK_LLVM_DYLIB}" 107 | "-DLLVM_ENABLE_PROJECTS=${LLVM_ENABLE_PROJECTS}" 108 | ) 109 | 110 | if(_ASSERTBUILD) 111 | set(LLVM_ENABLE_ASSERTIONS true CACHE STRING "desc" FORCE) 112 | set(LLVM_OPTIONS 113 | "${LLVM_OPTIONS}" 114 | "-DLLVM_ENABLE_ASSERTIONS=${LLVM_ENABLE_ASSERTIONS}" 115 | ) 116 | endif() 117 | 118 | if(WIN32) 119 | set(LLVM_USE_CRT_DEBUG MTd CACHE STRING "desc" FORCE) 120 | set(LLVM_USE_CRT_RELEASE MT CACHE STRING "desc" FORCE) 121 | set(LLVM_USE_CRT_RELEASEINTERNAL MT CACHE STRING "desc" FORCE) 122 | set(LLVM_OPTIONS 123 | "${LLVM_OPTIONS}" 124 | "-DLLVM_USE_CRT_DEBUG=${LLVM_USE_CRT_DEBUG}" 125 | "-DLLVM_USE_CRT_RELEASE=${LLVM_USE_CRT_RELEASE}" 126 | "-DLLVM_USE_CRT_RELEASEINTERNAL=${LLVM_USE_CRT_RELEASEINTERNAL}" 127 | ) 128 | else() 129 | set(LLVM_ENABLE_EH true CACHE BOOL "desc" FORCE) 130 | set(LLVM_ENABLE_RTTI true CACHE BOOL "desc" FORCE) 131 | if ("${ARCH}" STREQUAL "32") 132 | set(LLVM_BUILD_32_BITS true CACHE BOOL "desc" FORCE) 133 | else() 134 | set(LLVM_BUILD_32_BITS false CACHE BOOL "desc" FORCE) 135 | endif() 136 | set(LLVM_OPTIONS 137 | "${LLVM_OPTIONS}" 138 | "-DLLVM_ENABLE_EH=${LLVM_ENABLE_EH}" 139 | "-DLLVM_ENABLE_RTTI=${LLVM_ENABLE_RTTI}" 140 | "-DLLVM_BUILD_32_BITS=${LLVM_BUILD_32_BITS}" 141 | ) 142 | endif() 143 | 144 | if(COMMON_CLANG_LIBRARY_NAME) 145 | set(LLVM_OPTIONS 146 | "${LLVM_OPTIONS}" 147 | "-DCOMMON_CLANG_LIBRARY_NAME=${COMMON_CLANG_LIBRARY_NAME}" 148 | ) 149 | endif() 150 | 151 | if(((NOT EXISTS ${LLVM_SOURCE_URL}) AND (NOT EXPECTED_LLVM_VERSION)) OR DEFINED BUILD_PACKAGE) 152 | # Use LLVM sources stored at fixed location 153 | if(NOT DEFINED BUILD_PACKAGE) 154 | set(LLVM_SOURCE_URL ${CMAKE_CURRENT_SOURCE_DIR}/../llvm-project) 155 | endif() 156 | if(EXISTS ${LLVM_SOURCE_URL}) 157 | message(STATUS "[LLVM_PATCHER] : Manual read LLVM version from llvm-project/llvm/CMakeLists.txt file") 158 | file(STRINGS ${LLVM_SOURCE_URL}/llvm/CMakeLists.txt LLVM_VERSION_MAJOR_MATCH REGEX "set\\(LLVM_VERSION_MAJOR [0-9]+\\)") 159 | file(STRINGS ${LLVM_SOURCE_URL}/llvm/CMakeLists.txt LLVM_VERSION_MINOR_MATCH REGEX "set\\(LLVM_VERSION_MINOR [0-9]+\\)") 160 | file(STRINGS ${LLVM_SOURCE_URL}/llvm/CMakeLists.txt LLVM_VERSION_PATCH_MATCH REGEX "set\\(LLVM_VERSION_PATCH [0-9]+\\)") 161 | 162 | string(REGEX MATCH "[0-9]+" LLVM_VERSION_MAJOR ${LLVM_VERSION_MAJOR_MATCH}) 163 | string(REGEX MATCH "[0-9]+" LLVM_VERSION_MINOR ${LLVM_VERSION_MINOR_MATCH}) 164 | string(REGEX MATCH "[0-9]+" LLVM_VERSION_PATCH ${LLVM_VERSION_PATCH_MATCH}) 165 | 166 | set(EXPECTED_LLVM_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") 167 | 168 | message(STATUS "[LLVM_PATCHER] : In folder ${LLVM_SOURCE_URL} found LLVM version : ${EXPECTED_LLVM_VERSION}") 169 | endif() 170 | endif() 171 | 172 | # Use LLVM stock sources or patched stock sources 173 | if(LLVM_STOCK_SOURCES) 174 | set(LLVM_APPLY_PATCHES false) 175 | else() 176 | set(LLVM_APPLY_PATCHES true) 177 | endif() 178 | 179 | if(NOT EXPECTED_LLVM_VERSION) 180 | set(EXPECTED_LLVM_VERSION "10.0.0") 181 | endif() 182 | 183 | if(NOT LLVM_SOURCE_DIR) 184 | set(LLVM_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/../src/llvm") 185 | endif() 186 | 187 | if(NOT EXISTS ${LLVM_SOURCE_URL}) 188 | # Use LLVM sources stored at fixed location 189 | set(LLVM_SOURCE_URL /opt/src/llvm-project_${EXPECTED_LLVM_VERSION}) 190 | endif() 191 | if(NOT EXISTS ${LLVM_SOURCE_URL}) 192 | # Use LLVM sources stored at fixed location 193 | set(LLVM_SOURCE_URL ${CMAKE_CURRENT_SOURCE_DIR}/../llvm-project_${EXPECTED_LLVM_VERSION}) 194 | endif() 195 | if(NOT EXISTS ${LLVM_SOURCE_URL}) 196 | # Use LLVM sources stored at fixed location 197 | set(LLVM_SOURCE_URL ${CMAKE_CURRENT_SOURCE_DIR}/../../../../llvm-project_${EXPECTED_LLVM_VERSION}) 198 | endif() 199 | 200 | message(STATUS "[LLVM_PATCHER] : LLVM_SOURCE_URL = ${LLVM_SOURCE_URL}") 201 | message(STATUS "[LLVM_PATCHER] : LLVM_OPTIONS = ${LLVM_OPTIONS}") 202 | 203 | if(NOT EXISTS ${LLVM_SOURCE_DIR}) 204 | # Copy stock LLVM sources to LLVM_SOURCE_DIR 205 | message(STATUS "[LLVM_PATCHER] : Copying stock LLVM and CLANG sources ${LLVM_SOURCE_URL} to ${LLVM_SOURCE_DIR}") 206 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${LLVM_SOURCE_URL}/.git ${LLVM_SOURCE_DIR}/../.git) 207 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${LLVM_SOURCE_URL}/clang ${LLVM_SOURCE_DIR}/../clang) 208 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${LLVM_SOURCE_URL}/llvm ${LLVM_SOURCE_DIR}) 209 | 210 | FILE(GLOB dirsPatch RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/releases ${CMAKE_CURRENT_SOURCE_DIR}/releases/*) 211 | list(SORT dirsPatch) 212 | list(REVERSE dirsPatch) 213 | 214 | if(NOT LLVM_VERSION_MAJOR) 215 | string(REGEX MATCH "[0-9]+" LLVM_VERSION_MAJOR ${EXPECTED_LLVM_VERSION}) 216 | endif() 217 | 218 | if(LLVM_APPLY_PATCHES) 219 | # Customization patches will be applied if present. 220 | 221 | foreach(dirPatch ${dirsPatch}) 222 | #Apply all patches for given major version of LLVM 223 | string(REGEX MATCH "[0-9]+" LLVM_VER_MAJOR_FOLDER ${dirPatch}) 224 | if(NOT ${LLVM_VERSION_MAJOR} MATCHES ${LLVM_VER_MAJOR_FOLDER}) 225 | continue() 226 | endif() 227 | message(STATUS "[LLVM_PATCHER] : Applying patches for LLVM from version ${dirPatch}") 228 | 229 | file(GLOB LLVM_PATCH_FILES 230 | "${CMAKE_CURRENT_SOURCE_DIR}/releases/${dirPatch}/patches_external/*.patch" 231 | ) 232 | 233 | if(LLVM_VERSION_MAJOR EQUAL 10) 234 | file(GLOB LLVM_PATCH_FILES_INTERNAL 235 | "${CMAKE_CURRENT_SOURCE_DIR}/releases/${dirPatch}/patches_internal/*.patch" 236 | ) 237 | set(LLVM_PATCH_FILES ${LLVM_PATCH_FILES} ${LLVM_PATCH_FILES_INTERNAL}) 238 | endif() 239 | 240 | # Sort list of patch files. 241 | if(LLVM_PATCH_FILES) 242 | list(SORT LLVM_PATCH_FILES) 243 | endif() 244 | # Apply customization patches if any. 245 | foreach(patch_file ${LLVM_PATCH_FILES}) 246 | message(STATUS "[LLVM_PATCHER] : Apply ${patch_file} file") 247 | execute_process(COMMAND ${PATCH} -d ${LLVM_SOURCE_DIR} -p1 -i ${patch_file} RESULT_VARIABLE rv) 248 | if(NOT rv EQUAL 0) 249 | message(FATAL_ERROR "[LLVM_PATCHER] : error: applying patch '${patch_file}' failed") 250 | endif() 251 | endforeach() 252 | endforeach() 253 | endif() 254 | endif() 255 | 256 | if(CMAKE_CONFIGURATION_TYPES) 257 | # Multi-configuration generator. 258 | set (CMAKE_CONFIGURATION_TYPES "Debug" "Release" "ReleaseInternal") 259 | message(STATUS "[LLVM_PATCHER] : LLVM_CONFIGURATION_TYPES = ${CMAKE_CONFIGURATION_TYPES}") 260 | else() 261 | # Single-configuration generator. 262 | message(STATUS "[LLVM_PATCHER] : LLVM_BUILD_TYPE = ${CMAKE_BUILD_TYPE}") 263 | endif() 264 | 265 | # Set python interpreter for LLVM 266 | llvm_utils_python_set() 267 | # Do not alter LLVM compilation flags 268 | llvm_utils_push_build_flags() 269 | if(BUILD_PACKAGE) 270 | add_subdirectory(${LLVM_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src) 271 | else() 272 | add_subdirectory(${LLVM_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src EXCLUDE_FROM_ALL) 273 | endif() 274 | llvm_utils_pop_build_flags() 275 | llvm_utils_python_restore() 276 | # Get version of LLVM that we are currently using: 277 | get_directory_property(LLVM_VERSION_MAJOR DIRECTORY ${LLVM_SOURCE_DIR} DEFINITION "LLVM_VERSION_MAJOR") 278 | get_directory_property(LLVM_VERSION_MINOR DIRECTORY ${LLVM_SOURCE_DIR} DEFINITION "LLVM_VERSION_MINOR") 279 | get_directory_property(LLVM_VERSION_PATCH DIRECTORY ${LLVM_SOURCE_DIR} DEFINITION "LLVM_VERSION_PATCH") 280 | get_directory_property(LLVM_VERSION_SUFFIX DIRECTORY ${LLVM_SOURCE_DIR} DEFINITION "LLVM_VERSION_SUFFIX") 281 | # Make LLVM version accessible in parent scope: 282 | set(LLVM_VERSION_MAJOR ${LLVM_VERSION_MAJOR} PARENT_SCOPE) 283 | set(LLVM_VERSION_MINOR ${LLVM_VERSION_MINOR} PARENT_SCOPE) 284 | set(LLVM_VERSION_PATCH ${LLVM_VERSION_PATCH} PARENT_SCOPE) 285 | set(LLVM_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX} PARENT_SCOPE) 286 | 287 | set(PACKAGE_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}") 288 | 289 | if(NOT (${PACKAGE_VERSION} EQUAL ${EXPECTED_LLVM_VERSION})) 290 | message(FATAL_ERROR "[LLVM_PATCHER] : Expected LLVM version ${EXPECTED_LLVM_VERSION} but found ${PACKAGE_VERSION}.") 291 | endif() 292 | 293 | set(LLVM_INCLUDE_DIRS "${LLVM_SOURCE_DIR}/include;${CMAKE_CURRENT_BINARY_DIR}/src/include") 294 | set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} PARENT_SCOPE) 295 | 296 | if(BUILD_PACKAGE) 297 | if(UNIX) 298 | if(EXISTS "/etc/debian_version") 299 | set(CPACK_GENERATOR "DEB") 300 | elseif(EXISTS "/etc/redhat-release") 301 | set(CPACK_GENERATOR "RPM") 302 | else() 303 | set(CPACK_GENERATOR "TXZ") 304 | set(CPACK_SET_DESTDIR ON) 305 | endif() 306 | 307 | set(CPACK_DEBIAN_PACKAGE_MAINTAINER "intel") 308 | set(CPACK_PACKAGE_ARCHITECTURE "x86_64") 309 | set(CPACK_PACKAGE_NAME "intel") 310 | set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) 311 | set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR}) 312 | set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH}) 313 | set(CPACK_PACKAGE_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX}) 314 | set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}${CPACK_PACKAGE_VERSION_SUFFIX}") 315 | set(CPACK_PACKAGE_INSTALL_DIRECTORY ${IGC_INSTALL_TIME_ROOT_DIR}) 316 | set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "LLVM patched library version for Intel") 317 | set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) 318 | set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") 319 | set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE) 320 | set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64") 321 | 322 | if(DEFINED LLVM_PACKAGE_RELEASE) 323 | set(CPACK_DEBIAN_PACKAGE_RELEASE ${LLVM_PACKAGE_RELEASE}) 324 | set(CPACK_RPM_PACKAGE_RELEASE ${LLVM_PACKAGE_RELEASE}) 325 | else() 326 | set(CPACK_DEBIAN_PACKAGE_RELEASE 1) 327 | set(CPACK_RPM_PACKAGE_RELEASE 1) 328 | endif() 329 | 330 | set(CPACK_DEBIAN_INTEL-LLVM-PATCHED-LIBRARY_FILE_NAME "intel-llvm-patched-library_${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") 331 | set(CPACK_DEBIAN_INTEL-LLVM-PATCHED-LIBRARY-DEVEL_FILE_NAME "intel-llvm-patched-library-devel_${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") 332 | 333 | set(CPACK_RPM_INTEL-LLVM-PATCHED-LIBRARY_FILE_NAME "intel-llvm-patched-library-${CPACK_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}.${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm") 334 | set(CPACK_RPM_INTEL-LLVM-PATCHED-LIBRARY-DEVEL_FILE_NAME "intel-llvm-patched-library-devel-${CPACK_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}.${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm") 335 | 336 | set(CPACK_ARCHIVE_INTEL-LLVM-PATCHED-LIBRARY_FILE_NAME "intel-llvm-patched-library-${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}.${CPACK_PACKAGE_ARCHITECTURE}") 337 | set(CPACK_ARCHIVE_INTEL-LLVM-PATCHED-LIBRARY-DEVEL_FILE_NAME "intel-llvm-patched-library-devel-${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}.${CPACK_PACKAGE_ARCHITECTURE}") 338 | 339 | set(CPACK_DEB_COMPONENT_INSTALL ON) 340 | set(CPACK_RPM_COMPONENT_INSTALL ON) 341 | set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) 342 | set(CPACK_COMPONENTS_ALL intel-llvm-patched-library intel-llvm-patched-library-devel) 343 | 344 | include(CPack) 345 | include(GNUInstallDirs) 346 | 347 | install(FILES $ DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} COMPONENT intel-llvm-patched-library) 348 | 349 | set(BUILD_SRC_DIR_LLVM ${LLVM_SOURCE_DIR}/../build/src) 350 | 351 | install(DIRECTORY ${BUILD_SRC_DIR_LLVM}/lib/cmake/llvm 352 | DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/cmake 353 | COMPONENT intel-llvm-patched-library 354 | FILES_MATCHING PATTERN *.cmake 355 | PATTERN .svn EXCLUDE 356 | PATTERN LLVMConfig.cmake EXCLUDE 357 | PATTERN LLVMConfigVersion.cmake EXCLUDE 358 | PATTERN LLVM-Config.cmake EXCLUDE 359 | PATTERN LLVMExports.cmake EXCLUDE 360 | PATTERN GetHostTriple.cmake EXCLUDE) 361 | 362 | install(FILES 363 | ${BUILD_SRC_DIR_LLVM}/cmake/modules/CMakeFiles/LLVMConfig.cmake 364 | ${BUILD_SRC_DIR_LLVM}/lib/cmake/llvm/LLVMConfigVersion.cmake 365 | ${LLVM_SOURCE_DIR}/cmake/modules/LLVM-Config.cmake 366 | ${BUILD_SRC_DIR_LLVM}/cmake/modules/CMakeFiles/Export/lib/cmake/llvm/LLVMExports.cmake 367 | DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/cmake/llvm 368 | COMPONENT intel-llvm-patched-library) 369 | 370 | set(BIN_PATH ${BUILD_SRC_DIR_LLVM}/bin) 371 | install(FILES 372 | ${BIN_PATH}/llvm-link 373 | ${BIN_PATH}/llvm-config 374 | ${BIN_PATH}/llvm-tblgen 375 | ${BIN_PATH}/not 376 | ${BIN_PATH}/FileCheck 377 | ${BIN_PATH}/count 378 | DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} 379 | COMPONENT intel-llvm-patched-library 380 | ) 381 | 382 | install(DIRECTORY ${LLVM_SOURCE_DIR}/include/llvm ${LLVM_SOURCE_DIR}/include/llvm-c DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} 383 | COMPONENT intel-llvm-patched-library-devel 384 | FILES_MATCHING 385 | PATTERN "*.def" 386 | PATTERN "*.h" 387 | PATTERN "*.td" 388 | PATTERN "*.inc" 389 | PATTERN "LICENSE.TXT" 390 | PATTERN ".svn" EXCLUDE) 391 | 392 | set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/include) 393 | 394 | install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} 395 | COMPONENT intel-llvm-patched-library-devel 396 | FILES_MATCHING 397 | PATTERN "*.def" 398 | PATTERN "*.h" 399 | PATTERN "*.gen" 400 | PATTERN "*.inc" 401 | PATTERN "CMakeFiles" EXCLUDE 402 | PATTERN "config.h" EXCLUDE 403 | PATTERN ".svn" EXCLUDE) 404 | 405 | endif() 406 | endif() 407 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DISCONTINUATION OF PROJECT 2 | 3 | This project will no longer be maintained by Intel. 4 | 5 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 6 | 7 | Intel no longer accepts patches to this project. 8 | 9 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. 10 | 11 | Contact: webadmin@linux.intel.com 12 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Placeholder for llvm patches 2 | -------------------------------------------------------------------------------- /llvm_prebuilt.cmake: -------------------------------------------------------------------------------- 1 | #===================== begin_copyright_notice ================================== 2 | # 3 | # Copyright (c) 2018 Intel Corporation. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a 6 | # copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included 14 | # in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | # 24 | # 25 | # ======================= end_copyright_notice ================================== 26 | 27 | set(LLVM_BUILD_TYPE ${CMAKE_BUILD_TYPE}) 28 | 29 | if(DEFINED BUILD_TYPE) 30 | if(${BUILD_TYPE} STREQUAL "release") 31 | set(LLVM_BUILD_TYPE "Release") 32 | else() 33 | set(LLVM_BUILD_TYPE "Debug") 34 | endif() 35 | endif() 36 | 37 | if(NOT DEFINED LLVM_BUILD_PREBUILDS_DIR) 38 | if(NOT EXISTS ${LLVM_BUILD_PREBUILDS_DIR}) 39 | set(LLVM_BUILD_PREBUILDS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../prebuild-llvm/${LLVM_BUILD_TYPE}") 40 | endif() 41 | endif() 42 | 43 | 44 | if(EXISTS ${LLVM_BUILD_PREBUILDS_DIR}/include) 45 | list(APPEND CMAKE_MODULE_PATH "${LLVM_BUILD_PREBUILDS_DIR}/lib/cmake/llvm/") 46 | 47 | set(LLVM_DIR ${LLVM_BUILD_PREBUILDS_DIR}/lib/cmake/llvm) 48 | include(${LLVM_BUILD_PREBUILDS_DIR}/lib/cmake/llvm/LLVMConfig.cmake) 49 | include(${LLVM_BUILD_PREBUILDS_DIR}/lib/cmake/llvm/AddLLVM.cmake) 50 | 51 | find_package(LLVM REQUIRED CONFIG) 52 | 53 | set(LLVM_INCLUDE_DIRS "${LLVM_BUILD_PREBUILDS_DIR}/include") 54 | 55 | set(LLVM_USE_PREBUILT true) 56 | 57 | message(STATUS "[LLVM_PATCHER\\Prebuilt] : Found prebuilt of llvm in version ${PACKAGE_VERSION}") 58 | endif() -------------------------------------------------------------------------------- /llvm_utils.cmake: -------------------------------------------------------------------------------- 1 | #===================== begin_copyright_notice ================================== 2 | # 3 | # Copyright (c) 2018 Intel Corporation. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a 6 | # copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included 14 | # in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | # 24 | # 25 | # ======================= end_copyright_notice ================================== 26 | 27 | 28 | # 29 | # Macro to set python interpreter for LLVM 30 | # 31 | macro(llvm_utils_python_set) 32 | # Unset directory scope PYTHON_EXECUTABLE variable 33 | unset(PYTHON_EXECUTABLE) 34 | # Check for cached PYTHON_EXECUTABLE variable 35 | if(PYTHON_EXECUTABLE) 36 | # If cached PYTHON_EXECUTABLE already exists save it to restore 37 | set(PYTHON_EXECUTABLE_BACKUP ${PYTHON_EXECUTABLE}) 38 | endif() 39 | # Set python interpreter for LLVM 40 | set(PYTHON_EXECUTABLE ${PYTHON} CACHE PATH "desc" FORCE) 41 | message(STATUS "[LLVM] PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}") 42 | endmacro() 43 | 44 | # 45 | # Macro to restore python interpreter 46 | # 47 | macro(llvm_utils_python_restore) 48 | if(PYTHON_EXECUTABLE_BACKUP) 49 | # Restore python interpreter 50 | set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE_BACKUP} CACHE PATH "desc" FORCE) 51 | else() 52 | # Clear python interpreter for LLVM 53 | unset(PYTHON_EXECUTABLE CACHE) 54 | endif() 55 | endmacro() 56 | 57 | # 58 | # Macro to clear and backup build flags already set 59 | # 60 | macro(llvm_utils_push_build_flags) 61 | message(STATUS "[LLVM] Clearing build system compilation flags") 62 | 63 | set(CMAKE_C_FLAGS_BACKUP ${CMAKE_C_FLAGS}) 64 | set(CMAKE_CXX_FLAGS_BACKUP ${CMAKE_CXX_FLAGS}) 65 | set(CMAKE_SHARED_LINKER_FLAGS_BACKUP ${CMAKE_SHARED_LINKER_FLAGS}) 66 | set(CMAKE_EXE_LINKER_FLAGS_BACKUP ${CMAKE_EXE_LINKER_FLAGS}) 67 | set(CMAKE_STATIC_LINKER_FLAGS_BACKUP ${CMAKE_STATIC_LINKER_FLAGS}) 68 | set(CMAKE_LOCAL_LINKER_FLAGS_BACKUP ${CMAKE_LOCAL_LINKER_FLAGS}) 69 | set(CMAKE_MODULE_LINKER_FLAGS_BACKUP ${CMAKE_MODULE_LINKER_FLAGS}) 70 | 71 | if(PRINT_DEBUG) 72 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}") 73 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}") 74 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}") 75 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}") 76 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_STATIC_LINKER_FLAGS = ${CMAKE_STATIC_LINKER_FLAGS}") 77 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_LOCAL_LINKER_FLAGS = ${CMAKE_LOCAL_LINKER_FLAGS}") 78 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_MODULE_LINKER_FLAGS = ${CMAKE_MODULE_LINKER_FLAGS}") 79 | endif() 80 | 81 | unset(CMAKE_C_FLAGS) 82 | unset(CMAKE_CXX_FLAGS) 83 | unset(CMAKE_SHARED_LINKER_FLAGS) 84 | unset(CMAKE_EXE_LINKER_FLAGS) 85 | unset(CMAKE_STATIC_LINKER_FLAGS) 86 | unset(CMAKE_LOCAL_LINKER_FLAGS) 87 | unset(CMAKE_MODULE_LINKER_FLAGS) 88 | 89 | foreach(configuration_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE}) 90 | string(TOUPPER ${configuration_type} capitalized_configuration_type) 91 | 92 | set(CMAKE_C_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_C_FLAGS_${capitalized_configuration_type}}) 93 | set(CMAKE_CXX_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_CXX_FLAGS_${capitalized_configuration_type}}) 94 | set(CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}}) 95 | set(CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}}) 96 | set(CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}}) 97 | set(CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}}) 98 | 99 | if(PRINT_DEBUG) 100 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_C_FLAGS_${capitalized_configuration_type} = ${CMAKE_C_FLAGS_${capitalized_configuration_type}}") 101 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_CXX_FLAGS_${capitalized_configuration_type} = ${CMAKE_CXX_FLAGS_${capitalized_configuration_type}}") 102 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}}") 103 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}}") 104 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}}") 105 | message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}}") 106 | endif() 107 | 108 | unset(CMAKE_C_FLAGS_${capitalized_configuration_type}) 109 | unset(CMAKE_CXX_FLAGS_${capitalized_configuration_type}) 110 | unset(CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}) 111 | unset(CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}) 112 | unset(CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}) 113 | unset(CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}) 114 | 115 | endforeach() 116 | 117 | endmacro() 118 | 119 | # 120 | # Macro to restore build flags set previously 121 | # 122 | macro(llvm_utils_pop_build_flags) 123 | message(STATUS "[LLVM] Restoring build system compilation flags") 124 | 125 | set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_BACKUP}) 126 | set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_BACKUP}) 127 | set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS_BACKUP}) 128 | set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS_BACKUP}) 129 | set(CMAKE_STATIC_LINKER_FLAGS ${CMAKE_STATIC_LINKER_FLAGS_BACKUP}) 130 | set(CMAKE_LOCAL_LINKER_FLAGS ${CMAKE_LOCAL_LINKER_FLAGS_BACKUP}) 131 | set(CMAKE_MODULE_LINKER_FLAGS ${CMAKE_MODULE_LINKER_FLAGS_BACKUP}) 132 | 133 | if(PRINT_DEBUG) 134 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}") 135 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}") 136 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}") 137 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}") 138 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_STATIC_LINKER_FLAGS = ${CMAKE_STATIC_LINKER_FLAGS}") 139 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_LOCAL_LINKER_FLAGS = ${CMAKE_LOCAL_LINKER_FLAGS}") 140 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_MODULE_LINKER_FLAGS = ${CMAKE_MODULE_LINKER_FLAGS}") 141 | endif() 142 | 143 | unset(CMAKE_C_FLAGS_BACKUP) 144 | unset(CMAKE_CXX_FLAGS_BACKUP) 145 | unset(CMAKE_SHARED_LINKER_FLAGS_BACKUP) 146 | unset(CMAKE_EXE_LINKER_FLAGS_BACKUP) 147 | unset(CMAKE_STATIC_LINKER_FLAGS_BACKUP) 148 | unset(CMAKE_LOCAL_LINKER_FLAGS_BACKUP) 149 | unset(CMAKE_MODULE_LINKER_FLAGS_BACKUP) 150 | 151 | foreach(configuration_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE}) 152 | string(TOUPPER ${configuration_type} capitalized_configuration_type) 153 | 154 | set(CMAKE_C_FLAGS_${capitalized_configuration_type} ${CMAKE_C_FLAGS_${capitalized_configuration_type}_BACKUP}) 155 | set(CMAKE_CXX_FLAGS_${capitalized_configuration_type} ${CMAKE_CXX_FLAGS_${capitalized_configuration_type}_BACKUP}) 156 | set(CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type} ${CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP}) 157 | set(CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type} ${CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP}) 158 | set(CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type} ${CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP}) 159 | set(CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type} ${CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP}) 160 | 161 | if(PRINT_DEBUG) 162 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_C_FLAGS_${capitalized_configuration_type} = ${CMAKE_C_FLAGS_${capitalized_configuration_type}}") 163 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_CXX_FLAGS_${capitalized_configuration_type} = ${CMAKE_CXX_FLAGS_${capitalized_configuration_type}}") 164 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}}") 165 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}}") 166 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}}") 167 | message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}}") 168 | endif() 169 | 170 | unset(CMAKE_C_FLAGS_${capitalized_configuration_type}_BACKUP) 171 | unset(CMAKE_CXX_FLAGS_${capitalized_configuration_type}_BACKUP) 172 | unset(CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP) 173 | unset(CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP) 174 | unset(CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP) 175 | unset(CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP) 176 | 177 | endforeach() 178 | 179 | endmacro() 180 | 181 | -------------------------------------------------------------------------------- /releases/10.0.0/patches_external/BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch: -------------------------------------------------------------------------------- 1 | From eeb816d95f0910bd246e37bb2bb3923acf0edf6b Mon Sep 17 00:00:00 2001 2 | From: Aleksander Us 3 | Date: Mon, 26 Aug 2019 15:47:41 +0300 4 | Subject: [PATCH] [BasicBlockUtils] Add metadata fixing in 5 | SplitBlockPredecessors. 6 | 7 | In case when BB is header of some loop and predecessor is latch of 8 | this loop, metadata was not attached to newly created basic block. 9 | This led to loss of loop metadata for other passes. 10 | --- 11 | lib/Transforms/Utils/BasicBlockUtils.cpp | 23 ++++++++---- 12 | test/Transforms/LoopSimplify/loop_metadata.ll | 36 +++++++++++++++++++ 13 | 2 files changed, 52 insertions(+), 7 deletions(-) 14 | create mode 100644 test/Transforms/LoopSimplify/loop_metadata.ll 15 | 16 | diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp 17 | index 5fa371377c8..3a90ae061fb 100644 18 | --- a/lib/Transforms/Utils/BasicBlockUtils.cpp 19 | +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp 20 | @@ -579,24 +579,33 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, 21 | 22 | // The new block unconditionally branches to the old block. 23 | BranchInst *BI = BranchInst::Create(BB, NewBB); 24 | + bool IsBBHeader = LI && LI->isLoopHeader(BB); 25 | + Loop *BBLoop = LI ? LI->getLoopFor(BB) : nullptr; 26 | // Splitting the predecessors of a loop header creates a preheader block. 27 | - if (LI && LI->isLoopHeader(BB)) 28 | + if (IsBBHeader) 29 | // Using the loop start line number prevents debuggers stepping into the 30 | // loop body for this instruction. 31 | - BI->setDebugLoc(LI->getLoopFor(BB)->getStartLoc()); 32 | + BI->setDebugLoc(BBLoop->getStartLoc()); 33 | else 34 | BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc()); 35 | 36 | // Move the edges from Preds to point to NewBB instead of BB. 37 | - for (unsigned i = 0, e = Preds.size(); i != e; ++i) { 38 | + for (BasicBlock *Pred : Preds) { 39 | + Instruction *PI = Pred->getTerminator(); 40 | // This is slightly more strict than necessary; the minimum requirement 41 | // is that there be no more than one indirectbr branching to BB. And 42 | // all BlockAddress uses would need to be updated. 43 | - assert(!isa(Preds[i]->getTerminator()) && 44 | + assert(!isa(PI) && 45 | "Cannot split an edge from an IndirectBrInst"); 46 | - assert(!isa(Preds[i]->getTerminator()) && 47 | - "Cannot split an edge from a CallBrInst"); 48 | - Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB); 49 | + assert(!isa(PI) && "Cannot split an edge from a CallBrInst"); 50 | + if (IsBBHeader && BBLoop->contains(Pred) && BBLoop->isLoopLatch(Pred)) { 51 | + // Update loop metadata if it exists. 52 | + if (MDNode *LoopMD = PI->getMetadata(LLVMContext::MD_loop)) { 53 | + BI->setMetadata(LLVMContext::MD_loop, LoopMD); 54 | + PI->setMetadata(LLVMContext::MD_loop, nullptr); 55 | + } 56 | + } 57 | + PI->replaceUsesOfWith(BB, NewBB); 58 | } 59 | 60 | // Insert a new PHI node into NewBB for every PHI node in BB and that new PHI 61 | diff --git a/test/Transforms/LoopSimplify/loop_metadata.ll b/test/Transforms/LoopSimplify/loop_metadata.ll 62 | new file mode 100644 63 | index 00000000000..c15c92fe3ae 64 | --- /dev/null 65 | +++ b/test/Transforms/LoopSimplify/loop_metadata.ll 66 | @@ -0,0 +1,36 @@ 67 | +; RUN: opt -S -loop-simplify < %s | FileCheck %s 68 | + 69 | +; CHECK: for.cond.loopexit: 70 | +; CHECK: br label %for.cond, !llvm.loop !0 71 | +; CHECK: br i1 %cmp1, label %for.body1, label %for.cond.loopexit 72 | + 73 | +define void @foo() { 74 | +entry: 75 | + br label %for.cond 76 | + 77 | +for.cond: ; preds = %for.cond1, %entry 78 | + %j = phi i32 [ 0, %entry ], [ %add, %for.cond1 ] 79 | + %cmp = icmp ult i32 %j, 8 80 | + br i1 %cmp, label %for.body, label %for.end 81 | + 82 | +for.body: ; preds = %for.cond 83 | + %dummy1 = add i32 1, 1 84 | + %add = add nuw nsw i32 %j, 1 85 | + br label %for.cond1 86 | + 87 | +for.cond1: ; preds = %for.body1, %for.body 88 | + %i.0 = phi i32 [ 1, %for.body ], [ %inc, %for.body1 ] 89 | + %cmp1 = icmp ult i32 %i.0, 8 90 | + br i1 %cmp1, label %for.body1, label %for.cond, !llvm.loop !0 91 | + 92 | +for.body1: ; preds = %for.cond1 93 | + %dummy2 = add i32 1, 1 94 | + %inc = add nuw nsw i32 %i.0, 1 95 | + br label %for.cond1 96 | + 97 | +for.end: ; preds = %for.cond 98 | + ret void 99 | +} 100 | + 101 | +!0 = distinct !{!0, !1} 102 | +!1 = !{!"llvm.loop.unroll.full"} 103 | -- 104 | 2.18.0 105 | 106 | -------------------------------------------------------------------------------- /releases/10.0.0/patches_external/IndVarSimplify-Do-not-use-SCEV-expander-for-IVCount-.patch: -------------------------------------------------------------------------------- 1 | From 35e218a886f4c066eabd18685240d55270bd5a6d Mon Sep 17 00:00:00 2001 2 | From: Aleksander Us 3 | Date: Mon, 26 Aug 2019 15:45:47 +0300 4 | Subject: [PATCH] [IndVarSimplify] Do not use SCEV expander for IVCount in 5 | LFTR when possible. 6 | 7 | SCEV analysis cannot properly cache instruction with poison flags 8 | (for example, add nsw outside of loop will not be reused by expander). 9 | This can lead to generating of additional instructions by SCEV expander. 10 | 11 | Example IR: 12 | 13 | ... 14 | %maxval = add nuw nsw i32 %a1, %a2 15 | ... 16 | for.body: 17 | ... 18 | %cmp22 = icmp ult i32 %ivadd, %maxval 19 | br i1 %cmp22, label %for.body, label %for.end 20 | ... 21 | 22 | SCEV expander will generate copy of %maxval in preheader but without 23 | nuw/nsw flags. This can be avoided by explicit check that iv count 24 | value gives the same SCEV expressions as calculated by LFTR. 25 | --- 26 | lib/Transforms/Scalar/IndVarSimplify.cpp | 12 +++++++++- 27 | test/Transforms/IndVarSimplify/add_nsw.ll | 23 ++++++++++++++++++++ 28 | test/Transforms/IndVarSimplify/lftr-reuse.ll | 9 +++----- 29 | test/Transforms/IndVarSimplify/udiv.ll | 1 + 30 | 4 files changed, 38 insertions(+), 7 deletions(-) 31 | create mode 100644 test/Transforms/IndVarSimplify/add_nsw.ll 32 | 33 | diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp 34 | index f9fc698a4a9..5e04dac8aa6 100644 35 | --- a/lib/Transforms/Scalar/IndVarSimplify.cpp 36 | +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp 37 | @@ -2375,6 +2375,17 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB, 38 | if (UsePostInc) 39 | IVLimit = SE->getAddExpr(IVLimit, SE->getOne(IVLimit->getType())); 40 | 41 | + // If computed limit is equal to old limit then do not use SCEV expander 42 | + // because it can lost NUW/NSW flags and create extra instructions. 43 | + BranchInst *BI = cast(ExitingBB->getTerminator()); 44 | + if (ICmpInst *Cmp = dyn_cast(BI->getOperand(0))) { 45 | + Value *Limit = Cmp->getOperand(0); 46 | + if (!L->isLoopInvariant(Limit)) 47 | + Limit = Cmp->getOperand(1); 48 | + if (SE->getSCEV(Limit) == IVLimit) 49 | + return Limit; 50 | + } 51 | + 52 | // Expand the code for the iteration count. 53 | assert(SE->isLoopInvariant(IVLimit, L) && 54 | "Computed iteration count is not loop invariant!"); 55 | @@ -2383,7 +2394,6 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB, 56 | // SCEV expression (IVInit) for a pointer type IV value (IndVar). 57 | Type *LimitTy = ExitCount->getType()->isPointerTy() ? 58 | IndVar->getType() : ExitCount->getType(); 59 | - BranchInst *BI = cast(ExitingBB->getTerminator()); 60 | return Rewriter.expandCodeFor(IVLimit, LimitTy, BI); 61 | } 62 | } 63 | diff --git a/test/Transforms/IndVarSimplify/add_nsw.ll b/test/Transforms/IndVarSimplify/add_nsw.ll 64 | new file mode 100644 65 | index 00000000000..abd1cbb6c51 66 | --- /dev/null 67 | +++ b/test/Transforms/IndVarSimplify/add_nsw.ll 68 | @@ -0,0 +1,23 @@ 69 | +; RUN: opt -indvars -S %s | FileCheck %s 70 | + 71 | +target datalayout = "e-p:32:32-i64:64-n8:16:32" 72 | + 73 | +; CHECK: for.body.preheader: 74 | +; CHECK-NOT: add 75 | +; CHECK: for.body: 76 | + 77 | +define void @foo(i32 %a1, i32 %a2) { 78 | +entry: 79 | + %maxval = add nuw nsw i32 %a1, %a2 80 | + %cmp = icmp slt i32 %maxval, 1 81 | + br i1 %cmp, label %for.end, label %for.body 82 | + 83 | +for.body: ; preds = %entry, %for.body 84 | + %j.02 = phi i32 [ 0, %entry ], [ %add31, %for.body ] 85 | + %add31 = add nuw nsw i32 %j.02, 1 86 | + %cmp22 = icmp slt i32 %add31, %maxval 87 | + br i1 %cmp22, label %for.body, label %for.end 88 | + 89 | +for.end: ; preds = %for.body 90 | + ret void 91 | +} 92 | diff --git a/test/Transforms/IndVarSimplify/lftr-reuse.ll b/test/Transforms/IndVarSimplify/lftr-reuse.ll 93 | index 14ae9738696..509d662b767 100644 94 | --- a/test/Transforms/IndVarSimplify/lftr-reuse.ll 95 | +++ b/test/Transforms/IndVarSimplify/lftr-reuse.ll 96 | @@ -67,11 +67,9 @@ define void @expandOuterRecurrence(i32 %arg) nounwind { 97 | ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 0, [[SUB1]] 98 | ; CHECK-NEXT: br i1 [[CMP1]], label [[OUTER_PREHEADER:%.*]], label [[EXIT:%.*]] 99 | ; CHECK: outer.preheader: 100 | -; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[ARG]], -1 101 | ; CHECK-NEXT: br label [[OUTER:%.*]] 102 | ; CHECK: outer: 103 | -; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[TMP0]], [[OUTER_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[OUTER_INC:%.*]] ] 104 | -; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_INC:%.*]], [[OUTER_INC]] ], [ 0, [[OUTER_PREHEADER]] ] 105 | +; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_INC:%.*]], [[OUTER_INC:%.*]] ], [ 0, [[OUTER_PREHEADER]] ] 106 | ; CHECK-NEXT: [[SUB2:%.*]] = sub nsw i32 [[ARG]], [[I]] 107 | ; CHECK-NEXT: [[SUB3:%.*]] = sub nsw i32 [[SUB2]], 1 108 | ; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 0, [[SUB3]] 109 | @@ -81,14 +79,13 @@ define void @expandOuterRecurrence(i32 %arg) nounwind { 110 | ; CHECK: inner: 111 | ; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[INNER_PH]] ], [ [[J_INC:%.*]], [[INNER]] ] 112 | ; CHECK-NEXT: [[J_INC]] = add nuw nsw i32 [[J]], 1 113 | -; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[J_INC]], [[INDVARS_IV]] 114 | +; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[J_INC]], [[SUB3]] 115 | ; CHECK-NEXT: br i1 [[EXITCOND]], label [[INNER]], label [[OUTER_INC_LOOPEXIT:%.*]] 116 | ; CHECK: outer.inc.loopexit: 117 | ; CHECK-NEXT: br label [[OUTER_INC]] 118 | ; CHECK: outer.inc: 119 | ; CHECK-NEXT: [[I_INC]] = add nuw nsw i32 [[I]], 1 120 | -; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i32 [[INDVARS_IV]], -1 121 | -; CHECK-NEXT: [[EXITCOND1:%.*]] = icmp ne i32 [[I_INC]], [[TMP0]] 122 | +; CHECK-NEXT: [[EXITCOND1:%.*]] = icmp ne i32 [[I_INC]], [[SUB1]] 123 | ; CHECK-NEXT: br i1 [[EXITCOND1]], label [[OUTER]], label [[EXIT_LOOPEXIT:%.*]] 124 | ; CHECK: exit.loopexit: 125 | ; CHECK-NEXT: br label [[EXIT]] 126 | diff --git a/test/Transforms/IndVarSimplify/udiv.ll b/test/Transforms/IndVarSimplify/udiv.ll 127 | index b3f2c2a6a66..3530343ef4a 100644 128 | --- a/test/Transforms/IndVarSimplify/udiv.ll 129 | +++ b/test/Transforms/IndVarSimplify/udiv.ll 130 | @@ -133,6 +133,7 @@ declare i32 @printf(i8* nocapture, ...) nounwind 131 | ; CHECK-LABEL: @foo( 132 | ; CHECK: for.body.preheader: 133 | ; CHECK-NOT: udiv 134 | +; CHECK: for.body: 135 | 136 | define void @foo(double* %p, i64 %n) nounwind { 137 | entry: 138 | -- 139 | 2.18.0 140 | 141 | -------------------------------------------------------------------------------- /releases/10.0.0/patches_external/InstCombine-visitBitCast-do-not-crash-on-weird-bitca.patch: -------------------------------------------------------------------------------- 1 | From 381054a989ebd0b585fee46f2a01a7c5de10acf7 Mon Sep 17 00:00:00 2001 2 | From: Roman Lebedev 3 | Date: Wed, 24 Jun 2020 21:12:09 +0300 4 | Subject: [PATCH] [InstCombine] visitBitCast(): do not crash on weird `bitcast 5 | <1 x i8*> to i8*` 6 | 7 | Even if we know that RHS of a bitcast is a pointer, 8 | we can't assume LHS is, because it might be 9 | a single-element vector of pointer. 10 | --- 11 | lib/Transforms/InstCombine/InstCombineCasts.cpp | 3 ++- 12 | test/Transforms/InstCombine/bitcast.ll | 6 ++++++ 13 | 2 files changed, 8 insertions(+), 1 deletion(-) 14 | 15 | diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp 16 | index 3750f31e3cf..a8c87ea3558 100644 17 | --- a/lib/Transforms/InstCombine/InstCombineCasts.cpp 18 | +++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp 19 | @@ -2471,8 +2471,9 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { 20 | if (DestTy == Src->getType()) 21 | return replaceInstUsesWith(CI, Src); 22 | 23 | - if (PointerType *DstPTy = dyn_cast(DestTy)) { 24 | + if (isa(SrcTy) && isa(DestTy)) { 25 | PointerType *SrcPTy = cast(SrcTy); 26 | + PointerType *DstPTy = cast(DestTy); 27 | Type *DstElTy = DstPTy->getElementType(); 28 | Type *SrcElTy = SrcPTy->getElementType(); 29 | 30 | diff --git a/test/Transforms/InstCombine/bitcast.ll b/test/Transforms/InstCombine/bitcast.ll 31 | index 0f0cbdb364a..c4ee52f27a8 100644 32 | --- a/test/Transforms/InstCombine/bitcast.ll 33 | +++ b/test/Transforms/InstCombine/bitcast.ll 34 | @@ -561,3 +561,9 @@ define void @constant_fold_vector_to_half() { 35 | store volatile half bitcast (<4 x i4> to half), half* undef 36 | ret void 37 | } 38 | + 39 | +; Ensure that we do not crash when looking at such a weird bitcast. 40 | +define i8* @bitcast_from_single_element_pointer_vector_to_pointer(<1 x i8*> %ptrvec) { 41 | + %ptr = bitcast <1 x i8*> %ptrvec to i8* 42 | + ret i8* %ptr 43 | +} 44 | -- 45 | 2.17.1 46 | 47 | -------------------------------------------------------------------------------- /releases/10.0.0/patches_external/Instruction-Add-dropLocation-and-updateLocationAfter.patch: -------------------------------------------------------------------------------- 1 | From dfc5a9eb57aaaac972764bf731503419284bd3dc Mon Sep 17 00:00:00 2001 2 | From: Vedant Kumar 3 | Date: Tue, 8 Sep 2020 13:39:52 -0700 4 | Subject: [PATCH] [Instruction] Add dropLocation and updateLocationAfterHoist 5 | helpers 6 | 7 | Introduce a helper which can be used to update the debug location of an 8 | Instruction after the instruction is hoisted. This can be used to safely 9 | drop a source location as recommended by the docs. 10 | 11 | For more context, see the discussion in https://reviews.llvm.org/D60913. 12 | 13 | Differential Revision: https://reviews.llvm.org/D85670 14 | --- 15 | include/llvm/IR/Instruction.h | 14 ++++ 16 | lib/IR/DebugInfo.cpp | 32 +++++++++ 17 | lib/Transforms/Scalar/GVN.cpp | 4 +- 18 | lib/Transforms/Scalar/LICM.cpp | 5 +- 19 | test/DebugInfo/Generic/licm-hoist-debug-loc.ll | 3 +- 20 | test/Transforms/GVN/PRE/phi-translate.ll | 7 +- 21 | unittests/IR/InstructionsTest.cpp | 72 +++++++++++++++++++ 22 | 8 files changed, 125 insertions(+), 14 deletions(-) 23 | 24 | diff --git a/include/llvm/IR/Instruction.h b/include/llvm/IR/Instruction.h 25 | index ceec001dccf4..24f8e0d6a4b1 100644 26 | --- a/include/llvm/IR/Instruction.h 27 | +++ b/include/llvm/IR/Instruction.h 28 | @@ -492,6 +492,20 @@ public: 29 | /// merged DebugLoc. 30 | void applyMergedLocation(const DILocation *LocA, const DILocation *LocB); 31 | 32 | + /// Updates the debug location given that the instruction has been hoisted 33 | + /// from a block to a predecessor of that block. 34 | + /// Note: it is undefined behavior to call this on an instruction not 35 | + /// currently inserted into a function. 36 | + void updateLocationAfterHoist(); 37 | + 38 | + /// Drop the instruction's debug location. This does not guarantee removal 39 | + /// of the !dbg source location attachment, as it must set a line 0 location 40 | + /// with scope information attached on call instructions. To guarantee 41 | + /// removal of the !dbg attachment, use the \ref setDebugLoc() API. 42 | + /// Note: it is undefined behavior to call this on an instruction not 43 | + /// currently inserted into a function. 44 | + void dropLocation(); 45 | + 46 | private: 47 | /// Return true if we have an entry in the on-the-side metadata hash. 48 | bool hasMetadataHashEntry() const { 49 | diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp 50 | index 190b220dc9aa..603b88200001 100644 51 | --- a/lib/IR/DebugInfo.cpp 52 | +++ b/lib/IR/DebugInfo.cpp 53 | @@ -696,6 +696,38 @@ void Instruction::applyMergedLocation(const DILocation *LocA, 54 | setDebugLoc(DILocation::getMergedLocation(LocA, LocB)); 55 | } 56 | 57 | +void Instruction::updateLocationAfterHoist() { dropLocation(); } 58 | + 59 | +void Instruction::dropLocation() { 60 | + const DebugLoc &DL = getDebugLoc(); 61 | + if (!DL) 62 | + return; 63 | + 64 | + // If this isn't a call, drop the location to allow a location from a 65 | + // preceding instruction to propagate. 66 | + if (!isa(this)) { 67 | + setDebugLoc(DebugLoc()); 68 | + return; 69 | + } 70 | + 71 | + // Set a line 0 location for calls to preserve scope information in case 72 | + // inlining occurs. 73 | + const DISubprogram *SP = getFunction()->getSubprogram(); 74 | + if (SP) 75 | + // If a function scope is available, set it on the line 0 location. When 76 | + // hoisting a call to a predecessor block, using the function scope avoids 77 | + // making it look like the callee was reached earlier than it should be. 78 | + setDebugLoc(DebugLoc::get(0, 0, SP)); 79 | + else 80 | + // The parent function has no scope. Go ahead and drop the location. If 81 | + // the parent function is inlined, and the callee has a subprogram, the 82 | + // inliner will attach a location to the call. 83 | + // 84 | + // One alternative is to set a line 0 location with the existing scope and 85 | + // inlinedAt info. The location might be sensitive to when inlining occurs. 86 | + setDebugLoc(DebugLoc()); 87 | +} 88 | + 89 | //===----------------------------------------------------------------------===// 90 | // LLVM C API implementations. 91 | //===----------------------------------------------------------------------===// 92 | diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp 93 | index f8e8e2c773f9..c25fdd44dcf9 100644 94 | --- a/lib/Transforms/Scalar/GVN.cpp 95 | +++ b/lib/Transforms/Scalar/GVN.cpp 96 | @@ -48,7 +48,6 @@ 97 | #include "llvm/IR/Constant.h" 98 | #include "llvm/IR/Constants.h" 99 | #include "llvm/IR/DataLayout.h" 100 | -#include "llvm/IR/DebugInfoMetadata.h" 101 | #include "llvm/IR/DebugLoc.h" 102 | #include "llvm/IR/Dominators.h" 103 | #include "llvm/IR/Function.h" 104 | @@ -1323,8 +1322,7 @@ bool GVN::PerformLoadPRE(LoadInst *LI, AvailValInBlkVect &ValuesPerBlock, 105 | // Instructions that have been inserted in predecessor(s) to materialize 106 | // the load address do not retain their original debug locations. Doing 107 | // so could lead to confusing (but correct) source attributions. 108 | - if (const DebugLoc &DL = I->getDebugLoc()) 109 | - I->setDebugLoc(DebugLoc::get(0, 0, DL.getScope(), DL.getInlinedAt())); 110 | + I->updateLocationAfterHoist(); 111 | 112 | // FIXME: We really _ought_ to insert these value numbers into their 113 | // parent's availability map. However, in doing so, we risk getting into 114 | diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp 115 | index 1b1679e1b03d..631fa2f27c5b 100644 116 | --- a/lib/Transforms/Scalar/LICM.cpp 117 | +++ b/lib/Transforms/Scalar/LICM.cpp 118 | @@ -1736,10 +1736,7 @@ static void hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop, 119 | // Move the new node to the destination block, before its terminator. 120 | moveInstructionBefore(I, *Dest->getTerminator(), *SafetyInfo, MSSAU, SE); 121 | 122 | - // Apply line 0 debug locations when we are moving instructions to different 123 | - // basic blocks because we want to avoid jumpy line tables. 124 | - if (const DebugLoc &DL = I.getDebugLoc()) 125 | - I.setDebugLoc(DebugLoc::get(0, 0, DL.getScope(), DL.getInlinedAt())); 126 | + I.updateLocationAfterHoist(); 127 | 128 | if (isa(I)) 129 | ++NumMovedLoads; 130 | diff --git a/test/DebugInfo/Generic/licm-hoist-debug-loc.ll b/test/DebugInfo/Generic/licm-hoist-debug-loc.ll 131 | index 0a13e9604f0c..37c642170aa3 100644 132 | --- a/test/DebugInfo/Generic/licm-hoist-debug-loc.ll 133 | +++ b/test/DebugInfo/Generic/licm-hoist-debug-loc.ll 134 | @@ -18,9 +18,8 @@ 135 | ; We make sure that the instruction that is hoisted into the preheader 136 | ; does not have a debug location. 137 | ; CHECK: for.body.lr.ph: 138 | -; CHECK: getelementptr{{.*}}%p.addr, i64 4{{.*}} !dbg [[zero:![0-9]+]] 139 | +; CHECK: getelementptr{{.*}}%p.addr, i64 4{{$}} 140 | ; CHECK: for.body: 141 | -; CHECK: [[zero]] = !DILocation(line: 0 142 | ; 143 | ; ModuleID = 't.ll' 144 | source_filename = "test.c" 145 | diff --git a/test/Transforms/GVN/PRE/phi-translate.ll b/test/Transforms/GVN/PRE/phi-translate.ll 146 | index f80e002eab0a..2b6a577d6678 100644 147 | --- a/test/Transforms/GVN/PRE/phi-translate.ll 148 | +++ b/test/Transforms/GVN/PRE/phi-translate.ll 149 | @@ -4,8 +4,8 @@ target datalayout = "e-p:64:64:64" 150 | 151 | ; CHECK-LABEL: @foo( 152 | ; CHECK: entry.end_crit_edge: 153 | -; CHECK: %[[INDEX:[a-z0-9.]+]] = sext i32 %x to i64{{.*}} !dbg [[ZERO_LOC:![0-9]+]] 154 | -; CHECK: %[[ADDRESS:[a-z0-9.]+]] = getelementptr [100 x i32], [100 x i32]* @G, i64 0, i64 %[[INDEX]]{{.*}} !dbg [[ZERO_LOC]] 155 | +; CHECK: %[[INDEX:[a-z0-9.]+]] = sext i32 %x to i64{{$}} 156 | +; CHECK: %[[ADDRESS:[a-z0-9.]+]] = getelementptr [100 x i32], [100 x i32]* @G, i64 0, i64 %[[INDEX]]{{$}} 157 | ; CHECK: %n.pre = load i32, i32* %[[ADDRESS]], !dbg [[N_LOC:![0-9]+]] 158 | ; CHECK: br label %end 159 | ; CHECK: then: 160 | @@ -14,8 +14,7 @@ target datalayout = "e-p:64:64:64" 161 | ; CHECK: %n = phi i32 [ %n.pre, %entry.end_crit_edge ], [ %z, %then ], !dbg [[N_LOC]] 162 | ; CHECK: ret i32 %n 163 | 164 | -; CHECK-DAG: [[N_LOC]] = !DILocation(line: 47, column: 1, scope: !{{.*}}) 165 | -; CHECK-DAG: [[ZERO_LOC]] = !DILocation(line: 0 166 | +; CHECK: [[N_LOC]] = !DILocation(line: 47, column: 1, scope: !{{.*}}) 167 | 168 | @G = external global [100 x i32] 169 | define i32 @foo(i32 %x, i32 %z) !dbg !6 { 170 | diff --git a/unittests/IR/InstructionsTest.cpp b/unittests/IR/InstructionsTest.cpp 171 | index b25eee7279af..1324fe2d1dd7 100644 172 | --- a/unittests/IR/InstructionsTest.cpp 173 | +++ b/unittests/IR/InstructionsTest.cpp 174 | @@ -13,6 +13,7 @@ 175 | #include "llvm/IR/BasicBlock.h" 176 | #include "llvm/IR/Constants.h" 177 | #include "llvm/IR/DataLayout.h" 178 | +#include "llvm/IR/DebugInfoMetadata.h" 179 | #include "llvm/IR/DerivedTypes.h" 180 | #include "llvm/IR/Function.h" 181 | #include "llvm/IR/IRBuilder.h" 182 | @@ -1304,5 +1305,76 @@ TEST(InstructionsTest, UnaryOperator) { 183 | I->deleteValue(); 184 | } 185 | 186 | +TEST(InstructionsTest, DropLocation) { 187 | + LLVMContext C; 188 | + std::unique_ptr M = parseIR(C, 189 | + R"( 190 | + declare void @callee() 191 | + 192 | + define void @no_parent_scope() { 193 | + call void @callee() ; I1: Call with no location. 194 | + call void @callee(), !dbg !11 ; I2: Call with location. 195 | + ret void, !dbg !11 ; I3: Non-call with location. 196 | + } 197 | + 198 | + define void @with_parent_scope() !dbg !8 { 199 | + call void @callee() ; I1: Call with no location. 200 | + call void @callee(), !dbg !11 ; I2: Call with location. 201 | + ret void, !dbg !11 ; I3: Non-call with location. 202 | + } 203 | + 204 | + !llvm.dbg.cu = !{!0} 205 | + !llvm.module.flags = !{!3, !4} 206 | + !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) 207 | + !1 = !DIFile(filename: "t2.c", directory: "foo") 208 | + !2 = !{} 209 | + !3 = !{i32 2, !"Dwarf Version", i32 4} 210 | + !4 = !{i32 2, !"Debug Info Version", i32 3} 211 | + !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0, retainedNodes: !2) 212 | + !9 = !DISubroutineType(types: !10) 213 | + !10 = !{null} 214 | + !11 = !DILocation(line: 2, column: 7, scope: !8, inlinedAt: !12) 215 | + !12 = !DILocation(line: 3, column: 8, scope: !8) 216 | + )"); 217 | + ASSERT_TRUE(M); 218 | + 219 | + { 220 | + Function *NoParentScopeF = 221 | + cast(M->getNamedValue("no_parent_scope")); 222 | + BasicBlock &BB = NoParentScopeF->front(); 223 | + 224 | + auto *I1 = BB.getFirstNonPHI(); 225 | + auto *I2 = I1->getNextNode(); 226 | + auto *I3 = BB.getTerminator(); 227 | + 228 | + EXPECT_EQ(I1->getDebugLoc(), DebugLoc()); 229 | + I1->dropLocation(); 230 | + EXPECT_EQ(I1->getDebugLoc(), DebugLoc()); 231 | + 232 | + EXPECT_EQ(I2->getDebugLoc().getLine(), 2U); 233 | + I2->dropLocation(); 234 | + EXPECT_EQ(I1->getDebugLoc(), DebugLoc()); 235 | + 236 | + EXPECT_EQ(I3->getDebugLoc().getLine(), 2U); 237 | + I3->dropLocation(); 238 | + EXPECT_EQ(I3->getDebugLoc(), DebugLoc()); 239 | + } 240 | + 241 | + { 242 | + Function *WithParentScopeF = 243 | + cast(M->getNamedValue("with_parent_scope")); 244 | + BasicBlock &BB = WithParentScopeF->front(); 245 | + 246 | + auto *I2 = BB.getFirstNonPHI()->getNextNode(); 247 | + 248 | + MDNode *Scope = cast(WithParentScopeF->getSubprogram()); 249 | + EXPECT_EQ(I2->getDebugLoc().getLine(), 2U); 250 | + I2->dropLocation(); 251 | + EXPECT_EQ(I2->getDebugLoc().getLine(), 0U); 252 | + EXPECT_EQ(I2->getDebugLoc().getScope(), Scope); 253 | + EXPECT_EQ(I2->getDebugLoc().getInlinedAt(), nullptr); 254 | + } 255 | +} 256 | + 257 | } // end anonymous namespace 258 | } // end namespace llvm 259 | -- 260 | 2.29.2.windows.2 261 | 262 | -------------------------------------------------------------------------------- /releases/10.0.0/patches_external/fix_for_llvm-as_buildbreak.patch: -------------------------------------------------------------------------------- 1 | # Description : Fix build break for building llvm-as 2 | 3 | --- a/tools/llvm-as/CMakeLists.txt 4 | +++ b/tools/llvm-as/CMakeLists.txt 5 | @@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS 6 | AsmParser 7 | BitWriter 8 | Core 9 | + Demangle 10 | Support 11 | ) 12 | -------------------------------------------------------------------------------- /releases/10.0.0/patches_external/fix_for_llvm-link_buildbreak.patch: -------------------------------------------------------------------------------- 1 | # Description : Fix build break for building llvm-link 2 | 3 | --- a/tools/llvm-link/CMakeLists.txt 4 | +++ b/tools/llvm-link/CMakeLists.txt 5 | @@ -8,6 +8,7 @@ set(LLVM_LINK_COMPONENTS 6 | Support 7 | TransformUtils 8 | IPO 9 | + Demangle 10 | ) 11 | 12 | add_llvm_tool(llvm-link 13 | -------------------------------------------------------------------------------- /releases/10.0.0/patches_external/fix_for_opt_buildbreak.patch: -------------------------------------------------------------------------------- 1 | # Description : Fix build break for building opt 2 | 3 | --- a/tools/opt/CMakeLists.txt 4 | +++ b/tools/opt/CMakeLists.txt 5 | @@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS 6 | CodeGen 7 | Core 8 | Coroutines 9 | + Demangle 10 | IPO 11 | IRReader 12 | InstCombine 13 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/2_1-enable-aggressive-combining.patch: -------------------------------------------------------------------------------- 1 | # Description : Enable aggressive (gep (gep base, idx0), idx1) combining 2 | 3 | 4 | diff -Naur --strip-trailing-cr a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp 5 | --- a/lib/Transforms/InstCombine/InstructionCombining.cpp 2017-10-24 08:51:48.146973901 -0400 6 | +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp 2017-10-24 08:52:36.064972024 -0400 7 | @@ -1573,11 +1573,13 @@ 8 | // normalized. 9 | if (SO1->getType() != GO1->getType()) 10 | return nullptr; 11 | +#if 0 12 | // Only do the combine when GO1 and SO1 are both constants. Only in 13 | // this case, we are sure the cost after the merge is never more than 14 | // that before the merge. 15 | if (!isa(GO1) || !isa(SO1)) 16 | return nullptr; 17 | +#endif 18 | Sum = Builder->CreateAdd(SO1, GO1, PtrOp->getName()+".sum"); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/2_2-completely-turn-off-code-sinking-in-InstructionCombining.patch: -------------------------------------------------------------------------------- 1 | # Description : completely turn off code-sinking in InstructionCombining. 2 | 3 | 4 | diff -Naur --strip-trailing-cr a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp 5 | --- a/lib/Transforms/InstCombine/InstructionCombining.cpp 2017-10-23 09:48:44.308224955 -0400 6 | +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp 2017-10-23 09:49:06.404224089 -0400 7 | @@ -2871,7 +2871,9 @@ 8 | } 9 | 10 | // See if we can trivially sink this instruction to a successor basic block. 11 | - if (I->hasOneUse()) { 12 | + /*** turn off code-sinking ***/ 13 | + /*** if (I->hasOneUse()) { ***/ 14 | + if (0) { 15 | BasicBlock *BB = I->getParent(); 16 | Instruction *UserInst = cast(*I->user_begin()); 17 | BasicBlock *UserParent; 18 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/3_1-SimplifyCFG-SinkThenElseCodeToEnd-does-not-sink-code.patch: -------------------------------------------------------------------------------- 1 | # Description : SimplifyCFG::SinkThenElseCodeToEnd does not sink code similiar 2 | # to LLVM 3.8 3 | 4 | 5 | diff -Naur --strip-trailing-cr a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp 6 | --- a/lib/Transforms/Utils/SimplifyCFG.cpp 2017-10-23 09:53:04.934214744 -0400 7 | +++ b/lib/Transforms/Utils/SimplifyCFG.cpp 2017-10-23 13:44:20.401671146 -0400 8 | @@ -1835,6 +1835,183 @@ 9 | return Changed; 10 | } 11 | 12 | +/// Given an unconditional branch that goes to BBEnd, 13 | +/// check whether BBEnd has only two predecessors and the other predecessor 14 | +/// ends with an unconditional branch. If it is true, sink any common code 15 | +/// in the two predecessors to BBEnd. 16 | +static bool SinkThenElseCodeToEnd_LLVM38(BranchInst *BI1) { 17 | + assert(BI1->isUnconditional()); 18 | + BasicBlock *BB1 = BI1->getParent(); 19 | + BasicBlock *BBEnd = BI1->getSuccessor(0); 20 | + 21 | + // Check that BBEnd has two predecessors and the other predecessor ends with 22 | + // an unconditional branch. 23 | + pred_iterator PI = pred_begin(BBEnd), PE = pred_end(BBEnd); 24 | + BasicBlock *Pred0 = *PI++; 25 | + if (PI == PE) // Only one predecessor. 26 | + return false; 27 | + BasicBlock *Pred1 = *PI++; 28 | + if (PI != PE) // More than two predecessors. 29 | + return false; 30 | + BasicBlock *BB2 = (Pred0 == BB1) ? Pred1 : Pred0; 31 | + BranchInst *BI2 = dyn_cast(BB2->getTerminator()); 32 | + if (!BI2 || !BI2->isUnconditional()) 33 | + return false; 34 | + 35 | + // Gather the PHI nodes in BBEnd. 36 | + SmallDenseMap, PHINode *> JointValueMap; 37 | + Instruction *FirstNonPhiInBBEnd = nullptr; 38 | + for (BasicBlock::iterator I = BBEnd->begin(), E = BBEnd->end(); I != E; ++I) { 39 | + if (PHINode *PN = dyn_cast(I)) { 40 | + Value *BB1V = PN->getIncomingValueForBlock(BB1); 41 | + Value *BB2V = PN->getIncomingValueForBlock(BB2); 42 | + JointValueMap[std::make_pair(BB1V, BB2V)] = PN; 43 | + } else { 44 | + FirstNonPhiInBBEnd = &*I; 45 | + break; 46 | + } 47 | + } 48 | + if (!FirstNonPhiInBBEnd) 49 | + return false; 50 | + 51 | + // This does very trivial matching, with limited scanning, to find identical 52 | + // instructions in the two blocks. We scan backward for obviously identical 53 | + // instructions in an identical order. 54 | + BasicBlock::InstListType::reverse_iterator RI1 = BB1->getInstList().rbegin(), 55 | + RE1 = BB1->getInstList().rend(), 56 | + RI2 = BB2->getInstList().rbegin(), 57 | + RE2 = BB2->getInstList().rend(); 58 | + // Skip debug info. 59 | + while (RI1 != RE1 && isa(&*RI1)) ++RI1; 60 | + if (RI1 == RE1) 61 | + return false; 62 | + while (RI2 != RE2 && isa(&*RI2)) ++RI2; 63 | + if (RI2 == RE2) 64 | + return false; 65 | + // Skip the unconditional branches. 66 | + ++RI1; 67 | + ++RI2; 68 | + 69 | + bool Changed = false; 70 | + while (RI1 != RE1 && RI2 != RE2) { 71 | + // Skip debug info. 72 | + while (RI1 != RE1 && isa(&*RI1)) ++RI1; 73 | + if (RI1 == RE1) 74 | + return Changed; 75 | + while (RI2 != RE2 && isa(&*RI2)) ++RI2; 76 | + if (RI2 == RE2) 77 | + return Changed; 78 | + 79 | + Instruction *I1 = &*RI1, *I2 = &*RI2; 80 | + auto InstPair = std::make_pair(I1, I2); 81 | + // I1 and I2 should have a single use in the same PHI node, and they 82 | + // perform the same operation. 83 | + // Cannot move control-flow-involving, volatile loads, vaarg, etc. 84 | + if (isa(I1) || isa(I2) || 85 | + isa(I1) || isa(I2) || 86 | + I1->isEHPad() || I2->isEHPad() || 87 | + isa(I1) || isa(I2) || 88 | + I1->mayHaveSideEffects() || I2->mayHaveSideEffects() || 89 | + I1->mayReadOrWriteMemory() || I2->mayReadOrWriteMemory() || 90 | + !I1->hasOneUse() || !I2->hasOneUse() || 91 | + !JointValueMap.count(InstPair)) 92 | + return Changed; 93 | + 94 | + // Check whether we should swap the operands of ICmpInst. 95 | + // TODO: Add support of communativity. 96 | + ICmpInst *ICmp1 = dyn_cast(I1), *ICmp2 = dyn_cast(I2); 97 | + bool SwapOpnds = false; 98 | + if (ICmp1 && ICmp2 && 99 | + ICmp1->getOperand(0) != ICmp2->getOperand(0) && 100 | + ICmp1->getOperand(1) != ICmp2->getOperand(1) && 101 | + (ICmp1->getOperand(0) == ICmp2->getOperand(1) || 102 | + ICmp1->getOperand(1) == ICmp2->getOperand(0))) { 103 | + ICmp2->swapOperands(); 104 | + SwapOpnds = true; 105 | + } 106 | + if (!I1->isSameOperationAs(I2)) { 107 | + if (SwapOpnds) 108 | + ICmp2->swapOperands(); 109 | + return Changed; 110 | + } 111 | + 112 | + // The operands should be either the same or they need to be generated 113 | + // with a PHI node after sinking. We only handle the case where there is 114 | + // a single pair of different operands. 115 | + Value *DifferentOp1 = nullptr, *DifferentOp2 = nullptr; 116 | + unsigned Op1Idx = ~0U; 117 | + for (unsigned I = 0, E = I1->getNumOperands(); I != E; ++I) { 118 | + if (I1->getOperand(I) == I2->getOperand(I)) 119 | + continue; 120 | + // Early exit if we have more-than one pair of different operands or if 121 | + // we need a PHI node to replace a constant. 122 | + if (Op1Idx != ~0U || 123 | + isa(I1->getOperand(I)) || 124 | + isa(I2->getOperand(I))) { 125 | + // If we can't sink the instructions, undo the swapping. 126 | + if (SwapOpnds) 127 | + ICmp2->swapOperands(); 128 | + return Changed; 129 | + } 130 | + DifferentOp1 = I1->getOperand(I); 131 | + Op1Idx = I; 132 | + DifferentOp2 = I2->getOperand(I); 133 | + } 134 | + 135 | + DEBUG(dbgs() << "SINK common instructions " << *I1 << "\n"); 136 | + DEBUG(dbgs() << " " << *I2 << "\n"); 137 | + 138 | + // We insert the pair of different operands to JointValueMap and 139 | + // remove (I1, I2) from JointValueMap. 140 | + if (Op1Idx != ~0U) { 141 | + auto &NewPN = JointValueMap[std::make_pair(DifferentOp1, DifferentOp2)]; 142 | + if (!NewPN) { 143 | + NewPN = 144 | + PHINode::Create(DifferentOp1->getType(), 2, 145 | + DifferentOp1->getName() + ".sink", &BBEnd->front()); 146 | + NewPN->addIncoming(DifferentOp1, BB1); 147 | + NewPN->addIncoming(DifferentOp2, BB2); 148 | + DEBUG(dbgs() << "Create PHI node " << *NewPN << "\n";); 149 | + } 150 | + // I1 should use NewPN instead of DifferentOp1. 151 | + I1->setOperand(Op1Idx, NewPN); 152 | + } 153 | + PHINode *OldPN = JointValueMap[InstPair]; 154 | + JointValueMap.erase(InstPair); 155 | + 156 | + // We need to update RE1 and RE2 if we are going to sink the first 157 | + // instruction in the basic block down. 158 | + bool UpdateRE1 = (I1 == &*BB1->begin()), UpdateRE2 = (I2 == &*BB2->begin()); 159 | + // Sink the instruction. 160 | + BBEnd->getInstList().splice(FirstNonPhiInBBEnd->getIterator(), 161 | + BB1->getInstList(), I1); 162 | + if (!OldPN->use_empty()) 163 | + OldPN->replaceAllUsesWith(I1); 164 | + OldPN->eraseFromParent(); 165 | + 166 | + if (!I2->use_empty()) 167 | + I2->replaceAllUsesWith(I1); 168 | + I1->andIRFlags(I2); 169 | + // TODO: Use combineMetadata here to preserve what metadata we can 170 | + // (analogous to the hoisting case above). 171 | + I2->eraseFromParent(); 172 | + 173 | + if (UpdateRE1) 174 | + RE1 = BB1->getInstList().rend(); 175 | + if (UpdateRE2) 176 | + RE2 = BB2->getInstList().rend(); 177 | + FirstNonPhiInBBEnd = &*I1; 178 | + NumSinkCommons++; 179 | + RI1 = BB1->getInstList().rbegin(), 180 | + RI2 = BB2->getInstList().rbegin(), 181 | + ++RI1; 182 | + ++RI2; 183 | + 184 | + Changed = true; 185 | + } 186 | + return Changed; 187 | +} 188 | + 189 | /// \brief Determine if we can hoist sink a sole store instruction out of a 190 | /// conditional block. 191 | /// 192 | @@ -5681,7 +5858,7 @@ 193 | IRBuilder<> &Builder) { 194 | BasicBlock *BB = BI->getParent(); 195 | 196 | - if (SinkCommon && SinkThenElseCodeToEnd(BI)) 197 | + if (SinkCommon && SinkThenElseCodeToEnd_LLVM38(BI)) 198 | return true; 199 | 200 | // If the Terminator is the only non-phi instruction, simplify the block. 201 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/4_1-non-recursive-sink-hoist-region.patch: -------------------------------------------------------------------------------- 1 | # Description : Large CFGs can cause a stack overflow due to recursive step 2 | # for each basic block in a region. Instead create a worklist and iterate 3 | # to limit the stack usage 4 | 5 | 6 | diff -Naur --strip-trailing-cr a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp 7 | --- a/lib/Transforms/Scalar/LICM.cpp 2017-02-21 11:01:56.000000000 -0800 8 | +++ b/lib/Transforms/Scalar/LICM.cpp 2018-03-14 12:43:23.452319700 -0700 9 | @@ -323,6 +323,30 @@ 10 | return Changed; 11 | } 12 | 13 | +// Does a BFS from a given node to all of its children inside a given loop. 14 | +// The returned vector of nodes includes the starting point. 15 | +static SmallVector 16 | +collectChildrenInLoop(DomTreeNode *N, const Loop *CurLoop) { 17 | + SmallVector Worklist; 18 | + auto add_region_to_worklist = [&](DomTreeNode *DTN) { 19 | + // Only include subregions in the top level loop. 20 | + BasicBlock *BB = DTN->getBlock(); 21 | + if (CurLoop->contains(BB)) 22 | + Worklist.push_back(DTN); 23 | + }; 24 | + 25 | + add_region_to_worklist(N); 26 | + 27 | + for (size_t I = 0; I < Worklist.size(); I++) { 28 | + DomTreeNode *DTN = Worklist[I]; 29 | + for (DomTreeNode *Child : DTN->getChildren()) 30 | + add_region_to_worklist(Child); 31 | + } 32 | + 33 | + return Worklist; 34 | +} 35 | + 36 | + 37 | /// Walk the specified region of the CFG (defined by all blocks dominated by 38 | /// the specified block, and that are in the current loop) in reverse depth 39 | /// first order w.r.t the DominatorTree. This allows us to visit uses before 40 | @@ -338,51 +362,53 @@ 41 | CurLoop != nullptr && CurAST != nullptr && SafetyInfo != nullptr && 42 | "Unexpected input to sinkRegion"); 43 | 44 | - BasicBlock *BB = N->getBlock(); 45 | - // If this subregion is not in the top level loop at all, exit. 46 | - if (!CurLoop->contains(BB)) 47 | - return false; 48 | + // We want to visit children before parents. We will enque all the parents 49 | + // before their children in the worklist and process the worklist in reverse 50 | + // order. 51 | + SmallVector Worklist = collectChildrenInLoop(N, CurLoop); 52 | + 53 | 54 | - // We are processing blocks in reverse dfo, so process children first. 55 | bool Changed = false; 56 | - const std::vector &Children = N->getChildren(); 57 | - for (DomTreeNode *Child : Children) 58 | - Changed |= 59 | - sinkRegion(Child, AA, LI, DT, TLI, CurLoop, CurAST, SafetyInfo, ORE); 60 | - 61 | - // Only need to process the contents of this block if it is not part of a 62 | - // subloop (which would already have been processed). 63 | - if (inSubLoop(BB, CurLoop, LI)) 64 | - return Changed; 65 | - 66 | - for (BasicBlock::iterator II = BB->end(); II != BB->begin();) { 67 | - Instruction &I = *--II; 68 | - 69 | - // If the instruction is dead, we would try to sink it because it isn't used 70 | - // in the loop, instead, just delete it. 71 | - if (isInstructionTriviallyDead(&I, TLI)) { 72 | - DEBUG(dbgs() << "LICM deleting dead inst: " << I << '\n'); 73 | - ++II; 74 | - CurAST->deleteValue(&I); 75 | - I.eraseFromParent(); 76 | - Changed = true; 77 | + for (DomTreeNode *DTN : reverse(Worklist)) { 78 | + BasicBlock *BB = DTN->getBlock(); 79 | + 80 | + 81 | + 82 | + // Only need to process the contents of this block if it is not part of a 83 | + // subloop (which would already have been processed). 84 | + if (inSubLoop(BB, CurLoop, LI)) 85 | continue; 86 | - } 87 | 88 | - // Check to see if we can sink this instruction to the exit blocks 89 | - // of the loop. We can do this if the all users of the instruction are 90 | - // outside of the loop. In this case, it doesn't even matter if the 91 | - // operands of the instruction are loop invariant. 92 | - // 93 | - if (isNotUsedInLoop(I, CurLoop, SafetyInfo) && 94 | - canSinkOrHoistInst(I, AA, DT, CurLoop, CurAST, SafetyInfo, ORE)) { 95 | - ++II; 96 | - Changed |= sink(I, LI, DT, CurLoop, CurAST, SafetyInfo, ORE); 97 | + for (BasicBlock::iterator II = BB->end(); II != BB->begin();) { 98 | + Instruction &I = *--II; 99 | + 100 | + // If the instruction is dead, we would try to sink it because it isn't used 101 | + // in the loop, instead, just delete it. 102 | + if (isInstructionTriviallyDead(&I, TLI)) { 103 | + DEBUG(dbgs() << "LICM deleting dead inst: " << I << '\n'); 104 | + ++II; 105 | + CurAST->deleteValue(&I); 106 | + I.eraseFromParent(); 107 | + Changed = true; 108 | + continue; 109 | + } 110 | + 111 | + // Check to see if we can sink this instruction to the exit blocks 112 | + // of the loop. We can do this if the all users of the instruction are 113 | + // outside of the loop. In this case, it doesn't even matter if the 114 | + // operands of the instruction are loop invariant. 115 | + // 116 | + if (isNotUsedInLoop(I, CurLoop, SafetyInfo) && 117 | + canSinkOrHoistInst(I, AA, DT, CurLoop, CurAST, SafetyInfo, ORE)) { 118 | + ++II; 119 | + Changed |= sink(I, LI, DT, CurLoop, CurAST, SafetyInfo, ORE); 120 | + } 121 | } 122 | } 123 | return Changed; 124 | } 125 | 126 | + 127 | /// Walk the specified region of the CFG (defined by all blocks dominated by 128 | /// the specified block, and that are in the current loop) in depth first 129 | /// order w.r.t the DominatorTree. This allows us to visit definitions before 130 | @@ -397,50 +423,73 @@ 131 | CurLoop != nullptr && CurAST != nullptr && SafetyInfo != nullptr && 132 | "Unexpected input to hoistRegion"); 133 | 134 | - BasicBlock *BB = N->getBlock(); 135 | + // We want to visit parents before children. We will enque all the parents 136 | + // before their children in the worklist and process the worklist in order. 137 | + SmallVector Worklist = collectChildrenInLoop(N, CurLoop); 138 | + 139 | 140 | - // If this subregion is not in the top level loop at all, exit. 141 | - if (!CurLoop->contains(BB)) 142 | - return false; 143 | 144 | - // Only need to process the contents of this block if it is not part of a 145 | - // subloop (which would already have been processed). 146 | bool Changed = false; 147 | - if (!inSubLoop(BB, CurLoop, LI)) 148 | - for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) { 149 | - Instruction &I = *II++; 150 | - // Try constant folding this instruction. If all the operands are 151 | - // constants, it is technically hoistable, but it would be better to just 152 | - // fold it. 153 | - if (Constant *C = ConstantFoldInstruction( 154 | - &I, I.getModule()->getDataLayout(), TLI)) { 155 | - DEBUG(dbgs() << "LICM folding inst: " << I << " --> " << *C << '\n'); 156 | - CurAST->copyValue(&I, C); 157 | - I.replaceAllUsesWith(C); 158 | - if (isInstructionTriviallyDead(&I, TLI)) { 159 | - CurAST->deleteValue(&I); 160 | + for (DomTreeNode *DTN : Worklist) { 161 | + BasicBlock *BB = DTN->getBlock(); 162 | + // Only need to process the contents of this block if it is not part of a 163 | + // subloop (which would already have been processed). 164 | + 165 | + if (!inSubLoop(BB, CurLoop, LI)) 166 | + for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) { 167 | + Instruction &I = *II++; 168 | + // Try constant folding this instruction. If all the operands are 169 | + // constants, it is technically hoistable, but it would be better to 170 | + // just fold it. 171 | + if (Constant *C = ConstantFoldInstruction( 172 | + &I, I.getModule()->getDataLayout(), TLI)) { 173 | + DEBUG(dbgs() << "LICM folding inst: " << I << " --> " << *C << '\n'); 174 | + CurAST->copyValue(&I, C); 175 | + I.replaceAllUsesWith(C); 176 | + if (isInstructionTriviallyDead(&I, TLI)) { 177 | + CurAST->deleteValue(&I); 178 | + I.eraseFromParent(); 179 | + } 180 | + Changed = true; 181 | + continue; 182 | + } 183 | + 184 | + // Attempt to remove floating point division out of the loop by 185 | + // converting it to a reciprocal multiplication. 186 | + if (I.getOpcode() == Instruction::FDiv && 187 | + CurLoop->isLoopInvariant(I.getOperand(1)) && 188 | + I.hasAllowReciprocal()) { 189 | + auto Divisor = I.getOperand(1); 190 | + auto One = llvm::ConstantFP::get(Divisor->getType(), 1.0); 191 | + auto ReciprocalDivisor = BinaryOperator::CreateFDiv(One, Divisor); 192 | + ReciprocalDivisor->setFastMathFlags(I.getFastMathFlags()); 193 | + ReciprocalDivisor->insertBefore(&I); 194 | + 195 | + auto Product = 196 | + BinaryOperator::CreateFMul(I.getOperand(0), ReciprocalDivisor); 197 | + Product->setFastMathFlags(I.getFastMathFlags()); 198 | + Product->insertAfter(&I); 199 | + I.replaceAllUsesWith(Product); 200 | I.eraseFromParent(); 201 | + 202 | + hoist(*ReciprocalDivisor, DT, CurLoop, SafetyInfo, ORE); 203 | + Changed = true; 204 | + continue; 205 | } 206 | - Changed = true; 207 | - continue; 208 | - } 209 | 210 | - // Try hoisting the instruction out to the preheader. We can only do this 211 | - // if all of the operands of the instruction are loop invariant and if it 212 | - // is safe to hoist the instruction. 213 | - // 214 | - if (CurLoop->hasLoopInvariantOperands(&I) && 215 | - canSinkOrHoistInst(I, AA, DT, CurLoop, CurAST, SafetyInfo, ORE) && 216 | - isSafeToExecuteUnconditionally( 217 | - I, DT, CurLoop, SafetyInfo, ORE, 218 | - CurLoop->getLoopPreheader()->getTerminator())) 219 | - Changed |= hoist(I, DT, CurLoop, SafetyInfo, ORE); 220 | - } 221 | + // Try hoisting the instruction out to the preheader. We can only do 222 | + // this if all of the operands of the instruction are loop invariant and 223 | + // if it is safe to hoist the instruction. 224 | + // 225 | + if (CurLoop->hasLoopInvariantOperands(&I) && 226 | + canSinkOrHoistInst(I, AA, DT, CurLoop, CurAST, SafetyInfo, ORE) && 227 | + isSafeToExecuteUnconditionally( 228 | + I, DT, CurLoop, SafetyInfo, ORE, 229 | + CurLoop->getLoopPreheader()->getTerminator())) 230 | + Changed |= hoist(I, DT, CurLoop, SafetyInfo, ORE); 231 | + } 232 | + } 233 | 234 | - const std::vector &Children = N->getChildren(); 235 | - for (DomTreeNode *Child : Children) 236 | - Changed |= 237 | - hoistRegion(Child, AA, LI, DT, TLI, CurLoop, CurAST, SafetyInfo, ORE); 238 | return Changed; 239 | } 240 | 241 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/4_2-Fix_invariant_fdiv_hoisting_in_LICM.patch: -------------------------------------------------------------------------------- 1 | # Description : FDiv is replaced with multiplication by reciprocal and invariant 2 | # reciprocal is hoisted out of the loop, while multiplication remains 3 | # even if invariant. 4 | 5 | 6 | diff -Naur --strip-trailing-cr a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp 7 | --- a/lib/Transforms/Scalar/LICM.cpp 2018-08-09 14:04:49.868088200 -0700 8 | +++ b/lib/Transforms/Scalar/LICM.cpp 2018-08-09 13:57:15.100467100 -0700 9 | @@ -435,59 +435,72 @@ 10 | // Only need to process the contents of this block if it is not part of a 11 | // subloop (which would already have been processed). 12 | 13 | - if (!inSubLoop(BB, CurLoop, LI)) 14 | - for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) { 15 | - Instruction &I = *II++; 16 | - // Try constant folding this instruction. If all the operands are 17 | - // constants, it is technically hoistable, but it would be better to 18 | - // just fold it. 19 | - if (Constant *C = ConstantFoldInstruction( 20 | - &I, I.getModule()->getDataLayout(), TLI)) { 21 | - DEBUG(dbgs() << "LICM folding inst: " << I << " --> " << *C << '\n'); 22 | - CurAST->copyValue(&I, C); 23 | - I.replaceAllUsesWith(C); 24 | - if (isInstructionTriviallyDead(&I, TLI)) { 25 | - CurAST->deleteValue(&I); 26 | - I.eraseFromParent(); 27 | - } 28 | - Changed = true; 29 | - continue; 30 | - } 31 | + if (inSubLoop(BB, CurLoop, LI)) 32 | + continue; 33 | 34 | - // Attempt to remove floating point division out of the loop by 35 | - // converting it to a reciprocal multiplication. 36 | - if (I.getOpcode() == Instruction::FDiv && 37 | - CurLoop->isLoopInvariant(I.getOperand(1)) && 38 | - I.hasAllowReciprocal()) { 39 | - auto Divisor = I.getOperand(1); 40 | - auto One = llvm::ConstantFP::get(Divisor->getType(), 1.0); 41 | - auto ReciprocalDivisor = BinaryOperator::CreateFDiv(One, Divisor); 42 | - ReciprocalDivisor->setFastMathFlags(I.getFastMathFlags()); 43 | - ReciprocalDivisor->insertBefore(&I); 44 | - 45 | - auto Product = 46 | - BinaryOperator::CreateFMul(I.getOperand(0), ReciprocalDivisor); 47 | - Product->setFastMathFlags(I.getFastMathFlags()); 48 | - Product->insertAfter(&I); 49 | - I.replaceAllUsesWith(Product); 50 | + // Keep track of whether the prefix of instructions visited so far are such 51 | + // that the next instruction visited is guaranteed to execute if the loop 52 | + // is entered. 53 | + bool IsMustExecute = CurLoop->getHeader() == BB; 54 | + 55 | + for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) { 56 | + Instruction &I = *II++; 57 | + // Try constant folding this instruction. If all the operands are 58 | + // constants, it is technically hoistable, but it would be better to 59 | + // just fold it. 60 | + if (Constant *C = ConstantFoldInstruction( 61 | + &I, I.getModule()->getDataLayout(), TLI)) { 62 | + DEBUG(dbgs() << "LICM folding inst: " << I << " --> " << *C << '\n'); 63 | + CurAST->copyValue(&I, C); 64 | + I.replaceAllUsesWith(C); 65 | + if (isInstructionTriviallyDead(&I, TLI)) { 66 | + CurAST->deleteValue(&I); 67 | I.eraseFromParent(); 68 | - 69 | - hoist(*ReciprocalDivisor, DT, CurLoop, SafetyInfo, ORE); 70 | - Changed = true; 71 | - continue; 72 | } 73 | + Changed = true; 74 | + continue; 75 | + } 76 | + 77 | + // Try hoisting the instruction out to the preheader. We can only do 78 | + // this if all of the operands of the instruction are loop invariant and 79 | + // if it is safe to hoist the instruction. 80 | + // 81 | + if (CurLoop->hasLoopInvariantOperands(&I) && 82 | + canSinkOrHoistInst(I, AA, DT, CurLoop, CurAST, SafetyInfo, ORE) && 83 | + (IsMustExecute || 84 | + isSafeToExecuteUnconditionally( 85 | + I, DT, CurLoop, SafetyInfo, ORE, 86 | + CurLoop->getLoopPreheader()->getTerminator()))) { 87 | + Changed |= hoist(I, DT, CurLoop, SafetyInfo, ORE); 88 | + continue; 89 | + } 90 | 91 | - // Try hoisting the instruction out to the preheader. We can only do 92 | - // this if all of the operands of the instruction are loop invariant and 93 | - // if it is safe to hoist the instruction. 94 | - // 95 | - if (CurLoop->hasLoopInvariantOperands(&I) && 96 | - canSinkOrHoistInst(I, AA, DT, CurLoop, CurAST, SafetyInfo, ORE) && 97 | - isSafeToExecuteUnconditionally( 98 | - I, DT, CurLoop, SafetyInfo, ORE, 99 | - CurLoop->getLoopPreheader()->getTerminator())) 100 | - Changed |= hoist(I, DT, CurLoop, SafetyInfo, ORE); 101 | + // Attempt to remove floating point division out of the loop by 102 | + // converting it to a reciprocal multiplication. 103 | + if (I.getOpcode() == Instruction::FDiv && 104 | + CurLoop->isLoopInvariant(I.getOperand(1)) && 105 | + I.hasAllowReciprocal()) { 106 | + auto Divisor = I.getOperand(1); 107 | + auto One = llvm::ConstantFP::get(Divisor->getType(), 1.0); 108 | + auto ReciprocalDivisor = BinaryOperator::CreateFDiv(One, Divisor); 109 | + ReciprocalDivisor->setFastMathFlags(I.getFastMathFlags()); 110 | + ReciprocalDivisor->insertBefore(&I); 111 | + 112 | + auto Product = 113 | + BinaryOperator::CreateFMul(I.getOperand(0), ReciprocalDivisor); 114 | + Product->setFastMathFlags(I.getFastMathFlags()); 115 | + Product->insertAfter(&I); 116 | + I.replaceAllUsesWith(Product); 117 | + I.eraseFromParent(); 118 | + 119 | + hoist(*ReciprocalDivisor, DT, CurLoop, SafetyInfo, ORE); 120 | + Changed = true; 121 | + continue; 122 | } 123 | + 124 | + if (IsMustExecute) 125 | + IsMustExecute = isGuaranteedToTransferExecutionToSuccessor(&I); 126 | + } 127 | } 128 | 129 | return Changed; 130 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/Be-conservative-when-splitting-loop.patch: -------------------------------------------------------------------------------- 1 | # Description : Be conservative when splitting loop 2 | 3 | 4 | diff -Naur --strip-trailing-cr a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp 5 | --- a/lib/Transforms/Utils/LoopSimplify.cpp 2017-10-23 09:53:04.933214744 -0400 6 | +++ b/lib/Transforms/Utils/LoopSimplify.cpp 2017-10-23 13:13:03.698744669 -0400 7 | @@ -202,27 +202,67 @@ 8 | } while (!Worklist.empty()); 9 | } 10 | 11 | +/// \brief Simplify PHI nodes in loop header. 12 | +static bool simplifyLoopPHIs(Loop *L, const DataLayout &DL, 13 | + DominatorTree *DT, ScalarEvolution *SE, 14 | + AssumptionCache *AC) { 15 | + bool Changed = false; 16 | + 17 | + // Scan over the PHI nodes in the loop header and try to simplify PHI nodes. 18 | + PHINode *PN; 19 | + for (BasicBlock::iterator I = L->getHeader()->begin(); 20 | + (PN = dyn_cast(I++));/* EMPTY */) 21 | + if (Value *V = SimplifyInstruction(PN, DL, nullptr, DT, AC)) { 22 | + if (SE) SE->forgetValue(PN); 23 | + PN->replaceAllUsesWith(V); 24 | + PN->eraseFromParent(); 25 | + Changed = true; 26 | + } 27 | + 28 | + return Changed; 29 | +} 30 | + 31 | /// \brief The first part of loop-nestification is to find a PHI node that tells 32 | /// us how to partition the loops. 33 | static PHINode *findPHIToPartitionLoops(Loop *L, DominatorTree *DT, 34 | + ScalarEvolution *SE, 35 | AssumptionCache *AC) { 36 | const DataLayout &DL = L->getHeader()->getModule()->getDataLayout(); 37 | - for (BasicBlock::iterator I = L->getHeader()->begin(); isa(I); ) { 38 | + for (BasicBlock::iterator I = L->getHeader()->begin(); isa(I); ++I) { 39 | PHINode *PN = cast(I); 40 | - ++I; 41 | - if (Value *V = SimplifyInstruction(PN, DL, nullptr, DT, AC)) { 42 | - // This is a degenerate PHI already, don't modify it! 43 | - PN->replaceAllUsesWith(V); 44 | - PN->eraseFromParent(); 45 | - continue; 46 | - } 47 | 48 | + // Skip non induction variable candidates. 49 | +#if 0 50 | + if (SE && !SE->isSCEVable(PN->getType())) 51 | + continue; 52 | +#else 53 | + //If SCEV is not available, skip floating types directly. 54 | + if (PN->getType()->isFloatingPointTy()) 55 | + continue; 56 | +#endif 57 | // Scan this PHI node looking for a use of the PHI node by itself. 58 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) 59 | if (PN->getIncomingValue(i) == PN && 60 | - L->contains(PN->getIncomingBlock(i))) 61 | + L->contains(PN->getIncomingBlock(i))) { 62 | + // To be conservative when splitting a loop. Only do that when it's 63 | + // quite confident it's a loop nesting. 64 | + // TODO: Add missing post-dominance checking. 65 | + bool Found = true; 66 | + auto InnerLatch = PN->getIncomingBlock(i); 67 | + for (unsigned j = 0, f = PN->getNumIncomingValues(); j != f; ++j) { 68 | + if (j == i || PN->getIncomingValue(j) == PN) 69 | + continue; 70 | + auto OuterLatch = PN->getIncomingBlock(j); 71 | + if (!L->contains(OuterLatch)) 72 | + continue; 73 | + if (DT->dominates(InnerLatch, OuterLatch)) 74 | + continue; 75 | + Found = false; 76 | + } 77 | // We found something tasty to remove. 78 | - return PN; 79 | + if (Found) 80 | + return PN; 81 | + } 82 | } 83 | return nullptr; 84 | } 85 | @@ -258,7 +298,7 @@ 86 | BasicBlock *Header = L->getHeader(); 87 | assert(!Header->isEHPad() && "Can't insert backedge to EH pad"); 88 | 89 | - PHINode *PN = findPHIToPartitionLoops(L, DT, AC); 90 | + PHINode *PN = findPHIToPartitionLoops(L, DT, SE, AC); 91 | if (!PN) return nullptr; // No known way to partition. 92 | 93 | // Pull out all predecessors that have varying values in the loop. This 94 | @@ -587,10 +627,13 @@ 95 | } 96 | } 97 | 98 | + const DataLayout &DL = L->getHeader()->getModule()->getDataLayout(); 99 | + 100 | // If the header has more than two predecessors at this point (from the 101 | // preheader and from multiple backedges), we must adjust the loop. 102 | BasicBlock *LoopLatch = L->getLoopLatch(); 103 | if (!LoopLatch) { 104 | + Changed |= simplifyLoopPHIs(L, DL, DT, SE, AC); 105 | // If this is really a nested loop, rip it out into a child loop. Don't do 106 | // this for loops with a giant number of backedges, just factor them into a 107 | // common backedge instead. 108 | @@ -620,21 +663,10 @@ 109 | } 110 | } 111 | 112 | - const DataLayout &DL = L->getHeader()->getModule()->getDataLayout(); 113 | - 114 | // Scan over the PHI nodes in the loop header. Since they now have only two 115 | // incoming values (the loop is canonicalized), we may have simplified the PHI 116 | // down to 'X = phi [X, Y]', which should be replaced with 'Y'. 117 | - PHINode *PN; 118 | - for (BasicBlock::iterator I = L->getHeader()->begin(); 119 | - (PN = dyn_cast(I++)); ) 120 | - if (Value *V = SimplifyInstruction(PN, DL, nullptr, DT, AC)) { 121 | - if (SE) SE->forgetValue(PN); 122 | - if (!PreserveLCSSA || LI->replacementPreservesLCSSAForm(PN, V)) { 123 | - PN->replaceAllUsesWith(V); 124 | - PN->eraseFromParent(); 125 | - } 126 | - } 127 | + Changed |= simplifyLoopPHIs(L, DL, DT, SE, AC); 128 | 129 | // If this loop has multiple exits and the exits all go to the same 130 | // block, attempt to merge the exits. This helps several passes, such 131 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/ConstantFolding-Constant-fold-llvm.sqrt-x-like-other.patch: -------------------------------------------------------------------------------- 1 | # Description : Constant fold llvm.sqrt like other intrinsics 2 | 3 | 4 | From 12044b3dd7855fd39334ac5321645b27c6c7b49e Mon Sep 17 00:00:00 2001 5 | From: Justin Lebar 6 | Date: Sat, 21 Jan 2017 00:59:57 +0000 7 | Subject: [PATCH] [ConstantFolding] Constant-fold llvm.sqrt(x) like other 8 | intrinsics. 9 | 10 | Summary: 11 | Currently we return undef, but we're in the process of changing the 12 | LangRef so that llvm.sqrt behaves like the other math intrinsics, 13 | matching the return value of the standard libcall but not setting errno. 14 | 15 | This change is legal even without the LangRef change because currently 16 | calling llvm.sqrt(x) where x is negative is spec'ed to be UB. But in 17 | practice it's also safe because we're simply constant-folding fewer 18 | inputs: Inputs >= -0 get constant-folded as before, but inputs < -0 now 19 | aren't constant-folded, because ConstantFoldFP aborts if the host math 20 | function raises an fp exception. 21 | 22 | Reviewers: hfinkel, efriedma, sanjoy 23 | 24 | Subscribers: llvm-commits 25 | 26 | Differential Revision: https://reviews.llvm.org/D28929 27 | 28 | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292692 91177308-0d34-0410-b5e6-96231b3b80d8 29 | --- 30 | lib/Analysis/ConstantFolding.cpp | 15 ++------------- 31 | test/Transforms/InstCombine/constant-fold-math.ll | 5 +++-- 32 | 2 files changed, 5 insertions(+), 15 deletions(-) 33 | 34 | diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp 35 | index 7386727..db8ac82 100644 36 | --- a/lib/Analysis/ConstantFolding.cpp 37 | +++ b/lib/Analysis/ConstantFolding.cpp 38 | @@ -1630,6 +1630,8 @@ Constant *ConstantFoldScalarCall(StringRef Name, unsigned IntrinsicID, Type *Ty, 39 | return ConstantFoldFP(sin, V, Ty); 40 | case Intrinsic::cos: 41 | return ConstantFoldFP(cos, V, Ty); 42 | + case Intrinsic::sqrt: 43 | + return ConstantFoldFP(sqrt, V, Ty); 44 | } 45 | 46 | if (!TLI) 47 | @@ -1683,19 +1685,6 @@ Constant *ConstantFoldScalarCall(StringRef Name, unsigned IntrinsicID, Type *Ty, 48 | else if ((Name == "log10" && V > 0 && TLI->has(LibFunc::log10)) || 49 | (Name == "log10f" && V > 0 && TLI->has(LibFunc::log10f))) 50 | return ConstantFoldFP(log10, V, Ty); 51 | - else if (IntrinsicID == Intrinsic::sqrt && 52 | - (Ty->isHalfTy() || Ty->isFloatTy() || Ty->isDoubleTy())) { 53 | - if (V >= -0.0) 54 | - return ConstantFoldFP(sqrt, V, Ty); 55 | - else { 56 | - // Unlike the sqrt definitions in C/C++, POSIX, and IEEE-754 - which 57 | - // all guarantee or favor returning NaN - the square root of a 58 | - // negative number is not defined for the LLVM sqrt intrinsic. 59 | - // This is because the intrinsic should only be emitted in place of 60 | - // libm's sqrt function when using "no-nans-fp-math". 61 | - return UndefValue::get(Ty); 62 | - } 63 | - } 64 | break; 65 | case 'r': 66 | if ((Name == "round" && TLI->has(LibFunc::round)) || 67 | diff --git a/test/Transforms/InstCombine/constant-fold-math.ll b/test/Transforms/InstCombine/constant-fold-math.ll 68 | index ce8d337..6eb371a 100644 69 | --- a/test/Transforms/InstCombine/constant-fold-math.ll 70 | +++ b/test/Transforms/InstCombine/constant-fold-math.ll 71 | @@ -45,9 +45,10 @@ define double @constant_fold_fmuladd_f64() #0 { 72 | ret double %x 73 | } 74 | 75 | -; The sqrt intrinsic is undefined for negative inputs besides -0.0. 76 | +; Currently we don't constant-fold intrinsics whose corresponding libcalls 77 | +; raise an fp exception. 78 | ; CHECK-LABEL: @bad_sqrt 79 | -; CHECK-NEXT: ret double undef 80 | +; CHECK-NEXT: call double @llvm.sqrt.f64(double -2 81 | define double @bad_sqrt() { 82 | %x = call double @llvm.sqrt.f64(double -2.000000e+00) 83 | ret double %x 84 | -- 85 | 2.7.4 86 | 87 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/Enable-gcc-8-build.patch: -------------------------------------------------------------------------------- 1 | # Description : Enable LLVM build with gcc 8 2 | 3 | 4 | diff -Naur --strip-trailing-cr a/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h b/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h 5 | --- a/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h 6 | +++ b/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h 7 | @@ -687,8 +687,8 @@ private: 8 | 9 | uint32_t getTrampolineSize() const { return RemoteTrampolineSize; } 10 | 11 | - Expected> readMem(char *Dst, JITTargetAddress Src, 12 | - uint64_t Size) { 13 | + Expected> readMem(char *Dst, JITTargetAddress Src, 14 | + uint64_t Size) { 15 | // Check for an 'out-of-band' error, e.g. from an MM destructor. 16 | if (ExistingError) 17 | return std::move(ExistingError); 18 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/Enabling-test-Offset32-Regression-Fix.patch: -------------------------------------------------------------------------------- 1 | # Description : Limit recursion depth of constant evolving. 2 | 3 | 4 | diff -Naur --strip-trailing-cr a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp 5 | --- a/lib/Analysis/ScalarEvolution.cpp 2017-10-23 09:53:04.925214744 -0400 6 | +++ b/lib/Analysis/ScalarEvolution.cpp 2017-10-23 14:26:57.327570973 -0400 7 | @@ -137,6 +137,10 @@ 8 | cl::desc("Maximum depth of recursive value complexity comparisons"), 9 | cl::init(2)); 10 | 11 | +static cl::opt MaxConstantEvolvingDepth( 12 | + "scalar-evolution-max-constant-evolving-depth", cl::Hidden, 13 | + cl::desc("Maximum depth of recursive constant evolving"), 14 | + cl::init(32)); 15 | //===----------------------------------------------------------------------===// 16 | // SCEV class definitions 17 | //===----------------------------------------------------------------------===// 18 | @@ -6408,7 +6412,10 @@ 19 | /// recursing through each instruction operand until reaching a loop header phi. 20 | static PHINode * 21 | getConstantEvolvingPHIOperands(Instruction *UseInst, const Loop *L, 22 | - DenseMap &PHIMap) { 23 | + DenseMap &PHIMap, 24 | + unsigned Depth) { 25 | + if (Depth > MaxConstantEvolvingDepth) 26 | + return nullptr; 27 | 28 | // Otherwise, we can evaluate this instruction if all of its operands are 29 | // constant or derived from a PHI node themselves. 30 | @@ -6428,7 +6435,7 @@ 31 | if (!P) { 32 | // Recurse and memoize the results, whether a phi is found or not. 33 | // This recursive call invalidates pointers into PHIMap. 34 | - P = getConstantEvolvingPHIOperands(OpInst, L, PHIMap); 35 | + P = getConstantEvolvingPHIOperands(OpInst, L, PHIMap, Depth + 1); 36 | PHIMap[OpInst] = P; 37 | } 38 | if (!P) 39 | @@ -6455,7 +6462,8 @@ 40 | 41 | // Record non-constant instructions contained by the loop. 42 | DenseMap PHIMap; 43 | - return getConstantEvolvingPHIOperands(I, L, PHIMap); 44 | + 45 | + return getConstantEvolvingPHIOperands(I, L, PHIMap, 0); 46 | } 47 | 48 | /// EvaluateExpression - Given an expression that passes the 49 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/Fix-crash-due-to-bad-bitcast.patch: -------------------------------------------------------------------------------- 1 | # Description : [SROA] Fix crash due to bad bitcast 2 | 3 | 4 | diff -Naur --strip-trailing-cr a/lib/Transforms/Scalar/SROA.cpp b/lib/Transforms/Scalar/SROA.cpp 5 | --- a/lib/Transforms/Scalar/SROA.cpp 2017-10-23 15:06:46.139477387 -0400 6 | +++ b/lib/Transforms/Scalar/SROA.cpp 2017-10-23 15:06:52.595477134 -0400 7 | @@ -3692,7 +3692,8 @@ 8 | int Idx = 0, Size = Offsets.Splits.size(); 9 | for (;;) { 10 | auto *PartTy = Type::getIntNTy(Ty->getContext(), PartSize * 8); 11 | - auto *PartPtrTy = PartTy->getPointerTo(SI->getPointerAddressSpace()); 12 | + auto *LoadPartPtrTy = PartTy->getPointerTo(LI->getPointerAddressSpace()); 13 | + auto *StorePartPtrTy = PartTy->getPointerTo(SI->getPointerAddressSpace()); 14 | 15 | // Either lookup a split load or create one. 16 | LoadInst *PLoad; 17 | @@ -3703,7 +3704,7 @@ 18 | PLoad = IRB.CreateAlignedLoad( 19 | getAdjustedPtr(IRB, DL, LoadBasePtr, 20 | APInt(DL.getPointerSizeInBits(), PartOffset), 21 | - PartPtrTy, LoadBasePtr->getName() + "."), 22 | + LoadPartPtrTy, LoadBasePtr->getName() + "."), 23 | getAdjustedAlignment(LI, PartOffset, DL), /*IsVolatile*/ false, 24 | LI->getName()); 25 | } 26 | @@ -3713,7 +3714,7 @@ 27 | StoreInst *PStore = IRB.CreateAlignedStore( 28 | PLoad, getAdjustedPtr(IRB, DL, StoreBasePtr, 29 | APInt(DL.getPointerSizeInBits(), PartOffset), 30 | - PartPtrTy, StoreBasePtr->getName() + "."), 31 | + StorePartPtrTy, StoreBasePtr->getName() + "."), 32 | getAdjustedAlignment(SI, PartOffset, DL), /*IsVolatile*/ false); 33 | 34 | // Now build a new slice for the alloca. 35 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/Fixed-faulty-PHI-node-update.patch: -------------------------------------------------------------------------------- 1 | 2 | From 08bf51ee2ac040f0101a0755790df1176e9c07a0 Mon Sep 17 00:00:00 2001 3 | From: Karl-Johan Karlsson 4 | Date: Tue, 22 May 2018 08:46:48 +0000 5 | Subject: [PATCH] [LowerSwitch] Fixed faulty PHI node update 6 | 7 | Summary: 8 | When lowerswitch merge several cases into a new default block it's not 9 | updating the PHI nodes accordingly. The code that update the PHI nodes 10 | for the default edge only update the first entry and do not remove the 11 | remaining ones, to make sure the number of entries match the number of 12 | predecessors. 13 | 14 | This is easily fixed by replacing the code that update the PHI node with 15 | the already existing utility function for updating PHI nodes. 16 | 17 | Reviewers: hans, reames, arsenm 18 | 19 | Reviewed By: arsenm 20 | 21 | Subscribers: wdng, llvm-commits 22 | 23 | Differential Revision: https://reviews.llvm.org/D47055 24 | 25 | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332960 91177308-0d34-0410-b5e6-96231b3b80d8 26 | --- 27 | lib/Transforms/Utils/LowerSwitch.cpp | 18 +++++------ 28 | test/Transforms/Util/lowerswitch.ll | 58 +++++++++++++++++++++++++++++++++++- 29 | 2 files changed, 66 insertions(+), 10 deletions(-) 30 | 31 | diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp 32 | index 441c5fd8b5af..76ad35832dc3 100644 33 | --- a/lib/Transforms/Utils/LowerSwitch.cpp 34 | +++ b/lib/Transforms/Utils/LowerSwitch.cpp 35 | @@ -512,25 +512,25 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI, 36 | } 37 | } 38 | 39 | + unsigned NrOfDefaults = (SI->getDefaultDest() == Default) ? 1 : 0; 40 | + for (auto &Case : SI->cases()) 41 | + if (Case.getCaseSuccessor() == Default) 42 | + NrOfDefaults++; 43 | + 44 | // Create a new, empty default block so that the new hierarchy of 45 | // if-then statements go to this and the PHI nodes are happy. 46 | BasicBlock *NewDefault = BasicBlock::Create(SI->getContext(), "NewDefault"); 47 | F->getBasicBlockList().insert(Default->getIterator(), NewDefault); 48 | BranchInst::Create(Default, NewDefault); 49 | 50 | - // If there is an entry in any PHI nodes for the default edge, make sure 51 | - // to update them as well. 52 | - for (BasicBlock::iterator I = Default->begin(); isa(I); ++I) { 53 | - PHINode *PN = cast(I); 54 | - int BlockIdx = PN->getBasicBlockIndex(OrigBlock); 55 | - assert(BlockIdx != -1 && "Switch didn't go to this successor??"); 56 | - PN->setIncomingBlock((unsigned)BlockIdx, NewDefault); 57 | - } 58 | - 59 | BasicBlock *SwitchBlock = 60 | switchConvert(Cases.begin(), Cases.end(), LowerBound, UpperBound, Val, 61 | OrigBlock, OrigBlock, NewDefault, UnreachableRanges); 62 | 63 | + // If there are entries in any PHI nodes for the default edge, make sure 64 | + // to update them as well. 65 | + fixPhis(Default, OrigBlock, NewDefault, NrOfDefaults); 66 | + 67 | // Branch to our shiny new if-then stuff... 68 | BranchInst::Create(SwitchBlock, OrigBlock); 69 | 70 | diff --git a/test/Transforms/Util/lowerswitch.ll b/test/Transforms/Util/lowerswitch.ll 71 | index 1eddb43c1a06..70e1e239b3dd 100644 72 | --- a/test/Transforms/Util/lowerswitch.ll 73 | +++ b/test/Transforms/Util/lowerswitch.ll 74 | @@ -3,7 +3,7 @@ 75 | ; Test that we don't crash and have a different basic block for each incoming edge. 76 | define void @test0() { 77 | ; CHECK-LABEL: @test0 78 | -; CHECK: %merge = phi i64 [ 1, %BB3 ], [ 0, %NewDefault ], [ 0, %NodeBlock5 ], [ 0, %LeafBlock1 ] 79 | +; CHECK: %merge = phi i64 [ 1, %BB3 ], [ 0, %NodeBlock5 ], [ 0, %LeafBlock1 ], [ 0, %NewDefault ] 80 | BB1: 81 | switch i32 undef, label %BB2 [ 82 | i32 3, label %BB2 83 | @@ -186,3 +186,59 @@ define void @test2(i32 %mode) { 84 | ._crit_edge: ; preds = %34, %0 85 | ret void 86 | } 87 | + 88 | +; Test that the PHI node in for.cond should have one entry for each predecessor 89 | +; of its parent basic block after lowerswitch merged several cases into a new 90 | +; default block. 91 | +define void @test3() { 92 | +; CHECK-LABEL: @test3 93 | +entry: 94 | + br label %lbl1 95 | + 96 | +lbl1: ; preds = %cleanup, %entry 97 | + br label %lbl2 98 | + 99 | +lbl2: ; preds = %cleanup, %lbl1 100 | + br label %for.cond 101 | + 102 | +for.cond: ; preds = %cleanup, %cleanup, %lbl2 103 | +; CHECK: for.cond: 104 | +; CHECK: phi i16 [ undef, %lbl2 ], [ %b.3, %NewDefault ]{{$}} 105 | +; CHECK: for.cond1: 106 | + %b.2 = phi i16 [ undef, %lbl2 ], [ %b.3, %cleanup ], [ %b.3, %cleanup ] 107 | + br label %for.cond1 108 | + 109 | +for.cond1: ; preds = %for.inc, %for.cond 110 | + %b.3 = phi i16 [ %b.2, %for.cond ], [ undef, %for.inc ] 111 | + %tobool = icmp ne i16 %b.3, 0 112 | + br i1 %tobool, label %for.body, label %for.end 113 | + 114 | +for.body: ; preds = %for.cond1 115 | + br i1 undef, label %if.then, label %for.inc 116 | + 117 | +if.then: ; preds = %for.body 118 | + br label %cleanup 119 | + 120 | +for.inc: ; preds = %for.body 121 | + br label %for.cond1 122 | + 123 | +for.end: ; preds = %for.cond1 124 | + br i1 undef, label %if.then4, label %for.body7 125 | + 126 | +if.then4: ; preds = %for.end 127 | + br label %cleanup 128 | + 129 | +for.body7: ; preds = %for.end 130 | + br label %cleanup 131 | + 132 | +cleanup: ; preds = %for.body7, %if.then4, %if.then 133 | + switch i32 undef, label %unreachable [ 134 | + i32 0, label %for.cond 135 | + i32 2, label %lbl1 136 | + i32 5, label %for.cond 137 | + i32 3, label %lbl2 138 | + ] 139 | + 140 | +unreachable: ; preds = %cleanup 141 | + unreachable 142 | +} 143 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/Temporarily-disable-the-combination-on-b.patch: -------------------------------------------------------------------------------- 1 | # Description : Temporarily disable the combination on bitcasts through PHI 2 | 3 | 4 | diff -Naur --strip-trailing-cr a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp 5 | --- a/lib/Transforms/InstCombine/InstCombineCasts.cpp 2017-10-23 09:53:04.931214744 -0400 6 | +++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp 2017-10-23 13:38:30.378684858 -0400 7 | @@ -1886,6 +1886,12 @@ 8 | /// All the related PHI nodes can be replaced by new PHI nodes with type A. 9 | /// The uses of \p CI can be changed to the new PHI node corresponding to \p PN. 10 | Instruction *InstCombiner::optimizeBitCastFromPhi(CastInst &CI, PHINode *PN) { 11 | + // Temporarily disable optimization of bitcasts through phi as it creates 12 | + // significant amount of PHI nodes under certain patterns. As IGC has no 13 | + // general register coalescing, these PHI nodes won't be coalesced. It 14 | + // results in huge register pressure and slowdown lots of benchmarks 15 | + // significantly. 16 | + return nullptr; 17 | // BitCast used by Store can be handled in InstCombineLoadStoreAlloca.cpp. 18 | if (hasStoreUsersOnly(CI)) 19 | return nullptr; 20 | -------------------------------------------------------------------------------- /releases/4.0.0/patches_external/add_win_crt_info.patch: -------------------------------------------------------------------------------- 1 | # Description : Add possibility to use ChooseMSVCCRT-script, when 2 | # include LLVM library. 3 | 4 | --- a/cmake/modules/LLVMConfig.cmake.in 5 | +++ b/cmake/modules/LLVMConfig.cmake.in 6 | @@ -10,6 +10,11 @@ set(LLVM_PACKAGE_VERSION @PACKAGE_VERSION@) 7 | 8 | set(LLVM_BUILD_TYPE @CMAKE_BUILD_TYPE@) 9 | 10 | +set(LLVM_USE_CRT_DEBUG @LLVM_USE_CRT_DEBUG@) 11 | +set(LLVM_USE_CRT_MINSIZEREL @LLVM_USE_CRT_MINSIZEREL@) 12 | +set(LLVM_USE_CRT_RELEASE @LLVM_USE_CRT_RELEASE@) 13 | +set(LLVM_USE_CRT_RELWITHDEBINFO @LLVM_USE_CRT_RELWITHDEBINFO@) 14 | + 15 | set(LLVM_COMMON_DEPENDS @LLVM_COMMON_DEPENDS@) 16 | 17 | set(LLVM_AVAILABLE_LIBS @LLVM_AVAILABLE_LIBS@) 18 | -------------------------------------------------------------------------------- /releases/7.0.0/patches_external/BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch: -------------------------------------------------------------------------------- 1 | From cb729efafe85052dc43413ad403b5e67ee002303 Mon Sep 17 00:00:00 2001 2 | From: Aleksander Us 3 | Date: Mon, 26 Aug 2019 15:47:41 +0300 4 | Subject: [PATCH] [BasicBlockUtils] Add metadata fixing in 5 | SplitBlockPredecessors. 6 | 7 | In case when BB is header of some loop and predecessor is latch of 8 | this loop, metadata was not attached to newly created basic block. 9 | This led to loss of loop metadata for other passes. 10 | --- 11 | lib/Transforms/Utils/BasicBlockUtils.cpp | 17 +++++++-- 12 | test/Transforms/LoopSimplify/loop_metadata.ll | 36 +++++++++++++++++++ 13 | 2 files changed, 50 insertions(+), 3 deletions(-) 14 | create mode 100644 test/Transforms/LoopSimplify/loop_metadata.ll 15 | 16 | diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp 17 | index 516a785dce1..6a0a1826df2 100644 18 | --- a/lib/Transforms/Utils/BasicBlockUtils.cpp 19 | +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp 20 | @@ -507,14 +507,24 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, 21 | BranchInst *BI = BranchInst::Create(BB, NewBB); 22 | BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc()); 23 | 24 | + bool IsBBHeader = LI && LI->isLoopHeader(BB); 25 | + Loop *BBLoop = LI ? LI->getLoopFor(BB) : nullptr; 26 | // Move the edges from Preds to point to NewBB instead of BB. 27 | - for (unsigned i = 0, e = Preds.size(); i != e; ++i) { 28 | + for (BasicBlock *Pred : Preds) { 29 | + Instruction *PI = Pred->getTerminator(); 30 | // This is slightly more strict than necessary; the minimum requirement 31 | // is that there be no more than one indirectbr branching to BB. And 32 | // all BlockAddress uses would need to be updated. 33 | - assert(!isa(Preds[i]->getTerminator()) && 34 | + assert(!isa(PI) && 35 | "Cannot split an edge from an IndirectBrInst"); 36 | - Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB); 37 | + if (IsBBHeader && BBLoop->contains(Pred) && BBLoop->isLoopLatch(Pred)) { 38 | + // Update loop metadata if it exists. 39 | + if (MDNode *LoopMD = PI->getMetadata(LLVMContext::MD_loop)) { 40 | + BI->setMetadata(LLVMContext::MD_loop, LoopMD); 41 | + PI->setMetadata(LLVMContext::MD_loop, nullptr); 42 | + } 43 | + } 44 | + PI->replaceUsesOfWith(BB, NewBB); 45 | } 46 | 47 | // Insert a new PHI node into NewBB for every PHI node in BB and that new PHI 48 | diff --git a/test/Transforms/LoopSimplify/loop_metadata.ll b/test/Transforms/LoopSimplify/loop_metadata.ll 49 | new file mode 100644 50 | index 00000000000..c15c92fe3ae 51 | --- /dev/null 52 | +++ b/test/Transforms/LoopSimplify/loop_metadata.ll 53 | @@ -0,0 +1,36 @@ 54 | +; RUN: opt -S -loop-simplify < %s | FileCheck %s 55 | + 56 | +; CHECK: for.cond.loopexit: 57 | +; CHECK: br label %for.cond, !llvm.loop !0 58 | +; CHECK: br i1 %cmp1, label %for.body1, label %for.cond.loopexit 59 | + 60 | +define void @foo() { 61 | +entry: 62 | + br label %for.cond 63 | + 64 | +for.cond: ; preds = %for.cond1, %entry 65 | + %j = phi i32 [ 0, %entry ], [ %add, %for.cond1 ] 66 | + %cmp = icmp ult i32 %j, 8 67 | + br i1 %cmp, label %for.body, label %for.end 68 | + 69 | +for.body: ; preds = %for.cond 70 | + %dummy1 = add i32 1, 1 71 | + %add = add nuw nsw i32 %j, 1 72 | + br label %for.cond1 73 | + 74 | +for.cond1: ; preds = %for.body1, %for.body 75 | + %i.0 = phi i32 [ 1, %for.body ], [ %inc, %for.body1 ] 76 | + %cmp1 = icmp ult i32 %i.0, 8 77 | + br i1 %cmp1, label %for.body1, label %for.cond, !llvm.loop !0 78 | + 79 | +for.body1: ; preds = %for.cond1 80 | + %dummy2 = add i32 1, 1 81 | + %inc = add nuw nsw i32 %i.0, 1 82 | + br label %for.cond1 83 | + 84 | +for.end: ; preds = %for.cond 85 | + ret void 86 | +} 87 | + 88 | +!0 = distinct !{!0, !1} 89 | +!1 = !{!"llvm.loop.unroll.full"} 90 | -- 91 | 2.18.0 92 | 93 | -------------------------------------------------------------------------------- /releases/7.0.0/patches_external/IndVarSimplify-Do-not-use-SCEV-expander-for-IVCount-.patch: -------------------------------------------------------------------------------- 1 | From cbf2de408fa9a89ee446d0159ecd8bb81340f0b4 Mon Sep 17 00:00:00 2001 2 | From: Aleksander Us 3 | Date: Mon, 26 Aug 2019 15:45:47 +0300 4 | Subject: [PATCH] [IndVarSimplify] Do not use SCEV expander for IVCount in 5 | LFTR when possible. 6 | 7 | SCEV analysis cannot properly cache instruction with poison flags 8 | (for example, add nsw outside of loop will not be reused by expander). 9 | This can lead to generating of additional instructions by SCEV expander. 10 | 11 | Example IR: 12 | 13 | ... 14 | %maxval = add nuw nsw i32 %a1, %a2 15 | ... 16 | for.body: 17 | ... 18 | %cmp22 = icmp ult i32 %ivadd, %maxval 19 | br i1 %cmp22, label %for.body, label %for.end 20 | ... 21 | 22 | SCEV expander will generate copy of %maxval in preheader but without 23 | nuw/nsw flags. This can be avoided by explicit check that iv count 24 | value gives the same SCEV expressions as calculated by LFTR. 25 | --- 26 | lib/Transforms/Scalar/IndVarSimplify.cpp | 13 ++++++++++++- 27 | test/Transforms/IndVarSimplify/add_nsw.ll | 23 +++++++++++++++++++++++ 28 | test/Transforms/IndVarSimplify/udiv.ll | 1 + 29 | 3 files changed, 36 insertions(+), 1 deletion(-) 30 | create mode 100644 test/Transforms/IndVarSimplify/add_nsw.ll 31 | 32 | diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp 33 | index 8656e88b79c..1744b424722 100644 34 | --- a/lib/Transforms/Scalar/IndVarSimplify.cpp 35 | +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp 36 | @@ -2174,8 +2174,19 @@ static Value *genLoopLimit(PHINode *IndVar, const SCEV *IVCount, Loop *L, 37 | 38 | IVLimit = SE->getAddExpr(IVInit, IVCount); 39 | } 40 | - // Expand the code for the iteration count. 41 | + 42 | + // If computed limit is equal to old limit then do not use SCEV expander 43 | + // because it can lost NUW/NSW flags and create extra instructions. 44 | BranchInst *BI = cast(L->getExitingBlock()->getTerminator()); 45 | + if (ICmpInst *Cmp = dyn_cast(BI->getOperand(0))) { 46 | + Value *Limit = Cmp->getOperand(0); 47 | + if (!L->isLoopInvariant(Limit)) 48 | + Limit = Cmp->getOperand(1); 49 | + if (SE->getSCEV(Limit) == IVLimit) 50 | + return Limit; 51 | + } 52 | + 53 | + // Expand the code for the iteration count. 54 | IRBuilder<> Builder(BI); 55 | assert(SE->isLoopInvariant(IVLimit, L) && 56 | "Computed iteration count is not loop invariant!"); 57 | diff --git a/test/Transforms/IndVarSimplify/add_nsw.ll b/test/Transforms/IndVarSimplify/add_nsw.ll 58 | new file mode 100644 59 | index 00000000000..abd1cbb6c51 60 | --- /dev/null 61 | +++ b/test/Transforms/IndVarSimplify/add_nsw.ll 62 | @@ -0,0 +1,23 @@ 63 | +; RUN: opt -indvars -S %s | FileCheck %s 64 | + 65 | +target datalayout = "e-p:32:32-i64:64-n8:16:32" 66 | + 67 | +; CHECK: for.body.preheader: 68 | +; CHECK-NOT: add 69 | +; CHECK: for.body: 70 | + 71 | +define void @foo(i32 %a1, i32 %a2) { 72 | +entry: 73 | + %maxval = add nuw nsw i32 %a1, %a2 74 | + %cmp = icmp slt i32 %maxval, 1 75 | + br i1 %cmp, label %for.end, label %for.body 76 | + 77 | +for.body: ; preds = %entry, %for.body 78 | + %j.02 = phi i32 [ 0, %entry ], [ %add31, %for.body ] 79 | + %add31 = add nuw nsw i32 %j.02, 1 80 | + %cmp22 = icmp slt i32 %add31, %maxval 81 | + br i1 %cmp22, label %for.body, label %for.end 82 | + 83 | +for.end: ; preds = %for.body 84 | + ret void 85 | +} 86 | diff --git a/test/Transforms/IndVarSimplify/udiv.ll b/test/Transforms/IndVarSimplify/udiv.ll 87 | index b3f2c2a6a66..3530343ef4a 100644 88 | --- a/test/Transforms/IndVarSimplify/udiv.ll 89 | +++ b/test/Transforms/IndVarSimplify/udiv.ll 90 | @@ -133,6 +133,7 @@ declare i32 @printf(i8* nocapture, ...) nounwind 91 | ; CHECK-LABEL: @foo( 92 | ; CHECK: for.body.preheader: 93 | ; CHECK-NOT: udiv 94 | +; CHECK: for.body: 95 | 96 | define void @foo(double* %p, i64 %n) nounwind { 97 | entry: 98 | -- 99 | 2.18.0 100 | 101 | -------------------------------------------------------------------------------- /releases/7.0.0/patches_external/Use-depth-limit-for-trunc-analysis.patch: -------------------------------------------------------------------------------- 1 | From a4cc6b11f900f62e2570a43980290441cfcbc925 Mon Sep 17 00:00:00 2001 2 | From: Teresa Johnson 3 | Date: Tue, 12 Mar 2019 18:28:05 +0000 4 | Subject: [PATCH] Use depth limit for trunc analysis 5 | 6 | Summary: 7 | This fixes an extremely long compile time caused by recursive analysis 8 | of truncs, which were not previously subject to any depth limits unlike 9 | some of the other ops. I decided to use the same control used for 10 | sext/zext, since the routines analyzing these are sometimes mutually 11 | recursive with the trunc analysis. 12 | 13 | Reviewers: mkazantsev, sanjoy 14 | 15 | Subscribers: sanjoy, jdoerfert, llvm-commits 16 | 17 | Tags: #llvm 18 | 19 | Differential Revision: https://reviews.llvm.org/D58994 20 | 21 | llvm-svn: 355949 22 | --- 23 | llvm/include/llvm/Analysis/ScalarEvolution.h | 8 ++- 24 | llvm/lib/Analysis/ScalarEvolution.cpp | 65 ++++++++++--------- 25 | .../Analysis/ScalarEvolution/limit-depth.ll | 30 ++++++++- 26 | 3 files changed, 70 insertions(+), 33 deletions(-) 27 | 28 | diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h 29 | index 89918e3c205..b0855e18800 100644 30 | --- a/include/llvm/Analysis/ScalarEvolution.h 31 | +++ b/include/llvm/Analysis/ScalarEvolution.h 32 | @@ -521,7 +521,7 @@ public: 33 | const SCEV *getConstant(ConstantInt *V); 34 | const SCEV *getConstant(const APInt &Val); 35 | const SCEV *getConstant(Type *Ty, uint64_t V, bool isSigned = false); 36 | - const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty); 37 | + const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0); 38 | const SCEV *getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0); 39 | const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0); 40 | const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty); 41 | @@ -619,11 +619,13 @@ public: 42 | 43 | /// Return a SCEV corresponding to a conversion of the input value to the 44 | /// specified type. If the type must be extended, it is zero extended. 45 | - const SCEV *getTruncateOrZeroExtend(const SCEV *V, Type *Ty); 46 | + const SCEV *getTruncateOrZeroExtend(const SCEV *V, Type *Ty, 47 | + unsigned Depth = 0); 48 | 49 | /// Return a SCEV corresponding to a conversion of the input value to the 50 | /// specified type. If the type must be extended, it is sign extended. 51 | - const SCEV *getTruncateOrSignExtend(const SCEV *V, Type *Ty); 52 | + const SCEV *getTruncateOrSignExtend(const SCEV *V, Type *Ty, 53 | + unsigned Depth = 0); 54 | 55 | /// Return a SCEV corresponding to a conversion of the input value to the 56 | /// specified type. If the type must be extended, it is zero extended. The 57 | diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp 58 | index 0e715b8814f..30708125203 100644 59 | --- a/lib/Analysis/ScalarEvolution.cpp 60 | +++ b/lib/Analysis/ScalarEvolution.cpp 61 | @@ -197,9 +197,9 @@ static cl::opt MaxConstantEvolvingDepth( 62 | cl::desc("Maximum depth of recursive constant evolving"), cl::init(32)); 63 | 64 | static cl::opt 65 | - MaxExtDepth("scalar-evolution-max-ext-depth", cl::Hidden, 66 | - cl::desc("Maximum depth of recursive SExt/ZExt"), 67 | - cl::init(8)); 68 | + MaxCastDepth("scalar-evolution-max-cast-depth", cl::Hidden, 69 | + cl::desc("Maximum depth of recursive SExt/ZExt/Trunc"), 70 | + cl::init(8)); 71 | 72 | static cl::opt 73 | MaxAddRecSize("scalar-evolution-max-add-rec-size", cl::Hidden, 74 | @@ -1221,8 +1221,8 @@ const SCEV *SCEVAddRecExpr::evaluateAtIteration(const SCEV *It, 75 | // SCEV Expression folder implementations 76 | //===----------------------------------------------------------------------===// 77 | 78 | -const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, 79 | - Type *Ty) { 80 | +const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, Type *Ty, 81 | + unsigned Depth) { 82 | assert(getTypeSizeInBits(Op->getType()) > getTypeSizeInBits(Ty) && 83 | "This is not a truncating conversion!"); 84 | assert(isSCEVable(Ty) && 85 | @@ -1243,15 +1243,23 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, 86 | 87 | // trunc(trunc(x)) --> trunc(x) 88 | if (const SCEVTruncateExpr *ST = dyn_cast(Op)) 89 | - return getTruncateExpr(ST->getOperand(), Ty); 90 | + return getTruncateExpr(ST->getOperand(), Ty, Depth + 1); 91 | 92 | // trunc(sext(x)) --> sext(x) if widening or trunc(x) if narrowing 93 | if (const SCEVSignExtendExpr *SS = dyn_cast(Op)) 94 | - return getTruncateOrSignExtend(SS->getOperand(), Ty); 95 | + return getTruncateOrSignExtend(SS->getOperand(), Ty, Depth + 1); 96 | 97 | // trunc(zext(x)) --> zext(x) if widening or trunc(x) if narrowing 98 | if (const SCEVZeroExtendExpr *SZ = dyn_cast(Op)) 99 | - return getTruncateOrZeroExtend(SZ->getOperand(), Ty); 100 | + return getTruncateOrZeroExtend(SZ->getOperand(), Ty, Depth + 1); 101 | + 102 | + if (Depth > MaxCastDepth) { 103 | + SCEV *S = 104 | + new (SCEVAllocator) SCEVTruncateExpr(ID.Intern(SCEVAllocator), Op, Ty); 105 | + UniqueSCEVs.InsertNode(S, IP); 106 | + addToLoopUseLists(S); 107 | + return S; 108 | + } 109 | 110 | // trunc(x1 + ... + xN) --> trunc(x1) + ... + trunc(xN) and 111 | // trunc(x1 * ... * xN) --> trunc(x1) * ... * trunc(xN), 112 | @@ -1263,7 +1271,7 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, 113 | unsigned numTruncs = 0; 114 | for (unsigned i = 0, e = CommOp->getNumOperands(); i != e && numTruncs < 2; 115 | ++i) { 116 | - const SCEV *S = getTruncateExpr(CommOp->getOperand(i), Ty); 117 | + const SCEV *S = getTruncateExpr(CommOp->getOperand(i), Ty, Depth + 1); 118 | if (!isa(CommOp->getOperand(i)) && isa(S)) 119 | numTruncs++; 120 | Operands.push_back(S); 121 | @@ -1287,7 +1295,7 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, 122 | if (const SCEVAddRecExpr *AddRec = dyn_cast(Op)) { 123 | SmallVector Operands; 124 | for (const SCEV *Op : AddRec->operands()) 125 | - Operands.push_back(getTruncateExpr(Op, Ty)); 126 | + Operands.push_back(getTruncateExpr(Op, Ty, Depth + 1)); 127 | return getAddRecExpr(Operands, AddRec->getLoop(), SCEV::FlagAnyWrap); 128 | } 129 | 130 | @@ -1621,7 +1629,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 131 | ID.AddPointer(Ty); 132 | void *IP = nullptr; 133 | if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP)) return S; 134 | - if (Depth > MaxExtDepth) { 135 | + if (Depth > MaxCastDepth) { 136 | SCEV *S = new (SCEVAllocator) SCEVZeroExtendExpr(ID.Intern(SCEVAllocator), 137 | Op, Ty); 138 | UniqueSCEVs.InsertNode(S, IP); 139 | @@ -1639,7 +1647,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 140 | unsigned NewBits = getTypeSizeInBits(Ty); 141 | if (CR.truncate(TruncBits).zeroExtend(NewBits).contains( 142 | CR.zextOrTrunc(NewBits))) 143 | - return getTruncateOrZeroExtend(X, Ty); 144 | + return getTruncateOrZeroExtend(X, Ty, Depth); 145 | } 146 | 147 | // If the input value is a chrec scev, and we can prove that the value 148 | @@ -1681,9 +1689,9 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 149 | // Check whether the backedge-taken count can be losslessly casted to 150 | // the addrec's type. The count is always unsigned. 151 | const SCEV *CastedMaxBECount = 152 | - getTruncateOrZeroExtend(MaxBECount, Start->getType()); 153 | - const SCEV *RecastedMaxBECount = 154 | - getTruncateOrZeroExtend(CastedMaxBECount, MaxBECount->getType()); 155 | + getTruncateOrZeroExtend(MaxBECount, Start->getType(), Depth); 156 | + const SCEV *RecastedMaxBECount = getTruncateOrZeroExtend( 157 | + CastedMaxBECount, MaxBECount->getType(), Depth); 158 | if (MaxBECount == RecastedMaxBECount) { 159 | Type *WideTy = IntegerType::get(getContext(), BitWidth * 2); 160 | // Check whether Start+Step*MaxBECount has no unsigned overflow. 161 | @@ -1932,7 +1940,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 162 | void *IP = nullptr; 163 | if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP)) return S; 164 | // Limit recursion depth. 165 | - if (Depth > MaxExtDepth) { 166 | + if (Depth > MaxCastDepth) { 167 | SCEV *S = new (SCEVAllocator) SCEVSignExtendExpr(ID.Intern(SCEVAllocator), 168 | Op, Ty); 169 | UniqueSCEVs.InsertNode(S, IP); 170 | @@ -1950,7 +1958,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 171 | unsigned NewBits = getTypeSizeInBits(Ty); 172 | if (CR.truncate(TruncBits).signExtend(NewBits).contains( 173 | CR.sextOrTrunc(NewBits))) 174 | - return getTruncateOrSignExtend(X, Ty); 175 | + return getTruncateOrSignExtend(X, Ty, Depth); 176 | } 177 | 178 | if (auto *SA = dyn_cast(Op)) { 179 | @@ -2025,9 +2033,9 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 180 | // Check whether the backedge-taken count can be losslessly casted to 181 | // the addrec's type. The count is always unsigned. 182 | const SCEV *CastedMaxBECount = 183 | - getTruncateOrZeroExtend(MaxBECount, Start->getType()); 184 | - const SCEV *RecastedMaxBECount = 185 | - getTruncateOrZeroExtend(CastedMaxBECount, MaxBECount->getType()); 186 | + getTruncateOrZeroExtend(MaxBECount, Start->getType(), Depth); 187 | + const SCEV *RecastedMaxBECount = getTruncateOrZeroExtend( 188 | + CastedMaxBECount, MaxBECount->getType(), Depth); 189 | if (MaxBECount == RecastedMaxBECount) { 190 | Type *WideTy = IntegerType::get(getContext(), BitWidth * 2); 191 | // Check whether Start+Step*MaxBECount has no signed overflow. 192 | @@ -4017,29 +4025,28 @@ const SCEV *ScalarEvolution::getMinusSCEV(const SCEV *LHS, const SCEV *RHS, 193 | return getAddExpr(LHS, getNegativeSCEV(RHS, NegFlags), AddFlags, Depth); 194 | } 195 | 196 | -const SCEV * 197 | -ScalarEvolution::getTruncateOrZeroExtend(const SCEV *V, Type *Ty) { 198 | +const SCEV *ScalarEvolution::getTruncateOrZeroExtend(const SCEV *V, Type *Ty, 199 | + unsigned Depth) { 200 | Type *SrcTy = V->getType(); 201 | assert(SrcTy->isIntOrPtrTy() && Ty->isIntOrPtrTy() && 202 | "Cannot truncate or zero extend with non-integer arguments!"); 203 | if (getTypeSizeInBits(SrcTy) == getTypeSizeInBits(Ty)) 204 | return V; // No conversion 205 | if (getTypeSizeInBits(SrcTy) > getTypeSizeInBits(Ty)) 206 | - return getTruncateExpr(V, Ty); 207 | - return getZeroExtendExpr(V, Ty); 208 | + return getTruncateExpr(V, Ty, Depth); 209 | + return getZeroExtendExpr(V, Ty, Depth); 210 | } 211 | 212 | -const SCEV * 213 | -ScalarEvolution::getTruncateOrSignExtend(const SCEV *V, 214 | - Type *Ty) { 215 | +const SCEV *ScalarEvolution::getTruncateOrSignExtend(const SCEV *V, Type *Ty, 216 | + unsigned Depth) { 217 | Type *SrcTy = V->getType(); 218 | assert(SrcTy->isIntOrPtrTy() && Ty->isIntOrPtrTy() && 219 | "Cannot truncate or zero extend with non-integer arguments!"); 220 | if (getTypeSizeInBits(SrcTy) == getTypeSizeInBits(Ty)) 221 | return V; // No conversion 222 | if (getTypeSizeInBits(SrcTy) > getTypeSizeInBits(Ty)) 223 | - return getTruncateExpr(V, Ty); 224 | - return getSignExtendExpr(V, Ty); 225 | + return getTruncateExpr(V, Ty, Depth); 226 | + return getSignExtendExpr(V, Ty, Depth); 227 | } 228 | 229 | const SCEV * 230 | diff --git a/test/Analysis/ScalarEvolution/limit-depth.ll b/test/Analysis/ScalarEvolution/limit-depth.ll 231 | index f4154130233..6fdf8c5df97 100644 232 | --- a/test/Analysis/ScalarEvolution/limit-depth.ll 233 | +++ b/test/Analysis/ScalarEvolution/limit-depth.ll 234 | @@ -1,4 +1,4 @@ 235 | -; RUN: opt -scalar-evolution-max-arith-depth=0 -scalar-evolution-max-ext-depth=0 -analyze -scalar-evolution < %s | FileCheck %s 236 | +; RUN: opt -scalar-evolution-max-arith-depth=0 -scalar-evolution-max-cast-depth=0 -analyze -scalar-evolution < %s | FileCheck %s 237 | 238 | ; Check that depth set to 0 prevents getAddExpr and getMulExpr from making 239 | ; transformations in SCEV. We expect the result to be very straightforward. 240 | @@ -98,3 +98,31 @@ exit: 241 | %ze2 = zext i64 %iv2.inc to i128 242 | ret void 243 | } 244 | + 245 | +define void @test_trunc(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) { 246 | +; CHECK-LABEL: @test_trunc 247 | +; CHECK: %trunc2 = trunc i64 %iv2.inc to i32 248 | +; CHECK-NEXT: --> {(trunc i64 (1 + {7,+,1}<%loop>) to i32),+,1}<%loop2> 249 | +entry: 250 | + br label %loop 251 | + 252 | +loop: 253 | + %iv = phi i128 [ 6, %entry ], [ %iv.inc, %loop ] 254 | + %iv.inc = add nsw i128 %iv, 1 255 | + %cond = icmp sle i128 %iv.inc, 50 256 | + br i1 %cond, label %loop, label %between 257 | + 258 | +between: 259 | + %trunc = trunc i128 %iv.inc to i64 260 | + br label %loop2 261 | + 262 | +loop2: 263 | + %iv2 = phi i64 [ %trunc, %between ], [ %iv2.inc, %loop2 ] 264 | + %iv2.inc = add nuw i64 %iv2, 1 265 | + %cond2 = icmp sle i64 %iv2.inc, 50 266 | + br i1 %cond2, label %loop2, label %exit 267 | + 268 | +exit: 269 | + %trunc2 = trunc i64 %iv2.inc to i32 270 | + ret void 271 | +} 272 | -- 273 | 2.18.0 274 | 275 | -------------------------------------------------------------------------------- /releases/7.0.0/patches_external/add_win_crt_info.patch: -------------------------------------------------------------------------------- 1 | # Description : Add possibility to use ChooseMSVCCRT-script, when 2 | # include LLVM library. 3 | 4 | --- a/cmake/modules/LLVMConfig.cmake.in 5 | +++ b/cmake/modules/LLVMConfig.cmake.in 6 | @@ -10,6 +10,11 @@ set(LLVM_PACKAGE_VERSION @PACKAGE_VERSION@) 7 | 8 | set(LLVM_BUILD_TYPE @CMAKE_BUILD_TYPE@) 9 | 10 | +set(LLVM_USE_CRT_DEBUG @LLVM_USE_CRT_DEBUG@) 11 | +set(LLVM_USE_CRT_MINSIZEREL @LLVM_USE_CRT_MINSIZEREL@) 12 | +set(LLVM_USE_CRT_RELEASE @LLVM_USE_CRT_RELEASE@) 13 | +set(LLVM_USE_CRT_RELWITHDEBINFO @LLVM_USE_CRT_RELWITHDEBINFO@) 14 | + 15 | set(LLVM_COMMON_DEPENDS @LLVM_COMMON_DEPENDS@) 16 | 17 | set(LLVM_AVAILABLE_LIBS @LLVM_AVAILABLE_LIBS@) 18 | -------------------------------------------------------------------------------- /releases/7.0.0/patches_external/export-utility-to-targets-build-install_1.patch: -------------------------------------------------------------------------------- 1 | From 3436463bf7021c9986f3a52ea0b699abfcbd0b95 Mon Sep 17 00:00:00 2001 2 | From: Stefan Granitz 3 | Date: Fri, 11 Jan 2019 19:34:34 +0000 4 | Subject: [PATCH] [CMake] Export utility targets to the build/install tree 5 | depending on LLVM_BUILD/INSTALL_UTILS 6 | 7 | Summary: 8 | Allow external projects to import test-related targets like FileCheck, count, not etc. and query binary paths, properties, etc. 9 | This would be useful for LLDB, because it reduces the difference between in-tree vs. standalone builds and simplifies CMake logic. 10 | 11 | Reviewers: chapuni, gottesmm, beanz 12 | 13 | Reviewed By: beanz 14 | 15 | Subscribers: mgorny, lldb-commits, llvm-commits, #lldb 16 | 17 | Differential Revision: https://reviews.llvm.org/D56606 18 | 19 | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350959 91177308-0d34-0410-b5e6-96231b3b80d8 20 | --- 21 | cmake/modules/AddLLVM.cmake | 3 +++ 22 | 1 file changed, 3 insertions(+) 23 | 24 | diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake 25 | index 9b7d24184fe0..4dbc0ddaf4f0 100644 26 | --- a/cmake/modules/AddLLVM.cmake 27 | +++ b/cmake/modules/AddLLVM.cmake 28 | @@ -920,6 +920,9 @@ macro(add_llvm_utility name) 29 | DEPENDS ${name} 30 | COMPONENT ${name}) 31 | endif() 32 | + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) 33 | + elseif( LLVM_BUILD_UTILS ) 34 | + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name}) 35 | endif() 36 | endmacro(add_llvm_utility name) 37 | 38 | -------------------------------------------------------------------------------- /releases/7.0.0/patches_external/export-utility-to-targets-build-install_2.patch: -------------------------------------------------------------------------------- 1 | From 4ce5f86eddc0bf42a971db4509829036d5b17b92 Mon Sep 17 00:00:00 2001 2 | From: Stefan Granitz 3 | Date: Fri, 1 Feb 2019 13:08:09 +0000 4 | Subject: [PATCH] [CMake] Add install targets for utilities to LLVM exports if 5 | LLVM_INSTALL_UTILS=ON 6 | 7 | Summary: D56606 was only appending target names to the `LLVM_EXPORTS`/`LLVM_EXPORTS_BUILDTREE_ONLY` properties. Targets showed up correctly in the build-tree `LLVMExports.cmake`, but they were missing in the installed one (as we found in https://bugs.llvm.org/show_bug.cgi?id=40443), because install did not register them explicitly. 8 | 9 | Reviewers: mgorny, smeenai, beanz, gottesmm, dschuff, tstellar, serge-sans-paille 10 | 11 | Reviewed By: smeenai 12 | 13 | Subscribers: llvm-commits 14 | 15 | Differential Revision: https://reviews.llvm.org/D57383 16 | 17 | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352869 91177308-0d34-0410-b5e6-96231b3b80d8 18 | --- 19 | cmake/modules/AddLLVM.cmake | 32 +++++++++++++++++++++----------- 20 | 1 file changed, 21 insertions(+), 11 deletions(-) 21 | 22 | diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake 23 | index 39781bf34e24..607d6e682b49 100644 24 | --- a/cmake/modules/AddLLVM.cmake 25 | +++ b/cmake/modules/AddLLVM.cmake 26 | @@ -924,18 +924,28 @@ macro(add_llvm_utility name) 27 | 28 | add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN}) 29 | set_target_properties(${name} PROPERTIES FOLDER "Utils") 30 | - if( LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS ) 31 | - install (TARGETS ${name} 32 | - RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR} 33 | - COMPONENT ${name}) 34 | - if (NOT CMAKE_CONFIGURATION_TYPES) 35 | - add_llvm_install_targets(install-${name} 36 | - DEPENDS ${name} 37 | - COMPONENT ${name}) 38 | + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) 39 | + if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) 40 | + if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR 41 | + NOT LLVM_DISTRIBUTION_COMPONENTS) 42 | + set(export_to_llvmexports EXPORT LLVMExports) 43 | + set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True) 44 | + endif() 45 | + 46 | + install(TARGETS ${name} 47 | + ${export_to_llvmexports} 48 | + RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR} 49 | + COMPONENT ${name}) 50 | + 51 | + if (NOT LLVM_ENABLE_IDE) 52 | + add_llvm_install_targets(install-${name} 53 | + DEPENDS ${name} 54 | + COMPONENT ${name}) 55 | + endif() 56 | + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) 57 | + elseif(LLVM_BUILD_UTILS) 58 | + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name}) 59 | endif() 60 | - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) 61 | - elseif( LLVM_BUILD_UTILS ) 62 | - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name}) 63 | endif() 64 | endmacro(add_llvm_utility name) 65 | 66 | -------------------------------------------------------------------------------- /releases/7.0.0/patches_external/fix-pointer-for-lifetime-intrinsic.patch: -------------------------------------------------------------------------------- 1 | diff -Naur a/lib/Transforms/Scalar/SROA.cpp b/lib/Transforms/Scalar/SROA.cpp 2 | --- a/lib/Transforms/Scalar/SROA.cpp 2018-08-31 17:53:05.000000000 +0200 3 | +++ b/lib/Transforms/Scalar/SROA.cpp 2018-12-20 18:48:12.788662000 +0100 4 | @@ -3033,7 +3033,18 @@ 5 | ConstantInt *Size = 6 | ConstantInt::get(cast(II.getArgOperand(0)->getType()), 7 | NewEndOffset - NewBeginOffset); 8 | - Value *Ptr = getNewAllocaSlicePtr(IRB, OldPtr->getType()); 9 | + // For lifetime intrinsics it's ok to cast a pointer type of a new slice 10 | + // to a generic i8* pointer. There is a case when using the pointer type 11 | + // from whole alloca leads to an assertion in PromoteMemToReg. 12 | + // 13 | + // A patch is posted to fix this in LLVM: 14 | + // 15 | + // https://reviews.llvm.org/D55934 16 | + // [PATCH] D55934: Assertion in isAllocaPromotable due to extra bitcast 17 | + // goes into lifetime marker 18 | + Type *PointerTy = IRB.getInt8PtrTy(OldPtr->getType()->getPointerAddressSpace()); 19 | + Value *Ptr = getNewAllocaSlicePtr(IRB, PointerTy); 20 | + 21 | Value *New; 22 | if (II.getIntrinsicID() == Intrinsic::lifetime_start) 23 | New = IRB.CreateLifetimeStart(Ptr, Size); 24 | -------------------------------------------------------------------------------- /releases/7.0.0/patches_external/initializaton_order_fiasco-workaround.patch: -------------------------------------------------------------------------------- 1 | # Description : workaround for https://bugs.llvm.org/show_bug.cgi?id=41367 2 | # When Fixed in Open Source : Needed always 3 | # Category : Bugfix 4 | diff --git a/include/llvm/Support/ManagedStatic.h b/include/llvm/Support/ManagedStatic.h 5 | index b4bf321..3166d59 100644 6 | +++ b/include/llvm/Support/ManagedStatic.h 7 | --- a/include/llvm/Support/ManagedStatic.h 8 | @@ -17,6 +17,10 @@ 9 | #include 10 | #include 11 | 12 | +#if !defined(_MSC_VER) || (_MSC_VER >= 1925) || defined(__clang__) 13 | +#define LLVM_USE_CONSTEXPR_CTOR 14 | +#endif 15 | + 16 | namespace llvm { 17 | 18 | /// object_creator - Helper method for ManagedStatic. 19 | @@ -36,21 +40,33 @@ template struct object_deleter { 20 | /// ManagedStaticBase - Common base class for ManagedStatic instances. 21 | class ManagedStaticBase { 22 | protected: 23 | +#ifdef LLVM_USE_CONSTEXPR_CTOR 24 | + mutable std::atomic Ptr{}; 25 | + mutable void (*DeleterFn)(void *) = nullptr; 26 | + mutable const ManagedStaticBase *Next = nullptr; 27 | +#else 28 | // This should only be used as a static variable, which guarantees that this 29 | // will be zero initialized. 30 | mutable std::atomic Ptr; 31 | mutable void (*DeleterFn)(void*); 32 | mutable const ManagedStaticBase *Next; 33 | - 34 | +#endif 35 | void RegisterManagedStatic(void *(*creator)(), void (*deleter)(void*)) const; 36 | 37 | public: 38 | +#ifdef LLVM_USE_CONSTEXPR_CTOR 39 | + constexpr ManagedStaticBase() = default; 40 | +#endif 41 | /// isConstructed - Return true if this object has not been created yet. 42 | bool isConstructed() const { return Ptr != nullptr; } 43 | 44 | void destroy() const; 45 | }; 46 | 47 | +// we don't need LLVM_USE_CONSTEXPR_CTOR anymore as it is used only to define 48 | +// a proper constructor and initializers 49 | +#undef LLVM_USE_CONSTEXPR_CTOR 50 | + 51 | /// ManagedStatic - This transparently changes the behavior of global statics to 52 | /// be lazily constructed on demand (good for reducing startup times of dynamic 53 | /// libraries that link in LLVM components) and for making destruction be 54 | -------------------------------------------------------------------------------- /releases/8.0.0/patches_external/BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch: -------------------------------------------------------------------------------- 1 | From 2e01cb0653db81ce9fd9cc3a8a1f997920cf1b69 Mon Sep 17 00:00:00 2001 2 | From: Aleksander Us 3 | Date: Mon, 26 Aug 2019 15:47:41 +0300 4 | Subject: [PATCH] [BasicBlockUtils] Add metadata fixing in 5 | SplitBlockPredecessors. 6 | 7 | In case when BB is header of some loop and predecessor is latch of 8 | this loop, metadata was not attached to newly created basic block. 9 | This led to loss of loop metadata for other passes. 10 | --- 11 | lib/Transforms/Utils/BasicBlockUtils.cpp | 17 +++++++-- 12 | test/Transforms/LoopSimplify/loop_metadata.ll | 36 +++++++++++++++++++ 13 | 2 files changed, 50 insertions(+), 3 deletions(-) 14 | create mode 100644 test/Transforms/LoopSimplify/loop_metadata.ll 15 | 16 | diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp 17 | index 7da768252fc..c28682df298 100644 18 | --- a/lib/Transforms/Utils/BasicBlockUtils.cpp 19 | +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp 20 | @@ -536,14 +536,24 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, 21 | BranchInst *BI = BranchInst::Create(BB, NewBB); 22 | BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc()); 23 | 24 | + bool IsBBHeader = LI && LI->isLoopHeader(BB); 25 | + Loop *BBLoop = LI ? LI->getLoopFor(BB) : nullptr; 26 | // Move the edges from Preds to point to NewBB instead of BB. 27 | - for (unsigned i = 0, e = Preds.size(); i != e; ++i) { 28 | + for (BasicBlock *Pred : Preds) { 29 | + Instruction *PI = Pred->getTerminator(); 30 | // This is slightly more strict than necessary; the minimum requirement 31 | // is that there be no more than one indirectbr branching to BB. And 32 | // all BlockAddress uses would need to be updated. 33 | - assert(!isa(Preds[i]->getTerminator()) && 34 | + assert(!isa(PI) && 35 | "Cannot split an edge from an IndirectBrInst"); 36 | - Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB); 37 | + if (IsBBHeader && BBLoop->contains(Pred) && BBLoop->isLoopLatch(Pred)) { 38 | + // Update loop metadata if it exists. 39 | + if (MDNode *LoopMD = PI->getMetadata(LLVMContext::MD_loop)) { 40 | + BI->setMetadata(LLVMContext::MD_loop, LoopMD); 41 | + PI->setMetadata(LLVMContext::MD_loop, nullptr); 42 | + } 43 | + } 44 | + PI->replaceUsesOfWith(BB, NewBB); 45 | } 46 | 47 | // Insert a new PHI node into NewBB for every PHI node in BB and that new PHI 48 | diff --git a/test/Transforms/LoopSimplify/loop_metadata.ll b/test/Transforms/LoopSimplify/loop_metadata.ll 49 | new file mode 100644 50 | index 00000000000..c15c92fe3ae 51 | --- /dev/null 52 | +++ b/test/Transforms/LoopSimplify/loop_metadata.ll 53 | @@ -0,0 +1,36 @@ 54 | +; RUN: opt -S -loop-simplify < %s | FileCheck %s 55 | + 56 | +; CHECK: for.cond.loopexit: 57 | +; CHECK: br label %for.cond, !llvm.loop !0 58 | +; CHECK: br i1 %cmp1, label %for.body1, label %for.cond.loopexit 59 | + 60 | +define void @foo() { 61 | +entry: 62 | + br label %for.cond 63 | + 64 | +for.cond: ; preds = %for.cond1, %entry 65 | + %j = phi i32 [ 0, %entry ], [ %add, %for.cond1 ] 66 | + %cmp = icmp ult i32 %j, 8 67 | + br i1 %cmp, label %for.body, label %for.end 68 | + 69 | +for.body: ; preds = %for.cond 70 | + %dummy1 = add i32 1, 1 71 | + %add = add nuw nsw i32 %j, 1 72 | + br label %for.cond1 73 | + 74 | +for.cond1: ; preds = %for.body1, %for.body 75 | + %i.0 = phi i32 [ 1, %for.body ], [ %inc, %for.body1 ] 76 | + %cmp1 = icmp ult i32 %i.0, 8 77 | + br i1 %cmp1, label %for.body1, label %for.cond, !llvm.loop !0 78 | + 79 | +for.body1: ; preds = %for.cond1 80 | + %dummy2 = add i32 1, 1 81 | + %inc = add nuw nsw i32 %i.0, 1 82 | + br label %for.cond1 83 | + 84 | +for.end: ; preds = %for.cond 85 | + ret void 86 | +} 87 | + 88 | +!0 = distinct !{!0, !1} 89 | +!1 = !{!"llvm.loop.unroll.full"} 90 | -- 91 | 2.18.0 92 | 93 | -------------------------------------------------------------------------------- /releases/8.0.0/patches_external/IndVarSimplify-Do-not-use-SCEV-expander-for-IVCount-.patch: -------------------------------------------------------------------------------- 1 | From a64f085d0f1ce0725d2ca896e32ad213515658a0 Mon Sep 17 00:00:00 2001 2 | From: Aleksander Us 3 | Date: Mon, 26 Aug 2019 15:45:47 +0300 4 | Subject: [PATCH] [IndVarSimplify] Do not use SCEV expander for IVCount in 5 | LFTR when possible. 6 | 7 | SCEV analysis cannot properly cache instruction with poison flags 8 | (for example, add nsw outside of loop will not be reused by expander). 9 | This can lead to generating of additional instructions by SCEV expander. 10 | 11 | Example IR: 12 | 13 | ... 14 | %maxval = add nuw nsw i32 %a1, %a2 15 | ... 16 | for.body: 17 | ... 18 | %cmp22 = icmp ult i32 %ivadd, %maxval 19 | br i1 %cmp22, label %for.body, label %for.end 20 | ... 21 | 22 | SCEV expander will generate copy of %maxval in preheader but without 23 | nuw/nsw flags. This can be avoided by explicit check that iv count 24 | value gives the same SCEV expressions as calculated by LFTR. 25 | --- 26 | lib/Transforms/Scalar/IndVarSimplify.cpp | 13 ++++++++++++- 27 | test/Transforms/IndVarSimplify/add_nsw.ll | 23 +++++++++++++++++++++++ 28 | test/Transforms/IndVarSimplify/udiv.ll | 1 + 29 | 3 files changed, 36 insertions(+), 1 deletion(-) 30 | create mode 100644 test/Transforms/IndVarSimplify/add_nsw.ll 31 | 32 | diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp 33 | index 48d8e457ba7..4c7b6b4bbf4 100644 34 | --- a/lib/Transforms/Scalar/IndVarSimplify.cpp 35 | +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp 36 | @@ -2318,8 +2318,19 @@ static Value *genLoopLimit(PHINode *IndVar, const SCEV *IVCount, Loop *L, 37 | 38 | IVLimit = SE->getAddExpr(IVInit, IVCount); 39 | } 40 | - // Expand the code for the iteration count. 41 | + 42 | + // If computed limit is equal to old limit then do not use SCEV expander 43 | + // because it can lost NUW/NSW flags and create extra instructions. 44 | BranchInst *BI = cast(L->getExitingBlock()->getTerminator()); 45 | + if (ICmpInst *Cmp = dyn_cast(BI->getOperand(0))) { 46 | + Value *Limit = Cmp->getOperand(0); 47 | + if (!L->isLoopInvariant(Limit)) 48 | + Limit = Cmp->getOperand(1); 49 | + if (SE->getSCEV(Limit) == IVLimit) 50 | + return Limit; 51 | + } 52 | + 53 | + // Expand the code for the iteration count. 54 | IRBuilder<> Builder(BI); 55 | assert(SE->isLoopInvariant(IVLimit, L) && 56 | "Computed iteration count is not loop invariant!"); 57 | diff --git a/test/Transforms/IndVarSimplify/add_nsw.ll b/test/Transforms/IndVarSimplify/add_nsw.ll 58 | new file mode 100644 59 | index 00000000000..abd1cbb6c51 60 | --- /dev/null 61 | +++ b/test/Transforms/IndVarSimplify/add_nsw.ll 62 | @@ -0,0 +1,23 @@ 63 | +; RUN: opt -indvars -S %s | FileCheck %s 64 | + 65 | +target datalayout = "e-p:32:32-i64:64-n8:16:32" 66 | + 67 | +; CHECK: for.body.preheader: 68 | +; CHECK-NOT: add 69 | +; CHECK: for.body: 70 | + 71 | +define void @foo(i32 %a1, i32 %a2) { 72 | +entry: 73 | + %maxval = add nuw nsw i32 %a1, %a2 74 | + %cmp = icmp slt i32 %maxval, 1 75 | + br i1 %cmp, label %for.end, label %for.body 76 | + 77 | +for.body: ; preds = %entry, %for.body 78 | + %j.02 = phi i32 [ 0, %entry ], [ %add31, %for.body ] 79 | + %add31 = add nuw nsw i32 %j.02, 1 80 | + %cmp22 = icmp slt i32 %add31, %maxval 81 | + br i1 %cmp22, label %for.body, label %for.end 82 | + 83 | +for.end: ; preds = %for.body 84 | + ret void 85 | +} 86 | diff --git a/test/Transforms/IndVarSimplify/udiv.ll b/test/Transforms/IndVarSimplify/udiv.ll 87 | index b3f2c2a6a66..3530343ef4a 100644 88 | --- a/test/Transforms/IndVarSimplify/udiv.ll 89 | +++ b/test/Transforms/IndVarSimplify/udiv.ll 90 | @@ -133,6 +133,7 @@ declare i32 @printf(i8* nocapture, ...) nounwind 91 | ; CHECK-LABEL: @foo( 92 | ; CHECK: for.body.preheader: 93 | ; CHECK-NOT: udiv 94 | +; CHECK: for.body: 95 | 96 | define void @foo(double* %p, i64 %n) nounwind { 97 | entry: 98 | -- 99 | 2.18.0 100 | 101 | -------------------------------------------------------------------------------- /releases/8.0.0/patches_external/Use-depth-limit-for-trunc-analysis.patch: -------------------------------------------------------------------------------- 1 | From 9ad02e3f95d0f98a800966b2df1f5d9eaf5ff038 Mon Sep 17 00:00:00 2001 2 | From: Teresa Johnson 3 | Date: Tue, 12 Mar 2019 18:28:05 +0000 4 | Subject: [PATCH] Use depth limit for trunc analysis 5 | 6 | Summary: 7 | This fixes an extremely long compile time caused by recursive analysis 8 | of truncs, which were not previously subject to any depth limits unlike 9 | some of the other ops. I decided to use the same control used for 10 | sext/zext, since the routines analyzing these are sometimes mutually 11 | recursive with the trunc analysis. 12 | 13 | Reviewers: mkazantsev, sanjoy 14 | 15 | Subscribers: sanjoy, jdoerfert, llvm-commits 16 | 17 | Tags: #llvm 18 | 19 | Differential Revision: https://reviews.llvm.org/D58994 20 | 21 | llvm-svn: 355949 22 | --- 23 | llvm/include/llvm/Analysis/ScalarEvolution.h | 8 ++- 24 | llvm/lib/Analysis/ScalarEvolution.cpp | 65 ++++++++++--------- 25 | .../Analysis/ScalarEvolution/limit-depth.ll | 30 ++++++++- 26 | 3 files changed, 70 insertions(+), 33 deletions(-) 27 | 28 | diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h 29 | index 8f4200b07e5..044c369bba2 100644 30 | --- a/include/llvm/Analysis/ScalarEvolution.h 31 | +++ b/include/llvm/Analysis/ScalarEvolution.h 32 | @@ -521,7 +521,7 @@ public: 33 | const SCEV *getConstant(ConstantInt *V); 34 | const SCEV *getConstant(const APInt &Val); 35 | const SCEV *getConstant(Type *Ty, uint64_t V, bool isSigned = false); 36 | - const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty); 37 | + const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0); 38 | const SCEV *getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0); 39 | const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0); 40 | const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty); 41 | @@ -619,11 +619,13 @@ public: 42 | 43 | /// Return a SCEV corresponding to a conversion of the input value to the 44 | /// specified type. If the type must be extended, it is zero extended. 45 | - const SCEV *getTruncateOrZeroExtend(const SCEV *V, Type *Ty); 46 | + const SCEV *getTruncateOrZeroExtend(const SCEV *V, Type *Ty, 47 | + unsigned Depth = 0); 48 | 49 | /// Return a SCEV corresponding to a conversion of the input value to the 50 | /// specified type. If the type must be extended, it is sign extended. 51 | - const SCEV *getTruncateOrSignExtend(const SCEV *V, Type *Ty); 52 | + const SCEV *getTruncateOrSignExtend(const SCEV *V, Type *Ty, 53 | + unsigned Depth = 0); 54 | 55 | /// Return a SCEV corresponding to a conversion of the input value to the 56 | /// specified type. If the type must be extended, it is zero extended. The 57 | diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp 58 | index e5134f2eeda..21ec498339d 100644 59 | --- a/lib/Analysis/ScalarEvolution.cpp 60 | +++ b/lib/Analysis/ScalarEvolution.cpp 61 | @@ -203,9 +203,9 @@ static cl::opt MaxConstantEvolvingDepth( 62 | cl::desc("Maximum depth of recursive constant evolving"), cl::init(32)); 63 | 64 | static cl::opt 65 | - MaxExtDepth("scalar-evolution-max-ext-depth", cl::Hidden, 66 | - cl::desc("Maximum depth of recursive SExt/ZExt"), 67 | - cl::init(8)); 68 | + MaxCastDepth("scalar-evolution-max-cast-depth", cl::Hidden, 69 | + cl::desc("Maximum depth of recursive SExt/ZExt/Trunc"), 70 | + cl::init(8)); 71 | 72 | static cl::opt 73 | MaxAddRecSize("scalar-evolution-max-add-rec-size", cl::Hidden, 74 | @@ -1219,8 +1219,8 @@ const SCEV *SCEVAddRecExpr::evaluateAtIteration(const SCEV *It, 75 | // SCEV Expression folder implementations 76 | //===----------------------------------------------------------------------===// 77 | 78 | -const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, 79 | - Type *Ty) { 80 | +const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, Type *Ty, 81 | + unsigned Depth) { 82 | assert(getTypeSizeInBits(Op->getType()) > getTypeSizeInBits(Ty) && 83 | "This is not a truncating conversion!"); 84 | assert(isSCEVable(Ty) && 85 | @@ -1241,15 +1241,23 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, 86 | 87 | // trunc(trunc(x)) --> trunc(x) 88 | if (const SCEVTruncateExpr *ST = dyn_cast(Op)) 89 | - return getTruncateExpr(ST->getOperand(), Ty); 90 | + return getTruncateExpr(ST->getOperand(), Ty, Depth + 1); 91 | 92 | // trunc(sext(x)) --> sext(x) if widening or trunc(x) if narrowing 93 | if (const SCEVSignExtendExpr *SS = dyn_cast(Op)) 94 | - return getTruncateOrSignExtend(SS->getOperand(), Ty); 95 | + return getTruncateOrSignExtend(SS->getOperand(), Ty, Depth + 1); 96 | 97 | // trunc(zext(x)) --> zext(x) if widening or trunc(x) if narrowing 98 | if (const SCEVZeroExtendExpr *SZ = dyn_cast(Op)) 99 | - return getTruncateOrZeroExtend(SZ->getOperand(), Ty); 100 | + return getTruncateOrZeroExtend(SZ->getOperand(), Ty, Depth + 1); 101 | + 102 | + if (Depth > MaxCastDepth) { 103 | + SCEV *S = 104 | + new (SCEVAllocator) SCEVTruncateExpr(ID.Intern(SCEVAllocator), Op, Ty); 105 | + UniqueSCEVs.InsertNode(S, IP); 106 | + addToLoopUseLists(S); 107 | + return S; 108 | + } 109 | 110 | // trunc(x1 + ... + xN) --> trunc(x1) + ... + trunc(xN) and 111 | // trunc(x1 * ... * xN) --> trunc(x1) * ... * trunc(xN), 112 | @@ -1261,7 +1269,7 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, 113 | unsigned numTruncs = 0; 114 | for (unsigned i = 0, e = CommOp->getNumOperands(); i != e && numTruncs < 2; 115 | ++i) { 116 | - const SCEV *S = getTruncateExpr(CommOp->getOperand(i), Ty); 117 | + const SCEV *S = getTruncateExpr(CommOp->getOperand(i), Ty, Depth + 1); 118 | if (!isa(CommOp->getOperand(i)) && isa(S)) 119 | numTruncs++; 120 | Operands.push_back(S); 121 | @@ -1285,7 +1293,7 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, 122 | if (const SCEVAddRecExpr *AddRec = dyn_cast(Op)) { 123 | SmallVector Operands; 124 | for (const SCEV *Op : AddRec->operands()) 125 | - Operands.push_back(getTruncateExpr(Op, Ty)); 126 | + Operands.push_back(getTruncateExpr(Op, Ty, Depth + 1)); 127 | return getAddRecExpr(Operands, AddRec->getLoop(), SCEV::FlagAnyWrap); 128 | } 129 | 130 | @@ -1619,7 +1627,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 131 | ID.AddPointer(Ty); 132 | void *IP = nullptr; 133 | if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP)) return S; 134 | - if (Depth > MaxExtDepth) { 135 | + if (Depth > MaxCastDepth) { 136 | SCEV *S = new (SCEVAllocator) SCEVZeroExtendExpr(ID.Intern(SCEVAllocator), 137 | Op, Ty); 138 | UniqueSCEVs.InsertNode(S, IP); 139 | @@ -1637,7 +1645,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 140 | unsigned NewBits = getTypeSizeInBits(Ty); 141 | if (CR.truncate(TruncBits).zeroExtend(NewBits).contains( 142 | CR.zextOrTrunc(NewBits))) 143 | - return getTruncateOrZeroExtend(X, Ty); 144 | + return getTruncateOrZeroExtend(X, Ty, Depth); 145 | } 146 | 147 | // If the input value is a chrec scev, and we can prove that the value 148 | @@ -1679,9 +1687,9 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 149 | // Check whether the backedge-taken count can be losslessly casted to 150 | // the addrec's type. The count is always unsigned. 151 | const SCEV *CastedMaxBECount = 152 | - getTruncateOrZeroExtend(MaxBECount, Start->getType()); 153 | - const SCEV *RecastedMaxBECount = 154 | - getTruncateOrZeroExtend(CastedMaxBECount, MaxBECount->getType()); 155 | + getTruncateOrZeroExtend(MaxBECount, Start->getType(), Depth); 156 | + const SCEV *RecastedMaxBECount = getTruncateOrZeroExtend( 157 | + CastedMaxBECount, MaxBECount->getType(), Depth); 158 | if (MaxBECount == RecastedMaxBECount) { 159 | Type *WideTy = IntegerType::get(getContext(), BitWidth * 2); 160 | // Check whether Start+Step*MaxBECount has no unsigned overflow. 161 | @@ -1930,7 +1938,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 162 | void *IP = nullptr; 163 | if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP)) return S; 164 | // Limit recursion depth. 165 | - if (Depth > MaxExtDepth) { 166 | + if (Depth > MaxCastDepth) { 167 | SCEV *S = new (SCEVAllocator) SCEVSignExtendExpr(ID.Intern(SCEVAllocator), 168 | Op, Ty); 169 | UniqueSCEVs.InsertNode(S, IP); 170 | @@ -1948,7 +1956,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 171 | unsigned NewBits = getTypeSizeInBits(Ty); 172 | if (CR.truncate(TruncBits).signExtend(NewBits).contains( 173 | CR.sextOrTrunc(NewBits))) 174 | - return getTruncateOrSignExtend(X, Ty); 175 | + return getTruncateOrSignExtend(X, Ty, Depth); 176 | } 177 | 178 | if (auto *SA = dyn_cast(Op)) { 179 | @@ -2023,9 +2031,9 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) { 180 | // Check whether the backedge-taken count can be losslessly casted to 181 | // the addrec's type. The count is always unsigned. 182 | const SCEV *CastedMaxBECount = 183 | - getTruncateOrZeroExtend(MaxBECount, Start->getType()); 184 | - const SCEV *RecastedMaxBECount = 185 | - getTruncateOrZeroExtend(CastedMaxBECount, MaxBECount->getType()); 186 | + getTruncateOrZeroExtend(MaxBECount, Start->getType(), Depth); 187 | + const SCEV *RecastedMaxBECount = getTruncateOrZeroExtend( 188 | + CastedMaxBECount, MaxBECount->getType(), Depth); 189 | if (MaxBECount == RecastedMaxBECount) { 190 | Type *WideTy = IntegerType::get(getContext(), BitWidth * 2); 191 | // Check whether Start+Step*MaxBECount has no signed overflow. 192 | @@ -4022,29 +4030,28 @@ const SCEV *ScalarEvolution::getMinusSCEV(const SCEV *LHS, const SCEV *RHS, 193 | return getAddExpr(LHS, getNegativeSCEV(RHS, NegFlags), AddFlags, Depth); 194 | } 195 | 196 | -const SCEV * 197 | -ScalarEvolution::getTruncateOrZeroExtend(const SCEV *V, Type *Ty) { 198 | +const SCEV *ScalarEvolution::getTruncateOrZeroExtend(const SCEV *V, Type *Ty, 199 | + unsigned Depth) { 200 | Type *SrcTy = V->getType(); 201 | assert(SrcTy->isIntOrPtrTy() && Ty->isIntOrPtrTy() && 202 | "Cannot truncate or zero extend with non-integer arguments!"); 203 | if (getTypeSizeInBits(SrcTy) == getTypeSizeInBits(Ty)) 204 | return V; // No conversion 205 | if (getTypeSizeInBits(SrcTy) > getTypeSizeInBits(Ty)) 206 | - return getTruncateExpr(V, Ty); 207 | - return getZeroExtendExpr(V, Ty); 208 | + return getTruncateExpr(V, Ty, Depth); 209 | + return getZeroExtendExpr(V, Ty, Depth); 210 | } 211 | 212 | -const SCEV * 213 | -ScalarEvolution::getTruncateOrSignExtend(const SCEV *V, 214 | - Type *Ty) { 215 | +const SCEV *ScalarEvolution::getTruncateOrSignExtend(const SCEV *V, Type *Ty, 216 | + unsigned Depth) { 217 | Type *SrcTy = V->getType(); 218 | assert(SrcTy->isIntOrPtrTy() && Ty->isIntOrPtrTy() && 219 | "Cannot truncate or zero extend with non-integer arguments!"); 220 | if (getTypeSizeInBits(SrcTy) == getTypeSizeInBits(Ty)) 221 | return V; // No conversion 222 | if (getTypeSizeInBits(SrcTy) > getTypeSizeInBits(Ty)) 223 | - return getTruncateExpr(V, Ty); 224 | - return getSignExtendExpr(V, Ty); 225 | + return getTruncateExpr(V, Ty, Depth); 226 | + return getSignExtendExpr(V, Ty, Depth); 227 | } 228 | 229 | const SCEV * 230 | diff --git a/test/Analysis/ScalarEvolution/limit-depth.ll b/test/Analysis/ScalarEvolution/limit-depth.ll 231 | index f4154130233..6fdf8c5df97 100644 232 | --- a/test/Analysis/ScalarEvolution/limit-depth.ll 233 | +++ b/test/Analysis/ScalarEvolution/limit-depth.ll 234 | @@ -1,4 +1,4 @@ 235 | -; RUN: opt -scalar-evolution-max-arith-depth=0 -scalar-evolution-max-ext-depth=0 -analyze -scalar-evolution < %s | FileCheck %s 236 | +; RUN: opt -scalar-evolution-max-arith-depth=0 -scalar-evolution-max-cast-depth=0 -analyze -scalar-evolution < %s | FileCheck %s 237 | 238 | ; Check that depth set to 0 prevents getAddExpr and getMulExpr from making 239 | ; transformations in SCEV. We expect the result to be very straightforward. 240 | @@ -98,3 +98,31 @@ exit: 241 | %ze2 = zext i64 %iv2.inc to i128 242 | ret void 243 | } 244 | + 245 | +define void @test_trunc(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) { 246 | +; CHECK-LABEL: @test_trunc 247 | +; CHECK: %trunc2 = trunc i64 %iv2.inc to i32 248 | +; CHECK-NEXT: --> {(trunc i64 (1 + {7,+,1}<%loop>) to i32),+,1}<%loop2> 249 | +entry: 250 | + br label %loop 251 | + 252 | +loop: 253 | + %iv = phi i128 [ 6, %entry ], [ %iv.inc, %loop ] 254 | + %iv.inc = add nsw i128 %iv, 1 255 | + %cond = icmp sle i128 %iv.inc, 50 256 | + br i1 %cond, label %loop, label %between 257 | + 258 | +between: 259 | + %trunc = trunc i128 %iv.inc to i64 260 | + br label %loop2 261 | + 262 | +loop2: 263 | + %iv2 = phi i64 [ %trunc, %between ], [ %iv2.inc, %loop2 ] 264 | + %iv2.inc = add nuw i64 %iv2, 1 265 | + %cond2 = icmp sle i64 %iv2.inc, 50 266 | + br i1 %cond2, label %loop2, label %exit 267 | + 268 | +exit: 269 | + %trunc2 = trunc i64 %iv2.inc to i32 270 | + ret void 271 | +} 272 | -- 273 | 2.18.0 274 | 275 | -------------------------------------------------------------------------------- /releases/8.0.0/patches_external/add_win_crt_info.patch: -------------------------------------------------------------------------------- 1 | # Description : Add possibility to use ChooseMSVCCRT-script, when 2 | # include LLVM library. 3 | 4 | --- a/cmake/modules/LLVMConfig.cmake.in 5 | +++ b/cmake/modules/LLVMConfig.cmake.in 6 | @@ -10,6 +10,11 @@ set(LLVM_PACKAGE_VERSION @PACKAGE_VERSION@) 7 | 8 | set(LLVM_BUILD_TYPE @CMAKE_BUILD_TYPE@) 9 | 10 | +set(LLVM_USE_CRT_DEBUG @LLVM_USE_CRT_DEBUG@) 11 | +set(LLVM_USE_CRT_MINSIZEREL @LLVM_USE_CRT_MINSIZEREL@) 12 | +set(LLVM_USE_CRT_RELEASE @LLVM_USE_CRT_RELEASE@) 13 | +set(LLVM_USE_CRT_RELWITHDEBINFO @LLVM_USE_CRT_RELWITHDEBINFO@) 14 | + 15 | set(LLVM_COMMON_DEPENDS @LLVM_COMMON_DEPENDS@) 16 | 17 | set(LLVM_AVAILABLE_LIBS @LLVM_AVAILABLE_LIBS@) 18 | -------------------------------------------------------------------------------- /releases/8.0.0/patches_external/export-utility-to-targets-build-install.patch: -------------------------------------------------------------------------------- 1 | From 4ce5f86eddc0bf42a971db4509829036d5b17b92 Mon Sep 17 00:00:00 2001 2 | From: Stefan Granitz 3 | Date: Fri, 1 Feb 2019 13:08:09 +0000 4 | Subject: [PATCH] [CMake] Add install targets for utilities to LLVM exports if 5 | LLVM_INSTALL_UTILS=ON 6 | 7 | Summary: D56606 was only appending target names to the `LLVM_EXPORTS`/`LLVM_EXPORTS_BUILDTREE_ONLY` properties. Targets showed up correctly in the build-tree `LLVMExports.cmake`, but they were missing in the installed one (as we found in https://bugs.llvm.org/show_bug.cgi?id=40443), because install did not register them explicitly. 8 | 9 | Reviewers: mgorny, smeenai, beanz, gottesmm, dschuff, tstellar, serge-sans-paille 10 | 11 | Reviewed By: smeenai 12 | 13 | Subscribers: llvm-commits 14 | 15 | Differential Revision: https://reviews.llvm.org/D57383 16 | 17 | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352869 91177308-0d34-0410-b5e6-96231b3b80d8 18 | --- 19 | cmake/modules/AddLLVM.cmake | 32 +++++++++++++++++++++----------- 20 | 1 file changed, 21 insertions(+), 11 deletions(-) 21 | 22 | diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake 23 | index 39781bf34e24..607d6e682b49 100644 24 | --- a/cmake/modules/AddLLVM.cmake 25 | +++ b/cmake/modules/AddLLVM.cmake 26 | @@ -911,18 +911,28 @@ macro(add_llvm_utility name) 27 | 28 | add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN}) 29 | set_target_properties(${name} PROPERTIES FOLDER "Utils") 30 | - if( LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS ) 31 | - install (TARGETS ${name} 32 | - RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR} 33 | - COMPONENT ${name}) 34 | - if (NOT LLVM_ENABLE_IDE) 35 | - add_llvm_install_targets(install-${name} 36 | - DEPENDS ${name} 37 | - COMPONENT ${name}) 38 | + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) 39 | + if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) 40 | + if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR 41 | + NOT LLVM_DISTRIBUTION_COMPONENTS) 42 | + set(export_to_llvmexports EXPORT LLVMExports) 43 | + set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True) 44 | + endif() 45 | + 46 | + install(TARGETS ${name} 47 | + ${export_to_llvmexports} 48 | + RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR} 49 | + COMPONENT ${name}) 50 | + 51 | + if (NOT LLVM_ENABLE_IDE) 52 | + add_llvm_install_targets(install-${name} 53 | + DEPENDS ${name} 54 | + COMPONENT ${name}) 55 | + endif() 56 | + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) 57 | + elseif(LLVM_BUILD_UTILS) 58 | + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name}) 59 | endif() 60 | - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) 61 | - elseif( LLVM_BUILD_UTILS ) 62 | - set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name}) 63 | endif() 64 | endmacro(add_llvm_utility name) 65 | 66 | -------------------------------------------------------------------------------- /releases/8.0.0/patches_external/fix_for_typo_regex.patch: -------------------------------------------------------------------------------- 1 | --- a/tools/llvm-config/CMakeLists.txt 2 | +++ b/tools/llvm-config/CMakeLists.txt 3 | @@ -34,8 +34,8 @@ get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS) 4 | # NOTE: We don't want to start extracting any random C/CXX flags that the 5 | # user may add that could affect the ABI. We only want to extract flags 6 | # that have been added by the LLVM build system. 7 | -string(REGEX MATCH "-std=[^ ]\+" LLVM_CXX_STD_FLAG ${CMAKE_CXX_FLAGS}) 8 | -string(REGEX MATCH "-std=[^ ]\+" LLVM_C_STD_FLAG ${CMAKE_C_FLAGS}) 9 | +string(REGEX MATCH "-std=[^ ]\\+" LLVM_CXX_STD_FLAG ${CMAKE_CXX_FLAGS}) 10 | +string(REGEX MATCH "-std=[^ ]\\+" LLVM_C_STD_FLAG ${CMAKE_C_FLAGS}) 11 | 12 | # Use configure_file to create BuildVariables.inc. 13 | set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR}) 14 | -------------------------------------------------------------------------------- /releases/9.0.0/patches_external/BasicBlockUtils-Add-metadata-fixing-in-SplitBlockPre.patch: -------------------------------------------------------------------------------- 1 | From eeb816d95f0910bd246e37bb2bb3923acf0edf6b Mon Sep 17 00:00:00 2001 2 | From: Aleksander Us 3 | Date: Mon, 26 Aug 2019 15:47:41 +0300 4 | Subject: [PATCH] [BasicBlockUtils] Add metadata fixing in 5 | SplitBlockPredecessors. 6 | 7 | In case when BB is header of some loop and predecessor is latch of 8 | this loop, metadata was not attached to newly created basic block. 9 | This led to loss of loop metadata for other passes. 10 | --- 11 | lib/Transforms/Utils/BasicBlockUtils.cpp | 23 ++++++++---- 12 | test/Transforms/LoopSimplify/loop_metadata.ll | 36 +++++++++++++++++++ 13 | 2 files changed, 52 insertions(+), 7 deletions(-) 14 | create mode 100644 test/Transforms/LoopSimplify/loop_metadata.ll 15 | 16 | diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp 17 | index 5fa371377c8..3a90ae061fb 100644 18 | --- a/lib/Transforms/Utils/BasicBlockUtils.cpp 19 | +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp 20 | @@ -579,24 +579,33 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, 21 | 22 | // The new block unconditionally branches to the old block. 23 | BranchInst *BI = BranchInst::Create(BB, NewBB); 24 | + bool IsBBHeader = LI && LI->isLoopHeader(BB); 25 | + Loop *BBLoop = LI ? LI->getLoopFor(BB) : nullptr; 26 | // Splitting the predecessors of a loop header creates a preheader block. 27 | - if (LI && LI->isLoopHeader(BB)) 28 | + if (IsBBHeader) 29 | // Using the loop start line number prevents debuggers stepping into the 30 | // loop body for this instruction. 31 | - BI->setDebugLoc(LI->getLoopFor(BB)->getStartLoc()); 32 | + BI->setDebugLoc(BBLoop->getStartLoc()); 33 | else 34 | BI->setDebugLoc(BB->getFirstNonPHIOrDbg()->getDebugLoc()); 35 | 36 | // Move the edges from Preds to point to NewBB instead of BB. 37 | - for (unsigned i = 0, e = Preds.size(); i != e; ++i) { 38 | + for (BasicBlock *Pred : Preds) { 39 | + Instruction *PI = Pred->getTerminator(); 40 | // This is slightly more strict than necessary; the minimum requirement 41 | // is that there be no more than one indirectbr branching to BB. And 42 | // all BlockAddress uses would need to be updated. 43 | - assert(!isa(Preds[i]->getTerminator()) && 44 | + assert(!isa(PI) && 45 | "Cannot split an edge from an IndirectBrInst"); 46 | - assert(!isa(Preds[i]->getTerminator()) && 47 | - "Cannot split an edge from a CallBrInst"); 48 | - Preds[i]->getTerminator()->replaceUsesOfWith(BB, NewBB); 49 | + assert(!isa(PI) && "Cannot split an edge from a CallBrInst"); 50 | + if (IsBBHeader && BBLoop->contains(Pred) && BBLoop->isLoopLatch(Pred)) { 51 | + // Update loop metadata if it exists. 52 | + if (MDNode *LoopMD = PI->getMetadata(LLVMContext::MD_loop)) { 53 | + BI->setMetadata(LLVMContext::MD_loop, LoopMD); 54 | + PI->setMetadata(LLVMContext::MD_loop, nullptr); 55 | + } 56 | + } 57 | + PI->replaceUsesOfWith(BB, NewBB); 58 | } 59 | 60 | // Insert a new PHI node into NewBB for every PHI node in BB and that new PHI 61 | diff --git a/test/Transforms/LoopSimplify/loop_metadata.ll b/test/Transforms/LoopSimplify/loop_metadata.ll 62 | new file mode 100644 63 | index 00000000000..c15c92fe3ae 64 | --- /dev/null 65 | +++ b/test/Transforms/LoopSimplify/loop_metadata.ll 66 | @@ -0,0 +1,36 @@ 67 | +; RUN: opt -S -loop-simplify < %s | FileCheck %s 68 | + 69 | +; CHECK: for.cond.loopexit: 70 | +; CHECK: br label %for.cond, !llvm.loop !0 71 | +; CHECK: br i1 %cmp1, label %for.body1, label %for.cond.loopexit 72 | + 73 | +define void @foo() { 74 | +entry: 75 | + br label %for.cond 76 | + 77 | +for.cond: ; preds = %for.cond1, %entry 78 | + %j = phi i32 [ 0, %entry ], [ %add, %for.cond1 ] 79 | + %cmp = icmp ult i32 %j, 8 80 | + br i1 %cmp, label %for.body, label %for.end 81 | + 82 | +for.body: ; preds = %for.cond 83 | + %dummy1 = add i32 1, 1 84 | + %add = add nuw nsw i32 %j, 1 85 | + br label %for.cond1 86 | + 87 | +for.cond1: ; preds = %for.body1, %for.body 88 | + %i.0 = phi i32 [ 1, %for.body ], [ %inc, %for.body1 ] 89 | + %cmp1 = icmp ult i32 %i.0, 8 90 | + br i1 %cmp1, label %for.body1, label %for.cond, !llvm.loop !0 91 | + 92 | +for.body1: ; preds = %for.cond1 93 | + %dummy2 = add i32 1, 1 94 | + %inc = add nuw nsw i32 %i.0, 1 95 | + br label %for.cond1 96 | + 97 | +for.end: ; preds = %for.cond 98 | + ret void 99 | +} 100 | + 101 | +!0 = distinct !{!0, !1} 102 | +!1 = !{!"llvm.loop.unroll.full"} 103 | -- 104 | 2.18.0 105 | 106 | -------------------------------------------------------------------------------- /releases/9.0.0/patches_external/IndVarSimplify-Do-not-use-SCEV-expander-for-IVCount-.patch: -------------------------------------------------------------------------------- 1 | From 35e218a886f4c066eabd18685240d55270bd5a6d Mon Sep 17 00:00:00 2001 2 | From: Aleksander Us 3 | Date: Mon, 26 Aug 2019 15:45:47 +0300 4 | Subject: [PATCH] [IndVarSimplify] Do not use SCEV expander for IVCount in 5 | LFTR when possible. 6 | 7 | SCEV analysis cannot properly cache instruction with poison flags 8 | (for example, add nsw outside of loop will not be reused by expander). 9 | This can lead to generating of additional instructions by SCEV expander. 10 | 11 | Example IR: 12 | 13 | ... 14 | %maxval = add nuw nsw i32 %a1, %a2 15 | ... 16 | for.body: 17 | ... 18 | %cmp22 = icmp ult i32 %ivadd, %maxval 19 | br i1 %cmp22, label %for.body, label %for.end 20 | ... 21 | 22 | SCEV expander will generate copy of %maxval in preheader but without 23 | nuw/nsw flags. This can be avoided by explicit check that iv count 24 | value gives the same SCEV expressions as calculated by LFTR. 25 | --- 26 | lib/Transforms/Scalar/IndVarSimplify.cpp | 12 +++++++++- 27 | test/Transforms/IndVarSimplify/add_nsw.ll | 23 ++++++++++++++++++++ 28 | test/Transforms/IndVarSimplify/lftr-reuse.ll | 9 +++----- 29 | test/Transforms/IndVarSimplify/udiv.ll | 1 + 30 | 4 files changed, 38 insertions(+), 7 deletions(-) 31 | create mode 100644 test/Transforms/IndVarSimplify/add_nsw.ll 32 | 33 | diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp 34 | index f9fc698a4a9..5e04dac8aa6 100644 35 | --- a/lib/Transforms/Scalar/IndVarSimplify.cpp 36 | +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp 37 | @@ -2375,6 +2375,17 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB, 38 | if (UsePostInc) 39 | IVLimit = SE->getAddExpr(IVLimit, SE->getOne(IVLimit->getType())); 40 | 41 | + // If computed limit is equal to old limit then do not use SCEV expander 42 | + // because it can lost NUW/NSW flags and create extra instructions. 43 | + BranchInst *BI = cast(ExitingBB->getTerminator()); 44 | + if (ICmpInst *Cmp = dyn_cast(BI->getOperand(0))) { 45 | + Value *Limit = Cmp->getOperand(0); 46 | + if (!L->isLoopInvariant(Limit)) 47 | + Limit = Cmp->getOperand(1); 48 | + if (SE->getSCEV(Limit) == IVLimit) 49 | + return Limit; 50 | + } 51 | + 52 | // Expand the code for the iteration count. 53 | assert(SE->isLoopInvariant(IVLimit, L) && 54 | "Computed iteration count is not loop invariant!"); 55 | @@ -2383,7 +2394,6 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB, 56 | // SCEV expression (IVInit) for a pointer type IV value (IndVar). 57 | Type *LimitTy = ExitCount->getType()->isPointerTy() ? 58 | IndVar->getType() : ExitCount->getType(); 59 | - BranchInst *BI = cast(ExitingBB->getTerminator()); 60 | return Rewriter.expandCodeFor(IVLimit, LimitTy, BI); 61 | } 62 | } 63 | diff --git a/test/Transforms/IndVarSimplify/add_nsw.ll b/test/Transforms/IndVarSimplify/add_nsw.ll 64 | new file mode 100644 65 | index 00000000000..abd1cbb6c51 66 | --- /dev/null 67 | +++ b/test/Transforms/IndVarSimplify/add_nsw.ll 68 | @@ -0,0 +1,23 @@ 69 | +; RUN: opt -indvars -S %s | FileCheck %s 70 | + 71 | +target datalayout = "e-p:32:32-i64:64-n8:16:32" 72 | + 73 | +; CHECK: for.body.preheader: 74 | +; CHECK-NOT: add 75 | +; CHECK: for.body: 76 | + 77 | +define void @foo(i32 %a1, i32 %a2) { 78 | +entry: 79 | + %maxval = add nuw nsw i32 %a1, %a2 80 | + %cmp = icmp slt i32 %maxval, 1 81 | + br i1 %cmp, label %for.end, label %for.body 82 | + 83 | +for.body: ; preds = %entry, %for.body 84 | + %j.02 = phi i32 [ 0, %entry ], [ %add31, %for.body ] 85 | + %add31 = add nuw nsw i32 %j.02, 1 86 | + %cmp22 = icmp slt i32 %add31, %maxval 87 | + br i1 %cmp22, label %for.body, label %for.end 88 | + 89 | +for.end: ; preds = %for.body 90 | + ret void 91 | +} 92 | diff --git a/test/Transforms/IndVarSimplify/lftr-reuse.ll b/test/Transforms/IndVarSimplify/lftr-reuse.ll 93 | index 14ae9738696..509d662b767 100644 94 | --- a/test/Transforms/IndVarSimplify/lftr-reuse.ll 95 | +++ b/test/Transforms/IndVarSimplify/lftr-reuse.ll 96 | @@ -67,11 +67,9 @@ define void @expandOuterRecurrence(i32 %arg) nounwind { 97 | ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 0, [[SUB1]] 98 | ; CHECK-NEXT: br i1 [[CMP1]], label [[OUTER_PREHEADER:%.*]], label [[EXIT:%.*]] 99 | ; CHECK: outer.preheader: 100 | -; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[ARG]], -1 101 | ; CHECK-NEXT: br label [[OUTER:%.*]] 102 | ; CHECK: outer: 103 | -; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[TMP0]], [[OUTER_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[OUTER_INC:%.*]] ] 104 | -; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_INC:%.*]], [[OUTER_INC]] ], [ 0, [[OUTER_PREHEADER]] ] 105 | +; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_INC:%.*]], [[OUTER_INC:%.*]] ], [ 0, [[OUTER_PREHEADER]] ] 106 | ; CHECK-NEXT: [[SUB2:%.*]] = sub nsw i32 [[ARG]], [[I]] 107 | ; CHECK-NEXT: [[SUB3:%.*]] = sub nsw i32 [[SUB2]], 1 108 | ; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 0, [[SUB3]] 109 | @@ -81,14 +79,13 @@ define void @expandOuterRecurrence(i32 %arg) nounwind { 110 | ; CHECK: inner: 111 | ; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[INNER_PH]] ], [ [[J_INC:%.*]], [[INNER]] ] 112 | ; CHECK-NEXT: [[J_INC]] = add nuw nsw i32 [[J]], 1 113 | -; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[J_INC]], [[INDVARS_IV]] 114 | +; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[J_INC]], [[SUB3]] 115 | ; CHECK-NEXT: br i1 [[EXITCOND]], label [[INNER]], label [[OUTER_INC_LOOPEXIT:%.*]] 116 | ; CHECK: outer.inc.loopexit: 117 | ; CHECK-NEXT: br label [[OUTER_INC]] 118 | ; CHECK: outer.inc: 119 | ; CHECK-NEXT: [[I_INC]] = add nuw nsw i32 [[I]], 1 120 | -; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i32 [[INDVARS_IV]], -1 121 | -; CHECK-NEXT: [[EXITCOND1:%.*]] = icmp ne i32 [[I_INC]], [[TMP0]] 122 | +; CHECK-NEXT: [[EXITCOND1:%.*]] = icmp ne i32 [[I_INC]], [[SUB1]] 123 | ; CHECK-NEXT: br i1 [[EXITCOND1]], label [[OUTER]], label [[EXIT_LOOPEXIT:%.*]] 124 | ; CHECK: exit.loopexit: 125 | ; CHECK-NEXT: br label [[EXIT]] 126 | diff --git a/test/Transforms/IndVarSimplify/udiv.ll b/test/Transforms/IndVarSimplify/udiv.ll 127 | index b3f2c2a6a66..3530343ef4a 100644 128 | --- a/test/Transforms/IndVarSimplify/udiv.ll 129 | +++ b/test/Transforms/IndVarSimplify/udiv.ll 130 | @@ -133,6 +133,7 @@ declare i32 @printf(i8* nocapture, ...) nounwind 131 | ; CHECK-LABEL: @foo( 132 | ; CHECK: for.body.preheader: 133 | ; CHECK-NOT: udiv 134 | +; CHECK: for.body: 135 | 136 | define void @foo(double* %p, i64 %n) nounwind { 137 | entry: 138 | -- 139 | 2.18.0 140 | 141 | -------------------------------------------------------------------------------- /releases/9.0.0/patches_external/add_win_crt_info.patch: -------------------------------------------------------------------------------- 1 | # Description : Add possibility to use ChooseMSVCCRT-script, when 2 | # include LLVM library. 3 | 4 | --- a/cmake/modules/LLVMConfig.cmake.in 5 | +++ b/cmake/modules/LLVMConfig.cmake.in 6 | @@ -10,6 +10,11 @@ set(LLVM_PACKAGE_VERSION @PACKAGE_VERSION@) 7 | 8 | set(LLVM_BUILD_TYPE @CMAKE_BUILD_TYPE@) 9 | 10 | +set(LLVM_USE_CRT_DEBUG @LLVM_USE_CRT_DEBUG@) 11 | +set(LLVM_USE_CRT_MINSIZEREL @LLVM_USE_CRT_MINSIZEREL@) 12 | +set(LLVM_USE_CRT_RELEASE @LLVM_USE_CRT_RELEASE@) 13 | +set(LLVM_USE_CRT_RELWITHDEBINFO @LLVM_USE_CRT_RELWITHDEBINFO@) 14 | + 15 | set(LLVM_COMMON_DEPENDS @LLVM_COMMON_DEPENDS@) 16 | 17 | set(LLVM_AVAILABLE_LIBS @LLVM_AVAILABLE_LIBS@) 18 | -------------------------------------------------------------------------------- /releases/9.0.0/patches_external/disable-backtrace-on-Android.patch: -------------------------------------------------------------------------------- 1 | From c5b8f0f6cf83145bd0b35dc02ec577efe1f803d4 Mon Sep 17 00:00:00 2001 2 | From: "Lu,Yang A" 3 | Date: Fri, 13 Nov 2020 16:15:04 +0800 4 | Subject: [PATCH] disable backtrace on Android 5 | 6 | The backtrace uses execinfo.h which is not workable 7 | for Android bionic compiling, so disable it on Android. 8 | 9 | Change-Id: Ic57084906e9d836c6f2ca4fb0dbb7a1fb3d18b96 10 | Signed-off-by: Lu,Yang A 11 | --- 12 | llvm/include/llvm/Config/config.h.cmake | 3 ++- 13 | 1 file changed, 2 insertions(+), 1 deletion(-) 14 | 15 | diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake 16 | index 1a38bc15ab9..115a88be265 100644 17 | --- a/llvm/include/llvm/Config/config.h.cmake 18 | +++ b/llvm/include/llvm/Config/config.h.cmake 19 | @@ -17,9 +17,10 @@ 20 | #cmakedefine01 LLVM_ENABLE_CRASH_DUMPS 21 | 22 | /* Define to 1 if you have the `backtrace' function. */ 23 | +#if defined(__linux__) && !defined( __ANDROID__) 24 | #cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE} 25 | - 26 | #define BACKTRACE_HEADER <${BACKTRACE_HEADER}> 27 | +#endif 28 | 29 | /* Define to 1 if you have the header file. */ 30 | #cmakedefine HAVE_CRASHREPORTERCLIENT_H 31 | -- 32 | 2.17.1 33 | 34 | --------------------------------------------------------------------------------