Skip to content

Commit 111cdaa

Browse files
authored
[libclc] Add __attribute__((const)) to functions that don't access memory (#152456)
Before this PR, PostOrderFunctionAttrsPass in opt run can deduce memory(none) for these functions. This PR explicitly adds the attribute to align with Clang's OpenCL headers and ensures the attribute is present throughout the compilation flow. Generated bitcode files amdgcn--amdhsa.bc and nvptx64--nvidiacl.bc become slightly smaller.
1 parent a6e870d commit 111cdaa

File tree

80 files changed

+160
-151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+160
-151
lines changed

libclc/clc/include/clc/clcfunc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define _CLC_OVERLOAD __attribute__((overloadable))
1313
#define _CLC_DECL
1414
#define _CLC_INLINE __attribute__((always_inline)) inline
15+
#define _CLC_CONST __attribute__((const))
1516

1617
// avoid inlines for SPIR-V related targets since we'll optimise later in the
1718
// chain

libclc/clc/include/clc/common/clc_smoothstep.inc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_smoothstep(__CLC_GENTYPE edge0,
10-
__CLC_GENTYPE edge1,
11-
__CLC_GENTYPE x);
9+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL __CLC_GENTYPE
10+
__clc_smoothstep(__CLC_GENTYPE edge0, __CLC_GENTYPE edge1, __CLC_GENTYPE x);

libclc/clc/include/clc/geometric/binary_decl.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#if (__CLC_VECSIZE_OR_1 == 1 || __CLC_VECSIZE_OR_1 == 2 || \
1111
__CLC_VECSIZE_OR_1 == 3 || __CLC_VECSIZE_OR_1 == 4)
1212

13-
_CLC_OVERLOAD _CLC_DECL __CLC_SCALAR_GENTYPE FUNCTION(__CLC_GENTYPE a,
14-
__CLC_GENTYPE b);
13+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL __CLC_SCALAR_GENTYPE
14+
FUNCTION(__CLC_GENTYPE a, __CLC_GENTYPE b);
1515

1616
#endif

libclc/clc/include/clc/geometric/clc_cross.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111

1212
#include <clc/internal/clc.h>
1313

14-
_CLC_OVERLOAD _CLC_DECL float3 __clc_cross(float3 p0, float3 p1);
15-
_CLC_OVERLOAD _CLC_DECL float4 __clc_cross(float4 p0, float4 p1);
14+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL float3 __clc_cross(float3 p0, float3 p1);
15+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL float4 __clc_cross(float4 p0, float4 p1);
1616

1717
#ifdef cl_khr_fp64
1818
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
1919

20-
_CLC_OVERLOAD _CLC_DECL double3 __clc_cross(double3 p0, double3 p1);
21-
_CLC_OVERLOAD _CLC_DECL double4 __clc_cross(double4 p0, double4 p1);
20+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL double3 __clc_cross(double3 p0, double3 p1);
21+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL double4 __clc_cross(double4 p0, double4 p1);
2222

2323
#endif
2424

2525
#ifdef cl_khr_fp16
2626
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
2727

28-
_CLC_OVERLOAD _CLC_DECL half3 __clc_cross(half3 p0, half3 p1);
29-
_CLC_OVERLOAD _CLC_DECL half4 __clc_cross(half4 p0, half4 p1);
28+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL half3 __clc_cross(half3 p0, half3 p1);
29+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL half4 __clc_cross(half4 p0, half4 p1);
3030

3131
#endif
3232

libclc/clc/include/clc/geometric/unary_decl.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#if (__CLC_VECSIZE_OR_1 == 1 || __CLC_VECSIZE_OR_1 == 2 || \
1111
__CLC_VECSIZE_OR_1 == 3 || __CLC_VECSIZE_OR_1 == 4)
1212

13-
_CLC_OVERLOAD _CLC_DECL
13+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL
1414
#ifdef __CLC_GEOMETRIC_RET_GENTYPE
1515
__CLC_GENTYPE
1616
#else

libclc/clc/include/clc/integer/clc_abs.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x);
9+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x);

libclc/clc/include/clc/integer/clc_abs_diff.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL __CLC_U_GENTYPE __clc_abs_diff(__CLC_GENTYPE x,
10-
__CLC_GENTYPE y);
9+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL __CLC_U_GENTYPE
10+
__clc_abs_diff(__CLC_GENTYPE x, __CLC_GENTYPE y);

libclc/clc/include/clc/integer/clc_bitfield_extract_decl.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL __RETTYPE FUNCTION(__CLC_GENTYPE base, uint offset,
10-
uint count);
9+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL __RETTYPE FUNCTION(__CLC_GENTYPE base,
10+
uint offset, uint count);

libclc/clc/include/clc/integer/clc_bitfield_insert.inc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE FUNCTION(__CLC_GENTYPE base,
10-
__CLC_GENTYPE insert,
11-
uint offset, uint count);
9+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL __CLC_GENTYPE FUNCTION(__CLC_GENTYPE base,
10+
__CLC_GENTYPE insert,
11+
uint offset,
12+
uint count);

libclc/clc/include/clc/math/binary_decl_with_scalar_second_arg.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE FUNCTION(__CLC_GENTYPE a,
10-
__CLC_GENTYPE b);
11-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE FUNCTION(__CLC_GENTYPE a,
12-
__CLC_SCALAR_GENTYPE b);
9+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL __CLC_GENTYPE FUNCTION(__CLC_GENTYPE a,
10+
__CLC_GENTYPE b);
11+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL __CLC_GENTYPE
12+
FUNCTION(__CLC_GENTYPE a, __CLC_SCALAR_GENTYPE b);

0 commit comments

Comments
 (0)