Skip to content

Commit 932ca85

Browse files
authored
libclc: remove __attribute__((assume)) for clspv targets (#92126)
Instead add a proper attribute in clang, and add convert it to function metadata to keep the information in the IR. The goal is to remove the dependency on __attribute__((assume)) that should have not be there in the first place. Ref #84934
1 parent 3a32590 commit 932ca85

File tree

7 files changed

+38
-2
lines changed

7 files changed

+38
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ Attribute Changes in Clang
403403
- Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
404404
is ignored when applied to a local class or a member thereof.
405405

406+
- The ``clspv_libclc_builtin`` attribute has been added to allow clspv
407+
(`OpenCL-C to Vulkan SPIR-V compiler <https://github.com/google/clspv>`_) to identify functions coming from libclc
408+
(`OpenCL-C builtin library <https://libclc.llvm.org>`_).
409+
406410
Improvements to Clang's diagnostics
407411
-----------------------------------
408412
- Clang now applies syntax highlighting to the code snippets it

clang/include/clang/Basic/Attr.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,3 +4561,10 @@ def CodeAlign: StmtAttr {
45614561
static constexpr int MaximumAlignment = 4096;
45624562
}];
45634563
}
4564+
4565+
def ClspvLibclcBuiltin: InheritableAttr {
4566+
let Spellings = [Clang<"clspv_libclc_builtin">];
4567+
let Subjects = SubjectList<[Function]>;
4568+
let Documentation = [ClspvLibclcBuiltinDoc];
4569+
let SimpleHandler = 1;
4570+
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8087,3 +8087,17 @@ requirement:
80878087
}
80888088
}];
80898089
}
8090+
8091+
def ClspvLibclcBuiltinDoc : Documentation {
8092+
let Category = DocCatFunction;
8093+
let Content = [{
8094+
Attribute used by `clspv`_ (OpenCL-C to Vulkan SPIR-V compiler) to identify functions coming from `libclc`_ (OpenCL-C builtin library).
8095+
8096+
.. code-block:: c
8097+
8098+
void __attribute__((clspv_libclc_builtin)) libclc_builtin() {}
8099+
8100+
.. _`clspv`: https://github.com/google/clspv
8101+
.. _`libclc`: https://libclc.llvm.org
8102+
}];
8103+
}

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
985985
EmitKernelMetadata(FD, Fn);
986986
}
987987

988+
if (FD && FD->hasAttr<ClspvLibclcBuiltinAttr>()) {
989+
Fn->setMetadata("clspv_libclc_builtin",
990+
llvm::MDNode::get(getLLVMContext(), {}));
991+
}
992+
988993
// If we are checking function types, emit a function type signature as
989994
// prologue data.
990995
if (FD && SanOpts.has(SanitizerKind::Function)) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -triple spir -emit-llvm %s -o - | FileCheck %s
2+
3+
// CHECK: @foo()
4+
// CHECK-SAME: !clspv_libclc_builtin
5+
6+
void __attribute__((clspv_libclc_builtin)) foo() {}

clang/test/Misc/pragma-attribute-supported-attributes-list.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
// CHECK-NEXT: Capability (SubjectMatchRule_record, SubjectMatchRule_type_alias)
4949
// CHECK-NEXT: CarriesDependency (SubjectMatchRule_variable_is_parameter, SubjectMatchRule_objc_method, SubjectMatchRule_function)
5050
// CHECK-NEXT: Cleanup (SubjectMatchRule_variable_is_local)
51+
// CHECK-NEXT: ClspvLibclcBuiltin (SubjectMatchRule_function)
5152
// CHECK-NEXT: CmseNSEntry (SubjectMatchRule_function)
5253
// CHECK-NEXT: Cold (SubjectMatchRule_function)
5354
// CHECK-NEXT: Common (SubjectMatchRule_variable)

libclc/generic/include/clc/clcfunc.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
#if defined(CLC_SPIRV) || defined(CLC_SPIRV64)
88
#define _CLC_DEF
99
#elif defined(CLC_CLSPV) || defined(CLC_CLSPV64)
10-
#define _CLC_DEF \
11-
__attribute__((noinline)) __attribute__((assume("clspv_libclc_builtin")))
10+
#define _CLC_DEF __attribute__((noinline)) __attribute__((clspv_libclc_builtin))
1211
#else
1312
#define _CLC_DEF __attribute__((always_inline))
1413
#endif

0 commit comments

Comments
 (0)