Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL] Annotate virtual calls in device IR #14051

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5713,6 +5713,14 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
// Apply some call-site-specific attributes.
// TODO: work this into building the attribute set.

if (getContext().getLangOpts().SYCLIsDevice && Callee.isVirtual()) {
// Annotate virtual calls in SYCL device code to help passes that emit
// diagnostics on incorrect uses of virtual functions.
Attrs = Attrs.addFnAttribute(
getLLVMContext(),
llvm::Attribute::get(getLLVMContext(), "virtual-call"));
}

// Apply always_inline to all calls within flatten functions.
// FIXME: should this really take priority over __try, below?
if (CurCodeDecl && CurCodeDecl->hasAttr<FlattenAttr>() &&
Expand Down
42 changes: 42 additions & 0 deletions clang/test/CodeGenSYCL/attrs-on-virtual-calls.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Test verifies that clang codegen properly adds call site attributes to
// device code

// RUN: %clang_cc1 -triple spir64 -fsycl-allow-virtual-functions \
// RUN: -fsycl-is-device -emit-llvm %s -o %t.device
// RUN: FileCheck %s --input-file=%t.device --check-prefixes=CHECK,CHECK-DEVICE
// RUN: %clang_cc1 -triple x86_64 -fsycl-allow-virtual-functions \
// RUN: -fsycl-is-host -emit-llvm %s -o %t.host
// RUN: FileCheck %s --input-file=%t.host --check-prefixes=CHECK,CHECK-HOST

// CHECK-LABEL: define {{.*}} @_Z4testv
// CHECK: call{{.*}}void %[[#]](ptr
// CHECK-DEVICE-SAME: #[[#ATTRS:]]
// CHECK-HOST-SAME: %[[#]]){{[[:space:]]}}
// CHECK-DEVICE: attributes #[[#ATTRS]] = {{.*}} "virtual-call"
AlexeySachkov marked this conversation as resolved.
Show resolved Hide resolved

#ifndef SYCL_EXTERNAL
#define SYCL_EXTERNAL
#endif

SYCL_EXTERNAL bool rand();

class Base {
public:
[[__sycl_detail__::add_ir_attributes_function("indirectly-callable", "")]]
virtual void display() {}
};

class Derived1 : public Base {
public:
[[__sycl_detail__::add_ir_attributes_function("indirectly-callable", "")]]
void display() override {}
};

SYCL_EXTERNAL void test() {
Derived1 d1;
Base *b = nullptr;
if (rand())
b = &d1;
b->display();
AlexeySachkov marked this conversation as resolved.
Show resolved Hide resolved
}

Loading