12#include "llvm/Support/ErrorHandling.h"
21#define ACC_RTL(Enum, Str, ...) \
22 case RuntimeFunction::Enum: \
24#include "mlir/Dialect/OpenACC/OpenACCRuntimeFunctions.def"
26 llvm_unreachable(
"unknown ACC runtime function");
31 Type Void = LLVM::LLVMVoidType::get(ctx);
32 Type Ptr = LLVM::LLVMPointerType::get(ctx);
33 Type Int32 = IntegerType::get(ctx, 32);
34 Type Int64 = IntegerType::get(ctx, 64);
37#define ACC_RTL(Enum, Str, IsVarArg, ReturnType, ...) \
38 case RuntimeFunction::Enum: \
39 return LLVM::LLVMFunctionType::get(ReturnType, \
40 ArrayRef<Type>{__VA_ARGS__}, IsVarArg);
41#include "mlir/Dialect/OpenACC/OpenACCRuntimeFunctions.def"
43 llvm_unreachable(
"unknown ACC runtime function");
47 overrides[fn] = name.str();
51 if (
auto it = overrides.find(fn); it != overrides.end())
57 functionDisplayNameFn = std::move(fn);
62 if (functionDisplayNameFn)
63 return functionDisplayNameFn(mangledOrSymbol);
64 return mangledOrSymbol.str();
69 deviceTypeRuntimeValues[type] = runtimeValue;
73 if (
auto it = deviceTypeRuntimeValues.find(type);
74 it != deviceTypeRuntimeValues.end())
76 llvm::report_fatal_error(
77 llvm::Twine(
"missing OpenACC runtime device-type mapping for ") +
78 stringifyDeviceType(type));
82 asyncSyncRuntimeValue = runtimeValue;
86 return asyncSyncRuntimeValue;
90 asyncNoValueRuntimeValue = runtimeValue;
94 return asyncNoValueRuntimeValue;
99 for (uint32_t value = 0; value <= getMaxEnumValForDeviceType(); ++value)
100 if (std::optional<DeviceType> type = symbolizeDeviceType(value))
104FailureOr<LLVM::CallOp>
110 StringRef symbolName = config.
getName(fn);
113 auto func = symbolTable.
lookup<LLVM::LLVMFuncOp>(symbolName);
117 if (
func.getFunctionType() != fnTy)
118 return emitError(loc) <<
"OpenACC runtime function '" << symbolName
119 <<
"' is already declared with signature "
120 <<
func.getFunctionType() <<
", expected " << fnTy;
123 func = LLVM::LLVMFuncOp::create(moduleBuilder, loc, symbolName, fnTy);
126 return LLVM::CallOp::create(builder, loc,
func, arguments);
MLIRContext * getContext() const
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
This class helps build Operations.
static OpBuilder atBlockEnd(Block *block, Listener *listener=nullptr)
Create a builder and set the insertion point to after the last operation in the block but still insid...
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
Operation * lookup(StringRef name) const
Look up a symbol with the specified name, returning null if no such name exists.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Optional overrides for OpenACC to LLVM runtime lowering.
int64_t getAsyncNoValueRuntimeValue() const
StringRef getName(RuntimeFunction fn) const
std::string getFunctionDisplayName(StringRef mangledOrSymbol) const
int64_t getAsyncSyncRuntimeValue() 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.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.