[llvm-branch-commits] [flang] [llvm] [mlir] [OpenMP][MLIR] Modify OpenMP Dialect lowering to support attach mapping (PR #179023)
Sergio Afonso via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Apr 6 08:28:47 PDT 2026
================
@@ -5992,40 +6102,43 @@ handleDeclareTargetMapVar(MapInfoData &mapData,
// function to link the two variables in the runtime and then both the
// reference pointer and the pointer are assigned in the kernel argument
// structure for the host.
- if (mapData.IsDeclareTarget[i]) {
- // If the original map value is a constant, then we have to make sure all
- // of it's uses within the current kernel/function that we are going to
- // rewrite are converted to instructions, as we will be altering the old
- // use (OriginalValue) from a constant to an instruction, which will be
- // illegal and ICE the compiler if the user is a constant expression of
- // some kind e.g. a constant GEP.
- if (auto *constant = dyn_cast<llvm::Constant>(mapData.OriginalValue[i]))
- convertUsersOfConstantsToInstructions(constant, func, false);
-
- // The users iterator will get invalidated if we modify an element,
- // so we populate this vector of uses to alter each user on an
- // individual basis to emit its own load (rather than one load for
- // all).
- llvm::SmallVector<llvm::User *> userVec;
- for (llvm::User *user : mapData.OriginalValue[i]->users())
- userVec.push_back(user);
-
- for (llvm::User *user : userVec) {
- if (auto *insn = dyn_cast<llvm::Instruction>(user)) {
- if (insn->getFunction() == func) {
- auto mapOp = cast<omp::MapInfoOp>(mapData.MapClause[i]);
- llvm::Value *substitute = mapData.BasePointers[i];
- if (isDeclareTargetLink(mapOp.getVarPtrPtr() ? mapOp.getVarPtrPtr()
- : mapOp.getVarPtr())) {
- builder.SetCurrentDebugLocation(insn->getDebugLoc());
- substitute = builder.CreateLoad(
- mapData.BasePointers[i]->getType(), mapData.BasePointers[i]);
- cast<llvm::LoadInst>(substitute)->moveBefore(insn->getIterator());
- }
- user->replaceUsesOfWith(mapData.OriginalValue[i], substitute);
- }
- }
+ if (!mapData.IsDeclareTarget[i])
+ continue;
+ // If the original map value is a constant, then we have to make sure all
+ // of it's uses within the current kernel/function that we are going to
+ // rewrite are converted to instructions, as we will be altering the old
+ // use (OriginalValue) from a constant to an instruction, which will be
+ // illegal and ICE the compiler if the user is a constant expression of
+ // some kind e.g. a constant GEP.
+ if (auto *constant = dyn_cast<llvm::Constant>(mapData.OriginalValue[i]))
+ convertUsersOfConstantsToInstructions(constant, func, false);
+
+ // The users iterator will get invalidated if we modify an element,
+ // so we populate this vector of uses to alter each user on an
+ // individual basis to emit its own load (rather than one load for
+ // all).
+ llvm::SmallVector<llvm::User *> userVec;
+ for (llvm::User *user : mapData.OriginalValue[i]->users())
+ userVec.push_back(user);
+
+ for (llvm::User *user : userVec) {
+ auto *insn = dyn_cast<llvm::Instruction>(user);
+ if (!insn || insn->getFunction() != func)
+ continue;
+ auto mapOp = cast<omp::MapInfoOp>(mapData.MapClause[i]);
+ llvm::Value *substitute = mapData.BasePointers[i];
+ if (isDeclareTargetLink(mapOp.getVarPtrPtr() ? mapOp.getVarPtrPtr()
+ : mapOp.getVarPtr()) ||
+ (isDeclareTargetTo(mapOp.getVarPtrPtr() ? mapOp.getVarPtrPtr()
+ : mapOp.getVarPtr()) &&
----------------
skatrak wrote:
Nit: Maybe the `mapOp.getVarPtrPtr() ? mapOp.getVarPtrPtr() : mapOp.getVarPtr()` expression can be refactored and reused to simplify the `if` condition.
https://github.com/llvm/llvm-project/pull/179023
More information about the llvm-branch-commits
mailing list