Skip to content
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
91eeaf0
Add the functional identity and feature queries.
AlexVlx Apr 2, 2025
8bf1168
Fix format.
AlexVlx Apr 2, 2025
3421292
Fix broken patch merge.
AlexVlx Apr 2, 2025
539c7e6
Add release notes.
AlexVlx Apr 2, 2025
5926b9f
(Hopefully) Final format fix.
AlexVlx Apr 2, 2025
4381d93
Remove stray space.
AlexVlx Apr 2, 2025
d18f64e
Remove unused header, fix borked test.
AlexVlx Apr 2, 2025
7880ff4
Stars everywhere.
AlexVlx Apr 2, 2025
719dfde
Fix format without line break.
AlexVlx Apr 2, 2025
36b69b4
Add host tests.
AlexVlx Apr 2, 2025
e327e15
Fit code examples within 80-char limit.
AlexVlx Apr 2, 2025
d35efc5
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Apr 14, 2025
5dee670
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Apr 15, 2025
888a080
Fix tests.
AlexVlx Apr 16, 2025
e35ac62
Fix test.
AlexVlx Apr 16, 2025
6c41ed2
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Apr 16, 2025
8683148
Merge branch 'zcfs' of https://github.com/AlexVlx/llvm-project; branc…
AlexVlx Apr 22, 2025
a9b3e85
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Apr 24, 2025
468a517
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Apr 29, 2025
1b8b57e
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 2, 2025
18b4af2
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 5, 2025
a8bca2f
Re-work implementation to return a target specific type.
AlexVlx May 6, 2025
716cc1f
Fix formatting.
AlexVlx May 6, 2025
79035a9
Delete spurious whitespace.
AlexVlx May 6, 2025
6945c2e
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 7, 2025
9a7e250
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 7, 2025
0f04dbc
Handle jumps into controlled sequences.
AlexVlx May 7, 2025
39a9d55
Fix formatting.
AlexVlx May 7, 2025
3fe116e
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 8, 2025
49c862a
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 12, 2025
f293f39
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 16, 2025
251476d
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 16, 2025
ebde49b
Start incorporating review feedback.
AlexVlx May 16, 2025
4bdd30e
Less `auto`.
AlexVlx May 16, 2025
a1b4a11
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 20, 2025
18841c1
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 22, 2025
76848d5
Print out valid AMDGCN processor identifiers.
AlexVlx May 22, 2025
e1bfdf3
Use boolean type for the predicate, even though it should never get e…
AlexVlx May 22, 2025
4f65468
Register pass early.
AlexVlx May 22, 2025
e940d42
Clarify builtins are also available in C.
AlexVlx May 22, 2025
46adb74
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx May 26, 2025
ca9521d
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jun 2, 2025
11dd570
Try to fix potentially erroneous indentation in note.
AlexVlx Jun 2, 2025
fab0d14
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jun 2, 2025
611ec0d
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jun 2, 2025
03b029f
Add test for returning a predicate.
AlexVlx Jun 2, 2025
32be1c0
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jun 2, 2025
012f74d
Fix formatting.
AlexVlx Jun 2, 2025
cd7c920
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jun 10, 2025
33bbe35
Add predicate expansion pass to LTO pipeline.
AlexVlx Jun 10, 2025
46e5a91
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jun 10, 2025
8c1e1f5
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jun 13, 2025
81a55d8
Try to fix odd but persistent doc generation error.
AlexVlx Jun 13, 2025
bbe17fa
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jun 17, 2025
c495630
Adopt suggestions.
AlexVlx Jun 18, 2025
420a19c
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jun 18, 2025
dc0221e
Implement some of the review suggestions.
AlexVlx Jun 23, 2025
7f88eb7
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jun 24, 2025
3b727b9
Clean up unreachable BBs.
AlexVlx Jun 24, 2025
42f5de6
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jul 3, 2025
246ff38
Fix formatting.
AlexVlx Jul 3, 2025
adb6469
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jul 3, 2025
6b368d5
Remove internal functions made unreachable by predicate expansion.
AlexVlx Jul 4, 2025
435ce05
Fix formatting, tweak use count.
AlexVlx Jul 4, 2025
2c2f78b
Fix formatting, again.
AlexVlx Jul 4, 2025
09115e2
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jul 6, 2025
f1d41a8
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jul 7, 2025
5d2c2f6
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jul 8, 2025
05033ea
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jul 8, 2025
b886c55
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jul 9, 2025
63d059d
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jul 9, 2025
495b567
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jul 10, 2025
8ef5c70
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jul 10, 2025
8177876
Add warnings around unguarded builtin usage, suggesting `__builtin_am…
AlexVlx Jul 12, 2025
b4decc2
Fix formatting.
AlexVlx Jul 12, 2025
01b5e41
Merge branch 'main' into zcfs
AlexVlx Jul 23, 2025
585cde7
Merge branch 'main' into zcfs
AlexVlx Jul 31, 2025
283a52b
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 13, 2026
659dc76
Fix build.
AlexVlx Jan 14, 2026
2a406fc
Fix tests.
AlexVlx Jan 14, 2026
dd663c9
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 20, 2026
558fb60
Adopt TableGen based intrinsic definitions.
AlexVlx Jan 20, 2026
c431d41
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 23, 2026
6c96c9f
Start cleaning up vestigial predicate expansion infra.
AlexVlx Jan 24, 2026
6d23d0a
Predicates don't need noise when specialisation constants are available.
AlexVlx Jan 24, 2026
5710e31
Remove noise.
AlexVlx Jan 24, 2026
776c98b
Remove vestigial pass implementation.
AlexVlx Jan 24, 2026
1630673
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 24, 2026
915306f
Remove more noise.
AlexVlx Jan 24, 2026
5ac2a9e
Remove no longer useful tests.
AlexVlx Jan 24, 2026
6eb3199
Update tests.
AlexVlx Jan 24, 2026
eb4beb5
Include what we use.
AlexVlx Jan 24, 2026
e326aef
Tweak release notes.
AlexVlx Jan 24, 2026
84d01ac
Update BI docs.
AlexVlx Jan 24, 2026
a712868
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 25, 2026
0a211ba
Remove vestigial test.
AlexVlx Jan 25, 2026
89e5d01
Remove debugging bit.
AlexVlx Jan 26, 2026
097f274
Emit decoration AFTER defining the decorated register.
AlexVlx Jan 27, 2026
1cda4cb
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 27, 2026
d9012fa
Add BE test.
AlexVlx Jan 27, 2026
6f6f62c
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 29, 2026
c76c741
Finalise diagnostics.
AlexVlx Jan 30, 2026
b84d483
Fix formatting.
AlexVlx Jan 30, 2026
7fc508d
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 30, 2026
cc21799
Update release notes, fix more formatting.
AlexVlx Jan 30, 2026
8a11f65
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 30, 2026
19130f1
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 30, 2026
1711293
Add dedicated test for `__amdgpu_feature_predicate_t`.
AlexVlx Jan 30, 2026
5d0c189
Unbreak some test.
AlexVlx Jan 30, 2026
47cc6d7
Add missing file.
AlexVlx Jan 30, 2026
d362060
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 30, 2026
a6020cf
Remove noise.
AlexVlx Jan 30, 2026
62bd27a
Unbreak more tests.
AlexVlx Jan 30, 2026
0e2b326
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 31, 2026
64a31e2
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Jan 31, 2026
3e29297
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 1, 2026
48bb06d
Enhance diagnostics.
AlexVlx Feb 2, 2026
d1d5e49
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 2, 2026
e9d7397
Merge branch 'main' into zcfs
AlexVlx Feb 2, 2026
875bf68
Update llvm/lib/Target/SPIRV/SPIRVPrepareGlobals.cpp
AlexVlx Feb 6, 2026
b5a6fe3
Fix formatting.
AlexVlx Feb 6, 2026
e622583
Merge branch 'zcfs' of https://github.com/AlexVlx/llvm-project; branc…
AlexVlx Feb 6, 2026
2221c41
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 7, 2026
840d396
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 8, 2026
ccc8f94
Do not rely on `CallInst` names, use metadata instead; handle negated…
AlexVlx Feb 8, 2026
8ef2cf4
Fix oversight.
AlexVlx Feb 8, 2026
e215226
Clarify AMDGCN specific handling.
AlexVlx Feb 10, 2026
5c51979
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 12, 2026
cf5ba05
Add explicit test for the id string; remove vestigial metadata.
AlexVlx Feb 13, 2026
b5faaa2
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 15, 2026
8974de1
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 16, 2026
70209b6
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 19, 2026
c791b5c
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 19, 2026
d0fb131
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 20, 2026
29285a4
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 23, 2026
7cc60e4
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 24, 2026
865af2d
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 25, 2026
cf7edd8
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 26, 2026
5bc0be6
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Feb 26, 2026
a0492f4
Regenerate test.
AlexVlx Feb 26, 2026
33a9a41
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 1, 2026
e6ba156
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 2, 2026
0b0f27e
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 5, 2026
de56602
Fix tests.
AlexVlx Mar 5, 2026
bdd487b
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 6, 2026
42cd26a
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 7, 2026
9fbb33e
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 7, 2026
56a9fce
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 8, 2026
68da2c5
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 9, 2026
1b0e195
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 9, 2026
aa749a4
Do not use instruction metadata in a load-bearing way.
AlexVlx Mar 11, 2026
0bfba3d
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 11, 2026
2077a82
Undo erroneous deletion.
AlexVlx Mar 11, 2026
e42746b
Undo undo.
AlexVlx Mar 11, 2026
371feda
Fix formatting.
AlexVlx Mar 11, 2026
9ab6a3e
Really fix formatting.
AlexVlx Mar 11, 2026
ca374a8
Fix tests.
AlexVlx Mar 11, 2026
834ac16
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 11, 2026
008ba43
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 11, 2026
20c2b69
No need for a set, there are no duplicates.
AlexVlx Mar 12, 2026
0f13bf6
Remove unused code.
AlexVlx Mar 12, 2026
ea407e3
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 13, 2026
d85b148
Handle parens, handle binary ops taking `__amdgpu_feature_predicate_t…
AlexVlx Mar 13, 2026
9ca3b62
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 13, 2026
56be10e
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 15, 2026
e9ee69a
Merge branch 'zcfs' of https://github.com/AlexVlx/llvm-project; branc…
AlexVlx Mar 16, 2026
a5d4ec1
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 17, 2026
187b550
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 20, 2026
0a25aa2
Use dedicated intrinsic to create spec constants.
AlexVlx Mar 21, 2026
94341e0
Fix formatting.
AlexVlx Mar 22, 2026
767fd28
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 25, 2026
f0578b2
Fix tests.
AlexVlx Mar 25, 2026
71e9e5c
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
AlexVlx Mar 26, 2026
b68bcb8
Merge remote-tracking branch 'upstream/main' into zcfs
Mar 30, 2026
8086e95
Merge branch 'main' into zcfs
AlexVlx Mar 30, 2026
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
112 changes: 112 additions & 0 deletions clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5044,6 +5044,118 @@ If no address spaces names are provided, all address spaces are fenced.
__builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local")
__builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup", "local", "global")

