MLIR 24.0.0git
Utils.h
Go to the documentation of this file.
1//===- Utils.h - OpenMP dialect 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// This header file defines prototypes for various OpenMP utilities.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_OPENMP_UTILS_UTILS_H_
14#define MLIR_DIALECT_OPENMP_UTILS_UTILS_H_
15
16#include "mlir/IR/BuiltinOps.h"
17#include "mlir/IR/Operation.h"
18#include "mlir/IR/Value.h"
19#include "llvm/TargetParser/Triple.h"
20#include <cstdint>
21#include <string>
22#include <vector>
23
24namespace mlir {
25namespace omp {
26
27/// Offload-specific OpenMP module attributes, associated to the
28/// OffloadModuleInterface.
61
62/// Sets OpenMP offload module interface attributes on a ModuleOp, shared
63/// between Flang and Clang (CIR) frontends.
64void setOffloadModuleInterfaceAttributes(ModuleOp module,
65 const OffloadModuleOpts &opts);
66
67/// Adds or updates the omp.version attribute.
68void setOpenMPVersionAttribute(ModuleOp module, int64_t version);
69
70/// Returns the value of the omp.version attribute, if present, or the fallback.
71int64_t getOpenMPVersionAttribute(ModuleOp module, int64_t fallback = -1);
72
73/// Checks whether this is an OpenMP-enabled module.
74bool isOpenMPModule(ModuleOp module);
75
76/// Check whether the value representing an allocation, assumed to have been
77/// defined in a shared device context, is used in a manner that would require
78/// device shared memory for correctness.
79///
80/// When a use takes place inside an omp.parallel region and it's not as a
81/// private clause argument, or when it is a reduction argument passed to
82/// omp.parallel or a function call argument, then the defining allocation is
83/// eligible for replacement with shared memory.
84///
85/// \see mlir::omp::opInSharedDeviceContext().
87
88/// Check whether the given operation is located in a context where an
89/// allocation to be used by multiple threads in a parallel region would have to
90/// be placed in device shared memory to be accessible.
91///
92/// That means that it is inside of a target device module, it is a non-SPMD
93/// target region, is inside of one or it's located in a device function, and it
94/// is not not inside of a parallel region.
95///
96/// This represents a necessary but not sufficient set of conditions to use
97/// device shared memory in place of regular allocas. For some variables, the
98/// associated OpenMP construct or their uses might also need to be taken into
99/// account.
100///
101/// \see mlir::omp::allocaUsesRequireSharedMem().
103
104} // namespace omp
105} // namespace mlir
106
107#endif // MLIR_DIALECT_OPENMP_UTILS_UTILS_H_
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
void setOffloadModuleInterfaceAttributes(ModuleOp module, const OffloadModuleOpts &opts)
Sets OpenMP offload module interface attributes on a ModuleOp, shared between Flang and Clang (CIR) f...
Definition Utils.cpp:20
bool isOpenMPModule(ModuleOp module)
Checks whether this is an OpenMP-enabled module.
Definition Utils.cpp:57
int64_t getOpenMPVersionAttribute(ModuleOp module, int64_t fallback=-1)
Returns the value of the omp.version attribute, if present, or the fallback.
Definition Utils.cpp:50
bool opInSharedDeviceContext(Operation &op)
Check whether the given operation is located in a context where an allocation to be used by multiple ...
Definition Utils.cpp:107
void setOpenMPVersionAttribute(ModuleOp module, int64_t version)
Adds or updates the omp.version attribute.
Definition Utils.cpp:44
bool allocaUsesRequireSharedMem(Value alloc)
Check whether the value representing an allocation, assumed to have been defined in a shared device c...
Definition Utils.cpp:92
Include the generated interface declarations.
Offload-specific OpenMP module attributes, associated to the OffloadModuleInterface.
Definition Utils.h:29
std::vector< llvm::Triple > targetTriples
Definition Utils.h:58
OffloadModuleOpts(uint32_t targetDebugKind, bool assumeTeamsOversubscription, bool assumeThreadsOversubscription, bool assumeNoThreadState, bool assumeNoNestedParallelism, bool isTargetDevice, bool isGPU, bool forceUSM, uint32_t openMPDeviceVersion, const Twine &hostIRFile, ArrayRef< llvm::Triple > targetTriples={}, bool noGPULib=false)
Definition Utils.h:31