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

[CIR][CIRGen] Support for builtin __atomic_thread_fence #1287

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Rajveer100
Copy link
Contributor

@Rajveer100 Rajveer100 commented Jan 17, 2025

Fix #1274

Implements atomic thread fence synchronization primitive corresponding to atomic.thread_fence CIR.

@Rajveer100
Copy link
Contributor Author

I have just created the ODS definition at the moment to be sure if this is the way to go.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

Initial step looks good, some inline comments. Note that this PR should come with CIRGen and LLVM lowering support, I suggest you first handle a very simple case of the fence and mark all paths not currently support with llvm_unrecheable("NYI"), so that you can go about working in incremental PRs to complete this.

clang/include/clang/CIR/Dialect/IR/CIROps.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIROps.td Show resolved Hide resolved
@bcardosolopes bcardosolopes changed the title [CIRGen] Task 1: Support for builtin __atomic_thread_fence [CIR][CIRGen] Support for builtin __atomic_thread_fence Jan 21, 2025
@Rajveer100 Rajveer100 force-pushed the atomic-thread_signal-fence branch from c2cc1a9 to e8758ac Compare January 26, 2025 10:50
@bcardosolopes
Copy link
Member

We just went over a rebase against upstream, apologies for the churn but please update your branch for this PR and force-push!

Resolves llvm#1274

Implements atomic thread fence synchronization primitive
corresponding to `atomic.thread_fence` CIR.
@Rajveer100 Rajveer100 force-pushed the atomic-thread_signal-fence branch from e8758ac to ca75a57 Compare January 28, 2025 11:23
@ghehg ghehg self-requested a review January 28, 2025 20:57
@@ -820,6 +821,16 @@ class CIRToLLVMAtomicFetchLowering
mlir::ConversionPatternRewriter &) const override;
};

// class CIRToLLVMAtomicFenceLowering
Copy link
Member

Choose a reason for hiding this comment

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

So far so good, time to add support for LLVM lowering as well, so we make sure the CIR operations contain all the info we need to lower to LLVM. You also need to add tests to this PR, see example in clang/test/CIR/CodeGen/abstract-cond.c.

auto orderingAttr =
orderingVal.getDefiningOp()->getAttrOfType<mlir::IntegerAttr>("value");

cir::MemOrder ordering;
Copy link
Member

Choose a reason for hiding this comment

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

Probably no need for the switch: the order of the enum is already the value you are checking for, so just cast it directly:

// Memory order according to C++11 memory model
enum class MemOrder : uint32_t {
  Relaxed = 0,
  Consume = 1,
  Acquire = 2,
  Release = 3,
  AcquireRelease = 4,
  SequentiallyConsistent = 5,
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CIRGen support for *_atomic_{thread,signal}_fence
2 participants