__builtin_amdgcn_processor_is and __builtin_amdgcn_is_invocable
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``__builtin_amdgcn_processor_is`` and ``__builtin_amdgcn_is_invocable`` provide
a functional mechanism for programatically querying:

* the identity of the current target processor;
* the capability of the current target processor to invoke a particular builtin.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @sarnex @jhuber6 as this relates to __has_builtin behavior somewhat and we've been in discussions about whether that should mean "I know about the builtin" or "I can actually call the builtin".


**Syntax**:

.. code-block:: c

__amdgpu_feature_predicate_t __builtin_amdgcn_processor_is(const char*);
__amdgpu_feature_predicate_t __builtin_amdgcn_is_invocable(builtin_name);

**Example of use**:

.. code-block:: c++

if (__builtin_amdgcn_processor_is("gfx1201") ||
__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_sleep_var))
__builtin_amdgcn_s_sleep_var(x);

if (!__builtin_amdgcn_processor_is("gfx906"))
__builtin_amdgcn_s_wait_event_export_ready();
else if (__builtin_amdgcn_processor_is("gfx1010") ||
__builtin_amdgcn_processor_is("gfx1101"))
__builtin_amdgcn_s_ttracedata_imm(1);

while (__builtin_amdgcn_processor_is("gfx1101")) *p += x;

