[llvm] [mlir] [mlir][OpenMP] - Implement lowering from MLIR to LLVMIR for `private` clause on `target` constructs (PR #105471)

Kareem Ergawy via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 23 05:35:22 PDT 2024


================
@@ -3241,12 +3242,140 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
   DataLayout dl = DataLayout(opInst.getParentOfType<ModuleOp>());
   SmallVector<Value> mapVars = targetOp.getMapVars();
   llvm::Function *llvmOutlinedFn = nullptr;
-
   // TODO: It can also be false if a compile-time constant `false` IF clause is
   // specified.
   bool isOffloadEntry =
       isTargetDevice || !ompBuilder->Config.TargetTriples.empty();
 
+  if (!targetOp.getPrivateVars().empty()) {
+    OperandRange privateVars = targetOp.getPrivateVars();
+    std::optional<mlir::ArrayAttr> privateSyms = targetOp.getPrivateSyms();
+    auto &targetRegion = opInst.getRegion(0);
+    auto &firstTargetBlock = targetRegion.front();
+    auto *regionArgsStart = firstTargetBlock.getArguments().begin();
+    auto *privArgsStart = regionArgsStart + targetOp.getMapVars().size();
----------------
ergawy wrote:

Just to remove any `target`-specific logic as much as possible (we probably can outline this into a util that other ops use as well, for example `distribute` which I am working on now).
```suggestion
    auto *privArgsStart = regionArgsStart + targetOp.getPrivateVars().getBeginOperandIndex();
```

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


More information about the llvm-commits mailing list