Skip to content

Conversation

@seven-mile
Copy link
Collaborator

This PR adds the CIR address space attribute to GlobalOp and starts to resolve the missing feature flag addressSpaceInGlobalVar.

The same asm format in pointer type is used:

cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i

The parsing and printing helper is extracted into a common function to be reused by both GlobalOp and PointerType with two custom format proxy to it. That's because the signature of ODS generated method differs from the one for PointerType.

Lowering to LLVM IR and CIRGen will come sequentially.

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.

LGTM. For next PRs: what happens if a global has a type that has a different address space, is that possible?

@bcardosolopes bcardosolopes merged commit 1be8c1f into llvm:main Aug 8, 2024
@seven-mile
Copy link
Collaborator Author

Not sure if I got it! FYI: It seems there are two main aspects here, which are somewhat similar to the alloca address space handling:

  • For the get_global op's pointer type, it should be inferred within the CIR builder, which shall be included in one of the CIRGen PRs (num > 1 for sure).
  • If the AST requires other address spaces (as determined by CGM.getGlobalVarAddressSpace() based on the favor of language and target info), an addrspacecast will be inserted by CodeGen. However, this cast will not occur for the OpenCL C + SPIR-V target.

Aside from these CIRGen changes, it might be worth considering adding proper verification for get_global, correct?

@bcardosolopes
Copy link
Member

  • For the get_global op's pointer type, it should be inferred within the CIR builder, which shall be included in one of the CIRGen PRs (num > 1 for sure).
  • If the AST requires other address spaces (as determined by CGM.getGlobalVarAddressSpace() based on the favor of language and target info), an addrspacecast will be inserted by CodeGen. However, this cast will not occur for the OpenCL C + SPIR-V target.

Got it, so if we write .cl code where __attribute__ is used for a global, does that get ignored in favor of the default one then?

Aside from these CIRGen changes, it might be worth considering adding proper verification for get_global, correct?

Right, assuming that construct doesn't make sense.

@seven-mile
Copy link
Collaborator Author

Got it, so if we write .cl code where __attribute__ is used for a global, does that get ignored in favor of the default one then?

Actually it will be rejected by Sema. And there is not a "default one", sorry for the confusion here: the method has a parameter VarDecl *D in fact.

CGM.getGlobalVarAddressSpace(VarDecl *D) implemented by different languages may have different favor on how to fetch the result AS. OpenCL and SYCL respect D->getType()->getAddressSpace(), but CUDA uses their own UnitAttrs to identify AS instead: CUDAConstantAttr, CUDADeviceAttr... This method is abstracted to provide considerable design freedom on this issue.

Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This PR adds the CIR address space attribute to GlobalOp and starts to
resolve the missing feature flag `addressSpaceInGlobalVar`.

The same asm format in pointer type is used:

```
cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i
```

The parsing and printing helper is extracted into a common function to
be reused by both `GlobalOp` and `PointerType` with two custom format
proxy to it. That's because the signature of ODS generated method
differs from the one for PointerType.

Lowering to LLVM IR and CIRGen will come sequentially.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This PR adds the CIR address space attribute to GlobalOp and starts to
resolve the missing feature flag `addressSpaceInGlobalVar`.

The same asm format in pointer type is used:

```
cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i
```

The parsing and printing helper is extracted into a common function to
be reused by both `GlobalOp` and `PointerType` with two custom format
proxy to it. That's because the signature of ODS generated method
differs from the one for PointerType.

Lowering to LLVM IR and CIRGen will come sequentially.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This PR adds the CIR address space attribute to GlobalOp and starts to
resolve the missing feature flag `addressSpaceInGlobalVar`.

The same asm format in pointer type is used:

```
cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i
```

The parsing and printing helper is extracted into a common function to
be reused by both `GlobalOp` and `PointerType` with two custom format
proxy to it. That's because the signature of ODS generated method
differs from the one for PointerType.

Lowering to LLVM IR and CIRGen will come sequentially.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
This PR adds the CIR address space attribute to GlobalOp and starts to
resolve the missing feature flag `addressSpaceInGlobalVar`.

The same asm format in pointer type is used:

```
cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i
```

The parsing and printing helper is extracted into a common function to
be reused by both `GlobalOp` and `PointerType` with two custom format
proxy to it. That's because the signature of ODS generated method
differs from the one for PointerType.

Lowering to LLVM IR and CIRGen will come sequentially.
lanza pushed a commit that referenced this pull request Nov 5, 2024
This PR adds the CIR address space attribute to GlobalOp and starts to
resolve the missing feature flag `addressSpaceInGlobalVar`.

The same asm format in pointer type is used:

```
cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i
```

The parsing and printing helper is extracted into a common function to
be reused by both `GlobalOp` and `PointerType` with two custom format
proxy to it. That's because the signature of ODS generated method
differs from the one for PointerType.

Lowering to LLVM IR and CIRGen will come sequentially.
lanza pushed a commit that referenced this pull request Mar 18, 2025
This PR adds the CIR address space attribute to GlobalOp and starts to
resolve the missing feature flag `addressSpaceInGlobalVar`.

The same asm format in pointer type is used:

```
cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i
```

The parsing and printing helper is extracted into a common function to
be reused by both `GlobalOp` and `PointerType` with two custom format
proxy to it. That's because the signature of ODS generated method
differs from the one for PointerType.

Lowering to LLVM IR and CIRGen will come sequentially.
terapines-osc-cir pushed a commit to Terapines/clangir that referenced this pull request Sep 2, 2025
This PR adds the CIR address space attribute to GlobalOp and starts to
resolve the missing feature flag `addressSpaceInGlobalVar`.

The same asm format in pointer type is used:

```
cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i
```

The parsing and printing helper is extracted into a common function to
be reused by both `GlobalOp` and `PointerType` with two custom format
proxy to it. That's because the signature of ODS generated method
differs from the one for PointerType.

Lowering to LLVM IR and CIRGen will come sequentially.
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