Skip to content

Commit ac8329c

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web'
2 parents 6e65d17 + ab6cc47 commit ac8329c

22 files changed

+438
-47
lines changed

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ jobs:
5757

5858
# Upload the results to GitHub's code scanning dashboard.
5959
- name: "Upload to code-scanning"
60-
uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
60+
uses: github/codeql-action/upload-sarif@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
6161
with:
6262
sarif_file: results.sarif
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Ping issue assignees
2+
# We have some specific pool of the issues we would like to handle. Sometimes
3+
# the issue from this pool has an assignee, but doesn't get any updates for a
4+
# long time. In this case it'd be useful to periodically ping the assignee.
5+
6+
# Note: may be we could use "actions/stale@v*", but I'm not sure if it's
7+
# possible to not set the "stale" label at all. Even so, this action will not
8+
# ping the assignee of the "stale" issue more than onсe.
9+
10+
# Note2: probably it'd be useful to have a small doc describing this "specific
11+
# pool" to refer to.
12+
13+
on:
14+
schedule:
15+
- cron: '0 0 * * *'
16+
17+
jobs:
18+
run:
19+
runs-on: ubuntu-20.04
20+
env:
21+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
REPO: ${{ github.repository }}
23+
steps:
24+
# List specific issues with an assignee but without recent updates.
25+
# Note: for some reason gh returns 0 results if the "assignee:*" filter is
26+
# added, so we have to manually filter the results.
27+
- name: Get the specicifc list of issues
28+
run: |
29+
gh issue list --search '-label:"help wanted" -label:cuda \
30+
-label:confirmed -label:hip -label:sycl-mlir -label:upstream is:open \
31+
-label:genx -label:sycl-bindless-images -label:sycl-graph \
32+
-label:native-cpu' --limit 200 --json assignees --json number \
33+
--json updatedAt \
34+
-R https://github.com/${{ env.REPO }}.git > issues.json
35+
36+
- name: Filter issues and ping
37+
run: |
38+
days_to_stale=60
39+
current_time=$(date +%s)
40+
41+
cat issues.json | jq -c '.[]' | while read -r issue; do
42+
assignees=$(echo "$issue" | jq '.assignees | length')
43+
[ "$assignees" -eq 0 ] && continue
44+
45+
updated_at=$(echo "$issue" | jq -r '.updatedAt')
46+
updated_at_seconds=$(date -d "$updated_at" +%s)
47+
difference_days=$(( (current_time - updated_at_seconds) / 86400 ))
48+
[ "$difference_days" -lt $days_to_stale ] && continue
49+
50+
issue_number=$(echo "$issue" | jq '.number')
51+
assignee_logins=$(echo "$issue" | jq -r '.assignees[].login' | sed 's/^/@/' | paste -s -d ' ' -)
52+
comment_body="Hi! There have been no updates for at least the last $days_to_stale days, though the issue has assignee(s).
53+
54+
$assignee_logins, could you please take one of the following actions:
55+
- provide an update if you have any
56+
- unassign yourself if you're not looking / going to look into this issue
57+
- mark this issue with the 'confirmed' label if you have confirmed the problem/request and our team should work on it
58+
- close the issue if it has been resolved
59+
- take any other suitable action.
60+
61+
Thanks!"
62+
63+
gh issue comment $issue_number -R https://github.com/${{ env.REPO }}.git -b "$comment_body" >> $GITHUB_STEP_SUMMARY
64+
done

clang/lib/CodeGen/CGVTT.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
9090
llvm::Constant *Init = llvm::ConstantExpr::getGetElementPtr(
9191
VTable->getValueType(), VTable, Idxs, /*InBounds=*/true, InRange);
9292

93+
if (CGM.getTriple().isSPIR())
94+
Init = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
95+
Init, CGM.DefaultInt8PtrTy);
96+
9397
VTTComponents.push_back(Init);
9498
}
9599

clang/lib/CodeGen/CGVTables.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,19 @@ void CodeGenVTables::addVTableComponent(ConstantArrayBuilder &builder,
770770
// Method is acceptable, continue processing as usual.
771771
}
772772

