MLIR 24.0.0git
OpenACCRuntimeUtils.h
Go to the documentation of this file.
1//===- OpenACCRuntimeUtils.h - OpenACC runtime call 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// Utilities for resolving OpenACC compiler-to-runtime entry points declared in
10// OpenACCRuntimeFunctions.def.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_DIALECT_OPENACC_OPENACCRUNTIMEUTILS_H
15#define MLIR_DIALECT_OPENACC_OPENACCRUNTIMEUTILS_H
16
19#include "mlir/IR/Builders.h"
20#include "mlir/IR/BuiltinOps.h"
21#include "llvm/ADT/ArrayRef.h"
22#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/StringRef.h"
24
25#include <cstdint>
26#include <functional>
27#include <string>
28
29namespace mlir {
30namespace acc {
31
32/// IDs for OpenACC compiler-to-runtime entry points (`__tgt_acc_*`).
33enum class RuntimeFunction {
34#define ACC_RTL(Enum, ...) Enum,
35#include "mlir/Dialect/OpenACC/OpenACCRuntimeFunctions.def"
36};
37
38/// Returns the default runtime symbol name for \p fn.
40
41/// Builds the LLVM function type for \p fn in \p ctx.
42LLVM::LLVMFunctionType getRuntimeFunctionType(MLIRContext *ctx,
44
45/// Optional overrides for OpenACC to LLVM runtime lowering.
47public:
48 using FunctionDisplayNameFn = std::function<std::string(StringRef)>;
49
50 void setName(RuntimeFunction fn, StringRef name);
51 StringRef getName(RuntimeFunction fn) const;
52
54 std::string getFunctionDisplayName(StringRef mangledOrSymbol) const;
55
56 /// Map an OpenACC dialect \p DeviceType to the integer encoding expected by
57 /// the target runtime. Dialect ordinals and runtime ABI values are not
58 /// required to match; callers must install a mapping that matches their
59 /// runtime. Querying an unmapped type is an error.
60 void setDeviceTypeRuntimeValue(DeviceType type, int64_t runtimeValue);
61 int64_t getDeviceTypeRuntimeValue(DeviceType type) const;
62
63 /// Runtime encoding of `acc_async_sync`, used when an operation carries no
64 /// `async` clause. OpenACC defines the name of this queue but leaves its
65 /// value to the implementation, so it is part of the runtime ABI.
66 void setAsyncSyncRuntimeValue(int64_t runtimeValue);
68
69 /// Runtime encoding of `acc_async_noval`, used for an `async` clause without
70 /// an argument. As with `acc_async_sync`, the value is implementation-defined
71 void setAsyncNoValueRuntimeValue(int64_t runtimeValue);
73
74private:
76 DenseMap<DeviceType, int64_t> deviceTypeRuntimeValues;
77 FunctionDisplayNameFn functionDisplayNameFn;
78 // Default to the encodings used by openacc.h (`acc_async_sync` /
79 // `acc_async_noval`).
80 int64_t asyncSyncRuntimeValue = -1;
81 int64_t asyncNoValueRuntimeValue = -4;
82};
83
84/// Install a device-type mapping that uses OpenACC dialect enum ordinals as the
85/// runtime encoding. This is only correct when the target runtime happens to
86/// use the same numbering; runtimes with a different ABI must install their
87/// own mapping via \c setDeviceTypeRuntimeValue.
89
90/// Declares (if needed) and returns a call to the runtime function identified
91/// by \p fn using the name from \p config. Fails and emits a diagnostic if the
92/// symbol is already declared with a signature the runtime cannot be called
93/// through.
94FailureOr<LLVM::CallOp> createRuntimeCall(Location loc, OpBuilder &builder,
95 ModuleOp module, RuntimeFunction fn,
96 const ACCRuntimeCallConfig &config,
97 ArrayRef<Value> arguments);
98
99} // namespace acc
100} // namespace mlir
101
102#endif // MLIR_DIALECT_OPENACC_OPENACCRUNTIMEUTILS_H
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
This class helps build Operations.
Definition Builders.h:210
Optional overrides for OpenACC to LLVM runtime lowering.
StringRef getName(RuntimeFunction fn) const
std::string getFunctionDisplayName(StringRef mangledOrSymbol) const
void setName(RuntimeFunction fn, StringRef name)
void setAsyncSyncRuntimeValue(int64_t runtimeValue)
Runtime encoding of acc_async_sync, used when an operation carries no async clause.
void setDeviceTypeRuntimeValue(DeviceType type, int64_t runtimeValue)
Map an OpenACC dialect DeviceType to the integer encoding expected by the target runtime.
int64_t getDeviceTypeRuntimeValue(DeviceType type) const
void setFunctionDisplayNameFn(FunctionDisplayNameFn fn)
std::function< std::string(StringRef)> FunctionDisplayNameFn
void setAsyncNoValueRuntimeValue(int64_t runtimeValue)
Runtime encoding of acc_async_noval, used for an async clause without an argument.
LLVM::LLVMFunctionType getRuntimeFunctionType(MLIRContext *ctx, RuntimeFunction fn)
Builds the LLVM function type for fn in ctx.
void populateDialectIdentityDeviceTypeMapping(ACCRuntimeCallConfig &config)
Install a device-type mapping that uses OpenACC dialect enum ordinals as the runtime encoding.
StringRef getRuntimeFunctionName(RuntimeFunction fn)
Returns the default runtime symbol name for fn.
FailureOr< LLVM::CallOp > createRuntimeCall(Location loc, OpBuilder &builder, ModuleOp module, RuntimeFunction fn, const ACCRuntimeCallConfig &config, ArrayRef< Value > arguments)
Declares (if needed) and returns a call to the runtime function identified by fn using the name from ...
RuntimeFunction
IDs for OpenACC compiler-to-runtime entry points (__tgt_acc_*).
Include the generated interface declarations.
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
Definition LLVM.h:120