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

[CodeGenC] Use PrimFuncNode::ret_type in function signature #15073

Merged
merged 1 commit into from
Jun 13, 2023

Conversation

Lunderberg
Copy link
Contributor

Prior to this PR, the return type for CodeGenC was hard-coded as part of virtual CodeGenC::PrintFuncPrefix, regardless of the return type specified in the PrimFunc. This PR updates CodeGenC to use PrimFuncNode::ret_type for the return type in the generated C code.

This change should have no effect on observable behavior, while allowing the forward declaration of external functions to be improved. The majority of codegen classes specified a void return type, which matches the default DataType::Void() for a PrimFunc. The one exception is CodeGenCHost::PrintFuncPrefix, which specified an int32_t return type, matching the DataType::Int(32) used for the functions generated by MakePackedAPI and MakeUnpackedAPI.

Prior to this PR, the return type for `CodeGenC` was hard-coded as
part of `virtual CodeGenC::PrintFuncPrefix`, regardless of the return
type specified in the `PrimFunc`.  This PR updates `CodeGenC` to use
`PrimFuncNode::ret_type` for the return type in the generated C code.

This change should have no effect on observable behavior.  The
majority of codegen classes specified a `void` return type, which
matches the default `DataType::Void()` for a `PrimFunc`.  The one
exception is `CodeGenCHost::PrintFuncPrefix`, which specified an
`int32_t` return type, matching the `DataType::Int(32)` used for the
functions generated by `MakePackedAPI` and `MakeUnpackedAPI`.
@tvm-bot
Copy link
Collaborator

tvm-bot commented Jun 12, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to tag found in teams: codegenc See #10317 for details

Generated by tvm-bot

Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Jun 12, 2023
Previously, the return value of a PackedFunc was hard-coded as the
string `"return 0;"` in `CodeGenCHost`, which could cause compilation
errors for `PrimFunc` returning `DataType::Void()`.  This PR removes
this explicit return statement from `CodeGenCHost`, replacing it with
`tir::ret(Integer(0))` in the `MakePackedAPI` and `MakeUnpackedAPI`
transforms.

This is related to apache#15073, which
performs an analogous change for the function signature.
@tqchen tqchen merged commit 68ac909 into apache:main Jun 13, 2023
@Lunderberg Lunderberg deleted the codegen_c_function_return_type branch June 13, 2023 15:08
csullivan pushed a commit that referenced this pull request Jun 15, 2023
* [TIR][CodeGen] Define PackedFunc error code in MakePackedAPI

Previously, the return value of a PackedFunc was hard-coded as the
string `"return 0;"` in `CodeGenCHost`, which could cause compilation
errors for `PrimFunc` returning `DataType::Void()`.  This PR removes
this explicit return statement from `CodeGenCHost`, replacing it with
`tir::ret(Integer(0))` in the `MakePackedAPI` and `MakeUnpackedAPI`
transforms.

This is related to #15073, which
performs an analogous change for the function signature.

* Handle builtin::ret() in CodeGenC

* Place T.ret(0) inside asserts, rather than outside

This causes fewer unit tests to break, and has more readable
TVMScript.

* Update unit tests to look inside SeqStmt

* Handle T.ret(0) in CodeGenStackVM

* Update MakeUnpackedAPI tests to expect T.ret
junrushao pushed a commit to junrushao/tvm that referenced this pull request Jun 22, 2023
…5073)

Prior to this PR, the return type for `CodeGenC` was hard-coded as
part of `virtual CodeGenC::PrintFuncPrefix`, regardless of the return
type specified in the `PrimFunc`.  This PR updates `CodeGenC` to use
`PrimFuncNode::ret_type` for the return type in the generated C code.

This change should have no effect on observable behavior.  The
majority of codegen classes specified a `void` return type, which
matches the default `DataType::Void()` for a `PrimFunc`.  The one
exception is `CodeGenCHost::PrintFuncPrefix`, which specified an
`int32_t` return type, matching the `DataType::Int(32)` used for the
functions generated by `MakePackedAPI` and `MakeUnpackedAPI`.
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.

3 participants