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] Add support for builtin bit operations #474

Merged
merged 2 commits into from
Mar 5, 2024

Conversation

Lancern
Copy link
Member

@Lancern Lancern commented Feb 20, 2024

This PR adds CIRGen support for the following built-in bit operations:

  • __builtin_ffs{,l,ll,g}
  • __builtin_clz{,l,ll,g}
  • __builtin_ctz{,l,ll,g}
  • __builtin_clrsb{,l,ll,g}
  • __builtin_popcount{,l,ll,g}
  • __builtin_parity{,l,ll,g}

This PR adds a new operation, cir.bits, to represent such bit operations on the input integers. LLVMIR lowering support is not included in this PR.

Note

As a side note, C++20 adds the <bit> header which includes some bit operation functions with similar functionalities to the built-in functions mentioned above. However, these standard library functions have slightly different semantics than the built-in ones and this PR does not include support for these standard library functions. Support for these functions may be added later, or amended into this PR if the reviewers request so.

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.

Nice!

This mostly looks good, some cosmetic changes requested. Some food for thought for a future PR: do you think these could use the same technique from #434 ?

clang/include/clang/CIR/Dialect/IR/CIROps.td Outdated Show resolved Hide resolved
@Lancern
Copy link
Member Author

Lancern commented Feb 23, 2024

I made some changes in the latest commit. I removed the verification of input integer width, because I think these restrictions are unnecessarily strict and may prevent standard library bit operations from being lowered to cir.bit in the future.

@bcardosolopes
Copy link
Member

I made some changes in the latest commit. I removed the verification of input integer width

I rather see a more restrictive version until we have the optimization that does such lowering for library related ops. At that point we can relax based on what we see fit.

@Lancern
Copy link
Member Author

Lancern commented Feb 24, 2024

I rather see a more restrictive version until we have the optimization that does such lowering for library related ops. At that point we can relax based on what we see fit.

OK. I restored the type constraints on the input integer.

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.

LGTM, some conflict resolution remaining!

This patch adds CIRGen support for the following built-in bit operations:
  -`__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This patch adds a new operation, `cir.bits`, to represent such bit operations on
the input integers. LLVMIR lowering support is not included in this patch.

Rename CIR bit operations to cir.bit.*

Move all verification code into TableGen
@Lancern
Copy link
Member Author

Lancern commented Mar 1, 2024

@bcardosolopes Rebased onto the latest main.

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.

LGTM

@bcardosolopes bcardosolopes merged commit a964c7b into llvm:main Mar 5, 2024
6 checks passed
@Lancern Lancern deleted the builtin-bit-op branch March 6, 2024 01:26
lanza pushed a commit that referenced this pull request Mar 23, 2024
This PR adds CIRGen support for the following built-in bit operations:

  - `__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This PR adds a new operation, `cir.bits`, to represent such bit
operations on the input integers. LLVMIR lowering support is not
included in this PR.

> [!NOTE]
> As a side note, C++20 adds the `<bit>` header which includes some bit
operation functions with similar functionalities to the built-in
functions mentioned above. However, these standard library functions
have slightly different semantics than the built-in ones and this PR
does not include support for these standard library functions. Support
for these functions may be added later, or amended into this PR if the
reviewers request so.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
This PR adds CIRGen support for the following built-in bit operations:

  - `__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This PR adds a new operation, `cir.bits`, to represent such bit
operations on the input integers. LLVMIR lowering support is not
included in this PR.

> [!NOTE]
> As a side note, C++20 adds the `<bit>` header which includes some bit
operation functions with similar functionalities to the built-in
functions mentioned above. However, these standard library functions
have slightly different semantics than the built-in ones and this PR
does not include support for these standard library functions. Support
for these functions may be added later, or amended into this PR if the
reviewers request so.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds CIRGen support for the following built-in bit operations:

  - `__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This PR adds a new operation, `cir.bits`, to represent such bit
operations on the input integers. LLVMIR lowering support is not
included in this PR.

