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 CIRGen support for float16 and bfloat #571

Merged
merged 2 commits into from May 14, 2024

Conversation

Lancern
Copy link
Collaborator

@Lancern Lancern commented Apr 28, 2024

This PR adds two new CIR floating-point types, namely !cir.f16 and !cir.bf16, to represent the float16 format and bfloat format, respectively.

This PR converts the clang extension type _Float16 to !cir.f16, and converts the clang extension type __bf16 type to !cir.bf16. The type conversion for clang extension type __fp16 is not included in this PR since it requires additional work during CIRGen.

Only CIRGen is implemented here, LLVMIR lowering / MLIR lowering should come next.

@bcardosolopes
Copy link
Member

Nathan just did a rebase, can you please update? Sorry for the churn

@Lancern
Copy link
Collaborator Author

Lancern commented May 2, 2024

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.

Thanks for adding more floating point goodness. Comments inline.

clang/lib/CIR/CodeGen/CIRGenTypeCache.h Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRTypes.td Outdated Show resolved Hide resolved
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/float16-arithmetic.c Outdated Show resolved Hide resolved
@Lancern Lancern marked this pull request as draft May 10, 2024 13:18
This patch adds two new CIR floating-point types, namely `!cir.f16` and
`!cir.bf16`, to represent the float16 format and bfloat format, respectively.
CIRGen for the two new types and scalar expressions involving these two new
types is also included in this patch.

This patch converts the clang extension type `_Float16` to `!cir.f16`, and
converts the clang extension type `__bf16` type to `!cir.bf16`.
@Lancern Lancern marked this pull request as ready for review May 12, 2024 11:33
@Lancern
Copy link
Collaborator Author

Lancern commented May 12, 2024

Rebased onto the latest main and updated this PR according to the latest reviews:

  • This PR now only deals with the CIRGen of the two new floating point types as this is already complex enough to be stuffed into a single PR.
  • CIRGenExprScalar is updated according to the original clang CodeGen. Specifically, scalar promotion of the new half-precision types is added to the CIRGen.

@Lancern Lancern changed the title [CIR] Add support for float16 and bfloat [CIR][CIRGen] Add CIRGen support for float16 and bfloat May 12, 2024
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.

Great, thanks for all the promotion related improvements, they are very nice.

LLVMIR lowering, and MLIR lowering for the two new types are also included in this PR.

Fine for this, but for next PRs I might start getting more picky about adding LLVM IR checks, the unary questions below are one example where checking intended LLVM output could have made some of the choices easier.

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp Show resolved Hide resolved
@bcardosolopes bcardosolopes merged commit 43094d7 into llvm:main May 14, 2024
6 checks passed
@Lancern Lancern deleted the half-precision-fp branch May 15, 2024 02:47
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.

None yet

2 participants