do {
break;
} while (__builtin_amdgcn_processor_is("gfx1010"));

for (; __builtin_amdgcn_processor_is("gfx1201"); ++*p) break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question about inf. loop here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this'd be an infinite loop ever, it's either 0 trips or one trip, if the predicate is true we just break. Otherwise, the discussion from the previous inf loop applies.


if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_wait_event_export_ready))
__builtin_amdgcn_s_wait_event_export_ready();
else if (__builtin_amdgcn_is_invocable(__builtin_amdgcn_s_ttracedata_imm))
__builtin_amdgcn_s_ttracedata_imm(1);

do {
break;
} while (
__builtin_amdgcn_is_invocable(__builtin_amdgcn_global_load_tr_b64_i32));

for (; __builtin_amdgcn_is_invocable(__builtin_amdgcn_permlane64); ++*p)
break;

**Description**:

The builtins return a value of type ``__amdgpu_feature_predicate_t``, which is a
target specific type that behaves as if its C++ definition was the following:
Comment on lines +5614 to +5615

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this builtin work in C? If so, the docs should be updated to make it clear that this behavior applies to C as well as C++ and explain what it means in a bit more detail (presume that C users have no idea how C++ idioms work).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does work in C, although I'm not convinced it will see significant use. That being said, there's no good reason to make it C++ only. I have tried to add an explanation for that context / provide a fleshed out example, please do let me know if it's more or less aligned with what you had in mind. Thanks!


