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] introduce CIR floating-point types #385

Merged
merged 4 commits into from
Feb 21, 2024
Merged

Conversation

Lancern
Copy link
Member

@Lancern Lancern commented Jan 6, 2024

This PR adds a dedicated cir.float type for representing floating-point types. There are several issues linked to this PR: #5, #78, and #90.

The new cir.float type is parameterized by an enum FloatFormat which defines the format of the floating point values. Currently 7 formats are defined:

  • FF_Binary16, which represents IEEE-754 binary16 format;
  • FF_Binary32, which represents IEEE-754 binary32 format, and corresponds to the float type in C/C++;
  • FF_Binary64, which represents IEEE-754 binary64 format, and corresponds to to the double and long double type in C/C++;
  • FF_Binary128, which represents IEEE-754 binary128 format, and corresponds to the long double type in C/C++.
  • FF_X86Fp80, which represents x86 80-bit floating point format, and also corresponds to the long double type in C/C++;
  • FF_BFloat16, which represents brain float format;
  • FF_PpcFp128, which represents PowerPC 128-bit floating point format. It is also known as the double double format. It also corresponds to the long double type in C/C++.

What floating-point format the long double type uses depends both on the implementation and on the target platform.

TODOs

Updated on Jan 8, 2024

  • Add FF_Binary16 and FF_BFloat16 formats.

Updated on Jan 15, 2024

  • Rename FF_Binary64E to FF_X86Fp80 to avoid confusion.
  • Add ppc_fp128 format.

@philnik777
Copy link
Contributor

Is there a reason to not also add support for float16 and bfloat16?

@Lancern
Copy link
Member Author

Lancern commented Jan 8, 2024

Is there a reason to not also add support for float16 and bfloat16?

@philnik777 Thanks for your comment.

I thought there aren't any standard types corresponding to float16 and bfloat16. But seems that C++23 now supports fixed width floating-point types and there are now std::float16_t and std::bfloat16_t. I'll add support to these two formats in later commits.

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.

Hi, this is awesome, happy to see progress in this direction, it's been a while since we want to have CIR specific float support. Some initial feedback in the comments.

Please also add new testcases to test aliases and cir to cir.

clang/include/clang/CIR/Dialect/IR/CIROps.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRAttrs.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRTypes.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRTypes.td Outdated Show resolved Hide resolved
clang/lib/CIR/Dialect/IR/CIRTypes.cpp Outdated Show resolved Hide resolved
@bcardosolopes
Copy link
Member

@sitio-couto because you did cir.int it would be great to get your review here too!

@bcardosolopes
Copy link
Member

@Lancern when you update the PR, please also make sure tests pass, so reviewers can play around with it locally. I know this is a Draft, but no problem making it a first class PR already - incremental work is fine and encouraged!

Copy link
Collaborator

@sitio-couto sitio-couto left a comment

Choose a reason for hiding this comment

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

@Lancern thanks for tackling this! It's long overdue.

I just added a suggestion and a discussion with @bcardosolopes.

clang/include/clang/CIR/Dialect/IR/CIRTypes.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRTypes.td Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 10, 2024

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

@Lancern
Copy link
Member Author

Lancern commented Jan 15, 2024

I met a problem trying to lower cir.const that yields a floating-point value in FF_PpcFp128 format to LLVMIR. The operation is lowered to a llvm.mlir.constant operation, which takes an attribute that may be an integer attribute, floating point attribute, dense or sparse attribute containing integers or floats. However, the builtin mlir::FloatAttr does not support PPC fp128 format floating-point values. How should we deal with this?

PPC fp128 type is lowered to a special !llvm.ppc_fp128 type provided by the LLVM dialect.

@Lancern
Copy link
Member Author

Lancern commented Jan 16, 2024

However, the builtin mlir::FloatAttr does not support PPC fp128 format floating-point values.

I have asked in the MLIR channel on Discord. Seems that support for !llvm.ppc_fp128 constant is missing in the LLVMIR and we have to wait for upstream to resolve it before the PPC FP128 format can be lowered to LLVMIR from CIR.

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.

Thanks for the changes @Lancern, more feedback for you inline. Couple of big picture comments:

  • Please make this first PR as simple as possible, focus on float and double and we could go over the rest with incremental work.
  • Apply @sitio-couto changes and create individual types for each floating point type.
  • Remove changes (mostly formatting) that are not related to the functionality you are changing - the amount of noise makes reviewing pretty hard.

clang/include/clang/CIR/Dialect/IR/CIROps.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRTypes.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRTypes.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRTypes.td Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenExprConst.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenBuilder.h Outdated Show resolved Hide resolved
@Lancern
Copy link
Member Author

Lancern commented Jan 21, 2024

