Skip to content

Commit 3ce5091

Browse files
Fznamznonvladimirlaz
authored andcommitted
[SYCL] Added constexpr specifier to standard functions declarations in 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 <[email protected]> Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 4efe9fc commit 3ce5091

File tree

4 files changed

+85
-31
lines changed

4 files changed

+85
-31
lines changed

clang/lib/Headers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ set(cuda_wrapper_files
125125
set(sycl_wrapper_files
126126
sycl_wrappers/algorithm
127127
sycl_wrappers/random
128+
sycl_wrappers/__config
128129
)
129130

130131
set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// -*- C++ -*-
2+
//===--------------------------- __config ---------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP_STD_VER
11+
# if __cplusplus <= 201103L
12+
# define _LIBCPP_STD_VER 11
13+
# elif __cplusplus <= 201402L
14+
# define _LIBCPP_STD_VER 14
15+
# elif __cplusplus <= 201703L
16+
# define _LIBCPP_STD_VER 17
17+
# endif
18+
#endif
19+
20+
#if _LIBCPP_STD_VER > 11
21+
# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
22+
#else
23+
# define _LIBCPP_CONSTEXPR_AFTER_CXX11
24+
#endif
25+
26+
#if _LIBCPP_STD_VER > 14
27+
# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
28+
#else
29+
# define _LIBCPP_CONSTEXPR_AFTER_CXX14
30+
#endif
31+
32+
#if _LIBCPP_STD_VER > 17
33+
# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
34+
#else
35+
# define _LIBCPP_CONSTEXPR_AFTER_CXX17
36+
#endif

clang/lib/Headers/sycl_wrappers/algorithm

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// -*- C++ -*-
22
//===-------------------------- algorithm ---------------------------------===//
33
//
4-
// The LLVM Compiler Infrastructure
5-
//
6-
// This file is dual licensed under the MIT and the University of Illinois Open
7-
// Source Licenses. See LICENSE.TXT for details.
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
87
//
98
//===----------------------------------------------------------------------===//
109

10+
#include <__config>
1111
#include <initializer_list>
1212
#include <iterator>
1313

@@ -495,59 +495,77 @@ RandomAccessIterator is_heap_until(RandomAccessIterator first,
495495
RandomAccessIterator last, Compare comp);
496496

497497
template <class ForwardIterator>
498-
ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
498+
_LIBCPP_CONSTEXPR_AFTER_CXX11 ForwardIterator min_element(ForwardIterator first,
499+
ForwardIterator last);
499500

500501
template <class ForwardIterator, class Compare>
501-
ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
502-
Compare comp);
502+
_LIBCPP_CONSTEXPR_AFTER_CXX11 ForwardIterator min_element(ForwardIterator first,
503+
ForwardIterator last,
504+
Compare comp);
503505

504-
template <class T> const T &min(const T &a, const T &b);
506+
template <class T>
507+
_LIBCPP_CONSTEXPR_AFTER_CXX11 const T &min(const T &a, const T &b);
505508

506509
template <class T, class Compare>
507-
const T &min(const T &a, const T &b, Compare comp);
510+
_LIBCPP_CONSTEXPR_AFTER_CXX11 const T &min(const T &a, const T &b,
511+
Compare comp);
508512

509-
template <class T> T min(initializer_list<T> t);
513+
template <class T> _LIBCPP_CONSTEXPR_AFTER_CXX11 T min(initializer_list<T> t);
510514

511-
template <class T, class Compare> T min(initializer_list<T> t, Compare comp);
515+
template <class T, class Compare>
516+
_LIBCPP_CONSTEXPR_AFTER_CXX11 T min(initializer_list<T> t, Compare comp);
512517

513-
template <class T> const T &clamp(const T &v, const T &lo, const T &hi);
518+
#if _LIBCPP_STD_VER > 14
519+
template <class T>
520+
const T constexpr &clamp(const T &v, const T &lo, const T &hi);
514521

515522
template <class T, class Compare>
516-
const T &clamp(const T &v, const T &lo, const T &hi, Compare comp);
523+
const T constexpr &clamp(const T &v, const T &lo, const T &hi, Compare comp);
524+
#endif
517525

518526
template <class ForwardIterator>
519-
ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
527+
_LIBCPP_CONSTEXPR_AFTER_CXX11 ForwardIterator max_element(ForwardIterator first,
528+
ForwardIterator last);
520529

521530
template <class ForwardIterator, class Compare>
522-
ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
523-
Compare comp);
531+
_LIBCPP_CONSTEXPR_AFTER_CXX11 ForwardIterator max_element(ForwardIterator first,
532+
ForwardIterator last,
533+
Compare comp);
524534

525-
template <class T> const T &max(const T &a, const T &b);
535+
template <class T>
536+
_LIBCPP_CONSTEXPR_AFTER_CXX11 const T &max(const T &a, const T &b);
526537

527538
template <class T, class Compare>
528-
const T &max(const T &a, const T &b, Compare comp);
539+
_LIBCPP_CONSTEXPR_AFTER_CXX11 const T &max(const T &a, const T &b,
540+
Compare comp);
529541

530-
template <class T> T max(initializer_list<T> t);
542+
template <class T> _LIBCPP_CONSTEXPR_AFTER_CXX11 T max(initializer_list<T> t);
531543

532-
template <class T, class Compare> T max(initializer_list<T> t, Compare comp);
544+
template <class T, class Compare>
545+
_LIBCPP_CONSTEXPR_AFTER_CXX11 T max(initializer_list<T> t, Compare comp);
533546

534547
template <class ForwardIterator>
535-
pair<ForwardIterator, ForwardIterator> minmax_element(ForwardIterator first,
536-
ForwardIterator last);
548+
_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<ForwardIterator, ForwardIterator>
549+
minmax_element(ForwardIterator first, ForwardIterator last);
537550

538551
template <class ForwardIterator, class Compare>
539-
pair<ForwardIterator, ForwardIterator>
552+
pair<ForwardIterator, ForwardIterator> _LIBCPP_CONSTEXPR_AFTER_CXX11
540553
minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
541554

542-
template <class T> pair<const T &, const T &> minmax(const T &a, const T &b);
555+
template <class T>
556+
_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<const T &, const T &> minmax(const T &a,
557+
const T &b);
543558

544559
template <class T, class Compare>
545-
pair<const T &, const T &> minmax(const T &a, const T &b, Compare comp);
560+
_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<const T &, const T &>
561+
minmax(const T &a, const T &b, Compare comp);
546562

547-
template <class T> pair<T, T> minmax(initializer_list<T> t);
563+
template <class T>
564+
_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<T, T> minmax(initializer_list<T> t);
548565

549566
template <class T, class Compare>
550-
pair<T, T> minmax(initializer_list<T> t, Compare comp);
567+
_LIBCPP_CONSTEXPR_AFTER_CXX11 pair<T, T> minmax(initializer_list<T> t,
568+
Compare comp);
551569

552570
template <class InputIterator1, class InputIterator2>
553571
bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1,

clang/lib/Headers/sycl_wrappers/random

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// -*- C++ -*-
22
//===--------------------------- random -----------------------------------===//
33
//
4-
// The LLVM Compiler Infrastructure
5-
//
6-
// This file is dual licensed under the MIT and the University of Illinois Open
7-
// Source Licenses. See LICENSE.TXT for details.
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
87
//
98
//===----------------------------------------------------------------------===//
109

0 commit comments

Comments
 (0)