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] Let real function return nested StructType #7059

Merged
merged 7 commits into from
Jan 6, 2023

Conversation

lin-hitonami
Copy link
Contributor

@lin-hitonami lin-hitonami commented Jan 5, 2023

Stack from ghstack (oldest at bottom):

issue: #6983

Before this PR, if we want to return a struct type in a real function, we flatten the struct in LLVM. For example, struct(a: Ta, s: struct(b: Tb, c: Tc)) is flattened to struct(a: Ta, b: Tb, c: Tc). After this PR, we do not flatten anymore. We directly return struct(a: Ta, s: struct(b: Tb, c: Tc)).

Note that we still need to pass the flattened return values from Python to CHI-IR because we can't pass a Python struct into C++. We compose the target struct type from the flattened values and the return type in the codegen.

lin-hitonami added a commit that referenced this pull request Jan 5, 2023
ghstack-source-id: 9e9de3d852a8adaf4dae5810a868a31afefeae1a
Pull Request resolved: #7059
taichi/codegen/llvm/codegen_llvm.cpp Outdated Show resolved Hide resolved
@@ -2757,6 +2749,49 @@ llvm::Type *TaskCodeGenLLVM::get_real_func_ret_type(Function *real_func) {
return llvm::StructType::get(*llvm_context, tps);
}

void TaskCodeGenLLVM::create_return(llvm::Value *buffer,
llvm::Type *buffer_type,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we obtain buffer_type from buffer->getType()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No... While it works fine on linux machines, it doesn't work on Windows because the pointers are opaque pointers, and buffer->getType() only returns ptr in LLVM 15. I don't know why it works on linux machines... maybe the LLVM binaries are different....

taichi/codegen/llvm/codegen_llvm.cpp Show resolved Hide resolved
taichi/codegen/llvm/codegen_llvm.cpp Outdated Show resolved Hide resolved
taichi/codegen/llvm/codegen_llvm.h Outdated Show resolved Hide resolved
issue: #6983

Before this PR, if we want to return a struct type in a real function, we flatten the struct in LLVM. For example, `struct(a: Ta, s: struct(b: Tb, c: Tc))` is flattened to `struct(a: Ta, b: Tb, c: Tc)`. After this PR, we do not flatten anymore. We directly return `struct(a: Ta, s: struct(b: Tb, c: Tc))`. 

Note that we still need  to pass the flattened return values from Python to CHI-IR because we can't pass a Python struct into C++. We compose the target struct type from the flattened values and the return type in the codegen.

[ghstack-poisoned]
lin-hitonami added a commit that referenced this pull request Jan 6, 2023
ghstack-source-id: da419c9cae39d8a96490c01b5dbf0b50fd2137c3
Pull Request resolved: #7059
issue: #6983

Before this PR, if we want to return a struct type in a real function, we flatten the struct in LLVM. For example, `struct(a: Ta, s: struct(b: Tb, c: Tc))` is flattened to `struct(a: Ta, b: Tb, c: Tc)`. After this PR, we do not flatten anymore. We directly return `struct(a: Ta, s: struct(b: Tb, c: Tc))`. 

Note that we still need  to pass the flattened return values from Python to CHI-IR because we can't pass a Python struct into C++. We compose the target struct type from the flattened values and the return type in the codegen.

[ghstack-poisoned]
lin-hitonami added a commit that referenced this pull request Jan 6, 2023
ghstack-source-id: dc6954a0f04f99a8edb72a6b950315ccf60a7237
Pull Request resolved: #7059
issue: #6983

Before this PR, if we want to return a struct type in a real function, we flatten the struct in LLVM. For example, `struct(a: Ta, s: struct(b: Tb, c: Tc))` is flattened to `struct(a: Ta, b: Tb, c: Tc)`. After this PR, we do not flatten anymore. We directly return `struct(a: Ta, s: struct(b: Tb, c: Tc))`. 

Note that we still need  to pass the flattened return values from Python to CHI-IR because we can't pass a Python struct into C++. We compose the target struct type from the flattened values and the return type in the codegen.

[ghstack-poisoned]
lin-hitonami added a commit that referenced this pull request Jan 6, 2023
ghstack-source-id: 21a1ad6ce1912fd52267a176586bde2d56bd8148
Pull Request resolved: #7059
issue: #6983

Before this PR, if we want to return a struct type in a real function, we flatten the struct in LLVM. For example, `struct(a: Ta, s: struct(b: Tb, c: Tc))` is flattened to `struct(a: Ta, b: Tb, c: Tc)`. After this PR, we do not flatten anymore. We directly return `struct(a: Ta, s: struct(b: Tb, c: Tc))`. 

Note that we still need  to pass the flattened return values from Python to CHI-IR because we can't pass a Python struct into C++. We compose the target struct type from the flattened values and the return type in the codegen.

[ghstack-poisoned]
lin-hitonami added a commit that referenced this pull request Jan 6, 2023
ghstack-source-id: 2898ad5c64bbee12090e1546c3dbf24b85603a56
Pull Request resolved: #7059
issue: #6983

Before this PR, if we want to return a struct type in a real function, we flatten the struct in LLVM. For example, `struct(a: Ta, s: struct(b: Tb, c: Tc))` is flattened to `struct(a: Ta, b: Tb, c: Tc)`. After this PR, we do not flatten anymore. We directly return `struct(a: Ta, s: struct(b: Tb, c: Tc))`. 

Note that we still need  to pass the flattened return values from Python to CHI-IR because we can't pass a Python struct into C++. We compose the target struct type from the flattened values and the return type in the codegen.

[ghstack-poisoned]
lin-hitonami added a commit that referenced this pull request Jan 6, 2023
ghstack-source-id: 1384c5f237c9b2dda70d084668fe902226388bc0
Pull Request resolved: #7059
issue: #6983

Before this PR, if we want to return a struct type in a real function, we flatten the struct in LLVM. For example, `struct(a: Ta, s: struct(b: Tb, c: Tc))` is flattened to `struct(a: Ta, b: Tb, c: Tc)`. After this PR, we do not flatten anymore. We directly return `struct(a: Ta, s: struct(b: Tb, c: Tc))`. 

Note that we still need  to pass the flattened return values from Python to CHI-IR because we can't pass a Python struct into C++. We compose the target struct type from the flattened values and the return type in the codegen.

[ghstack-poisoned]
lin-hitonami added a commit that referenced this pull request Jan 6, 2023
ghstack-source-id: c7345fbae605793d13fd4c358e65ab20815c9155
Pull Request resolved: #7059
@lin-hitonami lin-hitonami merged commit 02943a4 into gh/lin-hitonami/3/base Jan 6, 2023
lin-hitonami added a commit that referenced this pull request Jan 6, 2023
ghstack-source-id: c7345fbae605793d13fd4c358e65ab20815c9155
Pull Request resolved: #7059
@lin-hitonami lin-hitonami deleted the gh/lin-hitonami/3/head branch January 6, 2023 09:50
quadpixels pushed a commit to quadpixels/taichi that referenced this pull request May 13, 2023
ghstack-source-id: c7345fbae605793d13fd4c358e65ab20815c9155
Pull Request resolved: taichi-dev#7059
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