Skip to content

Commit 9042d23

Browse files
committed
[SYCL] Fix formatting
1 parent 9318194 commit 9042d23

File tree

2 files changed

+39
-46
lines changed

2 files changed

+39
-46
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4414,41 +4414,40 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
44144414
}
44154415
}
44164416

4417-
44184417
// When using SYCLDeviceOnlyAttr, there can be two functions with the same
44194418
// mangling, the host function and the device overload. So when compiling for
44204419
// device we need to make sure we're selecting the SYCLDeviceOnlyAttr
44214420
// overload and dropping the host overload.
44224421
if (LangOpts.SYCLIsDevice) {
4423-
StringRef MangledName = getMangledName(GD);
4424-
auto DDI = DeferredDecls.find(MangledName);
4425-
// If we have an existing declaration with the same mangling for this
4426-
// symbol it may be a SYCLDeviceOnlyAttr case.
4427-
if (DDI != DeferredDecls.end()) {
4428-
auto *G = cast<ValueDecl>(DeferredDecls[MangledName].getDecl());
4429-
4430-
if (!G->hasAttr<SYCLDeviceOnlyAttr>() &&
4431-
Global->hasAttr<SYCLDeviceOnlyAttr>() &&
4432-
Global->hasAttr<SYCLDeviceAttr>()) {
4433-
// If the host declaration was already processed and the device only
4434-
// declaration is also a sycl external declaration, remove the host
4435-
// variant and skip. The device only variant will be generated later
4436-
// as it's marked sycl external.
4437-
DeferredDecls.erase(DDI);
4438-
return;
4439-
} else if (!G->hasAttr<SYCLDeviceOnlyAttr>() &&
4440-
Global->hasAttr<SYCLDeviceOnlyAttr>()) {
4441-
// If the host declaration was already processed, replace it with the
4442-
// device only declaration.
4443-
DeferredDecls[MangledName] = GD;
4444-
return;
4445-
} else if (!Global->hasAttr<SYCLDeviceOnlyAttr>() &&
4446-
G->hasAttr<SYCLDeviceOnlyAttr>()) {
4447-
// If the device only declaration was already processed, skip the
4448-
// host declaration.
4449-
return;
4450-
}
4422+
StringRef MangledName = getMangledName(GD);
4423+
auto DDI = DeferredDecls.find(MangledName);
4424+
// If we have an existing declaration with the same mangling for this
4425+
// symbol it may be a SYCLDeviceOnlyAttr case.
4426+
if (DDI != DeferredDecls.end()) {
4427+
auto *G = cast<ValueDecl>(DeferredDecls[MangledName].getDecl());
4428+
4429+
if (!G->hasAttr<SYCLDeviceOnlyAttr>() &&
4430+
Global->hasAttr<SYCLDeviceOnlyAttr>() &&
4431+
Global->hasAttr<SYCLDeviceAttr>()) {
4432+
// If the host declaration was already processed and the device only
4433+
// declaration is also a sycl external declaration, remove the host
4434+
// variant and skip. The device only variant will be generated later
4435+
// as it's marked sycl external.
4436+
DeferredDecls.erase(DDI);
4437+
return;
4438+
} else if (!G->hasAttr<SYCLDeviceOnlyAttr>() &&
4439+
Global->hasAttr<SYCLDeviceOnlyAttr>()) {
4440+
// If the host declaration was already processed, replace it with the
4441+
// device only declaration.
4442+
DeferredDecls[MangledName] = GD;
4443+
return;
4444+
} else if (!Global->hasAttr<SYCLDeviceOnlyAttr>() &&
4445+
G->hasAttr<SYCLDeviceOnlyAttr>()) {
4446+
// If the device only declaration was already processed, skip the
4447+
// host declaration.
4448+
return;
44514449
}
4450+
}
44524451
}
44534452

44544453
// clang::ParseAST ensures that we emit the SYCL devices at the end, so

clang/test/CodeGenSYCL/sycl-device-only.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ int foo(int a) { return a + 10; }
1111
__attribute__((sycl_device_only)) int foo(int a) { return a + 20; }
1212

1313
// Use a `sycl_device` function as entry point
14-
__attribute__((sycl_device)) int bar(int b) {
15-
return foo(b);
16-
}
14+
__attribute__((sycl_device)) int bar(int b) { return foo(b); }
1715

1816
// Verify that the order of declaration doesn't change the behavior.
1917
//
@@ -24,9 +22,7 @@ __attribute__((sycl_device_only)) int fooswap(int a) { return a + 20; }
2422
int fooswap(int a) { return a + 10; }
2523

2624
// Use a `sycl_device` function as entry point
27-
__attribute__((sycl_device)) int barswap(int b) {
28-
return fooswap(b);
29-
}
25+
__attribute__((sycl_device)) int barswap(int b) { return fooswap(b); }
3026

3127
// Verify that in extern C the attribute enables mangling.
3228
extern "C" {
@@ -37,30 +33,28 @@ int fooc(int a) { return a + 10; }
3733
__attribute__((sycl_device_only)) int fooc(int a) { return a + 20; }
3834

3935
// Use a `sycl_device` function as entry point
40-
__attribute__((sycl_device)) int barc(int b) {
41-
return fooc(b);
42-
}
36+
__attribute__((sycl_device)) int barc(int b) { return fooc(b); }
4337
}
4438

4539
// Check that both attributes can work together
4640
// CHECK-LABEL: _Z3fooai
4741
// CHECKH: %add = add nsw i32 %0, 10
4842
// CHECKD: %add = add nsw i32 %0, 20
4943
int fooa(int a) { return a + 10; }
50-
__attribute__((sycl_device_only, sycl_device)) int fooa(int a) { return a + 20; }
44+
__attribute__((sycl_device_only, sycl_device)) int fooa(int a) {
45+
return a + 20;
46+
}
5147

5248
// Use a `sycl_device` function as entry point
53-
__attribute__((sycl_device)) int bara(int b) {
54-
return fooa(b);
55-
}
49+
__attribute__((sycl_device)) int bara(int b) { return fooa(b); }
5650

5751
// CHECK-LABEL: _Z3fooaswapi
5852
// CHECKH: %add = add nsw i32 %0, 10
5953
// CHECKD: %add = add nsw i32 %0, 20
60-
__attribute__((sycl_device_only, sycl_device)) int fooaswap(int a) { return a + 20; }
54+
__attribute__((sycl_device_only, sycl_device)) int fooaswap(int a) {
55+
return a + 20;
56+
}
6157
int fooaswap(int a) { return a + 10; }
6258

6359
// Use a `sycl_device` function as entry point
64-
__attribute__((sycl_device)) int baraswap(int b) {
65-
return fooaswap(b);
66-
}
60+
__attribute__((sycl_device)) int baraswap(int b) { return fooaswap(b); }

0 commit comments

Comments
 (0)