From 95c585e258f6821619a19e9657d2f75e13405d15 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Mon, 1 Apr 2019 15:21:46 +0000 Subject: [PATCH] [pstl] Indent preprocessor directives as part of the clang-format rules Summary: Indenting preprocessor directives provides a significant gain in readability. We do it for normal if statements, and it makes sense to do it for preprocessor ifs too. Reviewers: rodgert, MikeDvorskiy Subscribers: jkorous, dexonsmith, jdoerfert, libcxx-commits Differential Revision: https://reviews.llvm.org/D59767 llvm-svn: 357401 --- pstl/.clang-format | 3 + pstl/include/pstl/algorithm | 6 +- pstl/include/pstl/execution | 8 +- pstl/include/pstl/internal/algorithm_impl.h | 10 +- .../pstl/internal/glue_execution_defs.h | 6 +- pstl/include/pstl/internal/numeric_impl.h | 2 +- pstl/include/pstl/internal/parallel_backend.h | 2 +- .../pstl/internal/parallel_backend_tbb.h | 2 +- pstl/include/pstl/internal/pstl_config.h | 98 +++++++++---------- pstl/include/pstl/memory | 6 +- pstl/include/pstl/numeric | 6 +- 11 files changed, 76 insertions(+), 73 deletions(-) diff --git a/pstl/.clang-format b/pstl/.clang-format index e6585794e0e4..8a110c1cec8b 100644 --- a/pstl/.clang-format +++ b/pstl/.clang-format @@ -15,3 +15,6 @@ BreakBeforeBraces: Allman # Disable formatting options which may break tests. SortIncludes: false ReflowComments: false + +# Indent preprocessor directives +IndentPPDirectives: AfterHash diff --git a/pstl/include/pstl/algorithm b/pstl/include/pstl/algorithm index 0a850f330129..c76ee53e0fc4 100644 --- a/pstl/include/pstl/algorithm +++ b/pstl/include/pstl/algorithm @@ -14,11 +14,11 @@ #if __PSTL_EXECUTION_POLICIES_DEFINED // If has already been included, pull in implementations -#include "internal/glue_algorithm_impl.h" +# include "internal/glue_algorithm_impl.h" #else // Otherwise just pull in forward declarations -#include "internal/glue_algorithm_defs.h" -#define __PSTL_ALGORITHM_FORWARD_DECLARED 1 +# include "internal/glue_algorithm_defs.h" +# define __PSTL_ALGORITHM_FORWARD_DECLARED 1 #endif #endif /* __PSTL_algorithm */ diff --git a/pstl/include/pstl/execution b/pstl/include/pstl/execution index c4fef99210fe..5e91c75d3c39 100644 --- a/pstl/include/pstl/execution +++ b/pstl/include/pstl/execution @@ -16,21 +16,21 @@ #define __PSTL_EXECUTION_POLICIES_DEFINED 1 #if __PSTL_ALGORITHM_FORWARD_DECLARED -#include "internal/glue_algorithm_impl.h" +# include "internal/glue_algorithm_impl.h" #endif #if __PSTL_MEMORY_FORWARD_DECLARED -#include "internal/glue_memory_impl.h" +# include "internal/glue_memory_impl.h" #endif #if __PSTL_NUMERIC_FORWARD_DECLARED -#include "internal/glue_numeric_impl.h" +# include "internal/glue_numeric_impl.h" #endif #if __PSTL_CPP17_EXECUTION_POLICIES_PRESENT __PSTL_PRAGMA_MESSAGE_POLICIES("The execution policies are defined in the namespace __pstl::execution") #else -#include "internal/glue_execution_defs.h" +# include "internal/glue_execution_defs.h" __PSTL_PRAGMA_MESSAGE_POLICIES( "The execution policies are injected into the standard namespace std::execution") #endif diff --git a/pstl/include/pstl/internal/algorithm_impl.h b/pstl/include/pstl/internal/algorithm_impl.h index 85a628209f77..e2cfb23fa41a 100644 --- a/pstl/include/pstl/internal/algorithm_impl.h +++ b/pstl/include/pstl/internal/algorithm_impl.h @@ -22,8 +22,8 @@ #include "unseq_backend_simd.h" #if __PSTL_USE_PAR_POLICIES -#include "parallel_backend.h" -#include "parallel_impl.h" +# include "parallel_backend.h" +# include "parallel_impl.h" #endif namespace __pstl @@ -2194,11 +2194,11 @@ __pattern_partial_sort_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __j1 = __first + (__j - __d_first); // 1. Copy elements from input to output -#if !__PSTL_ICC_18_OMP_SIMD_BROKEN +# if !__PSTL_ICC_18_OMP_SIMD_BROKEN __internal::__brick_copy(__i1, __j1, __i, __is_vector); -#else +# else std::copy(__i1, __j1, __i); -#endif +# endif // 2. Sort elements in output sequence std::sort(__i, __j, __comp); }, diff --git a/pstl/include/pstl/internal/glue_execution_defs.h b/pstl/include/pstl/internal/glue_execution_defs.h index dacd038cea57..ce684b0ceb21 100644 --- a/pstl/include/pstl/internal/glue_execution_defs.h +++ b/pstl/include/pstl/internal/glue_execution_defs.h @@ -19,12 +19,12 @@ namespace std // Type trait using __pstl::execution::is_execution_policy; #if __PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT -#if __INTEL_COMPILER +# if __INTEL_COMPILER template constexpr bool is_execution_policy_v = is_execution_policy::value; -#else +# else using __pstl::execution::is_execution_policy_v; -#endif +# endif #endif namespace execution diff --git a/pstl/include/pstl/internal/numeric_impl.h b/pstl/include/pstl/internal/numeric_impl.h index 72541dd5ce1a..ad395bf984c6 100644 --- a/pstl/include/pstl/internal/numeric_impl.h +++ b/pstl/include/pstl/internal/numeric_impl.h @@ -19,7 +19,7 @@ #include "algorithm_fwd.h" #if __PSTL_USE_PAR_POLICIES -#include "parallel_backend.h" +# include "parallel_backend.h" #endif namespace __pstl diff --git a/pstl/include/pstl/internal/parallel_backend.h b/pstl/include/pstl/internal/parallel_backend.h index 820e2b7f89b9..8c88966dd0dd 100644 --- a/pstl/include/pstl/internal/parallel_backend.h +++ b/pstl/include/pstl/internal/parallel_backend.h @@ -11,7 +11,7 @@ #define __PSTL_parallel_backend_H #if __PSTL_PAR_BACKEND_TBB -#include "parallel_backend_tbb.h" +# include "parallel_backend_tbb.h" #else __PSTL_PRAGMA_MESSAGE("Parallel backend was not specified"); #endif diff --git a/pstl/include/pstl/internal/parallel_backend_tbb.h b/pstl/include/pstl/internal/parallel_backend_tbb.h index b116068e84ef..3a838e19fe71 100644 --- a/pstl/include/pstl/internal/parallel_backend_tbb.h +++ b/pstl/include/pstl/internal/parallel_backend_tbb.h @@ -26,7 +26,7 @@ #include #if TBB_INTERFACE_VERSION < 10000 -#error Intel(R) Threading Building Blocks 2018 is required; older versions are not supported. +# error Intel(R) Threading Building Blocks 2018 is required; older versions are not supported. #endif namespace __pstl diff --git a/pstl/include/pstl/internal/pstl_config.h b/pstl/include/pstl/internal/pstl_config.h index d799028c592b..cf3d6b092cc8 100644 --- a/pstl/include/pstl/internal/pstl_config.h +++ b/pstl/include/pstl/internal/pstl_config.h @@ -16,35 +16,35 @@ // Check the user-defined macro for parallel policies #if defined(PSTL_USE_PARALLEL_POLICIES) -#undef __PSTL_USE_PAR_POLICIES -#define __PSTL_USE_PAR_POLICIES PSTL_USE_PARALLEL_POLICIES +# undef __PSTL_USE_PAR_POLICIES +# define __PSTL_USE_PAR_POLICIES PSTL_USE_PARALLEL_POLICIES // Check the internal macro for parallel policies #elif !defined(__PSTL_USE_PAR_POLICIES) -#define __PSTL_USE_PAR_POLICIES 1 +# define __PSTL_USE_PAR_POLICIES 1 #endif #if __PSTL_USE_PAR_POLICIES -#if !defined(__PSTL_PAR_BACKEND_TBB) -#define __PSTL_PAR_BACKEND_TBB 1 -#endif +# if !defined(__PSTL_PAR_BACKEND_TBB) +# define __PSTL_PAR_BACKEND_TBB 1 +# endif #else -#undef __PSTL_PAR_BACKEND_TBB +# undef __PSTL_PAR_BACKEND_TBB #endif // Check the user-defined macro for warnings #if defined(PSTL_USAGE_WARNINGS) -#undef __PSTL_USAGE_WARNINGS -#define __PSTL_USAGE_WARNINGS PSTL_USAGE_WARNINGS +# undef __PSTL_USAGE_WARNINGS +# define __PSTL_USAGE_WARNINGS PSTL_USAGE_WARNINGS // Check the internal macro for warnings #elif !defined(__PSTL_USAGE_WARNINGS) -#define __PSTL_USAGE_WARNINGS 0 +# define __PSTL_USAGE_WARNINGS 0 #endif // Portability "#pragma" definition #ifdef _MSC_VER -#define __PSTL_PRAGMA(x) __pragma(x) +# define __PSTL_PRAGMA(x) __pragma(x) #else -#define __PSTL_PRAGMA(x) _Pragma(#x) +# define __PSTL_PRAGMA(x) _Pragma(# x) #endif #define __PSTL_STRING_AUX(x) #x @@ -57,38 +57,38 @@ #if __clang__ // according to clang documentation, version can be vendor specific -#define __PSTL_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) +# define __PSTL_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) #endif // Enable SIMD for compilers that support OpenMP 4.0 #if (_OPENMP >= 201307) || (__INTEL_COMPILER >= 1600) || (!defined(__INTEL_COMPILER) && __PSTL_GCC_VERSION >= 40900) -#define __PSTL_PRAGMA_SIMD __PSTL_PRAGMA(omp simd) -#define __PSTL_PRAGMA_DECLARE_SIMD __PSTL_PRAGMA(omp declare simd) -#define __PSTL_PRAGMA_SIMD_REDUCTION(PRM) __PSTL_PRAGMA(omp simd reduction(PRM)) +# define __PSTL_PRAGMA_SIMD __PSTL_PRAGMA(omp simd) +# define __PSTL_PRAGMA_DECLARE_SIMD __PSTL_PRAGMA(omp declare simd) +# define __PSTL_PRAGMA_SIMD_REDUCTION(PRM) __PSTL_PRAGMA(omp simd reduction(PRM)) #elif !defined(_MSC_VER) //#pragma simd -#define __PSTL_PRAGMA_SIMD __PSTL_PRAGMA(simd) -#define __PSTL_PRAGMA_DECLARE_SIMD -#define __PSTL_PRAGMA_SIMD_REDUCTION(PRM) __PSTL_PRAGMA(simd reduction(PRM)) +# define __PSTL_PRAGMA_SIMD __PSTL_PRAGMA(simd) +# define __PSTL_PRAGMA_DECLARE_SIMD +# define __PSTL_PRAGMA_SIMD_REDUCTION(PRM) __PSTL_PRAGMA(simd reduction(PRM)) #else //no simd -#define __PSTL_PRAGMA_SIMD -#define __PSTL_PRAGMA_DECLARE_SIMD -#define __PSTL_PRAGMA_SIMD_REDUCTION(PRM) +# define __PSTL_PRAGMA_SIMD +# define __PSTL_PRAGMA_DECLARE_SIMD +# define __PSTL_PRAGMA_SIMD_REDUCTION(PRM) #endif //Enable SIMD #if (__INTEL_COMPILER) -#define __PSTL_PRAGMA_FORCEINLINE __PSTL_PRAGMA(forceinline) +# define __PSTL_PRAGMA_FORCEINLINE __PSTL_PRAGMA(forceinline) #else -#define __PSTL_PRAGMA_FORCEINLINE +# define __PSTL_PRAGMA_FORCEINLINE #endif #if (__INTEL_COMPILER >= 1900) -#define __PSTL_PRAGMA_SIMD_SCAN(PRM) __PSTL_PRAGMA(omp simd reduction(inscan, PRM)) -#define __PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) __PSTL_PRAGMA(omp scan inclusive(PRM)) -#define __PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) __PSTL_PRAGMA(omp scan exclusive(PRM)) +# define __PSTL_PRAGMA_SIMD_SCAN(PRM) __PSTL_PRAGMA(omp simd reduction(inscan, PRM)) +# define __PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) __PSTL_PRAGMA(omp scan inclusive(PRM)) +# define __PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) __PSTL_PRAGMA(omp scan exclusive(PRM)) #else -#define __PSTL_PRAGMA_SIMD_SCAN(PRM) -#define __PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) -#define __PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) +# define __PSTL_PRAGMA_SIMD_SCAN(PRM) +# define __PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) +# define __PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) #endif // Should be defined to 1 for environments with a vendor implementation of C++17 execution policies @@ -106,25 +106,25 @@ #define __PSTL_MONOTONIC_PRESENT (__INTEL_COMPILER >= 1800) #if (__INTEL_COMPILER >= 1900 || !defined(__INTEL_COMPILER) && __PSTL_GCC_VERSION >= 40900 || _OPENMP >= 201307) -#define __PSTL_UDR_PRESENT 1 +# define __PSTL_UDR_PRESENT 1 #else -#define __PSTL_UDR_PRESENT 0 +# define __PSTL_UDR_PRESENT 0 #endif #define __PSTL_UDS_PRESENT (__INTEL_COMPILER >= 1900 && __INTEL_COMPILER_BUILD_DATE >= 20180626) #if __PSTL_EARLYEXIT_PRESENT -#define __PSTL_PRAGMA_SIMD_EARLYEXIT __PSTL_PRAGMA(omp simd early_exit) +# define __PSTL_PRAGMA_SIMD_EARLYEXIT __PSTL_PRAGMA(omp simd early_exit) #else -#define __PSTL_PRAGMA_SIMD_EARLYEXIT +# define __PSTL_PRAGMA_SIMD_EARLYEXIT #endif #if __PSTL_MONOTONIC_PRESENT -#define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM) __PSTL_PRAGMA(omp ordered simd monotonic(PRM)) -#define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2) __PSTL_PRAGMA(omp ordered simd monotonic(PRM1, PRM2)) +# define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM) __PSTL_PRAGMA(omp ordered simd monotonic(PRM)) +# define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2) __PSTL_PRAGMA(omp ordered simd monotonic(PRM1, PRM2)) #else -#define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM) -#define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2) +# define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM) +# define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2) #endif // Declaration of reduction functor, where @@ -135,35 +135,35 @@ // omp_priv - refers to the private copy of the initial value // omp_orig - refers to the original variable to be reduced #define __PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ - __PSTL_PRAGMA(omp declare reduction(NAME : OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) + __PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) #if (__INTEL_COMPILER >= 1600) -#define __PSTL_PRAGMA_VECTOR_UNALIGNED __PSTL_PRAGMA(vector unaligned) +# define __PSTL_PRAGMA_VECTOR_UNALIGNED __PSTL_PRAGMA(vector unaligned) #else -#define __PSTL_PRAGMA_VECTOR_UNALIGNED +# define __PSTL_PRAGMA_VECTOR_UNALIGNED #endif // Check the user-defined macro to use non-temporal stores #if defined(PSTL_USE_NONTEMPORAL_STORES) && (__INTEL_COMPILER >= 1600) -#define __PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED __PSTL_PRAGMA(vector nontemporal) +# define __PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED __PSTL_PRAGMA(vector nontemporal) #else -#define __PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED +# define __PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED #endif #if _MSC_VER || __INTEL_COMPILER //the preprocessors don't type a message location -#define __PSTL_PRAGMA_LOCATION __FILE__ ":" __PSTL_STRING(__LINE__) ": [Parallel STL message]: " +# define __PSTL_PRAGMA_LOCATION __FILE__ ":" __PSTL_STRING(__LINE__) ": [Parallel STL message]: " #else -#define __PSTL_PRAGMA_LOCATION " [Parallel STL message]: " +# define __PSTL_PRAGMA_LOCATION " [Parallel STL message]: " #endif #define __PSTL_PRAGMA_MESSAGE_IMPL(x) __PSTL_PRAGMA(message(__PSTL_STRING_CONCAT(__PSTL_PRAGMA_LOCATION, x))) #if __PSTL_USAGE_WARNINGS -#define __PSTL_PRAGMA_MESSAGE(x) __PSTL_PRAGMA_MESSAGE_IMPL(x) -#define __PSTL_PRAGMA_MESSAGE_POLICIES(x) __PSTL_PRAGMA_MESSAGE_IMPL(x) +# define __PSTL_PRAGMA_MESSAGE(x) __PSTL_PRAGMA_MESSAGE_IMPL(x) +# define __PSTL_PRAGMA_MESSAGE_POLICIES(x) __PSTL_PRAGMA_MESSAGE_IMPL(x) #else -#define __PSTL_PRAGMA_MESSAGE(x) -#define __PSTL_PRAGMA_MESSAGE_POLICIES(x) +# define __PSTL_PRAGMA_MESSAGE(x) +# define __PSTL_PRAGMA_MESSAGE_POLICIES(x) #endif // broken macros diff --git a/pstl/include/pstl/memory b/pstl/include/pstl/memory index b456cce7e98c..69ecb3f24b5a 100644 --- a/pstl/include/pstl/memory +++ b/pstl/include/pstl/memory @@ -14,11 +14,11 @@ #if __PSTL_EXECUTION_POLICIES_DEFINED // If has already been included, pull in implementations -#include "internal/glue_memory_impl.h" +# include "internal/glue_memory_impl.h" #else // Otherwise just pull in forward declarations -#include "internal/glue_memory_defs.h" -#define __PSTL_MEMORY_FORWARD_DECLARED 1 +# include "internal/glue_memory_defs.h" +# define __PSTL_MEMORY_FORWARD_DECLARED 1 #endif #endif /* __PSTL_memory */ diff --git a/pstl/include/pstl/numeric b/pstl/include/pstl/numeric index d900bab3f4ac..20a9aea1ad80 100644 --- a/pstl/include/pstl/numeric +++ b/pstl/include/pstl/numeric @@ -14,11 +14,11 @@ #if __PSTL_EXECUTION_POLICIES_DEFINED // If has already been included, pull in implementations -#include "internal/glue_numeric_impl.h" +# include "internal/glue_numeric_impl.h" #else // Otherwise just pull in forward declarations -#include "internal/glue_numeric_defs.h" -#define __PSTL_NUMERIC_FORWARD_DECLARED 1 +# include "internal/glue_numeric_defs.h" +# define __PSTL_NUMERIC_FORWARD_DECLARED 1 #endif #endif /* __PSTL_numeric */