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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And I believe LLVM::FenceOp is what you need to lower to. For CIR::AtomicFence

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp Show resolved Hide resolved
case Builtin::BI__c11_atomic_thread_fence:
case Builtin::BI__c11_atomic_signal_fence:
llvm_unreachable("BI__atomic_thread_fence like NYI");
llvm_unreachable("BI__c11_atomic_thread_fence like NYI");
Copy link
Collaborator

@ghehg ghehg Feb 3, 2025

Choose a reason for hiding this comment

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

From OG's code, it looks like that c11 cases have same implementation? could we have them supported as well? You don't have to, it's a nice to have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I was unsure if it would be the same so marked it as unreachable.

: builder.getSIntNTy(cgf.getContext().getTypeSize(typ));

auto orderingVal =
emitToInt(cgf, cgf.emitScalarExpr(expr->getArg(1)), typ, intType);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I'm a bit lost here. looking at OG, and definition of builtin
The call expr should have only one argument, so what is this expr->getArg(1) about?

Also, it seems that memOrdering could be variable, in which case switch and blocks generated

The code added here seems only handling constant ordering case, which is totally fine to me, but we need to NYI or missing feature for the variable situation.

@@ -820,6 +821,16 @@ class CIRToLLVMAtomicFetchLowering
mlir::ConversionPatternRewriter &) const override;
};

// class CIRToLLVMAtomicFenceLowering
Copy link
Collaborator

Choose a reason for hiding this comment

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

And I believe LLVM::FenceOp is what you need to lower to. For CIR::AtomicFence

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
3 participants