.. code-block:: c++

struct __amdgpu_feature_predicate_t {
__amdgpu_feature_predicate_t() = delete;
__amdgpu_feature_predicate_t(const __amdgpu_feature_predicate_t&) = delete;
__amdgpu_feature_predicate_t(__amdgpu_feature_predicate_t&&) = delete;

explicit
operator bool() const noexcept;
};

The builtins can be used in C as well, wherein the
``__amdgpu_feature_predicate_t`` type behaves as an opaque, forward declared
type with conditional automated conversion to ``_Bool`` when used as the
Comment on lines +5629 to +5630

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a test case that stuff like this is diagnosed as using an incomplete type?

typeof(__builtin_amdgcn_processor_is("gfx900")) what;

Similar in C++ with decltype?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

predicate argument to a control structure:

.. code-block:: c

struct __amdgpu_feature_predicate_t ret(); // Error
void arg(struct __amdgpu_feature_predicate_t); // Error
void local() {
struct __amdgpu_feature_predicate_t x; // Error
struct __amdgpu_feature_predicate_t y =
__builtin_amdgcn_processor_is("gfx900"); // Error
}
void valid_use() {
_Bool x = (_Bool)__builtin_amdgcn_processor_is("gfx900"); // OK
if (__builtin_amdgcn_processor_is("gfx900")) // Implicit cast to _Bool
return;
for (; __builtin_amdgcn_processor_is("gfx900");) // Implicit cast to _Bool
break;
while (__builtin_amdgcn_processor_is("gfx900")) // Implicit cast to _Bool
break;
do {
break;
} while (__builtin_amdgcn_processor_is("gfx900")); // Implicit cast to _Bool

__builtin_amdgcn_processor_is("gfx900") ? x : !x;
}

The boolean interpretation of the predicate values returned by the builtins:

* indicates whether the current target matches the argument; the argument MUST
be a string literal and a valid AMDGPU target
* indicates whether the builtin function passed as the argument can be invoked
by the current target; the argument MUST be either a generic or AMDGPU
specific builtin name

When invoked while compiling for a concrete target, the builtins are evaluated
early by Clang, and never produce any CodeGen effects / have no observable
side-effects in IR. Conversely, when compiling for AMDGCN flavoured SPIR-v,
which is an abstract target, a series of predicate values are implicitly
created. These predicates get resolved when finalizing the compilation process
for a concrete target, and shall reflect the latter's identity and features.
Thus, it is possible to author high-level code, in e.g. HIP, that is target
adaptive in a dynamic fashion, contrary to macro based mechanisms.

ARM/AArch64 Language Extensions
-------------------------------
Expand Down
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ Target Specific Changes

AMDGPU Support
^^^^^^^^^^^^^^
- Introduced a new target specific builtin ``__builtin_amdgcn_processor_is``,
a late / deferred query for the current target processor.
- Introduced a new target specific builtin ``__builtin_amdgcn_is_invocable``,
which enables fine-grained, per-builtin, feature availability.

