This is an archive of the discontinued LLVM Phabricator instance.

[SPIR-V] Add atomic_flag builtin implementation
ClosedPublic

Authored by mpaszkowski on Oct 19 2022, 6:06 PM.

Details

Summary

This change:

  • Adds implementation details for the atomic_flag_test_and_set, atomic_flag_test_and_set_explicit, atomic_flag_clear, atomic_flag_clear_explicit builtins
  • Adds an atomic_flag.ll test from the SPIR-V translator with additional checks

The atomic_flag.ll passes after this change.

Diff Detail

Event Timeline

mpaszkowski created this revision.Oct 19 2022, 6:06 PM
mpaszkowski requested review of this revision.Oct 19 2022, 6:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 6:06 PM
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
634–647

It seems that this fragment is very similar to MemSemanticsReg evaluation in buildAtomicRMWInst(), so we could separate it into a static functionit and avoid the code duplication.

649–652

Move the if condition to the assertion.

654–664

This fragment also looks similar to getting ScopeRegister in buildAtomicRMWInst().

arsenm requested changes to this revision.Nov 16 2022, 3:43 PM
arsenm added inline comments.
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
649–652

Agree

llvm/test/CodeGen/SPIRV/transcoding/atomic_flag.ll
20

Should use opaque pointers in new tests

23

Use named values in tests

This revision now requires changes to proceed.Nov 16 2022, 3:43 PM
mpaszkowski marked 6 inline comments as done.Dec 1 2022, 9:28 AM

Thank you @iliya-diyachkov and @arsenm for your review! I apologize that this took so long, but I have now addressed all the comments in the new diff.

arsenm added inline comments.Dec 7 2022, 6:46 AM
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
438–440

Why is this something that would be materialized in a register instead of an immediate argument?

445

Don't need the 0

mpaszkowski marked 2 inline comments as done.Dec 15 2022, 3:05 AM
mpaszkowski added inline comments.
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
438–440

This is the way it is done by the Khronos LLVM SPIR-V Translator and we want the SPIR-V backend to be compatible.

Translator:

4 Constant 2 14 42 
...
7 AtomicUMin 2 30 4 12 13 14

Backend:

%10 = OpConstant %4 42 
...	
%30 = OpAtomicUMin %4 %18 %12 %13 %10
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
438–440

@arsenm, according to the SPIRV specification (see the link), the last operand of OpAtomicUMin instruction should be a register (<id> in the specification notation), not an immediate.

The patch looks good to me. Thank you for the implementation.

iliya-diyachkov accepted this revision.Dec 17 2022, 1:47 PM
This revision was not accepted when it landed; it landed in state Needs Review.Dec 21 2022, 2:00 PM
This revision was automatically updated to reflect the committed changes.
mpaszkowski marked an inline comment as done.