Thanks for all your comments and early reviews here! According to the early reviews, I'm going to further update this PR with the following TODOs list:

  • Remove all whitespace-only changes from this PR.
  • Focus on float and double types only, and remove other formats from this PR. These additional formats will be implemented in future PRs.
  • Instead of using a parameterized !cir.float type to represent all floating-point types, invent dedicated type for each floating format: !cir.float, !cir.double, etc.

@Lancern
Copy link
Member Author

Lancern commented Jan 21, 2024

Rebased onto main and removed any whitespace-only changes.

@bcardosolopes
Copy link
Member

@Lancern thanks for the fast fixes and the work you've been putting up into the PRs. I'm currently working on an RFC to upstream clangir, so I'm a bit behind on reviews, I'll take a look into this one and others as soon as possible.

@Lancern
Copy link
Member Author

Lancern commented Jan 24, 2024

@bcardosolopes Just take your time! IMO your review latency is already good enough and it's understandable to slow down a bit especially if you have more important thing to do first.

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.

Sound like many of the changes requested haven't applied yet, I still see lots of things around that are out of the scope of this patch. Let me know once you go over all of them.

clang/lib/CIR/Dialect/IR/CIRAttrs.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/Dialect/IR/CIRTypes.cpp Outdated Show resolved Hide resolved
@Lancern
Copy link
Member Author

Lancern commented Jan 25, 2024

Thanks for everyone's early comments and reviews! Now I should have resolved all confirmed problems during the early review and there're no more TODOs on my list. So I believe this PR should be ready.

CC @bcardosolopes

@Lancern Lancern marked this pull request as ready for review January 25, 2024 14:58
@Lancern Lancern changed the title [CIR] introduce cir.float for floating-point types [CIR] introduce CIR floating-point types Jan 25, 2024
@lanza lanza force-pushed the main branch 2 times, most recently from 4e069c6 to 79d4dc7 Compare January 29, 2024 23:34
@bcardosolopes
Copy link
Member

@lanza just rebased and this has the side effect of breaking GH PR workflow, making it impossible to review, apologies. Please rebase!

@Lancern
Copy link
Member Author

Lancern commented Jan 30, 2024

Please rebase!

@bcardosolopes Rebased.

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.

Thanks for your patience, getting closer!

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRTypes.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRTypes.td Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRTypes.h Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenModule.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenTypeCache.h Outdated Show resolved Hide resolved
@bcardosolopes
Copy link
Member

Let me know when you're done applying all reviews (without conflicts) and ready for another round of review!

@Lancern
Copy link
Member Author

Lancern commented Feb 19, 2024

@bcardosolopes Hey I should have resolved all reviews yet. The primary change is replacing the mlir::cir::FloatType type with an interface that provides the same methods. Have a look when you have time :)

@Lancern
Copy link
Member Author

Lancern commented Feb 19, 2024

Rebased onto the latest main. Updated some newly merged to start using the new !cir.float and !cir.double type.

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.

Thanks for the hard work, only a few nit remaining!

clang/include/clang/CIR/Interfaces/CMakeLists.txt Outdated Show resolved Hide resolved
clang/lib/CIR/Dialect/IR/CIRAttrs.cpp Outdated Show resolved Hide resolved
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.

Awesome, thanks for putting solid work here and for your patience. LGTM

@bcardosolopes bcardosolopes merged commit 941cb1d into llvm:main Feb 21, 2024
6 checks passed
@Lancern Lancern deleted the cir-float branch February 22, 2024 01:20
lanza pushed a commit that referenced this pull request Mar 23, 2024
This PR adds a dedicated `cir.float` type for representing
floating-point types. There are several issues linked to this PR: #5,
#78, and #90.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
This PR adds a dedicated `cir.float` type for representing
floating-point types. There are several issues linked to this PR: llvm#5,
llvm#78, and llvm#90.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds a dedicated `cir.float` type for representing
floating-point types. There are several issues linked to this PR: #5,
#78, and #90.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds a dedicated `cir.float` type for representing
floating-point types. There are several issues linked to this PR: #5,
#78, and #90.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Apr 29, 2024
This PR adds a dedicated `cir.float` type for representing
floating-point types. There are several issues linked to this PR: llvm#5,
llvm#78, and llvm#90.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds a dedicated `cir.float` type for representing
floating-point types. There are several issues linked to this PR: #5,
#78, and #90.
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
This PR adds a dedicated `cir.float` type for representing
floating-point types. There are several issues linked to this PR: llvm#5,
llvm#78, and llvm#90.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This PR adds a dedicated `cir.float` type for representing
floating-point types. There are several issues linked to this PR: llvm#5,
llvm#78, and llvm#90.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
This PR adds a dedicated `cir.float` type for representing
floating-point types. There are several issues linked to this PR: llvm#5,
lanza pushed a commit that referenced this pull request Nov 5, 2024
This PR adds a dedicated `cir.float` type for representing
floating-point types. There are several issues linked to this PR: #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.

5 participants