NVPTX Support
^^^^^^^^^^^^^^
Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/Basic/AMDGPUTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
AMDGPU_TYPE(Name, Id, SingletonId, Width, Align)
#endif

#ifndef AMDGPU_FEATURE_PREDICATE_TYPE
#define AMDGPU_FEATURE_PREDICATE_TYPE(Name, Id, SingletonId, Width, Align) \
AMDGPU_TYPE(Name, Id, SingletonId, Width, Align)
#endif

AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", AMDGPUBufferRsrc, AMDGPUBufferRsrcTy, 128, 128, 8)

AMDGPU_NAMED_BARRIER_TYPE("__amdgpu_named_workgroup_barrier_t", AMDGPUNamedWorkgroupBarrier, AMDGPUNamedWorkgroupBarrierTy, 128, 32, 0)

AMDGPU_FEATURE_PREDICATE_TYPE("__amdgpu_feature_predicate_t", AMDGPUFeaturePredicate, AMDGPUFeaturePredicateTy, 1, 1)

#undef AMDGPU_TYPE
#undef AMDGPU_OPAQUE_PTR_TYPE
#undef AMDGPU_NAMED_BARRIER_TYPE
#undef AMDGPU_FEATURE_PREDICATE_TYPE
1 change: 1 addition & 0 deletions clang/include/clang/Basic/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// Q -> target builtin type, followed by a character to distinguish the builtin type
// Qa -> AArch64 svcount_t builtin type.
// Qb -> AMDGPU __amdgpu_buffer_rsrc_t builtin type.
// Qc -> AMDGPU __amdgpu_feature_predicate_t builtin type.
// E -> ext_vector, followed by the number of elements and the base type.
// X -> _Complex, followed by the base type.
// Y -> ptrdiff_t
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/BuiltinsAMDGPU.def
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ BUILTIN(__builtin_amdgcn_endpgm, "v", "nr")
BUILTIN(__builtin_amdgcn_get_fpenv, "WUi", "n")
BUILTIN(__builtin_amdgcn_set_fpenv, "vWUi", "n")

// These are special FE only builtins intended for forwarding the requirements
// to the ME.
BUILTIN(__builtin_amdgcn_processor_is, "QccC*", "nctu")
BUILTIN(__builtin_amdgcn_is_invocable, "Qc", "nctu")

//===----------------------------------------------------------------------===//
// R600-NI only builtins.
//===----------------------------------------------------------------------===//
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -1758,3 +1758,6 @@ def ExplicitSpecializationStorageClass : DiagGroup<"explicit-specialization-stor

// A warning for options that enable a feature that is not yet complete
def ExperimentalOption : DiagGroup<"experimental-option">;

// Warnings about unguarded usages of AMDGPU target specific constructs
def UnguardedBuiltinUsageAMDGPU : DiagGroup<"amdgpu-unguarded-builtin-usage">;
29 changes: 28 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -12577,7 +12577,7 @@ def warn_zero_as_null_pointer_constant : Warning<
InGroup<DiagGroup<"zero-as-null-pointer-constant">>, DefaultIgnore;

def warn_not_eliding_copy_on_return : Warning<
"not eliding copy on return">,
"not eliding copy on return">,
InGroup<DiagGroup<"nrvo">>, DefaultIgnore;

def err_nullability_cs_multilevel : Error<
Expand Down Expand Up @@ -13535,4 +13535,31 @@ def warn_acc_var_referenced_lacks_op
// AMDGCN builtins diagnostics
def err_amdgcn_load_lds_size_invalid_value : Error<"invalid size value">;
def note_amdgcn_load_lds_size_valid_value : Note<"size must be %select{1, 2, or 4|1, 2, 4, 12 or 16}0">;
def err_amdgcn_processor_is_arg_not_literal
: Error<"the argument to __builtin_amdgcn_processor_is must be a string "
"literal">;
def err_amdgcn_processor_is_arg_invalid_value
: Error<"the argument to __builtin_amdgcn_processor_is must be a valid "
"AMDGCN processor identifier; '%0' is not valid">;
Comment thread
AlexVlx marked this conversation as resolved.
Resolved
def note_amdgcn_processor_is_valid_options
: Note<"valid AMDGCN processor identifiers are: %0">;
def err_amdgcn_is_invocable_arg_invalid_value
: Error<"the argument to __builtin_amdgcn_is_invocable must be either a "
"target agnostic builtin or an AMDGCN target specific builtin; `%0`"
" is not valid">;
def err_amdgcn_predicate_type_is_not_constructible
: Error<"%0 has type __amdgpu_feature_predicate_t, which is not"
" constructible">;
def err_amdgcn_predicate_type_needs_explicit_bool_cast
: Error<"%0 must be explicitly cast to %1; however, please note that this "
"is almost always an error and that it prevents the effective "
"guarding of target dependent code, and thus should be avoided">;
def note_amdgcn_protected_by_predicate : Note<"jump enters statement controlled"
" by AMDGPU feature predicate">;
def warn_amdgcn_unguarded_builtin :
Warning<"%0 might be unavailable on some AMDGPU targets">,
InGroup<UnguardedBuiltinUsageAMDGPU>, DefaultIgnore;
def note_amdgcn_unguarded_builtin_silence
: Note<"enclose %0 in a __builtin_amdgcn_is_invocable check to silence "
"this warning">;
} // end of sema component.
15 changes: 15 additions & 0 deletions clang/include/clang/Sema/SemaAMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@

