Skip to content

Commit 809d279

Browse files
committed
integrate libclang_rt.builtins into sycl compiler driver
Signed-off-by: jinge90 <ge.jin@intel.com>
1 parent d15bb64 commit 809d279

File tree

12 files changed

+34
-248
lines changed

12 files changed

+34
-248
lines changed

buildbot/configure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,18 @@ def do_configure(args, passthrough_args):
215215

216216
if sys.platform == "linux":
217217
if args.ci_defaults:
218-
llvm_builtin_targets = "default;spirv64-intel-sycl"
218+
llvm_builtin_targets = "default;spirv64-intel-unknown"
219219
cmake_cmd.extend(
220220
[
221221
"-DLLVM_BUILTIN_TARGETS={}".format(llvm_builtin_targets),
222222
]
223223
)
224224
else:
225-
llvm_runtime_targets = "spirv64-intel-sycl"
225+
llvm_runtime_targets = "spirv64-intel-unknown"
226226
llvm_spirv64_runtimes = "compiler-rt"
227227
cmake_cmd.extend(
228228
[
229-
"-DRUNTIMES_spirv64-intel-sycl_LLVM_ENABLE_RUNTIMES={}".format(
229+
"-DRUNTIMES_spirv64-intel-unknown_LLVM_ENABLE_RUNTIMES={}".format(
230230
llvm_spirv64_runtimes
231231
),
232232
"-DLLVM_RUNTIME_TARGETS={}".format(llvm_runtime_targets),

clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5826,6 +5826,13 @@ class OffloadingActionBuilder final {
58265826
int NumOfDeviceLibLinked = 0;
58275827
SmallVector<SmallString<128>, 4> LibLocCandidates;
58285828
SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates);
5829+
if (TC->getTriple().isSPIROrSPIRV()) {
5830+
std::string CompilerRTPath = TC->getCompilerRTPath();
5831+
SmallString<128> SPIRVCompilerRTPath(CompilerRTPath);
5832+
llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-intel-unknown");
5833+
if (llvm::sys::fs::exists(SPIRVCompilerRTPath))
5834+
LibLocCandidates.emplace_back(SPIRVCompilerRTPath);
5835+
}
58295836

58305837
const toolchains::SYCLToolChain &SYCLTC =
58315838
static_cast<const toolchains::SYCLToolChain &>(*TC);

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ SYCLToolChain::getDeviceLibNames(const Driver &D,
597597
"libsycl-fallback-complex-fp64",
598598
"libsycl-fallback-cmath",
599599
"libsycl-fallback-cmath-fp64",
600+
#if !defined(_WIN32)
601+
"libclang_rt.builtins",
602+
#endif
600603
"libsycl-fallback-imf",
601604
"libsycl-fallback-imf-fp64",
602605
"libsycl-fallback-imf-bf16"};
@@ -833,6 +836,8 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
833836
InputFilename.contains("libspirv") ||
834837
InputFilename.contains("libdevice")))
835838
return true;
839+
if (InputFilename.starts_with("libclang_rt.builtins"))
840+
return true;
836841
StringRef LibSyclPrefix("libsycl-");
837842
if (!InputFilename.starts_with(LibSyclPrefix) ||
838843
!InputFilename.ends_with(LibPostfix) ||
@@ -1920,7 +1925,13 @@ SYCLToolChain::getDeviceLibs(
19201925

19211926
SmallVector<SmallString<128>, 4> LibraryPaths;
19221927
SYCLInstallation.getSYCLDeviceLibPath(LibraryPaths);
1923-
1928+
if (getTriple().isSPIROrSPIRV()) {
1929+
std::string CompilerRTPath = getCompilerRTPath();
1930+
SmallString<128> SPIRVCompilerRTPath(CompilerRTPath);
1931+
llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-intel-unknown");
1932+
if (llvm::sys::fs::exists(SPIRVCompilerRTPath))
1933+
LibraryPaths.emplace_back(SPIRVCompilerRTPath);
1934+
}
19241935
// Formulate all of the device libraries needed for this compilation.
19251936
SmallVector<BitCodeLibraryInfo, 8> DeviceLibs =
19261937
getDeviceLibNames(getDriver(), DriverArgs, getTriple());

compiler-rt/cmake/Modules/CompilerRTUtils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ function(get_compiler_rt_target arch variable)
513513
elseif("${arch}" MATCHES "^nvptx")
514514
set(target "nvptx64-nvidia-cuda")
515515
elseif("${arch}" MATCHES "^spirv64")
516-
set(target "spirv64-intel-sycl")
516+
set(target "spirv64-intel-unknown")
517517
else()
518518
set(target "${arch}${triple_suffix}")
519519
endif()

compiler-rt/lib/builtins/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ else ()
10551055
list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128)
10561056
endif()
10571057

1058-
if("${LLVM_BUILTINS_TARGET}" MATCHES "sycl")
1058+
if("${LLVM_BUILTINS_TARGET}" MATCHES "spirv64")
10591059
add_compiler_rt_runtime(clang_rt.builtins
10601060
STATIC
10611061
ARCHS ${arch}

libdevice/complex_wrapper.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,4 @@ float __complex__ catanhf(float __complex__ z) {
8686
DEVICE_EXTERN_C_INLINE
8787
float __complex__ catanf(float __complex__ z) { return __devicelib_catanf(z); }
8888

89-
// __mulsc3
90-
// Returns: the product of a + ib and c + id
91-
DEVICE_EXTERN_C_INLINE
92-
float __complex__ __mulsc3(float __a, float __b, float __c, float __d) {
93-
return __devicelib___mulsc3(__a, __b, __c, __d);
94-
}
95-
96-
// __divsc3
97-
// Returns: the quotient of (a + ib) / (c + id)
98-
DEVICE_EXTERN_C_INLINE
99-
float __complex__ __divsc3(float __a, float __b, float __c, float __d) {
100-
return __devicelib___divsc3(__a, __b, __c, __d);
101-
}
10289
#endif // __SPIR__ || __SPIRV__

libdevice/complex_wrapper_fp64.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,4 @@ double __complex__ catanh(double __complex__ z) {
8787
DEVICE_EXTERN_C_INLINE
8888
double __complex__ catan(double __complex__ z) { return __devicelib_catan(z); }
8989

90-
// __muldc3
91-
// Returns: the product of a + ib and c + id
92-
DEVICE_EXTERN_C_INLINE
93-
double __complex__ __muldc3(double __a, double __b, double __c, double __d) {
94-
return __devicelib___muldc3(__a, __b, __c, __d);
95-
}
96-
97-
// __divdc3
98-
// Returns: the quotient of (a + ib) / (c + id)
99-
DEVICE_EXTERN_C_INLINE
100-
double __complex__ __divdc3(double __a, double __b, double __c, double __d) {
101-
return __devicelib___divdc3(__a, __b, __c, __d);
102-
}
10390
#endif // __SPIR__ || __SPIRV__

libdevice/device_complex.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,5 @@ double __complex__ __devicelib_catan(double __complex__ z);
153153

154154
DEVICE_EXTERN_C
155155
float __complex__ __devicelib_catanf(float __complex__ z);
156-
157-
DEVICE_EXTERN_C
158-
double __complex__ __devicelib___muldc3(double a, double b, double c, double d);
159-
160-
DEVICE_EXTERN_C
161-
float __complex__ __devicelib___mulsc3(float a, float b, float c, float d);
162-
163-
DEVICE_EXTERN_C
164-
double __complex__ __devicelib___divdc3(double a, double b, double c, double d);
165-
166-
DEVICE_EXTERN_C
167-
float __complex__ __devicelib___divsc3(float a, float b, float c, float d);
168156
#endif // __SPIR__ || __SPIRV__
169157
#endif // __LIBDEVICE_DEVICE_COMPLEX_H_

libdevice/fallback-complex-fp64.cpp

Lines changed: 3 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -21,102 +21,6 @@ double __devicelib_creal(double __complex__ z) { return __real__(z); }
2121
DEVICE_EXTERN_C_INLINE
2222
double __devicelib_cimag(double __complex__ z) { return __imag__(z); }
2323

24-
// __muldc3
25-
// Returns: the product of a + ib and c + id
26-
DEVICE_EXTERN_C_INLINE
27-
double __complex__ __devicelib___muldc3(double __a, double __b, double __c,
28-
double __d) {
29-
double __ac = __a * __c;
30-
double __bd = __b * __d;
31-
double __ad = __a * __d;
32-
double __bc = __b * __c;
33-
double __complex__ z;
34-
z = CMPLX((__ac - __bd), (__ad + __bc));
35-
if (__spirv_IsNan(__devicelib_creal(z)) &&
36-
__spirv_IsNan(__devicelib_cimag(z))) {
37-
int __recalc = 0;
38-
if (__spirv_IsInf(__a) || __spirv_IsInf(__b)) {
39-
__a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0 : 0.0, __a);
40-
__b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0 : 0.0, __b);
41-
if (__spirv_IsNan(__c))
42-
__c = __spirv_ocl_copysign(0.0, __c);
43-
if (__spirv_IsNan(__d))
44-
__d = __spirv_ocl_copysign(0.0, __d);
45-
__recalc = 1;
46-
}
47-
if (__spirv_IsInf(__c) || __spirv_IsInf(__d)) {
48-
__c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0 : 0.0, __c);
49-
__d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0 : 0.0, __d);
50-
if (__spirv_IsNan(__a))
51-
__a = __spirv_ocl_copysign(0.0, __a);
52-
if (__spirv_IsNan(__b))
53-
__b = __spirv_ocl_copysign(0.0, __b);
54-
__recalc = 1;
55-
}
56-
if (!__recalc && (__spirv_IsInf(__ac) || __spirv_IsInf(__bd) ||
57-
__spirv_IsInf(__ad) || __spirv_IsInf(__bc))) {
58-
if (__spirv_IsNan(__a))
59-
__a = __spirv_ocl_copysign(0.0, __a);
60-
if (__spirv_IsNan(__b))
61-
__b = __spirv_ocl_copysign(0.0, __b);
62-
if (__spirv_IsNan(__c))
63-
__c = __spirv_ocl_copysign(0.0, __c);
64-
if (__spirv_IsNan(__d))
65-
__d = __spirv_ocl_copysign(0.0, __d);
66-
__recalc = 1.0;
67-
}
68-
if (__recalc) {
69-
z = CMPLX((INFINITY * (__a * __c - __b * __d)),
70-
(INFINITY * (__a * __d + __b * __c)));
71-
}
72-
}
73-
return z;
74-
}
75-
76-
// __divdc3
77-
// Returns: the quotient of (a + ib) / (c + id)
78-
DEVICE_EXTERN_C_INLINE
79-
double __complex__ __devicelib___divdc3(double __a, double __b, double __c,
80-
double __d) {
81-
int __ilogbw = 0;
82-
double __logbw = __spirv_ocl_logb(
83-
__spirv_ocl_fmax(__spirv_ocl_fabs(__c), __spirv_ocl_fabs(__d)));
84-
if (__spirv_IsFinite(__logbw)) {
85-
__ilogbw = (int)__logbw;
86-
__c = __spirv_ocl_ldexp(__c, -__ilogbw);
87-
__d = __spirv_ocl_ldexp(__d, -__ilogbw);
88-
}
89-
double __denom = __c * __c + __d * __d;
90-
double __complex__ z;
91-
double z_real =
92-
__spirv_ocl_ldexp((__a * __c + __b * __d) / __denom, -__ilogbw);
93-
double z_imag =
94-
__spirv_ocl_ldexp((__b * __c - __a * __d) / __denom, -__ilogbw);
95-
z = CMPLX(z_real, z_imag);
96-
if (__spirv_IsNan(z_real) && __spirv_IsNan(z_imag)) {
97-
if ((__denom == 0.0) && (!__spirv_IsNan(__a) || !__spirv_IsNan(__b))) {
98-
z_real = __spirv_ocl_copysign((double)INFINITY, __c) * __a;
99-
z_imag = __spirv_ocl_copysign((double)INFINITY, __c) * __b;
100-
z = CMPLX(z_real, z_imag);
101-
} else if ((__spirv_IsInf(__a) || __spirv_IsInf(__b)) &&
102-
__spirv_IsFinite(__c) && __spirv_IsFinite(__d)) {
103-
__a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0 : 0.0, __a);
104-
__b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0 : 0.0, __b);
105-
z_real = INFINITY * (__a * __c + __b * __d);
106-
z_imag = INFINITY * (__b * __c - __a * __d);
107-
z = CMPLX(z_real, z_imag);
108-
} else if (__spirv_IsInf(__logbw) && __logbw > 0.0 &&
109-
__spirv_IsFinite(__a) && __spirv_IsFinite(__b)) {
110-
__c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0 : 0.0, __c);
111-
__d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0 : 0.0, __d);
112-
z_real = 0.0 * (__a * __c + __b * __d);
113-
z_imag = 0.0 * (__b * __c - __a * __d);
114-
z = CMPLX(z_real, z_imag);
115-
}
116-
}
117-
return z;
118-
}
119-
12024
DEVICE_EXTERN_C_INLINE
12125
double __devicelib_cabs(double __complex__ z) {
12226
return __spirv_ocl_hypot(__devicelib_creal(z), __devicelib_cimag(z));
@@ -178,7 +82,7 @@ double __complex__ __devicelib_cpow(double __complex__ x,
17882
double __complex__ y) {
17983
double __complex__ t = __devicelib_clog(x);
18084
double __complex__ w =
181-
__devicelib___muldc3(__devicelib_creal(y), __devicelib_cimag(y),
85+
__muldc3(__devicelib_creal(y), __devicelib_cimag(y),
18286
__devicelib_creal(t), __devicelib_cimag(t));
18387
return __devicelib_cexp(w);
18488
}
@@ -426,8 +330,8 @@ double __complex__ __devicelib_catanh(double __complex__ z) {
426330
__spirv_ocl_copysign(0.0, z_imag));
427331
double __complex__ t1 = 1.0 + z;
428332
double __complex__ t2 = 1.0 - z;
429-
double __complex__ t3 =
430-
__devicelib___divdc3(__devicelib_creal(t1), __devicelib_cimag(t1),
333+
double __complex__ t3 =
334+
__divdc3(__devicelib_creal(t1), __devicelib_cimag(t1),
431335
__devicelib_creal(t2), __devicelib_cimag(t2));
432336
double __complex__ w = __devicelib_clog(t3) / 2.0;
433337
return CMPLX(__spirv_ocl_copysign(__devicelib_creal(w), z_real),

libdevice/fallback-complex.cpp

Lines changed: 2 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -20,104 +20,6 @@ float __devicelib_crealf(float __complex__ z) { return __real__(z); }
2020
DEVICE_EXTERN_C_INLINE
2121
float __devicelib_cimagf(float __complex__ z) { return __imag__(z); }
2222

23-
// __mulsc3
24-
// Returns: the product of a + ib and c + id
25-
DEVICE_EXTERN_C_INLINE
26-
float __complex__ __devicelib___mulsc3(float __a, float __b, float __c,
27-
float __d) {
28-
float __ac = __a * __c;
29-
float __bd = __b * __d;
30-
float __ad = __a * __d;
31-
float __bc = __b * __c;
32-
float __complex__ z;
33-
z = CMPLXF((__ac - __bd), (__ad + __bc));
34-
if (__spirv_IsNan(__devicelib_crealf(z)) &&
35-
__spirv_IsNan(__devicelib_cimagf(z))) {
36-
int __recalc = 0;
37-
if (__spirv_IsInf(__a) || __spirv_IsInf(__b)) {
38-
__a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0f : 0.0f, __a);
39-
__b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0f : 0.0f, __b);
40-
if (__spirv_IsNan(__c))
41-
__c = __spirv_ocl_copysign(0.0f, __c);
42-
if (__spirv_IsNan(__d))
43-
__d = __spirv_ocl_copysign(0.0f, __d);
44-
__recalc = 1;
45-
}
46-
if (__spirv_IsInf(__c) || __spirv_IsInf(__d)) {
47-
__c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0f : 0.0f, __c);
48-
__d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0f : 0.0f, __d);
49-
if (__spirv_IsNan(__a))
50-
__a = __spirv_ocl_copysign(0.0f, __a);
51-
if (__spirv_IsNan(__b))
52-
__b = __spirv_ocl_copysign(0.0f, __b);
53-
__recalc = 1;
54-
}
55-
if (!__recalc && (__spirv_IsInf(__ac) || __spirv_IsInf(__bd) ||
56-
__spirv_IsInf(__ad) || __spirv_IsInf(__bc))) {
57-
if (__spirv_IsNan(__a))
58-
__a = __spirv_ocl_copysign(0.0f, __a);
59-
if (__spirv_IsNan(__b))
60-
__b = __spirv_ocl_copysign(0.0f, __b);
61-
if (__spirv_IsNan(__c))
62-
__c = __spirv_ocl_copysign(0.0f, __c);
63-
if (__spirv_IsNan(__d))
64-
__d = __spirv_ocl_copysign(0.0f, __d);
65-
__recalc = 1.0f;
66-
}
67-
if (__recalc) {
68-
z = CMPLXF((INFINITY * (__a * __c - __b * __d)),
69-
(INFINITY * (__a * __d + __b * __c)));
70-
}
71-
}
72-
return z;
73-
}
74-
75-
// __divsc3
76-
// Returns: the quotient of (a + ib) / (c + id)
77-
// FIXME: divsc3/divdc3 have overflow issue when dealing with large number.
78-
// And this overflow issue is from libc++/compiler-rt's implementation.
79-
DEVICE_EXTERN_C_INLINE
80-
float __complex__ __devicelib___divsc3(float __a, float __b, float __c,
81-
float __d) {
82-
int __ilogbw = 0;
83-
float __logbw = __spirv_ocl_logb(
84-
__spirv_ocl_fmax(__spirv_ocl_fabs(__c), __spirv_ocl_fabs(__d)));
85-
if (__spirv_IsFinite(__logbw)) {
86-
__ilogbw = (int)__logbw;
87-
__c = __spirv_ocl_ldexp(__c, -__ilogbw);
88-
__d = __spirv_ocl_ldexp(__d, -__ilogbw);
89-
}
90-
float __denom = __c * __c + __d * __d;
91-
float __complex__ z;
92-
float z_real =
93-
__spirv_ocl_ldexp((__a * __c + __b * __d) / __denom, -__ilogbw);
94-
float z_imag =
95-
__spirv_ocl_ldexp((__b * __c - __a * __d) / __denom, -__ilogbw);
96-
z = CMPLXF(z_real, z_imag);
97-
if (__spirv_IsNan(z_real) && __spirv_IsNan(z_imag)) {
98-
if ((__denom == 0.0f) && (!__spirv_IsNan(__a) || !__spirv_IsNan(__b))) {
99-
z_real = __spirv_ocl_copysign(INFINITY, __c) * __a;
100-
z_imag = __spirv_ocl_copysign(INFINITY, __c) * __b;
101-
z = CMPLXF(z_real, z_imag);
102-
} else if ((__spirv_IsInf(__a) || __spirv_IsInf(__b)) &&
103-
__spirv_IsFinite(__c) && __spirv_IsFinite(__d)) {
104-
__a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0f : 0.0f, __a);
105-
__b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0f : 0.0f, __b);
106-
z_real = INFINITY * (__a * __c + __b * __d);
107-
z_imag = INFINITY * (__b * __c - __a * __d);
108-
z = CMPLXF(z_real, z_imag);
109-
} else if (__spirv_IsInf(__logbw) && __logbw > 0.0f &&
110-
__spirv_IsFinite(__a) && __spirv_IsFinite(__b)) {
111-
__c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0f : 0.0f, __c);
112-
__d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0f : 0.0f, __d);
113-
z_real = 0.0f * (__a * __c + __b * __d);
114-
z_imag = 0.0f * (__b * __c - __a * __d);
115-
z = CMPLXF(z_real, z_imag);
116-
}
117-
}
118-
return z;
119-
}
120-
12123
DEVICE_EXTERN_C_INLINE
12224
float __devicelib_cargf(float __complex__ z) {
12325
return __spirv_ocl_atan2(__devicelib_cimagf(z), __devicelib_crealf(z));
@@ -170,7 +72,7 @@ DEVICE_EXTERN_C_INLINE
17072
float __complex__ __devicelib_cpowf(float __complex__ x, float __complex__ y) {
17173
float __complex__ t = __devicelib_clogf(x);
17274
float __complex__ w =
173-
__devicelib___mulsc3(__devicelib_crealf(y), __devicelib_cimagf(y),
75+
__mulsc3(__devicelib_crealf(y), __devicelib_cimagf(y),
17476
__devicelib_crealf(t), __devicelib_cimagf(t));
17577
return __devicelib_cexpf(w);
17678
}
@@ -421,7 +323,7 @@ float __complex__ __devicelib_catanhf(float __complex__ z) {
421323
float __complex__ t1 = 1.0f + z;
422324
float __complex__ t2 = 1.0f - z;
423325
float __complex__ t3 =
424-
__devicelib___divsc3(__devicelib_crealf(t1), __devicelib_cimagf(t1),
326+
__divsc3(__devicelib_crealf(t1), __devicelib_cimagf(t1),
425327
__devicelib_crealf(t2), __devicelib_cimagf(t2));
426328
float __complex__ w = __devicelib_clogf(t3) / 2.0f;
427329
return CMPLXF(__spirv_ocl_copysign(__devicelib_crealf(w), z_real),

0 commit comments

Comments
 (0)