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

[llvm] [lang] Add support for multiple return statements in real function #4536

Merged
merged 1 commit into from
Mar 18, 2022

Conversation

lin-hitonami
Copy link
Contributor

@lin-hitonami lin-hitonami commented Mar 15, 2022

Related issue = #602

For reviewers:
This PR inserts return instruction when visiting return statement in the codegen.

LLVM requires a basic block to have one and only one terminator instruction (return, branch, etc.) at the end of the block. So, this PR does the following things.

  1. Adds a flag returned in the codegen, indicating whether the current basic block has inserted a return instruction.
  2. If the current basic block has inserted a return instruction, the codegen stops processing all statements after it in a basic block, and does not add the branch instruction supposed to be added when constructing if/for/while statements.
  3. If the basic block does not have a terminator instruction, insert a return instruction.
  4. Restores the returned flag to false when the current basic block completes.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…tion
@netlify
Copy link

netlify bot commented Mar 15, 2022

✔️ Deploy Preview for docsite-preview ready!

🔨 Explore the source changes: e08e551

🔍 Inspect the deploy log: https://app.netlify.com/sites/docsite-preview/deploys/62304bda5c8c7e000895257c

😎 Browse the preview: https://deploy-preview-4536--docsite-preview.netlify.app

Copy link
Contributor

@strongoier strongoier left a comment

Choose a reason for hiding this comment

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

It might help reviewers if you leave some comments in the code or briefly introduce your solution in the PR description :-)

@lin-hitonami
Copy link
Contributor Author

It might help reviewers if you leave some comments in the code or briefly introduce your solution in the PR description :-)

Updated PR description.

Copy link
Contributor

@strongoier strongoier 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 clear description!

taichi/codegen/codegen_llvm.cpp Show resolved Hide resolved
Copy link
Contributor

@strongoier strongoier left a comment

Choose a reason for hiding this comment

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

LGTM!

@lin-hitonami lin-hitonami merged commit c57b8d2 into taichi-dev:master Mar 18, 2022
@lin-hitonami lin-hitonami deleted the return branch March 18, 2022 07:19
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