Skip to content

libclc: remove __attribute__((assume)) for clspv targets #92126

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

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ Attribute Changes in Clang
- Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
is ignored when applied to a local class or a member thereof.

- The ``clspv_libclc_builtin`` attribute has been added to allow clspv
(`OpenCL-C to Vulkan SPIR-V compiler <https://github.com/google/clspv>`_) to identify functions coming from libclc
(`OpenCL-C builtin library <https://libclc.llvm.org>`_).

Improvements to Clang's diagnostics
-----------------------------------
- Clang now applies syntax highlighting to the code snippets it
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -4561,3 +4561,10 @@ def CodeAlign: StmtAttr {
static constexpr int MaximumAlignment = 4096;
}];
}

def ClspvLibclcBuiltin: InheritableAttr {
let Spellings = [Clang<"clspv_libclc_builtin">];
let Subjects = SubjectList<[Function]>;
let Documentation = [ClspvLibclcBuiltinDoc];
let SimpleHandler = 1;
}
14 changes: 14 additions & 0 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -8087,3 +8087,17 @@ requirement:
}
}];
}

def ClspvLibclcBuiltinDoc : Documentation {
let Category = DocCatFunction;
let Content = [{
Attribute used by `clspv`_ (OpenCL-C to Vulkan SPIR-V compiler) to identify functions coming from `libclc`_ (OpenCL-C builtin library).

.. code-block:: c

void __attribute__((clspv_libclc_builtin)) libclc_builtin() {}

.. _`clspv`: https://github.com/google/clspv
.. _`libclc`: https://libclc.llvm.org
}];
}
5 changes: 5 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
EmitKernelMetadata(FD, Fn);
}

if (FD && FD->hasAttr<ClspvLibclcBuiltinAttr>()) {
Fn->setMetadata("clspv_libclc_builtin",
llvm::MDNode::get(getLLVMContext(), {}));
}

// If we are checking function types, emit a function type signature as
// prologue data.
if (FD && SanOpts.has(SanitizerKind::Function)) {
Expand Down
6 changes: 6 additions & 0 deletions clang/test/CodeGen/clspv_libclc_builtin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %clang_cc1 -triple spir -emit-llvm %s -o - | FileCheck %s

// CHECK: @foo()
// CHECK-SAME: !clspv_libclc_builtin

void __attribute__((clspv_libclc_builtin)) foo() {}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
// CHECK-NEXT: Capability (SubjectMatchRule_record, SubjectMatchRule_type_alias)
// CHECK-NEXT: CarriesDependency (SubjectMatchRule_variable_is_parameter, SubjectMatchRule_objc_method, SubjectMatchRule_function)
// CHECK-NEXT: Cleanup (SubjectMatchRule_variable_is_local)
// CHECK-NEXT: ClspvLibclcBuiltin (SubjectMatchRule_function)
// CHECK-NEXT: CmseNSEntry (SubjectMatchRule_function)
// CHECK-NEXT: Cold (SubjectMatchRule_function)
// CHECK-NEXT: Common (SubjectMatchRule_variable)
Expand Down
3 changes: 1 addition & 2 deletions libclc/generic/include/clc/clcfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#if defined(CLC_SPIRV) || defined(CLC_SPIRV64)
#define _CLC_DEF
#elif defined(CLC_CLSPV) || defined(CLC_CLSPV64)
#define _CLC_DEF \
__attribute__((noinline)) __attribute__((assume("clspv_libclc_builtin")))
#define _CLC_DEF __attribute__((noinline)) __attribute__((clspv_libclc_builtin))
#else
#define _CLC_DEF __attribute__((always_inline))
#endif
Loading