9#ifndef MLIR_CONVERSION_OPENACCTOLLVM_ACCTOLLVMUTILS_H
10#define MLIR_CONVERSION_OPENACCTOLLVM_ACCTOLLVMUTILS_H
20#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/STLForwardCompat.h"
22#include "llvm/ADT/STLFunctionalExtras.h"
23#include "llvm/ADT/StringRef.h"
37 bool errorOnInvalidLocation);
65 StringRef value, Region &globalSymbolRegion,
66 SymbolTable *symbolTable =
nullptr);
73Value
createIdent(Location loc, StringRef functionName, OpBuilder &builder,
74 Region &globalSymbolRegion,
76 SymbolTable *symbolTable =
nullptr);
80Value
castToI64(Location loc, Value value, OpBuilder &builder);
86Value
getAsyncQueue(Location loc, Value asyncOperand,
bool asyncOnly,
96 Value asyncQueue, OpBuilder &builder,
97 Region &globalSymbolRegion, SymbolTable &symbolTable,
99 Value deviceNum = {});
112 bool ifPresent, OpBuilder &builder,
113 Region &globalSymbolRegion,
114 SymbolTable &symbolTable,
121 RewriterBase &rewriter,
140 RewriterBase &rewriter);
153template <
typename OpTy>
155 decltype(std::declval<OpTy>().hasAsyncOnly(DeviceType::None));
156template <
typename OpTy>
158template <
typename OpTy>
165template <
typename OpTy>
171 if (op.hasAsyncOnly(candidate)) {
175 if (
Value asyncValue = op.getAsyncValue(candidate))
181 asyncOnly = op.getAsyncOnly();
182 return op.getAsyncOperand();
184 asyncOnly = op.getAsync();
185 return op.getAsyncOperand();
195template <
typename OpTy>
196std::optional<DeviceType>
202 if (op.hasWaitOnly(candidate))
204 auto values = op.getWaitValues(candidate);
205 if (!values.empty()) {
206 llvm::append_range(waitValues, values);
212 llvm::append_range(waitValues, op.getWaitOperands());
213 bool waitsForEveryQueue;
214 if constexpr (llvm::is_detected<detail::has_wait_only_t, OpTy>::value)
215 waitsForEveryQueue = op.getWaitOnly();
217 waitsForEveryQueue = op.getWait();
218 if (!waitsForEveryQueue && waitValues.empty())
222 return DeviceType::None;
230template <
typename OpTy>
234 return static_cast<bool>(op.getWaitDevnum(deviceType));
236 return static_cast<bool>(op.getWaitDevnum());
242template <
typename OpTy>
244 ConversionPatternRewriter &rewriter,
246 bool asyncOnly =
false;
249 asyncValue = rewriter.getRemappedValue(asyncValue);
250 return getAsyncQueue(op.getLoc(), asyncValue, asyncOnly, rewriter, config);
259template <
typename OpTy>
266 std::optional<DeviceType> clauseDeviceType =
268 if (!clauseDeviceType)
271 (
void)accSupport.
emitNYI(op.getLoc(),
"wait clause with a devnum modifier");
274 for (
Value &waitValue : waitValues)
275 waitValue = rewriter.getRemappedValue(waitValue);
276 return emitWaitCall(op.getLoc(), waitValues, asyncQueue, rewriter,
277 globalSymbolRegion, symbolTable, config);
This class contains a list of basic blocks and a link to the parent operation it is attached to.
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Configuration for OpenACC to LLVM runtime lowering.
InFlightDiagnostic emitNYI(Location loc, const Twine &message)
Report a case that is not yet supported by the implementation.
decltype(std::declval< OpTy >().getAsyncOnly()) has_async_only_t
decltype(std::declval< OpTy >().hasAsyncOnly(DeviceType::None)) has_device_type_clauses_t
The constructs carrying a device_type clause hold their async and wait clauses per device type.
decltype(std::declval< OpTy >().getWaitOnly()) has_wait_only_t
SmallVector< DeviceType, 3 > getDeviceTypesByPrecedence(DeviceType deviceType)
The clauses of a construct can be given once per device type.
std::optional< FileLineColLoc > getFileLineColLoc(Location loc, bool errorOnInvalidLocation)
Returns file:line:column location information when available.
std::optional< DeviceType > getWaitClauseValues(OpTy op, DeviceType deviceType, SmallVectorImpl< Value > &waitValues)
Appends to waitValues the queues the wait clause of op names for deviceType, and returns the device t...
LogicalResult emitWaitCall(Location loc, ValueRange waitOperands, Value asyncQueue, OpBuilder &builder, Region &globalSymbolRegion, SymbolTable &symbolTable, const ACCRuntimeCallConfig &config, Value deviceNum={})
Emits the runtime call that waits for waitOperands on asyncQueue, which is what a wait clause or an a...
Value getAsyncClauseValue(OpTy op, DeviceType deviceType, bool &asyncOnly)
Returns the value the async clause of op names for deviceType, and sets asyncOnly when the clause nam...
LogicalResult emitWaitClause(OpTy op, DeviceType deviceType, Value asyncQueue, ConversionPatternRewriter &rewriter, OpenACCSupport &accSupport, Region &globalSymbolRegion, SymbolTable &symbolTable, const ACCRuntimeCallConfig &config)
Emits the wait that a wait clause on op asks for before the runtime calls of the construct,...
Value getAsyncQueue(Location loc, Value asyncOperand, bool asyncOnly, OpBuilder &builder, const ACCRuntimeCallConfig &config)
Returns the queue an async clause selects: the value of the clause when it has one,...
bool hasWaitDevnum(OpTy op, DeviceType deviceType)
Returns whether the wait clause op gives for deviceType carries a devnum modifier,...
Value createIdent(Location loc, StringRef functionName, OpBuilder &builder, Region &globalSymbolRegion, const ACCRuntimeCallConfig &config, SymbolTable *symbolTable=nullptr)
Returns a pointer to a constant global holding an ident_t for OpenACC runtime calls.
FailureOr< Value > emitValueSelectedByIfCond(Location loc, Value ifCond, RewriterBase &rewriter, function_ref< FailureOr< Value >()> thenFn, function_ref< FailureOr< Value >()> elseFn)
Emits thenFn on the path a branch on ifCond takes and elseFn on the other one, and returns the value ...
std::string getInternalGlobalName(StringRef kind, StringRef detail)
Returns the name to give a global that the conversion creates to hold detail of kind,...
StringRef getParentFunctionName(Operation *op)
Returns the symbol name of the function op belongs to, or of op itself when it is a function.
LogicalResult emitGuardedByIfCond(Location loc, Value ifCond, RewriterBase &rewriter, function_ref< LogicalResult()> emitFn)
Runs emitFn guarded by a branch on ifCond, or unguarded when there is no condition.
Value castToI64(Location loc, Value value, OpBuilder &builder)
Sign-extends or truncates value to the i64 the runtime entry points take for values like queue number...
Value getOrCreateGlobalString(Location loc, OpBuilder &builder, StringRef name, StringRef value, Region &globalSymbolRegion, SymbolTable *symbolTable=nullptr)
Creates or reuses a null-terminated string global in globalSymbolRegion.
void spliceConstructRegion(Operation *op, Region ®ion, RewriterBase &rewriter)
Splices region, the body of a structured construct, into the block holding op, so that the construct ...
Location unfuseLoc(Location loc)
Unfuses fused locations, returning the last sub-location.
FailureOr< Value > emitGetDevicePtrCall(Operation *clauseOp, Value hostPtr, bool ifPresent, OpBuilder &builder, Region &globalSymbolRegion, SymbolTable &symbolTable, const ACCRuntimeCallConfig &config)
Emits the runtime call that asks for the device address the object of the data clause clauseOp is map...
Include the generated interface declarations.
llvm::function_ref< Fn > function_ref