> [!NOTE]
> As a side note, C++20 adds the `<bit>` header which includes some bit
operation functions with similar functionalities to the built-in
functions mentioned above. However, these standard library functions
have slightly different semantics than the built-in ones and this PR
does not include support for these standard library functions. Support
for these functions may be added later, or amended into this PR if the
reviewers request so.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds CIRGen support for the following built-in bit operations:

  - `__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This PR adds a new operation, `cir.bits`, to represent such bit
operations on the input integers. LLVMIR lowering support is not
included in this PR.

> [!NOTE]
> As a side note, C++20 adds the `<bit>` header which includes some bit
operation functions with similar functionalities to the built-in
functions mentioned above. However, these standard library functions
have slightly different semantics than the built-in ones and this PR
does not include support for these standard library functions. Support
for these functions may be added later, or amended into this PR if the
reviewers request so.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Apr 29, 2024
This PR adds CIRGen support for the following built-in bit operations:

  - `__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This PR adds a new operation, `cir.bits`, to represent such bit
operations on the input integers. LLVMIR lowering support is not
included in this PR.

> [!NOTE]
> As a side note, C++20 adds the `<bit>` header which includes some bit
operation functions with similar functionalities to the built-in
functions mentioned above. However, these standard library functions
have slightly different semantics than the built-in ones and this PR
does not include support for these standard library functions. Support
for these functions may be added later, or amended into this PR if the
reviewers request so.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds CIRGen support for the following built-in bit operations:

  - `__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This PR adds a new operation, `cir.bits`, to represent such bit
operations on the input integers. LLVMIR lowering support is not
included in this PR.

> [!NOTE]
> As a side note, C++20 adds the `<bit>` header which includes some bit
operation functions with similar functionalities to the built-in
functions mentioned above. However, these standard library functions
have slightly different semantics than the built-in ones and this PR
does not include support for these standard library functions. Support
for these functions may be added later, or amended into this PR if the
reviewers request so.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
This PR adds CIRGen support for the following built-in bit operations:

  - `__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This PR adds a new operation, `cir.bits`, to represent such bit
operations on the input integers. LLVMIR lowering support is not
included in this PR.

> [!NOTE]
> As a side note, C++20 adds the `<bit>` header which includes some bit
operation functions with similar functionalities to the built-in
functions mentioned above. However, these standard library functions
have slightly different semantics than the built-in ones and this PR
does not include support for these standard library functions. Support
for these functions may be added later, or amended into this PR if the
reviewers request so.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This PR adds CIRGen support for the following built-in bit operations:

  - `__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This PR adds a new operation, `cir.bits`, to represent such bit
operations on the input integers. LLVMIR lowering support is not
included in this PR.

> [!NOTE]
> As a side note, C++20 adds the `<bit>` header which includes some bit
operation functions with similar functionalities to the built-in
functions mentioned above. However, these standard library functions
have slightly different semantics than the built-in ones and this PR
does not include support for these standard library functions. Support
for these functions may be added later, or amended into this PR if the
reviewers request so.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
This PR adds CIRGen support for the following built-in bit operations:

  - `__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This PR adds a new operation, `cir.bits`, to represent such bit
operations on the input integers. LLVMIR lowering support is not
included in this PR.

> [!NOTE]
> As a side note, C++20 adds the `<bit>` header which includes some bit
operation functions with similar functionalities to the built-in
functions mentioned above. However, these standard library functions
have slightly different semantics than the built-in ones and this PR
does not include support for these standard library functions. Support
for these functions may be added later, or amended into this PR if the
reviewers request so.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
lanza pushed a commit that referenced this pull request Nov 5, 2024
This PR adds CIRGen support for the following built-in bit operations:

  - `__builtin_ffs{,l,ll,g}`
  - `__builtin_clz{,l,ll,g}`
  - `__builtin_ctz{,l,ll,g}`
  - `__builtin_clrsb{,l,ll,g}`
  - `__builtin_popcount{,l,ll,g}`
  - `__builtin_parity{,l,ll,g}`

This PR adds a new operation, `cir.bits`, to represent such bit
operations on the input integers. LLVMIR lowering support is not
included in this PR.

> [!NOTE]
> As a side note, C++20 adds the `<bit>` header which includes some bit
operation functions with similar functionalities to the built-in
functions mentioned above. However, these standard library functions
have slightly different semantics than the built-in ones and this PR
does not include support for these standard library functions. Support
for these functions may be added later, or amended into this PR if the
reviewers request so.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
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