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] Add FuncAttrs to cir.calls #637

Merged
merged 2 commits into from
Jun 13, 2024
Merged

[CIR] Add FuncAttrs to cir.calls #637

merged 2 commits into from
Jun 13, 2024

Conversation

roro47
Copy link
Contributor

@roro47 roro47 commented May 29, 2024

Some function attributes are also callsite attributes, for instance, nothrow. This means they are going to show up in both. We don't support that just yet, hence the PR.

CIR has an attribute ExtraFuncAttr that we current use as part of FuncOp, see CIROps.td. This attribute also needs to be added to CallOp and TryCalOp.

Right now, In CIRGenCall.cpp: AddAttributesFromFunctionProtoType fills in FuncAttrs, but doesn't use it for anything. We should use the FuncAttrs result to populate constructing a ExtraFuncAttr and add it to the aforementioned call operations.

@roro47 roro47 force-pushed the main branch 3 times, most recently from cd1dc1c to c176445 Compare May 29, 2024 09:25
@roro47
Copy link
Contributor Author

roro47 commented May 29, 2024

@bcardosolopes Currently when running ninja check-clang-cir, 8 test cases are failing from the new changes because of

'cir.call' op requires attribute extra_attrs

This is because CallOp are created in other places outside of CIRGenCall.cpp with cir::CIRGenBuilderTy.create<mlir::cir::CallOp> which didn't handle passing extra_attrs. I think the best way to fix this is to modify those calls so that they all use just the methods from CIRGenCall.cpp.

It makes sense to only use methods in CIRGenCall.cpp to create callop instead of directly calling cir::CIRGenBuilderTy.create<mlir::cir::CallOp>. What do you think about this approach?

@roro47 roro47 force-pushed the main branch 2 times, most recently from c79abfe to 5ef82f4 Compare May 29, 2024 09:54
@bcardosolopes
Copy link
Member

Thanks for your first PR, this is great!

This is because CallOp are created in other places outside of CIRGenCall.cpp with cir::CIRGenBuilderTy.create<mlir::cir::CallOp> which didn't handle passing extra_attrs. I think the best way to fix this is to modify those calls so that they all use just the methods from CIRGenCall.cpp.

Sounds like a good plan!

It makes sense to only use methods in CIRGenCall.cpp to create callop instead of directly calling cir::CIRGenBuilderTy.create<mlir::cir::CallOp>. What do you think about this approach?

I always prefer to refactor common code and boil down to one place that actually does the final calls to builder.create<...CallOp..>. But if it's too complex to tackle all existing ones, you can start incremental and only change existing helpers to pass down extra_attrs, and in a later PR you do further refactoring.

clang/test/CIR/CodeGen/call-extra-attrs.cpp Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/call-extra-attrs.cpp Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/call-extra-attrs.cpp Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/call-extra-attrs.cpp Show resolved Hide resolved
clang/lib/CIR/Dialect/IR/CIRDialect.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/Dialect/IR/CIRDialect.cpp Outdated Show resolved Hide resolved
@roro47 roro47 force-pushed the main branch 2 times, most recently from 36d7f6d to 475cba8 Compare June 6, 2024 13:08
@roro47
Copy link
Contributor Author

roro47 commented Jun 6, 2024

Thanks for your first PR, this is great!

This is because CallOp are created in other places outside of CIRGenCall.cpp with cir::CIRGenBuilderTy.create<mlir::cir::CallOp> which didn't handle passing extra_attrs. I think the best way to fix this is to modify those calls so that they all use just the methods from CIRGenCall.cpp.

Sounds like a good plan!

It makes sense to only use methods in CIRGenCall.cpp to create callop instead of directly calling cir::CIRGenBuilderTy.create<mlir::cir::CallOp>. What do you think about this approach?

I always prefer to refactor common code and boil down to one place that actually does the final calls to builder.create<...CallOp..>. But if it's too complex to tackle all existing ones, you can start incremental and only change existing helpers to pass down extra_attrs, and in a later PR you do further refactoring.

I didn't see any extra helper that was calling create<milr::cir::CallOp> so I added a new helper called createCallOp to replace it.

