Pointers of certain GPUs in AMDGCN target in private address space is 32 bit but pointers in other address spaces are 64 bit. size_t type should be defined as 64 bit for these GPUs so that it could hold pointers in all address spaces.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/Basic/Targets.cpp | ||
---|---|---|
2008–2010 ↗ | (On Diff #67554) | Should use ternary operator and check the triple arch instead |
I think Clang is supposed to generate the IR specific to the target architecture. It seems strange to ignore the pointer size. I am not sure if it might lead to some issues for the backends.
lib/CodeGen/CodeGenModule.cpp | ||
---|---|---|
107 ↗ | (On Diff #67687) | It seems wrong to call OpenCL specific function in generic code path? |
This change only affects AMDGCN target which has different pointer size for different address spaces. There is no change for other targets.
For AMDGCN target, since there can be only one definition for size_t type, it has to be 64 bit to accommodate all pointers.
For operations not involving pointers, this is fine since it does not matter whether size_t is i32 or i64.
For operations involving pointers, it only affects ptrtoint instruction, which allows a pointer to be casted to any integer. If the integer size is larger than the pointer size, it is zero extended. If the integer is smaller than the pointer size, it is truncated.
When clang casts a pointer to size_t, there are two cases:
- non-private pointers: before this change, it was casted to i32, which is wrong. now it is casted to i64 correctly.
- private pointer: before this change, it was casted to i32, now it is casted to i64. It is still correct. Backend should be able to optimize these instructions.
lib/CodeGen/CodeGenModule.cpp | ||
---|---|---|
101 ↗ | (On Diff #67687) | What if you create a new function in TargetInfo called getMaxPointerWidth(unsigned AddrSpace), and call that here? That would by default just call 'getPointerWidth', but in your AMDGPU TargetInfo you can override that. |
lib/CodeGen/CodeGenModule.cpp | ||
---|---|---|
101 ↗ | (On Diff #67687) | Thanks for your suggestion. There are some other changes needed in addition to that. |
lib/CodeGen/CodeGenModule.h | ||
---|---|---|
664 ↗ | (On Diff #68241) | This has the same purpose as DataLayout::getIntPtrType, should probably just use that |
lib/CodeGen/CGExprScalar.cpp | ||
---|---|---|
1513 ↗ | (On Diff #68360) | Yes. |
2447 ↗ | (On Diff #68360) | PtrDiffTy and IntPtrTy are members of an anonymous union /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size. union { llvm::IntegerType *IntPtrTy; llvm::IntegerType *SizeTy; llvm::IntegerType *PtrDiffTy; }; so they are actually the same thing. |