[Mlir-commits] [flang] [mlir] [mlir][OpenMP] - MLIR to LLVMIR translation support for delayed privatization of allocatables in `omp.target` ops (PR #116576)
Tom Eccles
llvmlistbot at llvm.org
Mon Nov 18 03:44:13 PST 2024
================
@@ -3842,6 +3901,49 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
bool isOffloadEntry =
isTargetDevice || !ompBuilder->Config.TargetTriples.empty();
+ // For some private variables, the MapsForPrivatizedVariablesPass
+ // creates MapInfoOp instances. Go through the private variables and
+ // the mapped variables so that during codegeneration we are able
+ // to quickly look up the corresponding map variable, if any for each
+ // private variable.
+ if (!targetOp.getPrivateVars().empty() && !targetOp.getMapVars().empty()) {
+ auto argIface = llvm::cast<omp::BlockArgOpenMPOpInterface>(*targetOp);
+ unsigned lastMapBlockArgsIdx =
+ argIface.getMapBlockArgsStart() + argIface.numMapBlockArgs() - 1;
+ OperandRange privateVars = targetOp.getPrivateVars();
+ std::optional<ArrayAttr> privateSyms = targetOp.getPrivateSyms();
+ auto reverseIt = mapVars.rbegin();
+ for (auto [privVar, privSym] :
+ llvm::reverse(llvm::zip_equal(privateVars, *privateSyms))) {
+ SymbolRefAttr privatizerName = llvm::cast<SymbolRefAttr>(privSym);
+ omp::PrivateClauseOp privatizer =
+ findPrivatizer(targetOp, privatizerName);
+ if (!privatizer.needsMap())
+ continue;
+
+ // The MapInfoOp defining the map var isn't really needed later.
+ // So, we don't store it in any datastructure. Instead, we just
+ // do some sanity checks on it right now.
+ omp::MapInfoOp mapInfoOp =
+ llvm::cast<omp::MapInfoOp>((*reverseIt).getDefiningOp());
+ Type varType = mapInfoOp.getVarType();
+
+ // Check #1: Check that the type of the private variable matches
+ // the type of the variable being mapped.
+ if (!isa<LLVM::LLVMPointerType>(privVar.getType()))
+ assert(
+ varType == privVar.getType() &&
+ "Type of private var doesn't match the type of the mapped value");
+
+ // Ok, only 1 sanity check for now.
+ // Record the index of the block argument corresponding to this
+ // mapvar.
+ mappedPrivateVars.insert({privVar, lastMapBlockArgsIdx});
+ lastMapBlockArgsIdx--;
----------------
tblah wrote:
How does this stay consistent if we hit `continue` on line 3922?
https://github.com/llvm/llvm-project/pull/116576
More information about the Mlir-commits
mailing list