@@ -95,25 +95,21 @@ class OMPTargetPrepareDelayedPrivatizationPattern
9595 newPrivVars.push_back (privVar);
9696 continue ;
9797 }
98- // Treat the privVar as varPtr. TODO: For boxchars this likely wont be a
99- // pointer. Allocate heap memory that corresponds to the type of memory
98+
99+ // Allocate heap memory that corresponds to the type of memory
100100 // pointed to by varPtr
101+ // TODO: For boxchars this likely wont be a pointer.
101102 mlir::Value varPtr = privVar;
102103 mlir::Value heapMem = allocateHeapMem (targetOp, privVar, mod, rewriter);
103- if (!heapMem) {
104- newPrivVars.push_back (privVar);
104+ if (!heapMem)
105105 return failure ();
106- }
107- newPrivVars.push_back (heapMem);
108-
109- // Find the earliest insertion point for the copy.
110-
111- // Now, fix up the omp::MapInfoOp instances that use varPtr to refer
112- // to heapMem instead.
113- using ReplacementEntry = std::pair<Operation *, Operation *>;
114- llvm::SmallVector<ReplacementEntry> replRecord;
115106
107+ newPrivVars.push_back (heapMem);
116108
109+ // Find the earliest insertion point for the copy. This will be before
110+ // the first in the list of omp::MapInfoOp instances that use varPtr.
111+ // After the copy these omp::MapInfoOp instances will refer to heapMem
112+ // instead.
117113 Operation *varPtrDefiningOp = varPtr.getDefiningOp ();
118114 std::set<Operation *> users;
119115 users.insert (varPtrDefiningOp->user_begin (),
@@ -122,11 +118,9 @@ class OMPTargetPrepareDelayedPrivatizationPattern
122118 auto usesVarPtr = [&users](Operation *op) -> bool {
123119 return users.count (op);
124120 };
125-
126121 SmallVector<Operation *> chainOfOps;
127122 chainOfOps.push_back (mapInfoOperation);
128123 if (!mapInfoOp.getMembers ().empty ()) {
129-
130124 for (auto member : mapInfoOp.getMembers ()) {
131125 if (usesVarPtr (member.getDefiningOp ()))
132126 chainOfOps.push_back (member.getDefiningOp ());
@@ -144,13 +138,15 @@ class OMPTargetPrepareDelayedPrivatizationPattern
144138 });
145139
146140 rewriter.setInsertionPoint (chainOfOps.front ());
141+ // Copy the value of the local variable into the heap-allocated location.
147142 mlir::Location loc = chainOfOps.front ()->getLoc ();
148143 mlir::Type varType = getElemType (varPtr);
149- // Copy the value of the local variable into the heap-allocated location.
150144 auto loadVal = rewriter.create <LLVM::LoadOp>(loc, varType, varPtr);
151145 LLVM_ATTRIBUTE_UNUSED auto storeInst =
152146 rewriter.create <LLVM::StoreOp>(loc, loadVal.getResult (), heapMem);
153147
148+ using ReplacementEntry = std::pair<Operation *, Operation *>;
149+ llvm::SmallVector<ReplacementEntry> replRecord;
154150 auto cloneAndMarkForDeletion = [&](Operation *origOp) -> Operation * {
155151 Operation *clonedOp = rewriter.clone (*origOp);
156152 rewriter.replaceAllOpUsesWith (origOp, clonedOp);
0 commit comments