773+
if (CGM.getLangOpts().SYCLIsDevice) {
774+
// Some virtual function may be only valid in host code. Don't emit
775+
// virtual functions which were not specifically marked as device code.
776+
const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
777+
// FIXME: Update check to use compile-time property instead of
778+
// SYCLDeviceIndirectlyCallableAttr once Virtual function extension
779+
// specification is accepted.
780+
if (!MD->hasAttr<SYCLDeviceIndirectlyCallableAttr>() &&
781+
!MD->hasAttr<SYCLDeviceAttr>())
782+
return builder.add(
783+
llvm::ConstantExpr::getNullValue(CGM.DefaultInt8PtrTy));
784+
}
785+
773786
auto getSpecialVirtualFn = [&](StringRef name) -> llvm::Constant * {
774787
// FIXME(PR43094): When merging comdat groups, lld can select a local
775788
// symbol as the signature symbol even though it cannot be accessed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,17 @@ CodeGenModule::CodeGenModule(ASTContext &C,
393393
LLVMContext, C.getTargetAddressSpace(GetGlobalConstantAddressSpace()));
394394
ASTAllocaAddressSpace = getTargetCodeGenInfo().getASTAllocaAddressSpace();
395395

396+
if (getTriple().isSPIR()) {
397+
// Currently code uses GlobalsInt8PtrTy for virtual table elements but for
398+
// SPIR-V targets default address space pointers are needed.
399+
GlobalsInt8PtrTy = DefaultInt8PtrTy;
400+
// Pointer to runtime globals such as virtual tables.
401+
RuntimeGlobalsInt8PtrTy = Int8Ty->getPointerTo(
402+
getContext().getTargetAddressSpace(LangAS::opencl_global));
403+
} else {
404+
RuntimeGlobalsInt8PtrTy = GlobalsInt8PtrTy;
405+
}
406+
396407
// Build C++20 Module initializers.
397408
// TODO: Add Microsoft here once we know the mangling required for the
398409
// initializers.
@@ -5537,8 +5548,10 @@ llvm::GlobalVariable *CodeGenModule::CreateOrReplaceCXXRuntimeVariable(
55375548
}
55385549

55395550
// Create a new variable.
5540-
GV = new llvm::GlobalVariable(getModule(), Ty, /*isConstant=*/true,
5541-
Linkage, nullptr, Name);
5551+
GV = new llvm::GlobalVariable(getModule(), Ty, /*isConstant=*/true, Linkage,
5552+
nullptr, Name, nullptr,
5553+
llvm::GlobalValue::NotThreadLocal,
5554+
RuntimeGlobalsInt8PtrTy->getAddressSpace());
55425555

