clang 24.0.0git
CIROpenACCOpsInterfaces.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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// Implementation of external OpenACC operation interfaces for CIR.
10//
11//===----------------------------------------------------------------------===//
12
14
17
18namespace cir::acc {
19
20mlir::SymbolRefAttr AddressOfGlobalModel::getSymbol(mlir::Operation *op) const {
21 return llvm::cast<cir::GetGlobalOp>(op).getNameAttr();
22}
23
24bool GlobalVariableModel::isConstant(mlir::Operation *op) const {
25 return llvm::cast<cir::GlobalOp>(op).getConstant();
26}
27
28bool GlobalVariableModel::hasInitializer(mlir::Operation *op) const {
29 return llvm::cast<cir::GlobalOp>(op).hasInitializer();
30}
31
32mlir::Region *GlobalVariableModel::getInitRegion(mlir::Operation *op) const {
33 mlir::Region &ctorRegion = llvm::cast<cir::GlobalOp>(op).getCtorRegion();
34 return ctorRegion.empty() ? nullptr : &ctorRegion;
35}
36
37// Only language address spaces describe where data lives relative to the
38// device. A target address space is a target-defined number, typically picked
39// by the user through an attribute, so nothing is assumed about it: such a
40// global is reported as neither device accessible nor in device memory.
41bool GlobalVariableModel::isDeviceAccessible(mlir::Operation *op) const {
42 auto lang = llvm::dyn_cast_if_present<cir::LangAddressSpaceAttr>(
43 llvm::cast<cir::GlobalOp>(op).getAddrSpaceAttr());
44 return lang && isDeviceAccessibleAddressSpace(lang.getValue());
45}
46
47bool GlobalVariableModel::isInDeviceMemory(mlir::Operation *op) const {
48 auto lang = llvm::dyn_cast_if_present<cir::LangAddressSpaceAttr>(
49 llvm::cast<cir::GlobalOp>(op).getAddrSpaceAttr());
50 return lang && isDeviceResidentAddressSpace(lang.getValue());
51}
52
53// A leading '.' marks a symbol that is not a source identifier. A leading `__`
54// marks a symbol reserved for the implementation. Ideally this should be a
55// property of the global itself, but having a property puts burden on every
56// creation site to decide it and this is a reasonable approximation for now.
57bool GlobalVariableModel::isCompilerGenerated(mlir::Operation *op) const {
58 llvm::StringRef name = llvm::cast<cir::GlobalOp>(op).getSymName();
59 return name.starts_with(".") || name.starts_with("__");
60}
61
62bool GlobalVariableModel::hasLocalLinkage(mlir::Operation *op) const {
63 return llvm::cast<cir::GlobalOp>(op).hasLocalLinkage();
64}
65
66} // namespace cir::acc
bool isDeviceResidentAddressSpace(cir::LangAddressSpace space)
Returns true if storage in space physically resides on the device.
bool isDeviceAccessibleAddressSpace(cir::LangAddressSpace space)
Returns true if code on the device can reach storage in space.
mlir::SymbolRefAttr getSymbol(mlir::Operation *op) const
bool isInDeviceMemory(mlir::Operation *op) const
bool hasInitializer(mlir::Operation *op) const
bool hasLocalLinkage(mlir::Operation *op) const
bool isCompilerGenerated(mlir::Operation *op) const
bool isDeviceAccessible(mlir::Operation *op) const
mlir::Region * getInitRegion(mlir::Operation *op) const
bool isConstant(mlir::Operation *op) const