#include "clang/AST/ASTFwd.h"
#include "clang/Sema/SemaBase.h"
#include "llvm/ADT/SmallPtrSet.h"

namespace clang {
class AttributeCommonInfo;
class Expr;
class ParsedAttr;

class SemaAMDGPU : public SemaBase {
llvm::SmallPtrSet<Expr *, 32> ExpandedPredicates;
llvm::SmallPtrSet<FunctionDecl *, 32> PotentiallyUnguardedBuiltinUsers;

public:
SemaAMDGPU(Sema &S);

Expand Down Expand Up @@ -64,6 +69,16 @@ class SemaAMDGPU : public SemaBase {
void handleAMDGPUNumVGPRAttr(Decl *D, const ParsedAttr &AL);
void handleAMDGPUMaxNumWorkGroupsAttr(Decl *D, const ParsedAttr &AL);
void handleAMDGPUFlatWorkGroupSizeAttr(Decl *D, const ParsedAttr &AL);

/// Expand a valid use of the feature identification builtins into its
/// corresponding sequence of instructions.
Expr *ExpandAMDGPUPredicateBI(CallExpr *CE);
Comment thread
AlexVlx marked this conversation as resolved.
Resolved
bool IsPredicate(Expr *E) const;
/// Diagnose unguarded usages of AMDGPU builtins and recommend guarding with
/// __builtin_amdgcn_is_invocable
void AddPotentiallyUnguardedBuiltinUser(FunctionDecl *FD);
bool HasPotentiallyUnguardedBuiltinUsage(FunctionDecl *FD) const;
void DiagnoseUnguardedBuiltinUsage(FunctionDecl *FD);
};
} // namespace clang

Expand Down
11 changes: 10 additions & 1 deletion clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,12 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
}

if (Target.getTriple().isAMDGPU() ||
(AuxTarget && AuxTarget->getTriple().isAMDGPU())) {
(Target.getTriple().isSPIRV() &&
Target.getTriple().getVendor() == llvm::Triple::AMD) ||
(AuxTarget &&
(AuxTarget->getTriple().isAMDGPU() ||
((AuxTarget->getTriple().isSPIRV() &&
AuxTarget->getTriple().getVendor() == llvm::Triple::AMD))))) {
#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
InitBuiltinType(SingletonId, BuiltinType::Id);
#include "clang/Basic/AMDGPUTypes.def"
Expand Down Expand Up @@ -12519,6 +12524,10 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context,
Type = Context.AMDGPUBufferRsrcTy;
break;
}
case 'c': {
Type = Context.AMDGPUFeaturePredicateTy;
break;
}
default:
llvm_unreachable("Unexpected target builtin type");
}
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/Basic/Targets/SPIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,12 @@ void SPIRV64AMDGCNTargetInfo::setAuxTarget(const TargetInfo *Aux) {
Float128Format = DoubleFormat;
}
}

bool SPIRV64AMDGCNTargetInfo::isValidCPUName(StringRef CPU) const {
return AMDGPUTI.isValidCPUName(CPU);
}

void SPIRV64AMDGCNTargetInfo::fillValidCPUList(
SmallVectorImpl<StringRef> &Values) const {
return AMDGPUTI.fillValidCPUList(Values);
}
5 changes: 5 additions & 0 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final
}

