llvm-project/mlir/lib/Conversion/GPUCommon/AttrToSPIRVConverter.cpp
Victor Perez 75cb9edf09
[MLIR][GPU-LLVM] Add GPU to LLVM-SPV address space mapping (#102621)
Implement mapping:

- `global`: 1
- `workgroup`: 3
- `private`: 0

Add `addressSpaceToStorageClass`, mapping GPU address spaces to SPIR-V
storage classes to be able to use SPIR-V's
`storageClassToAddressSpace`, mapping SPIR-V storage classes to LLVM
address spaces according to our mapping above *by definition*.

---------

Signed-off-by: Victor Perez <victor.perez@codeplay.com>
2024-08-16 11:18:35 +02:00

24 lines
866 B
C++

//===- AttrToSPIRVConverter.cpp - GPU attributes conversion to SPIR-V - C++===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <mlir/Conversion/GPUCommon/AttrToSPIRVConverter.h>
namespace mlir {
spirv::StorageClass addressSpaceToStorageClass(gpu::AddressSpace addressSpace) {
switch (addressSpace) {
case gpu::AddressSpace::Global:
return spirv::StorageClass::CrossWorkgroup;
case gpu::AddressSpace::Workgroup:
return spirv::StorageClass::Workgroup;
case gpu::AddressSpace::Private:
return spirv::StorageClass::Private;
}
llvm_unreachable("Unhandled storage class");
}
} // namespace mlir