Author: Schrodinger ZHU Yifan Date: 2025-08-05T22:05:02-04:00 New Revision: cda3c279733bc534550f757162e65794c288b981
URL: https://github.com/llvm/llvm-project/commit/cda3c279733bc534550f757162e65794c288b981 DIFF: https://github.com/llvm/llvm-project/commit/cda3c279733bc534550f757162e65794c288b981.diff LOG: Merge branch 'main' into revert-152096-revert-151622-libc-fix-integeration-alloc Added: libclc/clc/include/clc/mem_fence/clc_mem_fence.h libclc/clc/include/clc/synchronization/clc_work_group_barrier.h libclc/clc/lib/amdgcn/mem_fence/clc_mem_fence.cl libclc/clc/lib/amdgcn/synchronization/clc_work_group_barrier.cl libclc/clc/lib/ptx-nvidiacl/mem_fence/clc_mem_fence.cl libclc/clc/lib/ptx-nvidiacl/synchronization/clc_work_group_barrier.cl libclc/opencl/include/clc/opencl/synchronization/utils.h Modified: clang/lib/Sema/SemaModule.cpp libclc/clc/lib/amdgcn/SOURCES libclc/clc/lib/ptx-nvidiacl/SOURCES libclc/opencl/include/clc/opencl/synchronization/cl_mem_fence_flags.h libclc/opencl/lib/amdgcn/mem_fence/fence.cl libclc/opencl/lib/amdgcn/synchronization/barrier.cl libclc/opencl/lib/ptx-nvidiacl/mem_fence/fence.cl libclc/opencl/lib/ptx-nvidiacl/synchronization/barrier.cl llvm/cmake/modules/LLVMProcessSources.cmake llvm/include/llvm/CodeGen/TargetLowering.h llvm/include/llvm/IR/RuntimeLibcalls.td llvm/include/llvm/Support/DebugLog.h llvm/lib/Target/AArch64/AArch64ISelLowering.cpp llvm/lib/Target/AArch64/AArch64Subtarget.h llvm/lib/Target/ARM/ARMISelLowering.cpp llvm/test/CodeGen/AArch64/stacksmash-arm64ec.ll Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index b137549b8f859..ff9f85f960d93 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -1222,7 +1222,8 @@ bool ExposureChecker::isTULocal(const NamedDecl *D) { // [basic.link]p15.5 // - a specialization of a template whose (possibly instantiated) declaration // is an exposure. - if (checkExposure(PrimaryTemplate, /*Diag=*/false)) + if (ExposureSet.count(PrimaryTemplate) || + checkExposure(PrimaryTemplate, /*Diag=*/false)) return true; // Avoid calling checkExposure again since it is expensive. diff --git a/libclc/clc/include/clc/mem_fence/clc_mem_fence.h b/libclc/clc/include/clc/mem_fence/clc_mem_fence.h new file mode 100644 index 0000000000000..2321634c76842 --- /dev/null +++ b/libclc/clc/include/clc/mem_fence/clc_mem_fence.h @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef __CLC_MEM_FENCE_CLC_MEM_FENCE_H__ +#define __CLC_MEM_FENCE_CLC_MEM_FENCE_H__ + +#include <clc/internal/clc.h> + +_CLC_OVERLOAD _CLC_DECL void __clc_mem_fence(int memory_scope, + int memory_order); + +#endif // __CLC_MEM_FENCE_CLC_MEM_FENCE_H__ diff --git a/libclc/clc/include/clc/synchronization/clc_work_group_barrier.h b/libclc/clc/include/clc/synchronization/clc_work_group_barrier.h new file mode 100644 index 0000000000000..5f864e1057b8b --- /dev/null +++ b/libclc/clc/include/clc/synchronization/clc_work_group_barrier.h @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef __CLC_SYNCHRONIZATION_CLC_WORK_GROUP_BARRIER_H__ +#define __CLC_SYNCHRONIZATION_CLC_WORK_GROUP_BARRIER_H__ + +#include <clc/internal/clc.h> + +_CLC_OVERLOAD _CLC_DECL void __clc_work_group_barrier(int memory_scope, + int memory_order); + +#endif // __CLC_SYNCHRONIZATION_CLC_WORK_GROUP_BARRIER_H__ diff --git a/libclc/clc/lib/amdgcn/SOURCES b/libclc/clc/lib/amdgcn/SOURCES index d91f08533e149..76c3266e3af7b 100644 --- a/libclc/clc/lib/amdgcn/SOURCES +++ b/libclc/clc/lib/amdgcn/SOURCES @@ -1,4 +1,6 @@ math/clc_ldexp_override.cl +mem_fence/clc_mem_fence.cl +synchronization/clc_work_group_barrier.cl workitem/clc_get_global_offset.cl workitem/clc_get_global_size.cl workitem/clc_get_group_id.cl diff --git a/libclc/clc/lib/amdgcn/mem_fence/clc_mem_fence.cl b/libclc/clc/lib/amdgcn/mem_fence/clc_mem_fence.cl new file mode 100644 index 0000000000000..9e6460313718e --- /dev/null +++ b/libclc/clc/lib/amdgcn/mem_fence/clc_mem_fence.cl @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <clc/mem_fence/clc_mem_fence.h> + +void __clc_amdgcn_s_waitcnt(unsigned flags); + +// s_waitcnt takes 16bit argument with a combined number of maximum allowed +// pending operations: +// [12:8] LGKM -- LDS, GDS, Konstant (SMRD), Messages +// [7] -- undefined +// [6:4] -- exports, GDS, and mem write +// [3:0] -- vector memory operations + +// Newer clang supports __builtin_amdgcn_s_waitcnt +#if __clang_major__ >= 5 +#define __waitcnt(x) __builtin_amdgcn_s_waitcnt(x) +#else +#define __waitcnt(x) __clc_amdgcn_s_waitcnt(x) +_CLC_DEF void __clc_amdgcn_s_waitcnt(unsigned) __asm("llvm.amdgcn.s.waitcnt"); +#endif + +_CLC_OVERLOAD _CLC_DEF void __clc_mem_fence(int memory_scope, + int memory_order) { + if (memory_scope & __MEMORY_SCOPE_DEVICE) { + // scalar loads are counted with LGKM but we don't know whether + // the compiler turned any loads to scalar + __waitcnt(0); + } else if (memory_scope & __MEMORY_SCOPE_WRKGRP) + __waitcnt(0xff); // LGKM is [12:8] +} +#undef __waitcnt diff --git a/libclc/clc/lib/amdgcn/synchronization/clc_work_group_barrier.cl b/libclc/clc/lib/amdgcn/synchronization/clc_work_group_barrier.cl new file mode 100644 index 0000000000000..ff3628fa7c339 --- /dev/null +++ b/libclc/clc/lib/amdgcn/synchronization/clc_work_group_barrier.cl @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <clc/mem_fence/clc_mem_fence.h> +#include <clc/synchronization/clc_work_group_barrier.h> + +_CLC_OVERLOAD _CLC_DEF void __clc_work_group_barrier(int memory_scope, + int memory_order) { + __clc_mem_fence(memory_scope, memory_order); + __builtin_amdgcn_s_barrier(); +} diff --git a/libclc/clc/lib/ptx-nvidiacl/SOURCES b/libclc/clc/lib/ptx-nvidiacl/SOURCES index 05368c5e4d4e3..b6f50654f89c5 100644 --- a/libclc/clc/lib/ptx-nvidiacl/SOURCES +++ b/libclc/clc/lib/ptx-nvidiacl/SOURCES @@ -1,3 +1,5 @@ +mem_fence/clc_mem_fence.cl +synchronization/clc_work_group_barrier.cl workitem/clc_get_global_id.cl workitem/clc_get_group_id.cl workitem/clc_get_local_id.cl diff --git a/libclc/clc/lib/ptx-nvidiacl/mem_fence/clc_mem_fence.cl b/libclc/clc/lib/ptx-nvidiacl/mem_fence/clc_mem_fence.cl new file mode 100644 index 0000000000000..b3e2375e755a2 --- /dev/null +++ b/libclc/clc/lib/ptx-nvidiacl/mem_fence/clc_mem_fence.cl @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <clc/mem_fence/clc_mem_fence.h> + +_CLC_OVERLOAD _CLC_DEF void __clc_mem_fence(int memory_scope, + int memory_order) { + if (memory_scope & (__MEMORY_SCOPE_DEVICE | __MEMORY_SCOPE_WRKGRP)) + __nvvm_membar_cta(); +} diff --git a/libclc/clc/lib/ptx-nvidiacl/synchronization/clc_work_group_barrier.cl b/libclc/clc/lib/ptx-nvidiacl/synchronization/clc_work_group_barrier.cl new file mode 100644 index 0000000000000..6cb37a38f06ac --- /dev/null +++ b/libclc/clc/lib/ptx-nvidiacl/synchronization/clc_work_group_barrier.cl @@ -0,0 +1,14 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <clc/synchronization/clc_work_group_barrier.h> + +_CLC_OVERLOAD _CLC_DEF void __clc_work_group_barrier(int memory_scope, + int memory_order) { + __syncthreads(); +} diff --git a/libclc/opencl/include/clc/opencl/synchronization/cl_mem_fence_flags.h b/libclc/opencl/include/clc/opencl/synchronization/cl_mem_fence_flags.h index 6636515fca47d..7b2f701c1ff99 100644 --- a/libclc/opencl/include/clc/opencl/synchronization/cl_mem_fence_flags.h +++ b/libclc/opencl/include/clc/opencl/synchronization/cl_mem_fence_flags.h @@ -13,5 +13,6 @@ typedef uint cl_mem_fence_flags; #define CLK_LOCAL_MEM_FENCE 1 #define CLK_GLOBAL_MEM_FENCE 2 +#define CLK_IMAGE_MEM_FENCE 4 #endif // __CLC_OPENCL_SYNCHRONIZATION_CL_MEM_FENCE_FLAGS_H__ diff --git a/libclc/opencl/include/clc/opencl/synchronization/utils.h b/libclc/opencl/include/clc/opencl/synchronization/utils.h new file mode 100644 index 0000000000000..cf3baf28cb5f1 --- /dev/null +++ b/libclc/opencl/include/clc/opencl/synchronization/utils.h @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef __CLC_OPENCL_SYNCHRONIZATION_UTILS_H__ +#define __CLC_OPENCL_SYNCHRONIZATION_UTILS_H__ + +#include <clc/internal/clc.h> +#include <clc/opencl/synchronization/cl_mem_fence_flags.h> + +_CLC_INLINE int getCLCMemoryScope(cl_mem_fence_flags flag) { + int memory_scope = 0; + if (flag & CLK_GLOBAL_MEM_FENCE) + memory_scope |= __MEMORY_SCOPE_DEVICE; + if (flag & CLK_LOCAL_MEM_FENCE) + memory_scope |= __MEMORY_SCOPE_WRKGRP; + return memory_scope; +} + +#endif // __CLC_OPENCL_SYNCHRONIZATION_UTILS_H__ diff --git a/libclc/opencl/lib/amdgcn/mem_fence/fence.cl b/libclc/opencl/lib/amdgcn/mem_fence/fence.cl index 88b953005aae6..81216d6a26cf2 100644 --- a/libclc/opencl/lib/amdgcn/mem_fence/fence.cl +++ b/libclc/opencl/lib/amdgcn/mem_fence/fence.cl @@ -6,34 +6,15 @@ // //===----------------------------------------------------------------------===// +#include <clc/mem_fence/clc_mem_fence.h> #include <clc/opencl/explicit_fence/explicit_memory_fence.h> - -void __clc_amdgcn_s_waitcnt(unsigned flags); - -// s_waitcnt takes 16bit argument with a combined number of maximum allowed -// pending operations: -// [12:8] LGKM -- LDS, GDS, Konstant (SMRD), Messages -// [7] -- undefined -// [6:4] -- exports, GDS, and mem write -// [3:0] -- vector memory operations - -// Newer clang supports __builtin_amdgcn_s_waitcnt -#if __clang_major__ >= 5 -#define __waitcnt(x) __builtin_amdgcn_s_waitcnt(x) -#else -#define __waitcnt(x) __clc_amdgcn_s_waitcnt(x) -_CLC_DEF void __clc_amdgcn_s_waitcnt(unsigned) __asm("llvm.amdgcn.s.waitcnt"); -#endif +#include <clc/opencl/synchronization/utils.h> _CLC_DEF _CLC_OVERLOAD void mem_fence(cl_mem_fence_flags flags) { - if (flags & CLK_GLOBAL_MEM_FENCE) { - // scalar loads are counted with LGKM but we don't know whether - // the compiler turned any loads to scalar - __waitcnt(0); - } else if (flags & CLK_LOCAL_MEM_FENCE) - __waitcnt(0xff); // LGKM is [12:8] + int memory_scope = getCLCMemoryScope(flags); + int memory_order = __ATOMIC_SEQ_CST; + __clc_mem_fence(memory_scope, memory_order); } -#undef __waitcnt // We don't have separate mechanism for read and write fences _CLC_DEF _CLC_OVERLOAD void read_mem_fence(cl_mem_fence_flags flags) { diff --git a/libclc/opencl/lib/amdgcn/synchronization/barrier.cl b/libclc/opencl/lib/amdgcn/synchronization/barrier.cl index 5203db72f484c..c8322e602302c 100644 --- a/libclc/opencl/lib/amdgcn/synchronization/barrier.cl +++ b/libclc/opencl/lib/amdgcn/synchronization/barrier.cl @@ -6,10 +6,12 @@ // //===----------------------------------------------------------------------===// -#include <clc/opencl/explicit_fence/explicit_memory_fence.h> #include <clc/opencl/synchronization/barrier.h> +#include <clc/opencl/synchronization/utils.h> +#include <clc/synchronization/clc_work_group_barrier.h> _CLC_DEF _CLC_OVERLOAD void barrier(cl_mem_fence_flags flags) { - mem_fence(flags); - __builtin_amdgcn_s_barrier(); + int memory_scope = getCLCMemoryScope(flags); + int memory_order = __ATOMIC_SEQ_CST; + __clc_work_group_barrier(memory_scope, memory_order); } diff --git a/libclc/opencl/lib/ptx-nvidiacl/mem_fence/fence.cl b/libclc/opencl/lib/ptx-nvidiacl/mem_fence/fence.cl index d24569ecda1bc..e22ed870a7e6b 100644 --- a/libclc/opencl/lib/ptx-nvidiacl/mem_fence/fence.cl +++ b/libclc/opencl/lib/ptx-nvidiacl/mem_fence/fence.cl @@ -6,11 +6,14 @@ // //===----------------------------------------------------------------------===// +#include <clc/mem_fence/clc_mem_fence.h> #include <clc/opencl/explicit_fence/explicit_memory_fence.h> +#include <clc/opencl/synchronization/utils.h> _CLC_DEF _CLC_OVERLOAD void mem_fence(cl_mem_fence_flags flags) { - if (flags & (CLK_GLOBAL_MEM_FENCE | CLK_LOCAL_MEM_FENCE)) - __nvvm_membar_cta(); + int memory_scope = getCLCMemoryScope(flags); + int memory_order = __ATOMIC_SEQ_CST; + __clc_mem_fence(memory_scope, memory_order); } // We do not have separate mechanism for read and write fences. diff --git a/libclc/opencl/lib/ptx-nvidiacl/synchronization/barrier.cl b/libclc/opencl/lib/ptx-nvidiacl/synchronization/barrier.cl index 7c57478795dda..c8322e602302c 100644 --- a/libclc/opencl/lib/ptx-nvidiacl/synchronization/barrier.cl +++ b/libclc/opencl/lib/ptx-nvidiacl/synchronization/barrier.cl @@ -7,7 +7,11 @@ //===----------------------------------------------------------------------===// #include <clc/opencl/synchronization/barrier.h> +#include <clc/opencl/synchronization/utils.h> +#include <clc/synchronization/clc_work_group_barrier.h> _CLC_DEF _CLC_OVERLOAD void barrier(cl_mem_fence_flags flags) { - __syncthreads(); + int memory_scope = getCLCMemoryScope(flags); + int memory_order = __ATOMIC_SEQ_CST; + __clc_work_group_barrier(memory_scope, memory_order); } diff --git a/llvm/cmake/modules/LLVMProcessSources.cmake b/llvm/cmake/modules/LLVMProcessSources.cmake index cf358a88f5fb6..0670d60bf2afd 100644 --- a/llvm/cmake/modules/LLVMProcessSources.cmake +++ b/llvm/cmake/modules/LLVMProcessSources.cmake @@ -58,21 +58,6 @@ function(llvm_process_sources OUT_VAR) set(sources ${ARG_UNPARSED_ARGUMENTS}) llvm_check_source_file_list(${sources}) - # Don't generate __SHORT_FILE__ on VS builds as it can prevent build parallelisation. - if(NOT CMAKE_GENERATOR MATCHES "Visual Studio") - foreach(fn ${sources}) - get_filename_component(suf ${fn} EXT) - if("${suf}" STREQUAL ".cpp" OR "${suf}" STREQUAL ".c") - get_filename_component(short_name ${fn} NAME) - set_property( - SOURCE ${fn} - APPEND - PROPERTY COMPILE_DEFINITIONS __SHORT_FILE__="${short_name}") - endif() - endforeach() - endif() - - # This adds .td and .h files to the Visual Studio solution: add_td_sources(sources) find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}") diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h index 52729e9e7cee7..01f8fb5ed061f 100644 --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -3553,6 +3553,11 @@ class LLVM_ABI TargetLoweringBase { return Libcalls.getLibcallName(Call); } + /// Get the libcall routine name for the specified libcall implementation + const char *getLibcallImplName(RTLIB::LibcallImpl Call) const { + return Libcalls.getLibcallImplName(Call); + } + const char *getMemcpyName() const { return Libcalls.getMemcpyName(); } /// Get the comparison predicate that's to be used to test the result of the diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index 553a302aa47b6..df472d4b9cfee 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -25,7 +25,8 @@ def isNotOSMSVCRT : RuntimeLibcallPredicate<"!TT.isOSMSVCRT()">; def isPS : RuntimeLibcallPredicate<"TT.isPS()">; def isNotOSWindowsOrIsCygwinMinGW : RuntimeLibcallPredicate<"!TT.isOSWindows() || TT.isOSCygMing()">; - +def isWindowsMSVCEnvironment : RuntimeLibcallPredicate< + [{TT.isWindowsMSVCEnvironment()}]>; def isGNUEnvironment : RuntimeLibcallPredicate<"TT.isGNUEnvironment()">; def darwinHasSinCosStret : RuntimeLibcallPredicate<"darwinHasSinCosStret(TT)">; @@ -369,6 +370,8 @@ def STACK_SMASH_HANDLER : RuntimeLibcall; // Safe stack def SAFESTACK_POINTER_ADDRESS : RuntimeLibcall; +def SECURITY_CHECK_COOKIE : RuntimeLibcall; + // Deoptimization def DEOPTIMIZE : RuntimeLibcall; @@ -1009,6 +1012,10 @@ def __stack_smash_handler : RuntimeLibcallImpl<STACK_SMASH_HANDLER>; def __riscv_flush_icache : RuntimeLibcallImpl<RISCV_FLUSH_ICACHE>; +def __security_check_cookie : RuntimeLibcallImpl<SECURITY_CHECK_COOKIE>; +def __security_check_cookie_arm64ec : RuntimeLibcallImpl<SECURITY_CHECK_COOKIE, + "#__security_check_cookie_arm64ec">; + //===----------------------------------------------------------------------===// // F128 libm Runtime Libcalls //===----------------------------------------------------------------------===// @@ -1111,6 +1118,9 @@ defvar DarwinSinCosStret = LibcallImpls<(add __sincosf_stret, __sincos_stret), darwinHasSinCosStret>; defvar DarwinExp10 = LibcallImpls<(add __exp10f, __exp10), darwinHasExp10>; +defvar SecurityCheckCookieIfWinMSVC = + LibcallImpls<(add __security_check_cookie), isWindowsMSVCEnvironment>; + defvar LibmHasSinCosF32 = LibcallImpls<(add sincosf), hasSinCos>; defvar LibmHasSinCosF64 = LibcallImpls<(add sincos), hasSinCos>; defvar LibmHasSinCosF80 = LibcallImpls<(add sincos_f80), hasSinCos>; @@ -1233,7 +1243,8 @@ def AArch64SystemLibrary : SystemRuntimeLibrary< DarwinExp10, DarwinSinCosStret, LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128, DefaultLibmExp10, - DefaultStackProtector) + DefaultStackProtector, + SecurityCheckCookieIfWinMSVC) >; // Prepend a # to every name @@ -1252,7 +1263,9 @@ def arm64ec___stack_chk_fail : DuplicateLibcallImplWithPrefix<__stack_chk_fail, def WindowsARM64ECSystemLibrary : SystemRuntimeLibrary<isWindowsArm64EC, (add WinArm64ECDefaultRuntimeLibcallImpls, - arm64ec___stack_chk_fail)>; + arm64ec___stack_chk_fail, + LibcallImpls<(add __security_check_cookie_arm64ec), + isWindowsMSVCEnvironment>)>; //===----------------------------------------------------------------------===// // AMDGPU Runtime Libcalls @@ -1500,6 +1513,7 @@ def ARMSystemLibrary LibmHasFrexpF128, LibmHasLdexpF128, WindowARMDivRemCalls, WindowARMFPIntCasts, + SecurityCheckCookieIfWinMSVC, AEABIDivRemCalls, DarwinSinCosStret, DarwinExp10, LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128, @@ -2158,6 +2172,7 @@ defvar X86CommonLibcalls = DefaultRuntimeLibcallImpls_f80, LibmHasExp10F32, LibmHasExp10F64, LibmHasExp10F80, LibcallImpls<(add MostPowI), isNotOSMSVCRT>, + SecurityCheckCookieIfWinMSVC, // FIXME: MSVCRT doesn't have powi. The f128 case is added as a // hack for one test relying on it. __powitf2_f128, diff --git a/llvm/include/llvm/Support/DebugLog.h b/llvm/include/llvm/Support/DebugLog.h index a3312950da94e..386cb7f1f9716 100644 --- a/llvm/include/llvm/Support/DebugLog.h +++ b/llvm/include/llvm/Support/DebugLog.h @@ -41,81 +41,32 @@ namespace llvm { // #define LDBG(...) _GET_LDBG_MACRO(__VA_ARGS__)(__VA_ARGS__) -// Helper macros to choose the correct macro based on the number of arguments. -#define LDBG_FUNC_CHOOSER(_f1, _f2, ...) _f2 -#define LDBG_FUNC_RECOMPOSER(argsWithParentheses) \ - LDBG_FUNC_CHOOSER argsWithParentheses -#define LDBG_CHOOSE_FROM_ARG_COUNT(...) \ - LDBG_FUNC_RECOMPOSER((__VA_ARGS__, LDBG_LOG_LEVEL, )) -#define LDBG_NO_ARG_EXPANDER() , LDBG_LOG_LEVEL_1 -#define _GET_LDBG_MACRO(...) \ - LDBG_CHOOSE_FROM_ARG_COUNT(LDBG_NO_ARG_EXPANDER __VA_ARGS__()) - -// Dispatch macros to support the `level` argument or none (default to 1) -#define LDBG_LOG_LEVEL(LEVEL) \ - DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), LEVEL, DEBUG_TYPE) -#define LDBG_LOG_LEVEL_1() LDBG_LOG_LEVEL(1) - -#define DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE, \ - LINE) \ - for (bool _c = \ - (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE, LEVEL)); \ - _c; _c = false) \ - for (::llvm::impl::RAIINewLineStream NewLineStream{(STREAM)}; _c; \ - _c = false) \ - ::llvm::impl::raw_ldbg_ostream{ \ - ::llvm::impl::computePrefix(TYPE, FILE, LINE, LEVEL), NewLineStream} \ - .asLvalue() - -#define DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, FILE) \ - DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE, __LINE__) -// When __SHORT_FILE__ is not defined, the File is the full path, -// otherwise __SHORT_FILE__ is defined in CMake to provide the file name -// without the path prefix. -#if defined(__SHORT_FILE__) -#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE) \ - DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, __SHORT_FILE__) -#else -#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE) \ - DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, \ - ::llvm::impl::getShortFileName(__FILE__)) -#endif +#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \ + for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \ + _c = false) \ + ::llvm::impl::LogWithNewline(TYPE, __FILE__, __LINE__, (STREAM)) namespace impl { - -/// A raw_ostream that tracks `\n` and print the prefix after each -/// newline. -class LLVM_ABI raw_ldbg_ostream final : public raw_ostream { - std::string Prefix; - raw_ostream &Os; - bool HasPendingNewline; - - /// Split the line on newlines and insert the prefix before each - /// newline. Forward everything to the underlying stream. - void write_impl(const char *Ptr, size_t Size) final { - auto Str = StringRef(Ptr, Size); - // Handle the initial prefix. - if (!Str.empty()) - writeWithPrefix(StringRef()); - - auto Eol = Str.find('\n'); - while (Eol != StringRef::npos) { - StringRef Line = Str.take_front(Eol + 1); - if (!Line.empty()) - writeWithPrefix(Line); - HasPendingNewline = true; - Str = Str.drop_front(Eol + 1); - Eol = Str.find('\n'); - } - if (!Str.empty()) - writeWithPrefix(Str); +class LogWithNewline { +public: + LogWithNewline(const char *debug_type, const char *file, int line, + raw_ostream &os) + : os(os) { + if (debug_type) + os << "[" << debug_type << "] "; + os << file << ":" << line << " "; } - void emitPrefix() { Os.write(Prefix.c_str(), Prefix.size()); } - void writeWithPrefix(StringRef Str) { - flushEol(); - Os.write(Str.data(), Str.size()); + ~LogWithNewline() { os << '\n'; } + template <typename T> raw_ostream &operator<<(const T &t) && { + return os << t; } + // Prevent copying, as this class manages newline responsibility and is + // intended for use as a temporary. + LogWithNewline(const LogWithNewline &) = delete; + LogWithNewline &operator=(const LogWithNewline &) = delete; + LogWithNewline &operator=(LogWithNewline &&) = delete; + public: explicit raw_ldbg_ostream(std::string Prefix, raw_ostream &Os, bool HasPendingNewline = true) diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index 2b6ea86ee1af5..018c16d61b12d 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -28609,14 +28609,16 @@ Value *AArch64TargetLowering::getIRStackGuard(IRBuilderBase &IRB) const { void AArch64TargetLowering::insertSSPDeclarations(Module &M) const { // MSVC CRT provides functionalities for stack protection. - if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment()) { + RTLIB::LibcallImpl SecurityCheckCookieLibcall = + getLibcallImpl(RTLIB::SECURITY_CHECK_COOKIE); + if (SecurityCheckCookieLibcall != RTLIB::Unsupported) { // MSVC CRT has a global variable holding security cookie. M.getOrInsertGlobal("__security_cookie", PointerType::getUnqual(M.getContext())); // MSVC CRT has a function to validate security cookie. FunctionCallee SecurityCheckCookie = - M.getOrInsertFunction(Subtarget->getSecurityCheckCookieName(), + M.getOrInsertFunction(getLibcallImplName(SecurityCheckCookieLibcall), Type::getVoidTy(M.getContext()), PointerType::getUnqual(M.getContext())); if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee())) { @@ -28637,8 +28639,10 @@ Value *AArch64TargetLowering::getSDagStackGuard(const Module &M) const { Function *AArch64TargetLowering::getSSPStackGuardCheck(const Module &M) const { // MSVC CRT has a function to validate security cookie. - if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment()) - return M.getFunction(Subtarget->getSecurityCheckCookieName()); + RTLIB::LibcallImpl SecurityCheckCookieLibcall = + getLibcallImpl(RTLIB::SECURITY_CHECK_COOKIE); + if (SecurityCheckCookieLibcall != RTLIB::Unsupported) + return M.getFunction(getLibcallImplName(SecurityCheckCookieLibcall)); return TargetLowering::getSSPStackGuardCheck(M); } diff --git a/llvm/lib/Target/AArch64/AArch64Subtarget.h b/llvm/lib/Target/AArch64/AArch64Subtarget.h index 061ed611e5e47..d00e4471e107d 100644 --- a/llvm/lib/Target/AArch64/AArch64Subtarget.h +++ b/llvm/lib/Target/AArch64/AArch64Subtarget.h @@ -451,12 +451,6 @@ class AArch64Subtarget final : public AArch64GenSubtargetInfo { return "__chkstk"; } - const char* getSecurityCheckCookieName() const { - if (isWindowsArm64EC()) - return "#__security_check_cookie_arm64ec"; - return "__security_check_cookie"; - } - /// Choose a method of checking LR before performing a tail call. AArch64PAuth::AuthCheckMethod getAuthenticatedLRCheckMethod(const MachineFunction &MF) const; diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index 18766c8c6befa..74c7c97e6e927 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -21358,7 +21358,9 @@ bool ARMTargetLowering::useLoadStackGuardNode(const Module &M) const { } void ARMTargetLowering::insertSSPDeclarations(Module &M) const { - if (!Subtarget->getTargetTriple().isWindowsMSVCEnvironment()) + RTLIB::LibcallImpl SecurityCheckCookieLibcall = + getLibcallImpl(RTLIB::SECURITY_CHECK_COOKIE); + if (SecurityCheckCookieLibcall == RTLIB::Unsupported) return TargetLowering::insertSSPDeclarations(M); // MSVC CRT has a global variable holding security cookie. @@ -21367,23 +21369,32 @@ void ARMTargetLowering::insertSSPDeclarations(Module &M) const { // MSVC CRT has a function to validate security cookie. FunctionCallee SecurityCheckCookie = M.getOrInsertFunction( - "__security_check_cookie", Type::getVoidTy(M.getContext()), - PointerType::getUnqual(M.getContext())); + getLibcallImplName(SecurityCheckCookieLibcall), + Type::getVoidTy(M.getContext()), PointerType::getUnqual(M.getContext())); if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee())) F->addParamAttr(0, Attribute::AttrKind::InReg); } Value *ARMTargetLowering::getSDagStackGuard(const Module &M) const { - // MSVC CRT has a global variable holding security cookie. - if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment()) + RTLIB::LibcallImpl SecurityCheckCookieLibcall = + getLibcallImpl(RTLIB::SECURITY_CHECK_COOKIE); + if (SecurityCheckCookieLibcall != RTLIB::Unsupported) { + // MSVC CRT has a global variable holding security cookie. + // + // FIXME: We have a libcall entry for the correlated check function, but not + // the global name. return M.getGlobalVariable("__security_cookie"); + } + return TargetLowering::getSDagStackGuard(M); } Function *ARMTargetLowering::getSSPStackGuardCheck(const Module &M) const { // MSVC CRT has a function to validate security cookie. - if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment()) - return M.getFunction("__security_check_cookie"); + RTLIB::LibcallImpl SecurityCheckCookie = + getLibcallImpl(RTLIB::SECURITY_CHECK_COOKIE); + if (SecurityCheckCookie != RTLIB::Unsupported) + return M.getFunction(getLibcallImplName(SecurityCheckCookie)); return TargetLowering::getSSPStackGuardCheck(M); } diff --git a/llvm/test/CodeGen/AArch64/stacksmash-arm64ec.ll b/llvm/test/CodeGen/AArch64/stacksmash-arm64ec.ll index 0960133d7d054..bd4110173f013 100644 --- a/llvm/test/CodeGen/AArch64/stacksmash-arm64ec.ll +++ b/llvm/test/CodeGen/AArch64/stacksmash-arm64ec.ll @@ -1,8 +1,10 @@ -; RUN: llc -mtriple=arm64ec-unknown-windows-gnu < %s | FileCheck %s +; RUN: llc -mtriple=arm64ec-unknown-windows < %s | FileCheck -check-prefixes=CHECK,NONGNU %s +; RUN: llc -mtriple=arm64ec-unknown-windows-gnu < %s | FileCheck -check-prefixes=CHECK,GNU %s ; CHECK-LABEL: func = "#func" ; CHECK: bl "#other" -; CHECK: bl "#__stack_chk_fail" +; NONGNU: bl "#__security_check_cookie_arm64ec" +; GNU: bl "#__stack_chk_fail" define void @func() #0 { entry: %buf = alloca [10 x i8], align 1 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits