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][LLVMLowering] Add LLVM lowering for unary fp2fp builtins #651

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

Lancern
Copy link
Member

@Lancern Lancern commented Jun 2, 2024

This patch adds LLVM lowering support for unary fp2fp builtins.

Those builtins that should be lowered to runtime function calls are lowered to such calls during lowering prepare. Other builtins are lowered to LLVM intrinsic calls during LLVM lowering.

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! Some inline comments.

@@ -713,7 +803,8 @@ void LoweringPreparePass::runOnOperation() {
op->walk([&](Operation *op) {
if (isa<CmpThreeWayOp, VAArgOp, GlobalOp, DynamicCastOp, StdFindOp,
IterEndOp, IterBeginOp, ArrayCtor, ArrayDtor, mlir::cir::FuncOp,
FModOp, PowOp>(op))
CosOp, ExpOp, Exp2Op, LogOp, Log10Op, Log2Op, SinOp, SqrtOp, FModOp,
PowOp>(op))
Copy link
Member

Choose a reason for hiding this comment

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

The chain of ifs is getting a bit bigger in runOnOp. How about:

  • We track these in another small vec mathOpsToTransform.
  • runOnOp calls only one function to handle them. Instead of this function dispatching to many lowerUnaryFPToFPBuiltinOp calls, it could do a table lookup to pick the strings: { {"cosf", "cos", "cosl"}, .... }, etc.

This should help us pave the road for some later tablegen based approach.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great! Implemented this refactor.

This patch adds LLVM lowering support for unary fp2fp builtins.

Those builtins that should be lowered to runtime function calls are lowered to
such calls during lowering prepare. Other builtins are lowered to LLVM intrinsic
calls during LLVM lowering.
@bcardosolopes bcardosolopes merged commit 76613f6 into llvm:main Jun 5, 2024
6 checks passed
@Lancern Lancern deleted the unary-fp2fp-lowering branch June 6, 2024 02:18
Lancern added a commit to Lancern/clangir that referenced this pull request Jun 8, 2024
LLVM lowering for the following operations is introduced in llvm#616 and llvm#651: cos,
exp, exp2, log, log10, log2, sin, sqrt, fmod, and pow. However, they are not
lowered to their corresponding LLVM intrinsics; instead they are transformed to
libc calls during lowering prepare. This does not match the upstream behavior.

This patch tries to correct this mistake.
Lancern added a commit to Lancern/clangir that referenced this pull request Jun 15, 2024
LLVM lowering for the following operations is introduced in llvm#616 and llvm#651: cos,
exp, exp2, log, log10, log2, sin, sqrt, fmod, and pow. However, they are not
lowered to their corresponding LLVM intrinsics; instead they are transformed to
libc calls during lowering prepare. This does not match the upstream behavior.

This patch tries to correct this mistake.
Lancern added a commit to Lancern/clangir that referenced this pull request Jun 24, 2024
LLVM lowering for the following operations is introduced in llvm#616 and llvm#651: cos,
exp, exp2, log, log10, log2, sin, sqrt, fmod, and pow. However, they are not
lowered to their corresponding LLVM intrinsics; instead they are transformed to
libc calls during lowering prepare. This does not match the upstream behavior.

This patch tries to correct this mistake.
Lancern added a commit to Lancern/clangir that referenced this pull request Jul 11, 2024
LLVM lowering for the following operations is introduced in llvm#616 and llvm#651: cos,
exp, exp2, log, log10, log2, sin, sqrt, fmod, and pow. However, they are not
lowered to their corresponding LLVM intrinsics; instead they are transformed to
libc calls during lowering prepare. This does not match the upstream behavior.

This patch tries to correct this mistake.
bcardosolopes pushed a commit that referenced this pull request Jul 11, 2024
LLVM lowering for the following operations is introduced in #616 and
#651: `cos`, `exp`, `exp2`, `log`, `log10`, `log2`, `sin`, `sqrt`,
`fmod`, and `pow`. However, they are not lowered to their corresponding
LLVM intrinsics; instead they are transformed to libc calls during
lowering prepare. This does not match the upstream behavior.

This PR tries to correct this mistake. It makes all CIR FP intrinsic ops
lower to their corresponding LLVM intrinsics (`fmod` is a special case
and it is lowered to the `frem` LLVM instruction).
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
)

This patch adds LLVM lowering support for unary fp2fp builtins.

Those builtins that should be lowered to runtime function calls are
lowered to such calls during lowering prepare. Other builtins are
lowered to LLVM intrinsic calls during LLVM lowering.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
)

This patch adds LLVM lowering support for unary fp2fp builtins.

Those builtins that should be lowered to runtime function calls are
lowered to such calls during lowering prepare. Other builtins are
lowered to LLVM intrinsic calls during LLVM lowering.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
LLVM lowering for the following operations is introduced in llvm#616 and
llvm#651: `cos`, `exp`, `exp2`, `log`, `log10`, `log2`, `sin`, `sqrt`,
`fmod`, and `pow`. However, they are not lowered to their corresponding
LLVM intrinsics; instead they are transformed to libc calls during
lowering prepare. This does not match the upstream behavior.

This PR tries to correct this mistake. It makes all CIR FP intrinsic ops
lower to their corresponding LLVM intrinsics (`fmod` is a special case
and it is lowered to the `frem` LLVM instruction).
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
)

This patch adds LLVM lowering support for unary fp2fp builtins.

Those builtins that should be lowered to runtime function calls are
lowered to such calls during lowering prepare. Other builtins are
lowered to LLVM intrinsic calls during LLVM lowering.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
LLVM lowering for the following operations is introduced in llvm#616 and
llvm#651: `cos`, `exp`, `exp2`, `log`, `log10`, `log2`, `sin`, `sqrt`,
`fmod`, and `pow`. However, they are not lowered to their corresponding
LLVM intrinsics; instead they are transformed to libc calls during
lowering prepare. This does not match the upstream behavior.

This PR tries to correct this mistake. It makes all CIR FP intrinsic ops
lower to their corresponding LLVM intrinsics (`fmod` is a special case
and it is lowered to the `frem` LLVM instruction).
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
LLVM lowering for the following operations is introduced in llvm#616 and
llvm#651: `cos`, `exp`, `exp2`, `log`, `log10`, `log2`, `sin`, `sqrt`,
`fmod`, and `pow`. However, they are not lowered to their corresponding
LLVM intrinsics; instead they are transformed to libc calls during
lowering prepare. This does not match the upstream behavior.

This PR tries to correct this mistake. It makes all CIR FP intrinsic ops
lower to their corresponding LLVM intrinsics (`fmod` is a special case
and it is lowered to the `frem` LLVM instruction).
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
)

This patch adds LLVM lowering support for unary fp2fp builtins.

Those builtins that should be lowered to runtime function calls are
lowered to such calls during lowering prepare. Other builtins are
lowered to LLVM intrinsic calls during LLVM lowering.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
LLVM lowering for the following operations is introduced in llvm#616 and
llvm#651: `cos`, `exp`, `exp2`, `log`, `log10`, `log2`, `sin`, `sqrt`,
`fmod`, and `pow`. However, they are not lowered to their corresponding
LLVM intrinsics; instead they are transformed to libc calls during
lowering prepare. This does not match the upstream behavior.

This PR tries to correct this mistake. It makes all CIR FP intrinsic ops
lower to their corresponding LLVM intrinsics (`fmod` is a special case
and it is lowered to the `frem` LLVM instruction).
lanza pushed a commit that referenced this pull request Nov 5, 2024
This patch adds LLVM lowering support for unary fp2fp builtins.

Those builtins that should be lowered to runtime function calls are
lowered to such calls during lowering prepare. Other builtins are
lowered to LLVM intrinsic calls during LLVM lowering.
lanza pushed a commit that referenced this pull request Nov 5, 2024
LLVM lowering for the following operations is introduced in #616 and
#651: `cos`, `exp`, `exp2`, `log`, `log10`, `log2`, `sin`, `sqrt`,
`fmod`, and `pow`. However, they are not lowered to their corresponding
LLVM intrinsics; instead they are transformed to libc calls during
lowering prepare. This does not match the upstream behavior.

This PR tries to correct this mistake. It makes all CIR FP intrinsic ops
lower to their corresponding LLVM intrinsics (`fmod` is a special case
and it is lowered to the `frem` LLVM instruction).
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