MLIR 24.0.0git
OpenACCUtils.cpp
Go to the documentation of this file.
1//===- OpenACCUtils.cpp ---------------------------------------------------===//
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
10
15#include "mlir/IR/BuiltinOps.h"
17#include "mlir/IR/Dominance.h"
18#include "mlir/IR/SymbolTable.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/SetVector.h"
23#include "llvm/ADT/TypeSwitch.h"
24#include "llvm/IR/Intrinsics.h"
25#include "llvm/Support/Casting.h"
26
28 return region
29 .getParentOfType<ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::ComputeRegionOp>();
30}
31
33 auto barg = mlir::dyn_cast<mlir::BlockArgument>(v);
34 if (!barg)
35 return nullptr;
36
37 mlir::Block *block = barg.getOwner();
38 auto computeReg =
39 mlir::dyn_cast<mlir::acc::ComputeRegionOp>(block->getParentOp());
40 if (!computeReg)
41 return nullptr;
42 assert(block == computeReg.getBody() &&
43 "block must be the body of acc.compute_region");
44 return computeReg.getOperand(barg);
45}
46
49 if (!orig)
50 return nullptr;
51 mlir::Operation *def = orig.getDefiningOp();
52 return mlir::isa_and_nonnull<ACC_DATA_ENTRY_OPS>(def) ? def : nullptr;
53}
54
55template <typename OpTy>
57 auto checkIfUsedOnlyByOpInside = [&](mlir::Operation *user) {
58 // For any users which are not in the current acc region, we can ignore.
59 // Return true so that it can be used in a `all_of` check.
60 if (!region.isAncestor(user->getParentRegion()))
61 return true;
62 return mlir::isa<OpTy>(user);
63 };
64
65 return llvm::all_of(val.getUsers(), checkIfUsedOnlyByOpInside);
66}
67
72
77
78std::optional<mlir::acc::ClauseDefaultValue>
80 std::optional<mlir::acc::ClauseDefaultValue> defaultAttr;
81 Operation *currOp = op;
82
83 // Iterate outwards until a default clause is found (since OpenACC
84 // specification notes that a visible default clause is the nearest default
85 // clause appearing on the compute construct or a lexically containing data
86 // construct.
87 while (!defaultAttr.has_value() && currOp) {
88 defaultAttr =
90 std::optional<mlir::acc::ClauseDefaultValue>>(currOp)
91 .Case<ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::DataOp>(
92 [&](auto op) { return op.getDefaultAttr(); })
93 .Default([&](Operation *) { return std::nullopt; });
94 currOp = currOp->getParentOp();
95 }
96
97 return defaultAttr;
98}
99
100mlir::acc::VariableTypeCategory mlir::acc::getTypeCategory(mlir::Value var) {
101 mlir::acc::VariableTypeCategory typeCategory =
102 mlir::acc::VariableTypeCategory::uncategorized;
103 if (auto mappableTy = dyn_cast<mlir::acc::MappableType>(var.getType()))
104 typeCategory = mappableTy.getTypeCategory(var);
105 else if (auto pointerLikeTy =
106 dyn_cast<mlir::acc::PointerLikeType>(var.getType()))
107 typeCategory = pointerLikeTy.getPointeeTypeCategory(
109 pointerLikeTy.getElementType());
110 return typeCategory;
111}
112
113llvm::StringLiteral mlir::acc::getVarNamePlaceholder() {
114 return llvm::StringLiteral("<acc.varname.placeholder>");
115}
116
118 Value current = v;
119
120 // Walk through view operations until a name is found or can't go further
121 while (Operation *definingOp = current.getDefiningOp()) {
122 // For integer constants, return their value as a string.
123 if (std::optional<int64_t> constVal = getConstantIntValue(current))
124 return std::to_string(*constVal);
125
126 // Check for `acc.var_name` attribute
127 if (auto varNameAttr = definingOp->getDiscardableAttrOfType<VarNameAttr>(
129 return varNameAttr.getName().str();
130
131 // If it is a data entry operation, get name via getVarName
132 if (isa<ACC_DATA_ENTRY_OPS, MapInfoOp>(definingOp))
133 if (auto name = acc::getVarName(definingOp))
134 return name->str();
135
136 // A global goes by the symbol it is addressed through.
137 if (auto addressOf = dyn_cast<AddressOfGlobalOpInterface>(definingOp))
138 return addressOf.getSymbol().getLeafReference().str();
139
140 // If it's a view operation, continue to the source
141 if (auto viewOp = dyn_cast<ViewLikeOpInterface>(definingOp)) {
142 current = viewOp.getViewSource();
143 continue;
144 }
145
146 break;
147 }
148
149 return "";
150}
151
152std::string mlir::acc::getRecipeName(mlir::acc::RecipeKind kind,
153 mlir::Type type) {
154 assert(kind == mlir::acc::RecipeKind::private_recipe ||
155 kind == mlir::acc::RecipeKind::firstprivate_recipe ||
156 kind == mlir::acc::RecipeKind::reduction_recipe);
157 if (!llvm::isa<mlir::acc::PointerLikeType, mlir::acc::MappableType>(type))
158 return "";
159
160 std::string recipeName;
161 llvm::raw_string_ostream ss(recipeName);
162 ss << (kind == mlir::acc::RecipeKind::private_recipe ? "privatization_"
163 : kind == mlir::acc::RecipeKind::firstprivate_recipe
164 ? "firstprivatization_"
165 : "reduction_");
166
167 // Print the type using its dialect-defined textual format.
168 type.print(ss);
169 ss.flush();
170
171 // Replace invalid characters (anything that's not a letter, number, or
172 // period) since this needs to be a valid MLIR identifier.
173 for (char &c : recipeName) {
174 if (!std::isalnum(static_cast<unsigned char>(c)) && c != '.' && c != '_') {
175 if (c == '?')
176 c = 'U';
177 else if (c == '*')
178 c = 'Z';
179 else if (c == '(' || c == ')' || c == '[' || c == ']' || c == '{' ||
180 c == '}' || c == '<' || c == '>')
181 c = '_';
182 else
183 c = 'X';
184 }
185 }
186
187 return recipeName;
188}
189
191 if (auto partialEntityAccessOp =
192 val.getDefiningOp<PartialEntityAccessOpInterface>()) {
193 if (!partialEntityAccessOp.isCompleteView())
194 return partialEntityAccessOp.getBaseEntity();
195 }
196
197 return val;
198}
199
200/// Look up `symbol` in the `gpu.module`s of the enclosing module. A
201/// `gpu.module` is its own symbol table, so `lookupNearestSymbolFrom` from a
202/// user outside of it does not find definitions placed inside.
204 mlir::SymbolRefAttr symbol) {
205 auto moduleOp = user->getParentOfType<mlir::ModuleOp>();
206 if (!moduleOp)
207 return nullptr;
208 for (auto gpuModule : moduleOp.getOps<mlir::gpu::GPUModuleOp>()) {
210 gpuModule, symbol.getRootReference()))
211 return op;
212 }
213 return nullptr;
214}
215
217 mlir::SymbolRefAttr symbol,
218 mlir::Operation **definingOpPtr) {
219 // A pass may prepare the device-side definition of a symbol inside a
220 // `gpu.module` while the use is still a reference from host IR. Such a
221 // symbol is meant to be used on device, so the use is valid.
222 if (mlir::Operation *gpuOp = lookupSymbolInGPUModules(user, symbol)) {
223 if (definingOpPtr)
224 *definingOpPtr = gpuOp;
225 return true;
226 }
227
228 mlir::Operation *definingOp =
230
231 // If there are no defining ops, we have no way to ensure validity because
232 // we cannot check for any attributes.
233 if (!definingOp)
234 return false;
235
236 if (definingOpPtr)
237 *definingOpPtr = definingOp;
238
239 // Check if the defining op is a recipe.
240 // Recipes are valid as they get materialized before being offloaded to
241 // device. They are only instructions for how to materialize.
242 if (mlir::isa<mlir::accomp::RecipeInterface>(definingOp))
243 return true;
244
245 // Check if the defining op is a global variable that is device data.
246 // Device data is already resident on the device and does not need mapping.
247 if (auto globalVar =
248 mlir::dyn_cast<mlir::acc::GlobalVariableOpInterface>(definingOp))
249 if (globalVar.isDeviceAccessible())
250 return true;
251
252 // Check if the defining op is a function
253 if (auto func =
254 mlir::dyn_cast_if_present<mlir::FunctionOpInterface>(definingOp)) {
255 // If this symbol is actually an acc routine or a specialized acc routine -
256 // then it is expected for it to be offloaded - therefore it is valid.
257 if (func->hasDiscardableAttr(mlir::acc::getRoutineInfoAttrName()) ||
258 func->hasDiscardableAttr(mlir::acc::getSpecializedRoutineAttrName()))
259 return true;
260
261 // If this symbol is a call to an LLVM intrinsic, then it is likely valid.
262 // Check the following:
263 // 1. The function is private
264 // 2. The function has no body
265 // 3. Name starts with "llvm."
266 // 4. The function's name is a valid LLVM intrinsic name
267 if (func.getVisibility() == mlir::SymbolTable::Visibility::Private &&
268 func.getFunctionBody().empty() && func.getName().starts_with("llvm.") &&
269 llvm::Intrinsic::lookupIntrinsicID(func.getName()) !=
270 llvm::Intrinsic::not_intrinsic)
271 return true;
272 }
273
274 // A declare attribute is needed for symbol references.
275 bool hasDeclare =
277 return hasDeclare;
278}
279
281 // Check if the value is device data via type interfaces.
282 // Device data is already resident on the device and does not need mapping.
283 if (auto mappableTy = dyn_cast<mlir::acc::MappableType>(val.getType()))
284 if (mappableTy.isDeviceAccessible(val))
285 return true;
286
287 if (auto pointerLikeTy = dyn_cast<mlir::acc::PointerLikeType>(val.getType()))
288 if (pointerLikeTy.isDeviceAccessible(val))
289 return true;
290
291 mlir::Operation *defOp = val.getDefiningOp();
292 if (!defOp)
293 return false;
294
295 // `acc.declare` with deviceptr marks data that is already associated with
296 // the device.
297 if (auto declareAttr =
298 defOp->getDiscardableAttrOfType<mlir::acc::DeclareAttr>(
300 if (declareAttr.getDataClause().getValue() ==
301 mlir::acc::DataClause::acc_deviceptr)
302 return true;
303
304 // Handle operations that access a partial entity - check if the base entity
305 // is device data.
306 if (auto partialAccess =
307 dyn_cast<mlir::acc::PartialEntityAccessOpInterface>(defOp)) {
308 if (mlir::Value base = partialAccess.getBaseEntity())
309 return isDeviceAccessibleValue(base);
310 }
311
312 // Handle address_of - check if the referenced global is device data.
313 if (auto addrOfIface =
314 dyn_cast<mlir::acc::AddressOfGlobalOpInterface>(defOp)) {
315 auto symbol = addrOfIface.getSymbol();
317 mlir::acc::GlobalVariableOpInterface>(defOp, symbol))
318 return global.isDeviceAccessible();
319 }
320
321 return false;
322}
323
325 // In-device-memory data is a subset of device-accessible data: it must be
326 // accessible and its storage must physically reside in device memory.
327 if (auto mappableTy = dyn_cast<mlir::acc::MappableType>(val.getType()))
328 if (mappableTy.isInDeviceMemory(val))
329 return true;
330
331 if (auto pointerLikeTy = dyn_cast<mlir::acc::PointerLikeType>(val.getType()))
332 if (pointerLikeTy.isInDeviceMemory(val))
333 return true;
334
335 mlir::Operation *defOp = val.getDefiningOp();
336 if (!defOp)
337 return false;
338
339 // `acc.declare` with deviceptr marks data whose storage is already in device
340 // memory.
341 if (auto declareAttr =
342 defOp->getDiscardableAttrOfType<mlir::acc::DeclareAttr>(
344 if (declareAttr.getDataClause().getValue() ==
345 mlir::acc::DataClause::acc_deviceptr)
346 return true;
347
348 // Handle operations that access a partial entity - check if the base entity
349 // is in device memory.
350 if (auto partialAccess =
351 dyn_cast<mlir::acc::PartialEntityAccessOpInterface>(defOp)) {
352 if (mlir::Value base = partialAccess.getBaseEntity())
353 return isInDeviceMemoryValue(base);
354 }
355
356 // Handle address_of - check if the referenced global is in device memory.
357 if (auto addrOfIface =
358 dyn_cast<mlir::acc::AddressOfGlobalOpInterface>(defOp)) {
359 auto symbol = addrOfIface.getSymbol();
361 mlir::acc::GlobalVariableOpInterface>(defOp, symbol))
362 return global.isInDeviceMemory();
363 }
364
365 return false;
366}
367
369 // Types that can be passed by value are legal.
370 Type type = val.getType();
371 if (type.isIntOrIndexOrFloat() || isa<mlir::ComplexType>(type) ||
372 llvm::isa<mlir::VectorType>(type))
373 return true;
374
375 // If this is produced by an ACC data entry operation, it is valid.
376 if (isa_and_nonnull<ACC_DATA_ENTRY_OPS>(val.getDefiningOp()))
377 return true;
378
379 // If the value is only used by private clauses, it is not a live-in.
380 if (isOnlyUsedByPrivateClauses(val, region))
381 return true;
382
383 // If this is device data, it is valid.
385 return true;
386
387 // Arguments of an enclosing acc routine are already on the device.
388 if (mlir::Operation *parent = region.getParentOp()) {
389 if (auto func = parent->getParentOfType<mlir::FunctionOpInterface>()) {
392 llvm::is_contained(func.getArguments(), val))
393 return true;
394 }
395 }
396
397 return false;
398}
399
402 mlir::DominanceInfo &domInfo,
403 mlir::PostDominanceInfo &postDomInfo) {
404 llvm::SmallSetVector<mlir::Value, 8> dominatingDataClauses;
405
406 llvm::TypeSwitch<mlir::Operation *>(computeConstructOp)
407 .Case<mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp>(
408 [&](auto op) {
409 for (auto dataClause : op.getDataClauseOperands()) {
410 dominatingDataClauses.insert(dataClause);
411 }
412 })
413 .Default([](mlir::Operation *) {});
414
415 // Collect the data clauses from enclosing data constructs.
416 mlir::Operation *currParentOp = computeConstructOp->getParentOp();
417 while (currParentOp) {
418 if (mlir::isa<mlir::acc::DataOp>(currParentOp)) {
419 for (auto dataClause : mlir::dyn_cast<mlir::acc::DataOp>(currParentOp)
420 .getDataClauseOperands()) {
421 dominatingDataClauses.insert(dataClause);
422 }
423 }
424 currParentOp = currParentOp->getParentOp();
425 }
426
427 // Find the enclosing function/subroutine
428 auto funcOp =
429 computeConstructOp->getParentOfType<mlir::FunctionOpInterface>();
430 if (!funcOp)
431 return dominatingDataClauses.takeVector();
432
433 // Walk the function to find `acc.declare_enter`/`acc.declare_exit` pairs that
434 // dominate and post-dominate the compute construct and add their data
435 // clauses to the list.
436 funcOp->walk([&](mlir::acc::DeclareEnterOp declareEnterOp) {
437 if (domInfo.dominates(declareEnterOp.getOperation(), computeConstructOp)) {
438 // Collect all `acc.declare_exit` ops for this token.
440 for (auto *user : declareEnterOp.getToken().getUsers())
441 if (auto declareExit = mlir::dyn_cast<mlir::acc::DeclareExitOp>(user))
442 exits.push_back(declareExit);
443
444 // Only add clauses if every `acc.declare_exit` op post-dominates the
445 // compute construct.
446 if (!exits.empty() &&
447 llvm::all_of(exits, [&](mlir::acc::DeclareExitOp exitOp) {
448 return postDomInfo.postDominates(exitOp, computeConstructOp);
449 })) {
450 for (auto dataClause : declareEnterOp.getDataClauseOperands())
451 dominatingDataClauses.insert(dataClause);
452 }
453 }
454 });
455
456 return dominatingDataClauses.takeVector();
457}
458
460 if (auto ifOp = mlir::dyn_cast<mlir::scf::IfOp>(op))
461 return ifOp.getCondition();
462
463 if (!mlir::isa<mlir::RegionBranchOpInterface>(op) ||
464 mlir::isa<mlir::LoopLikeOpInterface>(op))
465 return {};
466 if (op->getNumOperands() != 1 || op->getNumRegions() != 2 ||
468 return {};
469 return op->getOperand(0);
470}
471
473 llvm::ArrayRef<int64_t> deviceTypes) {
474 // No device type is known to be true, so no branch can be classified.
475 if (deviceTypes.empty())
476 return false;
477
478 for (mlir::Operation *parent = op->getParentOp();
479 parent &&
480 !mlir::isa<ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::ComputeRegionOp,
481 mlir::FunctionOpInterface>(parent);
482 parent = parent->getParentOp()) {
483 mlir::Value condition = getIfCondition(parent);
484 if (!condition)
485 continue;
486
487 // The condition must be the `acc.on_device` result itself.
488 auto onDeviceOp = condition.getDefiningOp<mlir::acc::OnDeviceOp>();
489 if (!onDeviceOp)
490 continue;
491
492 std::optional<int64_t> deviceTypeValue =
493 mlir::getConstantIntValue(onDeviceOp.getDeviceType());
494 if (!deviceTypeValue)
495 continue;
496
497 bool onTarget = llvm::is_contained(deviceTypes, *deviceTypeValue);
498 bool inThen = parent->getRegion(0).isAncestor(op->getParentRegion());
499 bool inElse = parent->getRegion(1).isAncestor(op->getParentRegion());
500 // Off the target: the then of a device type outside `deviceTypes`, or
501 // the else of a device type in `deviceTypes`.
502 if ((!onTarget && inThen) || (onTarget && inElse))
503 return true;
504 }
505 return false;
506}
507
510 const std::function<std::string()> &messageFn,
511 llvm::StringRef category) {
512 using namespace mlir::remark;
513 mlir::Location loc = op->getLoc();
514 auto *engine = loc->getContext()->getRemarkEngine();
515 if (!engine)
517
518 llvm::StringRef funcName;
519 if (auto func = dyn_cast<mlir::FunctionOpInterface>(op))
520 funcName = func.getName();
521 else if (auto funcOp = op->getParentOfType<mlir::FunctionOpInterface>())
522 funcName = funcOp.getName();
523
524 auto opts = RemarkOpts::name("openacc").category(category);
525 if (!funcName.empty())
526 opts = opts.function(funcName);
527
528 auto remark = engine->emitOptimizationRemark(loc, opts);
529 if (remark)
530 remark << messageFn();
531 return remark;
532}
static bool isOnlyUsedByOpClauses(mlir::Value val, mlir::Region &region)
static mlir::Value getIfCondition(mlir::Operation *op)
static mlir::Operation * lookupSymbolInGPUModules(mlir::Operation *user, mlir::SymbolRefAttr symbol)
Look up symbol in the gpu.modules of the enclosing module.
static std::optional< int64_t > getConstantIntValue(OpFoldResult ofr)
If ofr is a constant integer or an IntegerAttr, return the integer.
MLIRContext * getContext() const
Return the context this attribute belongs to.
Block represents an ordered list of Operations.
Definition Block.h:34
Operation * getParentOp()
Returns the closest surrounding operation that contains this block.
Definition Block.cpp:31
A class for computing basic dominance information.
Definition Dominance.h:143
bool dominates(Operation *a, Operation *b) const
Return true if operation A dominates operation B, i.e.
Definition Dominance.h:161
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
remark::detail::RemarkEngine * getRemarkEngine()
Returns the remark engine for this context, or nullptr if none has been set.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
Value getOperand(unsigned idx)
Definition Operation.h:375
unsigned getNumRegions()
Returns the number of regions held by this operation.
Definition Operation.h:726
Location getLoc()
The source location the operation was defined or derived from.
Definition Operation.h:240
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Definition Operation.h:251
unsigned getNumOperands()
Definition Operation.h:371
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
Definition Operation.h:255
bool hasDiscardableAttr(StringRef name)
Return true if this operation has a discardable attribute with the provided name.
Definition Operation.h:503
AttrClass getDiscardableAttrOfType(StringRef name)
Access a discardable attribute by name and cast it to AttrClass.
Definition Operation.h:493
Region * getParentRegion()
Returns the region to which the instruction belongs.
Definition Operation.h:247
A class for computing basic postdominance information.
Definition Dominance.h:207
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition Region.h:26
bool isAncestor(Region *other)
Return true if this region is ancestor of the other region.
Definition Region.h:234
Operation * getParentOp()
Return the parent operation this region is attached to.
Definition Region.h:198
ParentT getParentOfType()
Find the first parent operation of the given type, or nullptr if there is no ancestor operation.
Definition Region.h:206
@ Private
The symbol is private and may only be referenced by SymbolRefAttrs local to the operations within the...
Definition SymbolTable.h:92
static Operation * lookupSymbolIn(Operation *op, StringAttr symbol)
Returns the operation registered with the given symbol name with the regions of 'symbolTableOp'.
static Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
void print(raw_ostream &os) const
Print the current type.
bool isSignlessInteger() const
Return true if this is a signless integer type (with the specified width).
Definition Types.cpp:66
bool isIntOrIndexOrFloat() const
Return true if this is an integer (of any signedness), index, or float type.
Definition Types.cpp:122
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Type getType() const
Return the type of this value.
Definition Value.h:105
user_range getUsers() const
Definition Value.h:218
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
Definition Value.cpp:18
A wrapper for linking remarks by query - searches the engine's registry at stream time and links to a...
Definition Remarks.h:402
#define ACC_COMPUTE_CONSTRUCT_OPS
Definition OpenACC.h:64
mlir::acc::VariableTypeCategory getTypeCategory(mlir::Value var)
Get the type category of an OpenACC variable.
std::string getVariableName(mlir::Value v)
Attempts to extract the variable name from a value by walking through view-like operations until an a...
bool isValidSymbolUse(mlir::Operation *user, mlir::SymbolRefAttr symbol, mlir::Operation **definingOpPtr=nullptr)
Check if a symbol use is valid for use in an OpenACC region.
bool isAccRoutine(mlir::Operation *op)
Used to check whether the current operation is marked with acc routine.
Definition OpenACC.h:214
static constexpr StringLiteral getSpecializedRoutineAttrName()
Definition OpenACC.h:208
mlir::Value getACCOperandForBlockArg(mlir::Value v)
If v is not a block argument of an acc.compute_region body, returns nullptr.
mlir::Operation * getACCDataClauseOpForBlockArg(mlir::Value v)
If v is not a block argument of an acc.compute_region body, returns nullptr.
std::optional< ClauseDefaultValue > getDefaultAttr(mlir::Operation *op)
Looks for an OpenACC default attribute on the current operation op or in a parent operation which enc...
bool isSpecializedAccRoutine(mlir::Operation *op)
Used to check whether this is a specialized accelerator version of acc routine function.
Definition OpenACC.h:220
bool isOnlyUsedByReductionClauses(mlir::Value val, mlir::Region &region)
Returns true if this value is only used by acc.reduction operations in the region.
std::optional< llvm::StringRef > getVarName(mlir::Operation *accOp)
Used to obtain the name from an acc operation.
Definition OpenACC.cpp:5510
static constexpr StringLiteral getRoutineInfoAttrName()
Definition OpenACC.h:204
bool isValidValueUse(mlir::Value val, mlir::Region &region)
Check if a value use is valid in an OpenACC region.
mlir::Operation * getEnclosingComputeOp(mlir::Region &region)
Used to obtain the enclosing compute construct operation that contains the provided region.
llvm::StringLiteral getVarNamePlaceholder()
Returns a placeholder string for use as an acc.var_name attribute value when the actual variable name...
llvm::SmallVector< mlir::Value > getDominatingDataClauses(mlir::Operation *computeConstructOp, mlir::DominanceInfo &domInfo, mlir::PostDominanceInfo &postDomInfo)
Collects all data clauses that dominate the compute construct.
static constexpr StringLiteral getVarNameAttrName()
Definition OpenACC.h:249
std::string getRecipeName(mlir::acc::RecipeKind kind, mlir::Type type)
Get the recipe name for a given recipe kind and type.
remark::detail::InFlightRemark emitRemark(mlir::Operation *op, const std::function< std::string()> &messageFn, llvm::StringRef category="openacc")
Emit an OpenACC remark with lazy message generation.
bool isDeviceAccessibleValue(mlir::Value val)
Check if a value represents device data.
static constexpr StringLiteral getDeclareAttrName()
Used to obtain the attribute name for declare.
Definition OpenACC.h:196
bool isInDeviceMemoryValue(mlir::Value val)
Check if a value is backed by memory that is residing in the current device, and therefore requires n...
bool isInOffTargetBranch(mlir::Operation *op, llvm::ArrayRef< int64_t > deviceTypes)
Returns true if op is in a branch that does not execute on the target.
mlir::Value getBaseEntity(mlir::Value val)
bool isOnlyUsedByPrivateClauses(mlir::Value val, mlir::Region &region)
Returns true if this value is only used by acc.private operations in the region.
std::optional< int64_t > getConstantIntValue(OpFoldResult ofr)
If ofr is a constant integer or an IntegerAttr, return the integer.
std::conditional_t< std::is_same_v< Ty, mlir::Type >, mlir::Value, detail::TypedValue< Ty > > TypedValue
If Ty is mlir::Type this will select Value instead of having a wrapper around it.
Definition Value.h:494
static RemarkOpts name(StringRef n)
Definition Remarks.h:105