[llvm-branch-commits] [flang] [llvm] [mlir] [Flang][OpenMP][MLIR] Initial declare target to for variables implementation (PR #119589)

Sergio Afonso via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 11 07:37:14 PDT 2025


================
@@ -3566,8 +3568,12 @@ getDeclareTargetRefPtrSuffix(LLVM::GlobalOp globalOp,
   return suffix;
 }
 
-static bool isDeclareTargetLink(mlir::Value value) {
-  if (auto addressOfOp = value.getDefiningOp<LLVM::AddressOfOp>()) {
+static bool isDeclareTargetLink(Value value) {
+  Operation *op = value.getDefiningOp();
+  if (auto addrCast = llvm::dyn_cast_if_present<LLVM::AddrSpaceCastOp>(op))
+    op = addrCast->getOperand(0).getDefiningOp();
+
+  if (auto addressOfOp = llvm::dyn_cast_if_present<LLVM::AddressOfOp>(op)) {
     auto modOp = addressOfOp->getParentOfType<mlir::ModuleOp>();
     Operation *gOp = modOp.lookupSymbol(addressOfOp.getGlobalName());
----------------
skatrak wrote:

Nit: The logic to initialize `gOp` can be shared between `isDeclareTargetLink` and `isDeclareTargetTo`, which should help keep things consistent in the future.
```c++
static bool isDeclareTargetLink(Value value) {
  omp::DeclareTargetInterface declareTargetGlobal = findDeclareTargetGlobal(value);
  return declareTargetGlobal && declareTargetGlobal.getDeclareTargetCaptureClause() == omp::DeclareTargetCaptureClause::link;
}
```
`getRefPtrIfDeclareTarget` might also benefit from that helper function.

https://github.com/llvm/llvm-project/pull/119589


More information about the llvm-branch-commits mailing list