Skip to content

Commit

Permalink
[SYCL] Added constexpr specifier to standard functions declarations i…
Browse files Browse the repository at this point in the history
…n sycl_wrapper to support c++14 sources

Starting from c++14 several standard functions(e.g. min, max) should be
marked with constexpr specifier.

Also updated license in existing sycl_wrappers in accordance with LLVM.

Signed-off-by: Podchishchaeva, Mariya <mariya.podchishchaeva@intel.com>
Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com>
  • Loading branch information
Fznamznon authored and vladimirlaz committed Feb 12, 2019
1 parent 4efe9fc commit 3ce5091
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 31 deletions.
1 change: 1 addition & 0 deletions clang/lib/Headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ set(cuda_wrapper_files
set(sycl_wrapper_files
sycl_wrappers/algorithm
sycl_wrappers/random
sycl_wrappers/__config
)

set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include)
Expand Down
36 changes: 36 additions & 0 deletions clang/lib/Headers/sycl_wrappers/__config
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// -*- C++ -*-
//===--------------------------- __config ---------------------------------===//
//
// 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 _LIBCPP_STD_VER
# if __cplusplus <= 201103L
# define _LIBCPP_STD_VER 11
# elif __cplusplus <= 201402L
# define _LIBCPP_STD_VER 14
# elif __cplusplus <= 201703L
# define _LIBCPP_STD_VER 17
# endif
#endif

#if _LIBCPP_STD_VER > 11
# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
#else
# define _LIBCPP_CONSTEXPR_AFTER_CXX11
#endif

#if _LIBCPP_STD_VER > 14
# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
#else
# define _LIBCPP_CONSTEXPR_AFTER_CXX14
#endif

#if _LIBCPP_STD_VER > 17
# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
#else
# define _LIBCPP_CONSTEXPR_AFTER_CXX17
#endif
72 changes: 45 additions & 27 deletions clang/lib/Headers/sycl_wrappers/algorithm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// -*- C++ -*-
//===-------------------------- algorithm ---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
// 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 <__config>
#include <initializer_list>
#include <iterator>

Expand Down Expand Up @@ -495,59 +495,77 @@ RandomAccessIterator is_heap_until(RandomAccessIterator first,
RandomAccessIterator last, Compare comp);

template <class ForwardIterator>
ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
_LIBCPP_CONSTEXPR_AFTER_CXX11 ForwardIterator min_element(ForwardIterator first,
ForwardIterator last);

template <class ForwardIterator, class Compare>
ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
Compare comp);
_LIBCPP_CONSTEXPR_AFTER_CXX11 ForwardIterator min_element(ForwardIterator first,
ForwardIterator last,
Compare comp);

template <class T> const T &min(const T &a, const T &b);
template <class T>
_LIBCPP_CONSTEXPR_AFTER_CXX11 const T &min(const T &a, const T &b);

template <class T, class Compare>
const T &min(const T &a, const T &b, Compare comp);
_LIBCPP_CONSTEXPR_AFTER_CXX11 const T &min(const T &a, const T &b,
Compare comp);

template <class T> T min(initializer_list<T> t);
template <class T> _LIBCPP_CONSTEXPR_AFTER_CXX11 T min(initializer_list<T> t);

template <class T, class Compare> T min(initializer_list<T> t, Compare comp);
template <class T, class Compare>
_LIBCPP_CONSTEXPR_AFTER_CXX11 T min(initializer_list<T> t, Compare comp);

template <class T> const T &clamp(const T &v, const T &lo, const T &hi);
#if _LIBCPP_STD_VER > 14
template <class T>
const T constexpr &clamp(const T &v, const T &lo, const T &hi);

template <class T, class Compare>
const T &clamp(const T &v, const T &lo, const T &hi, Compare comp);
const T constexpr &clamp(const T &v, const T &lo, const T &hi, Compare comp);
#endif

template <class ForwardIterator>
ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
_LIBCPP_CONSTEXPR_AFTER_CXX11 ForwardIterator max_element(ForwardIterator first,
ForwardIterator last);

template <class ForwardIterator, class Compare>
ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
Compare comp);
_LIBCPP_CONSTEXPR_AFTER_CXX11 ForwardIterator max_element(ForwardIterator first,
ForwardIterator last,
Compare comp);

template <class T> const T &max(const T &a, const T &b);
template <class T>
_LIBCPP_CONSTEXPR_AFTER_CXX11 const T &max(const T &a, const T &b);

template <class T, class Compare>
const T &max(const T &a, const T &b, Compare comp);
_LIBCPP_CONSTEXPR_AFTER_CXX11 const T &max(const T &a, const T &b,
Compare comp);

template <class T> T max(initializer_list<T> t);
template <class T> _LIBCPP_CONSTEXPR_AFTER_CXX11 T max(initializer_list<T> t);

template <class T, class Compare> T max(initializer_list<T> t, Compare comp);
template <class T, class Compare>
_LIBCPP_CONSTEXPR_AFTER_CXX11 T max(initializer_list<T> t, Compare comp);

template <class ForwardIterator>
pair<ForwardIterator, ForwardIterator> minmax_element(ForwardIterator first,
ForwardIterator last);
_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<ForwardIterator, ForwardIterator>
minmax_element(ForwardIterator first, ForwardIterator last);

template <class ForwardIterator, class Compare>
pair<ForwardIterator, ForwardIterator>
pair<ForwardIterator, ForwardIterator> _LIBCPP_CONSTEXPR_AFTER_CXX11
minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);

template <class T> pair<const T &, const T &> minmax(const T &a, const T &b);
template <class T>
_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<const T &, const T &> minmax(const T &a,
const T &b);

template <class T, class Compare>
pair<const T &, const T &> minmax(const T &a, const T &b, Compare comp);
_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<const T &, const T &>
minmax(const T &a, const T &b, Compare comp);

template <class T> pair<T, T> minmax(initializer_list<T> t);
template <class T>
_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<T, T> minmax(initializer_list<T> t);

template <class T, class Compare>
pair<T, T> minmax(initializer_list<T> t, Compare comp);
_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<T, T> minmax(initializer_list<T> t,
Compare comp);

template <class InputIterator1, class InputIterator2>
bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
Expand Down
7 changes: 3 additions & 4 deletions clang/lib/Headers/sycl_wrappers/random
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// -*- C++ -*-
//===--------------------------- random -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
// 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
//
//===----------------------------------------------------------------------===//

Expand Down

0 comments on commit 3ce5091

Please sign in to comment.