9#ifndef MLIR_CONVERSION_OPENACCTOLLVM_ACCTOLLVMUTILS_H
10#define MLIR_CONVERSION_OPENACCTOLLVM_ACCTOLLVMUTILS_H
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/STLForwardCompat.h"
23#include "llvm/ADT/STLFunctionalExtras.h"
24#include "llvm/ADT/StringRef.h"
38 bool errorOnInvalidLocation);
66 StringRef value, Region &globalSymbolRegion,
67 SymbolTable *symbolTable =
nullptr);
74Value
createIdent(Location loc, StringRef functionName, OpBuilder &builder,
75 Region &globalSymbolRegion,
77 SymbolTable *symbolTable =
nullptr);
81Value
castToI64(Location loc, Value value, OpBuilder &builder);
84Value
constantI64(Location loc, int64_t value, OpBuilder &builder);
88Value
remapOrSelf(Value value, ConversionPatternRewriter &rewriter);
94Value
getAsyncQueue(Location loc, Value asyncOperand,
bool asyncOnly,
104 Value asyncQueue, OpBuilder &builder,
105 Region &globalSymbolRegion, SymbolTable &symbolTable,
107 Value deviceNum = {});
120 bool ifPresent, OpBuilder &builder,
121 Region &globalSymbolRegion,
122 SymbolTable &symbolTable,
129 RewriterBase &rewriter,
148 RewriterBase &rewriter);
155template <
typename OpTy>
157 decltype(std::declval<OpTy>().hasAsyncOnly(DeviceType::None));
158template <
typename OpTy>
160template <
typename OpTy>
167template <
typename OpTy>
173 if (op.hasAsyncOnly(candidate)) {
177 if (
Value asyncValue = op.getAsyncValue(candidate))
183 asyncOnly = op.getAsyncOnly();
184 return op.getAsyncOperand();
186 asyncOnly = op.getAsync();
187 return op.getAsyncOperand();
197template <
typename OpTy>
198std::optional<DeviceType>
204 if (op.hasWaitOnly(candidate))
206 auto values = op.getWaitValues(candidate);
207 if (!values.empty()) {
208 llvm::append_range(waitValues, values);
214 llvm::append_range(waitValues, op.getWaitOperands());
215 bool waitsForEveryQueue;
216 if constexpr (llvm::is_detected<detail::has_wait_only_t, OpTy>::value)
217 waitsForEveryQueue = op.getWaitOnly();
219 waitsForEveryQueue = op.getWait();
220 if (!waitsForEveryQueue && waitValues.empty())
224 return DeviceType::None;
232template <
typename OpTy>
236 return static_cast<bool>(op.getWaitDevnum(deviceType));
238 return static_cast<bool>(op.getWaitDevnum());
244template <
typename OpTy>
246 ConversionPatternRewriter &rewriter,
248 bool asyncOnly =
false;
251 asyncValue = rewriter.getRemappedValue(asyncValue);
252 return getAsyncQueue(op.getLoc(), asyncValue, asyncOnly, rewriter, config);
261template <
typename OpTy>
268 std::optional<DeviceType> clauseDeviceType =
270 if (!clauseDeviceType)
273 (
void)accSupport.
emitNYI(op.getLoc(),
"wait clause with a devnum modifier");
276 for (
Value &waitValue : waitValues)
277 waitValue = rewriter.getRemappedValue(waitValue);
278 return emitWaitCall(op.getLoc(), waitValues, asyncQueue, rewriter,
279 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.
Value remapOrSelf(Value value, ConversionPatternRewriter &rewriter)
Returns the value value was converted to, or value itself when the conversion left it as it was.
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 ...
Value constantI64(Location loc, int64_t value, OpBuilder &builder)
Creates an i64 constant.
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