bool hasInt128Type() const override { return TargetInfo::hasInt128Type(); }

// This is only needed for validating arguments passed to
// __builtin_amdgcn_processor_is
bool isValidCPUName(StringRef Name) const override;
void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
};

} // namespace targets
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,13 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
DBuilder.createBasicType(Name, Width, llvm::dwarf::DW_ATE_unsigned); \
return SingletonId; \
}
#define AMDGPU_FEATURE_PREDICATE_TYPE(Name, Id, SingletonId, Width, Align) \
case BuiltinType::Id: { \
if (!SingletonId) \
SingletonId = \
DBuilder.createBasicType(Name, Width, llvm::dwarf::DW_ATE_boolean); \
return SingletonId; \
}
#include "clang/Basic/AMDGPUTypes.def"
case BuiltinType::UChar:
case BuiltinType::Char_U:
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CGExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,10 @@ Value *ScalarExprEmitter::EmitConversionToBool(Value *Src, QualType SrcType) {
if (const MemberPointerType *MPT = dyn_cast<MemberPointerType>(SrcType))
return CGF.CGM.getCXXABI().EmitMemberPointerIsNotNull(CGF, Src, MPT);

// The conversion is a NOP, and will be done when CodeGening the builtin.
if (SrcType == CGF.getContext().AMDGPUFeaturePredicateTy)
return Src;

assert((SrcType->isIntegerType() || isa<llvm::PointerType>(Src->getType())) &&
"Unknown scalar type to convert");

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CodeGen/CodeGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
case BuiltinType::Id: \
return llvm::TargetExtType::get(getLLVMContext(), "amdgcn.named.barrier", \
{}, {Scope});
#define AMDGPU_FEATURE_PREDICATE_TYPE(Name, Id, SingletonId, Width, Align) \
case BuiltinType::Id: \
return ConvertType(getContext().getLogicalOperationType());
#include "clang/Basic/AMDGPUTypes.def"
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
#include "clang/Basic/HLSLIntangibleTypes.def"
Expand Down
29 changes: 29 additions & 0 deletions clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ void CodeGenFunction::AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst,
Inst->setMetadata(LLVMContext::MD_mmra, MMRAMetadata::getMD(Ctx, MMRAs));
}

static Value *GetOrInsertAMDGPUPredicate(CodeGenFunction &CGF, Twine Name) {
auto PTy = IntegerType::getInt1Ty(CGF.getLLVMContext());

auto *P = cast<GlobalVariable>(
CGF.CGM.getModule().getOrInsertGlobal(Name.str(), PTy));
P->setConstant(true);
P->setExternallyInitialized(true);

return CGF.Builder.CreateLoad(
RawAddress(P, PTy, CharUnits::One(), KnownNonNull));
}

Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
const CallExpr *E) {
llvm::AtomicOrdering AO = llvm::AtomicOrdering::SequentiallyConsistent;
Expand Down Expand Up @@ -684,6 +696,23 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
llvm::Value *Env = EmitScalarExpr(E->getArg(0));
return Builder.CreateCall(F, {Env});
}
case AMDGPU::BI__builtin_amdgcn_processor_is: {
assert(CGM.getTriple().isSPIRV() &&
Comment thread
yxsamliu marked this conversation as resolved.
Resolved
"__builtin_amdgcn_processor_is should never reach CodeGen for "
"concrete targets!");
StringRef Proc = cast<clang::StringLiteral>(E->getArg(0))->getString();
return GetOrInsertAMDGPUPredicate(*this, "llvm.amdgcn.is." + Proc);
}
case AMDGPU::BI__builtin_amdgcn_is_invocable: {
assert(CGM.getTriple().isSPIRV() &&
"__builtin_amdgcn_is_invocable should never reach CodeGen for "
"concrete targets!");
auto *FD = cast<FunctionDecl>(
cast<DeclRefExpr>(E->getArg(0))->getReferencedDeclOfCallee());
StringRef RF =
getContext().BuiltinInfo.getRequiredFeatures(FD->getBuiltinID());
return GetOrInsertAMDGPUPredicate(*this, "llvm.amdgcn.has." + RF);
}
case AMDGPU::BI__builtin_amdgcn_read_exec:
return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
Expand Down
Loading