@roro47 roro47 changed the title [CIR][WIP] Add FuncAttrs to cir.calls [CIR] Add FuncAttrs to cir.calls Jun 6, 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.

Overall looks good, thanks! Some extra nits before I land this.

clang/lib/CIR/Dialect/IR/CIRDialect.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/Dialect/IR/CIRDialect.cpp Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h Outdated Show resolved Hide resolved
@roro47 roro47 force-pushed the main branch 3 times, most recently from 03fdf41 to bedeb43 Compare June 11, 2024 18:23
@roro47 roro47 force-pushed the main branch 2 times, most recently from 2921e81 to f6374a6 Compare June 12, 2024 14:41
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.

Very close, one more round of review!

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIROps.td Show resolved Hide resolved
@bcardosolopes
Copy link
Member

Looks like there are some failing tests, possibly some refactoring went wrong. You can catch those locally by running ninja check-clang-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.

Awesome, LGTM. If all test pass going to be landing it soon!

@bcardosolopes bcardosolopes merged commit f07bad4 into llvm:main Jun 13, 2024
6 checks passed
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
Some function attributes are also callsite attributes, for instance,
nothrow. This means they are going to show up in both. We don't support
that just yet, hence the PR.

CIR has an attribute `ExtraFuncAttr` that we current use as part of
`FuncOp`, see CIROps.td. This attribute also needs to be added to
`CallOp` and `TryCalOp`.

Right now, In `CIRGenCall.cpp: AddAttributesFromFunctionProtoType` fills
in `FuncAttrs`, but doesn't use it for anything. We should use the
`FuncAttrs` result to populate constructing a `ExtraFuncAttr` and add it
to the aforementioned call operations.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
Some function attributes are also callsite attributes, for instance,
nothrow. This means they are going to show up in both. We don't support
that just yet, hence the PR.

CIR has an attribute `ExtraFuncAttr` that we current use as part of
`FuncOp`, see CIROps.td. This attribute also needs to be added to
`CallOp` and `TryCalOp`.

Right now, In `CIRGenCall.cpp: AddAttributesFromFunctionProtoType` fills
in `FuncAttrs`, but doesn't use it for anything. We should use the
`FuncAttrs` result to populate constructing a `ExtraFuncAttr` and add it
to the aforementioned call operations.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
Some function attributes are also callsite attributes, for instance,
nothrow. This means they are going to show up in both. We don't support
that just yet, hence the PR.

CIR has an attribute `ExtraFuncAttr` that we current use as part of
`FuncOp`, see CIROps.td. This attribute also needs to be added to
`CallOp` and `TryCalOp`.

Right now, In `CIRGenCall.cpp: AddAttributesFromFunctionProtoType` fills
in `FuncAttrs`, but doesn't use it for anything. We should use the
`FuncAttrs` result to populate constructing a `ExtraFuncAttr` and add it
to the aforementioned call operations.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
Some function attributes are also callsite attributes, for instance,
nothrow. This means they are going to show up in both. We don't support
that just yet, hence the PR.

CIR has an attribute `ExtraFuncAttr` that we current use as part of
`FuncOp`, see CIROps.td. This attribute also needs to be added to
`CallOp` and `TryCalOp`.

Right now, In `CIRGenCall.cpp: AddAttributesFromFunctionProtoType` fills
in `FuncAttrs`, but doesn't use it for anything. We should use the
`FuncAttrs` result to populate constructing a `ExtraFuncAttr` and add it
to the aforementioned call operations.
lanza pushed a commit that referenced this pull request Nov 5, 2024
Some function attributes are also callsite attributes, for instance,
nothrow. This means they are going to show up in both. We don't support
that just yet, hence the PR.

CIR has an attribute `ExtraFuncAttr` that we current use as part of
`FuncOp`, see CIROps.td. This attribute also needs to be added to
`CallOp` and `TryCalOp`.

Right now, In `CIRGenCall.cpp: AddAttributesFromFunctionProtoType` fills
in `FuncAttrs`, but doesn't use it for anything. We should use the
`FuncAttrs` result to populate constructing a `ExtraFuncAttr` and add it
to the aforementioned call operations.
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