55435556
if (OldGV) {
55445557
// Replace occurrences of the old variable if needed.

clang/lib/CodeGen/CodeGenTypeCache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ struct CodeGenTypeCache {
6969
/// void* in target address space
7070
llvm::PointerType *DefaultInt8PtrTy;
7171

72+
/// void* used for virtual table globals.
73+
llvm::PointerType *RuntimeGlobalsInt8PtrTy;
74+
7275
/// void* in default globals address space
7376
union {
7477
llvm::PointerType *GlobalsVoidPtrTy;

clang/test/CodeGenSYCL/simple-sycl-virtual-function.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
// Test verifying that RTTI information is not emitted during SYCL device compilation.
1+
// Test verifies the following
2+
// 1. RTTI information is not emitted during SYCL device compilation.
3+
// 2. Virtual table elements are generated in AS4.
4+
// 3. Runtime Global Variables are generated in AS1.
25

36
// RUN: %clang_cc1 -triple spir64 -fsycl-allow-virtual-functions -fsycl-is-device -emit-llvm %s -o - | FileCheck %s --implicit-check-not _ZTI4Base --implicit-check-not _ZTI8Derived1 -check-prefix VTABLE
4-
// RUN: %clang_cc1 -triple spir64 -fsycl-allow-virtual-functions -fsycl-is-device -fexperimental-relative-c++-abi-vtables -emit-llvm %s -o - | FileCheck %s --implicit-check-not _ZTI4Base --implicit-check-not _ZTI8Derived1
7+
// RUNx: %clang_cc1 -triple spir64 -fsycl-allow-virtual-functions -fsycl-is-device -fexperimental-relative-c++-abi-vtables -emit-llvm %s -o - | FileCheck %s --implicit-check-not _ZTI4Base --implicit-check-not _ZTI8Derived1
58

6-
// VTABLE: @_ZTV8Derived1 = linkonce_odr unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN8Derived17displayEv] }, comdat, align 8
7-
// VTABLE: @_ZTV4Base = linkonce_odr unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN4Base7displayEv] }, comdat, align 8
9+
// Since experimental-relative-c++-abi-vtables is some experimental option, temporary disabling the check for now
10+
// until we emit proper address spaces (and casts) everywhere.
11+
12+
// VTABLE: @_ZTV8Derived1 = linkonce_odr unnamed_addr addrspace(1) constant { [3 x ptr addrspace(4)] } { [3 x ptr addrspace(4)] [ptr addrspace(4) null, ptr addrspace(4) null, ptr addrspace(4) addrspacecast (ptr @_ZN8Derived17displayEv to ptr addrspace(4))] }, comdat, align 8
13+
// VTABLE: @_ZTV4Base = linkonce_odr unnamed_addr addrspace(1) constant { [3 x ptr addrspace(4)] } { [3 x ptr addrspace(4)] [ptr addrspace(4) null, ptr addrspace(4) null, ptr addrspace(4) addrspacecast (ptr @_ZN4Base7displayEv to ptr addrspace(4))] }, comdat, align 8
814

915
SYCL_EXTERNAL bool rand();
1016

1117
class Base {
1218
public:
13-
virtual void display() {}
19+
[[intel::device_indirectly_callable]] virtual void display() {}
1420
};
1521

1622
class Derived1 : public Base {
1723
public:
18-
void display() {}
24+
[[intel::device_indirectly_callable]] void display() override {}
1925
};
2026

2127
SYCL_EXTERNAL void test() {
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Purpose of this test is to ensure that in SYCL device code mode, we are only
2+
// emitting those virtual functions into vtable, which are marked with
3+
// [[intel::device_indirectly_callable]] attribute or SYCL_EXTERNAL macro.
4+
//
5+
// RUN: %clang_cc1 -emit-llvm -o - -fsycl-is-device \
6+
// RUN: -fsycl-allow-virtual-functions -internal-isystem %S/Inputs \
7+
// RUN: -triple spir64 %s -o %t.ll
8+
// RUN: FileCheck %s --input-file %t.ll --implicit-check-not host \
9+
// RUN: --implicit-check-not _ZN8Derived416maybe_device_barEv
10+
//
11+
// Check that vtable contains null pointers for host-only virtual functions:
12+
//
13+
// CHECK: @_ZTV4Base =
14+
// CHECK-SAME:, {{.*}} @_ZN4Base10device_fooEv
15+
// CHECK-SAME:, {{.*}} @_ZN4Base10device_barEv
16+
// CHECK-SAME:, ptr addrspace(4) null
17+
// CHECK-SAME:, ptr addrspace(4) null
18+
//
19+
// CHECK: @_ZTV8Derived1 =
20+
// CHECK-SAME:, {{.*}} @_ZN8Derived110device_fooEv
21+
// CHECK-SAME:, {{.*}} @_ZN4Base10device_barEv
22+
// CHECK-SAME:, ptr addrspace(4) null
23+
// CHECK-SAME:, ptr addrspace(4) null
24+
// CHECK-SAME:, {{.*}} @_ZN8Derived110device_bazEv
25+
// CHECK-SAME:, ptr addrspace(4) null
26+
//
27+
// CHECK: @_ZTV8Derived2 =
28+
// CHECK-SAME:, {{.*}} @_ZN4Base10device_fooEv
29+
// CHECK-SAME:, {{.*}} @_ZN8Derived210device_barEv
30+
// CHECK-SAME:, ptr addrspace(4) null
31+
// CHECK-SAME:, ptr addrspace(4) null
32+
//
33+
// CHECK: @_ZTV10SubDerived =
34+
// CHECK-SAME:, {{.*}} @_ZN8Derived110device_fooEv
35+
// CHECK-SAME:, {{.*}} @_ZN4Base10device_barEv
36+
// CHECK-SAME:, ptr addrspace(4) null
37+
// CHECK-SAME:, ptr addrspace(4) null
38+
// CHECK-SAME:, {{.*}} @_ZN10SubDerived10device_bazEv
39+
// CHECK-SAME:, ptr addrspace(4) null
40+
//
41+
// CHECK: @_ZTV8Derived3 =
42+
// CHECK-SAME:, {{.*}} @_ZN8Derived310device_fooEv
43+
// CHECK-SAME:, {{.*}} @_ZN8Derived316maybe_device_barEv
44+
// CHECK-SAME:, ptr addrspace(4) null
45+
//
46+
// CHECK: @_ZTV12AbstractBase =
47+
// CHECK-SAME: zeroinitializer
48+
//
49+
// CHECK: @_ZTV8Derived4 =
50+
// CHECK-SAME:, {{.*}} @_ZN8Derived410device_fooEv
51+
// CHECK-SAME:, ptr addrspace(4) null
52+
// CHECK-SAME:, ptr addrspace(4) null
53+
//
54+
// Check that bodies of device virtual functions are present:
55+
//
56+
// CHECK-DAG: define linkonce_odr spir_func void @_ZN4Base10device_fooEv
57+
// CHECK-DAG: define linkonce_odr spir_func void @_ZN4Base10device_barEv
58+
//
59+
// CHECK-DAG: define linkonce_odr spir_func void @_ZN8Derived110device_fooEv
60+
// CHECK-DAG: define linkonce_odr spir_func void @_ZN8Derived110device_bazEv
61+
//
62+
// CHECK-DAG: define linkonce_odr spir_func void @_ZN10SubDerived10device_bazEv
63+
//
64+
// CHECK-DAG: define linkonce_odr spir_func void @_ZN8Derived210device_barEv
65+
//
66+
// CHECK-DAG: define linkonce_odr spir_func void @_ZN8Derived310device_fooEv
67+
// CHECK-DAG: define linkonce_odr spir_func void @_ZN8Derived316maybe_device_barEv
68+
//
69+
// CHECK-DAG: define linkonce_odr spir_func void @_ZN8Derived410device_fooEv
70+
71+
#include "sycl.hpp"
72+
73+
struct Base {
74+
[[intel::device_indirectly_callable]] virtual void device_foo() {}
75+
[[intel::device_indirectly_callable]] virtual void device_bar() {}
76+
77+
virtual void host_foo() {}
78+
virtual void host_bar() {}
79+
};
80+
81+
struct Derived1 : public Base {
82+
[[intel::device_indirectly_callable]] void device_foo() override {}
83+
84+
void host_bar() override {}
85+
86+
[[intel::device_indirectly_callable]] virtual void device_baz() {}
87+
virtual void host_baz() {}
88+
};
89+
90+
struct SubDerived : public Derived1 {
91+
[[intel::device_indirectly_callable]] void device_baz() override {}
92+
void host_baz() override {}
93+
};
94+
95+
struct Derived2 : public Base {
96+
[[intel::device_indirectly_callable]] void device_bar() override {}
97+
98+
void host_foo() override {}
99+
};
100+
101+
class AbstractBase {
102+
virtual void device_foo() = 0;
103+
virtual void maybe_device_bar() = 0;
104+
virtual void host_foo() = 0;
105+
};
106+
107+
class Derived3 : public AbstractBase {
108+
SYCL_EXTERNAL void device_foo() override {}
109+
SYCL_EXTERNAL void maybe_device_bar() override {}
110+
void host_foo() override {}
111+
};
112+
113+
class Derived4 : public AbstractBase {
114+
SYCL_EXTERNAL void device_foo() override {}
115+
void host_foo() override {}
116+
void maybe_device_bar() override {}
117+
};
118+
119+
int main(int argc, char *argv[]) {
120+
sycl::kernel_single_task<class kernel_function>([=]() {
121+
Base b;
122+
Derived1 d1;
123+
Derived2 d2;
124+
SubDerived sd;
125+
Base *ptr;
126+
if (argc > 5) {
127+
ptr = &d1;
128+
} else if (argc > 42) {
129+
ptr = &d2;
130+
} else {
131+
ptr = &sd;
132+
}
133+
134+
Derived3 d3;
135+
Derived4 d4;
136+
AbstractBase *aptr;
137+
if (argc > 5) {
138+
aptr = &d3;
139+
} else {
140+
aptr = &d4;
141+
}
142+
});
143+
144+
return 0;
145+
}

0 commit comments

Comments
 (0)