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][Builtin] Support __sync_add_and_fetch #1077

Merged
merged 4 commits into from
Nov 11, 2024

Conversation

ghehg
Copy link
Collaborator

@ghehg ghehg commented Nov 7, 2024

Notable change is to introduce helper function buildBinaryAtomicPost which models on OG's EmitBinaryAtomicPost. Comparing to EmitBinaryAtomicPost, buildBinaryAtomicPost is more concise as OG's EmitBinaryAtomicPost duplicates quite a bit of code from MakeBinaryAtomicValue
Also, didn't implement invert as __sync_add_and_fetch does not need it, but will add it (which is a trivial work) when we implement a builtin that needs it.
Test cases are from OG

@ghehg ghehg marked this pull request as ready for review November 7, 2024 15:36
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.

Also, didn't implement invert as __sync_add_and_fetch does not need it

What do you mean?


// These output arguments are needed for post atomic fetch operations
// that calculate the result of the operation as return value of
// <binop>_and_fetch builtins. The `AtomicFetch` operation ony updates the
Copy link
Member

Choose a reason for hiding this comment

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

*only

@ghehg
Copy link
Collaborator Author

ghehg commented Nov 9, 2024

Also, didn't implement invert as __sync_add_and_fetch does not need it

What do you mean?

OG has additional argument invert and code like the following to flip bits of result.

 if (Invert)
    Result =
        CGF.Builder.CreateBinOp(llvm::Instruction::Xor, Result,
                                llvm::ConstantInt::getAllOnesValue(IntType));

I didn't implement them so to keep test coverage , but will implement them when we implement __sync_nand_and_fetch which seems to be only case for this logic.
Or I might just do it at client site as again, __sync_nand_and_fetch seems to be the only use.

Copy link

github-actions bot commented Nov 9, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@bcardosolopes
Copy link
Member

I didn't implement them so to keep test coverage

Where's the missing feature assert + comments talking about that in code?

@ghehg
Copy link
Collaborator Author

ghehg commented Nov 10, 2024

I didn't implement them so to keep test coverage

Where's the missing feature assert + comments talking about that in code?
You are right, should add missing feature assert + comments when the code is different from OG.

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.

One minor conflict, but otherwise LGTM

@bcardosolopes bcardosolopes merged commit ab1df14 into llvm:main Nov 11, 2024
6 checks passed
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.

2 participants