MLIR 23.0.0git
MemorySpaceUtils.h
Go to the documentation of this file.
1//===- MemorySpaceUtils.h - AMDGPU memory space utilities -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef MLIR_DIALECT_AMDGPU_UTILS_MEMORYSPACEUTILS_H
10#define MLIR_DIALECT_AMDGPU_UTILS_MEMORYSPACEUTILS_H
11
15#include "mlir/Support/LLVM.h"
16#include "llvm/Support/Compiler.h"
17
18namespace mlir::amdgpu {
19
20// Integer memory-space attributes are deprecated, but still accepted here for
21// compatibility with existing IR.
22
23inline bool isGlobalMemorySpace(Attribute memorySpace, bool allowFlat) {
24 if (!memorySpace)
25 return allowFlat;
26 if (auto gpuMemorySpace = dyn_cast<gpu::AddressSpaceAttr>(memorySpace))
27 return gpuMemorySpace.getValue() == gpu::AddressSpace::Global;
28 if (auto intMemorySpace = dyn_cast<IntegerAttr>(memorySpace);
29 LLVM_UNLIKELY(intMemorySpace)) {
30 int64_t memorySpaceValue = intMemorySpace.getInt();
31 return memorySpaceValue == 1 || (allowFlat && memorySpaceValue == 0);
32 }
33 return false;
34}
35
36inline bool isWorkgroupMemorySpace(Attribute memorySpace) {
37 if (!memorySpace)
38 return false;
39 if (auto gpuMemorySpace = dyn_cast<gpu::AddressSpaceAttr>(memorySpace))
40 return gpuMemorySpace.getValue() == gpu::AddressSpace::Workgroup;
41 if (auto intMemorySpace = dyn_cast<IntegerAttr>(memorySpace);
42 LLVM_UNLIKELY(intMemorySpace)) {
43 int64_t memorySpaceValue = intMemorySpace.getInt();
44 return memorySpaceValue == 3;
45 }
46 return false;
47}
48
49inline bool isFatRawBufferMemorySpace(Attribute memorySpace) {
50 if (!memorySpace)
51 return false;
52 if (auto amdgpuMemorySpace = dyn_cast<amdgpu::AddressSpaceAttr>(memorySpace))
53 return amdgpuMemorySpace.getValue() == amdgpu::AddressSpace::FatRawBuffer;
54 if (auto intMemorySpace = dyn_cast<IntegerAttr>(memorySpace);
55 LLVM_UNLIKELY(intMemorySpace)) {
56 int64_t memorySpaceValue = intMemorySpace.getInt();
57 return memorySpaceValue == 7;
58 }
59 return false;
60}
61
62} // namespace mlir::amdgpu
63
64#endif // MLIR_DIALECT_AMDGPU_UTILS_MEMORYSPACEUTILS_H
Attributes are known-constant values of operations.
Definition Attributes.h:25
bool isGlobalMemorySpace(Attribute memorySpace, bool allowFlat)
bool isWorkgroupMemorySpace(Attribute memorySpace)
bool isFatRawBufferMemorySpace(Attribute memorySpace)