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][CodeGen] Set address space for OpenCL globals #788

Merged
merged 2 commits into from
Aug 14, 2024

Conversation

seven-mile
Copy link
Collaborator

This PR sets proper address space when creating cir.global and cir.get_global.

Different languages use different ways to encode the address space in AST constructs (i.e. VarDecl *). OpenCL and SYCL use an address space qualifier on the type of VarDecl, while CUDA uses separate AST attributes like CUDASharedAttr. Similarily, some targets may want to use special address space for global variables. So a per-language + per-target hook is needed to provide this customization point. In the LLVM CodeGen, it's the helper method getGlobalVarAddressSpace that takes on the role.

For OpenCL C + SPIR-V combination, OpenCL C converts the address space qualifier to corresponding LangAS, but SPIR-V does not require any action.

This PR implements global qualifier in OpenCL C, but does not include constant qualifier. Although the modified part works for constant, CIRGen is not yet able to set constant attribute for global ops (there is a TODO line).

Static variable decl and local qualifier work in a similar way and come in later patches.

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.

Mostly good, some nits!

Copy link
Collaborator Author

@seven-mile seven-mile left a comment

Choose a reason for hiding this comment

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

Suggestions applied.

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

@bcardosolopes bcardosolopes merged commit 4cc61c4 into llvm:main Aug 14, 2024
6 checks passed
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This PR sets proper address space when creating `cir.global` and
`cir.get_global`.

Different languages use different ways to encode the address space in
AST constructs (i.e. VarDecl *). OpenCL and SYCL use an address space
qualifier on the type of `VarDecl`, while CUDA uses separate AST
attributes like `CUDASharedAttr`. Similarily, some targets may want to
use special address space for global variables. So a per-language +
per-target hook is needed to provide this customization point. In the
LLVM CodeGen, it's the helper method `getGlobalVarAddressSpace` that
takes on the role.

For OpenCL C + SPIR-V combination, OpenCL C converts the address space
qualifier to corresponding LangAS, but SPIR-V does not require any
action.

This PR implements `global` qualifier in OpenCL C, but does not include
`constant` qualifier. Although the modified part works for `constant`,
CIRGen is not yet able to set constant attribute for global ops (there
is a TODO line).

Static variable decl and `local` qualifier work in a similar way and
come in later patches.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This PR sets proper address space when creating `cir.global` and
`cir.get_global`.

Different languages use different ways to encode the address space in
AST constructs (i.e. VarDecl *). OpenCL and SYCL use an address space
qualifier on the type of `VarDecl`, while CUDA uses separate AST
attributes like `CUDASharedAttr`. Similarily, some targets may want to
use special address space for global variables. So a per-language +
per-target hook is needed to provide this customization point. In the
LLVM CodeGen, it's the helper method `getGlobalVarAddressSpace` that
takes on the role.

For OpenCL C + SPIR-V combination, OpenCL C converts the address space
qualifier to corresponding LangAS, but SPIR-V does not require any
action.

This PR implements `global` qualifier in OpenCL C, but does not include
`constant` qualifier. Although the modified part works for `constant`,
CIRGen is not yet able to set constant attribute for global ops (there
is a TODO line).

Static variable decl and `local` qualifier work in a similar way and
come in later patches.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This PR sets proper address space when creating `cir.global` and
`cir.get_global`.

Different languages use different ways to encode the address space in
AST constructs (i.e. VarDecl *). OpenCL and SYCL use an address space
qualifier on the type of `VarDecl`, while CUDA uses separate AST
attributes like `CUDASharedAttr`. Similarily, some targets may want to
use special address space for global variables. So a per-language +
per-target hook is needed to provide this customization point. In the
LLVM CodeGen, it's the helper method `getGlobalVarAddressSpace` that
takes on the role.

For OpenCL C + SPIR-V combination, OpenCL C converts the address space
qualifier to corresponding LangAS, but SPIR-V does not require any
action.

This PR implements `global` qualifier in OpenCL C, but does not include
`constant` qualifier. Although the modified part works for `constant`,
CIRGen is not yet able to set constant attribute for global ops (there
is a TODO line).

Static variable decl and `local` qualifier work in a similar way and
come in later patches.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
This PR sets proper address space when creating `cir.global` and
`cir.get_global`.

Different languages use different ways to encode the address space in
AST constructs (i.e. VarDecl *). OpenCL and SYCL use an address space
qualifier on the type of `VarDecl`, while CUDA uses separate AST
attributes like `CUDASharedAttr`. Similarily, some targets may want to
use special address space for global variables. So a per-language +
per-target hook is needed to provide this customization point. In the
LLVM CodeGen, it's the helper method `getGlobalVarAddressSpace` that
takes on the role.

For OpenCL C + SPIR-V combination, OpenCL C converts the address space
qualifier to corresponding LangAS, but SPIR-V does not require any
action.

This PR implements `global` qualifier in OpenCL C, but does not include
`constant` qualifier. Although the modified part works for `constant`,
CIRGen is not yet able to set constant attribute for global ops (there
is a TODO line).

Static variable decl and `local` qualifier work in a similar way and
come in later patches.
lanza pushed a commit that referenced this pull request Nov 5, 2024
This PR sets proper address space when creating `cir.global` and
`cir.get_global`.

Different languages use different ways to encode the address space in
AST constructs (i.e. VarDecl *). OpenCL and SYCL use an address space
qualifier on the type of `VarDecl`, while CUDA uses separate AST
attributes like `CUDASharedAttr`. Similarily, some targets may want to
use special address space for global variables. So a per-language +
per-target hook is needed to provide this customization point. In the
LLVM CodeGen, it's the helper method `getGlobalVarAddressSpace` that
takes on the role.

For OpenCL C + SPIR-V combination, OpenCL C converts the address space
qualifier to corresponding LangAS, but SPIR-V does not require any
action.

This PR implements `global` qualifier in OpenCL C, but does not include
`constant` qualifier. Although the modified part works for `constant`,
CIRGen is not yet able to set constant attribute for global ops (there
is a TODO line).

Static variable decl and `local` qualifier work in a similar way and
come in later patches.
lanza pushed a commit that referenced this pull request Mar 18, 2025
This PR sets proper address space when creating `cir.global` and
`cir.get_global`.

Different languages use different ways to encode the address space in
AST constructs (i.e. VarDecl *). OpenCL and SYCL use an address space
qualifier on the type of `VarDecl`, while CUDA uses separate AST
attributes like `CUDASharedAttr`. Similarily, some targets may want to
use special address space for global variables. So a per-language +
per-target hook is needed to provide this customization point. In the
LLVM CodeGen, it's the helper method `getGlobalVarAddressSpace` that
takes on the role.

For OpenCL C + SPIR-V combination, OpenCL C converts the address space
qualifier to corresponding LangAS, but SPIR-V does not require any
action.

This PR implements `global` qualifier in OpenCL C, but does not include
`constant` qualifier. Although the modified part works for `constant`,
CIRGen is not yet able to set constant attribute for global ops (there
is a TODO line).

Static variable decl and `local` qualifier work in a similar way and
come in later patches.
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