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

[IR] Add an IR Builder with some basic functions #2204

Merged
merged 6 commits into from
Mar 8, 2021

Conversation

xumingkuan
Copy link
Contributor

Related issue = #2193

This PR renames the existing IRBuilder class to ASTBuilder, since it actually builds the frontend AST in C++.

The IRBuilder newly added in this PR is able to build the following instructions now:

  • Kernel argument loads (I'm not sure if exposing the DataType dt, bool is_ptr arguments is a good idea)
  • (Some) Constants
  • (Some) Binary operations
  • Prints

However, we cannot use the new IRBuilder to build a whole program now, since the constructor Kernel::Kernel() fetches the IR from ASTBuilder. I'm not sure how to solve it -- would it be fine to simply add a constructor to the Kernel class, and let developers call it to use the new IRBuilder?

And... the new IRBuilder is not unit-tested now.

[Click here for the format server]


Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

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

Thanks! A few nits

taichi/ir/ir_builder.h Outdated Show resolved Hide resolved

class IRBuilder {
public:
struct InsertPoint {
Copy link
Member

Choose a reason for hiding this comment

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

nit: does this need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if we need to modify the insertion point... I think it's fine to make it private now.

taichi/ir/ir_builder.h Outdated Show resolved Hide resolved
taichi/ir/ir_builder.h Outdated Show resolved Hide resolved
Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

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

Looks like a great first step!

Copy link
Member

@yuanming-hu yuanming-hu left a comment

Choose a reason for hiding this comment

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

Great! LGTM.

However, we cannot use the new IRBuilder to build a whole program now, since the constructor Kernel::Kernel() fetches the IR from ASTBuilder. I'm not sure how to solve it -- would it be fine to simply add a constructor to the Kernel class, and let developers call it to use the new IRBuilder?

Your solution sounds good!

Stmt *insert(std::unique_ptr<Stmt> &&stmt);

// Constants. TODO: add more types
Stmt *get_int32(int32 value);
Copy link
Member

Choose a reason for hiding this comment

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

You may also consider a template <typename T> Stmt *get_const(T val) template function and then specialize for different types (or use if constexpr (std::is_same_v<T, int32>)). Just a random idea and the decision is yours :-)

@xumingkuan xumingkuan merged commit 582335e into taichi-dev:master Mar 8, 2021
@xumingkuan xumingkuan deleted the ir-builder branch March 13, 2021 12:15
@k-ye k-ye mentioned this pull request Mar 14, 2021
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.

4 participants