@@ -237,11 +237,6 @@ class ACCImplicitData : public acc::impl::ACCImplicitDataBase<ACCImplicitData> {
237237 void runOnOperation () override ;
238238
239239private:
240- // / Collects all data clauses that dominate the compute construct.
241- // / Needed to determine if a variable is already covered by an existing data
242- // / clause.
243- SmallVector<Value> getDominatingDataClauses (Operation *computeConstructOp);
244-
245240 // / Looks through the `dominatingDataClauses` to find the original data clause
246241 // / op for an alias. Returns nullptr if no original data clause op is found.
247242 template <typename OpT>
@@ -300,62 +295,6 @@ static bool isCandidateForImplicitData(Value val, Region &accRegion) {
300295 return true ;
301296}
302297
303- SmallVector<Value>
304- ACCImplicitData::getDominatingDataClauses (Operation *computeConstructOp) {
305- llvm::SmallSetVector<Value, 8 > dominatingDataClauses;
306-
307- llvm::TypeSwitch<Operation *>(computeConstructOp)
308- .Case <acc::ParallelOp, acc::KernelsOp, acc::SerialOp>([&](auto op) {
309- for (auto dataClause : op.getDataClauseOperands ()) {
310- dominatingDataClauses.insert (dataClause);
311- }
312- })
313- .Default ([](Operation *) {});
314-
315- // Collect the data clauses from enclosing data constructs.
316- Operation *currParentOp = computeConstructOp->getParentOp ();
317- while (currParentOp) {
318- if (isa<acc::DataOp>(currParentOp)) {
319- for (auto dataClause :
320- dyn_cast<acc::DataOp>(currParentOp).getDataClauseOperands ()) {
321- dominatingDataClauses.insert (dataClause);
322- }
323- }
324- currParentOp = currParentOp->getParentOp ();
325- }
326-
327- // Find the enclosing function/subroutine
328- auto funcOp = computeConstructOp->getParentOfType <FunctionOpInterface>();
329- if (!funcOp)
330- return dominatingDataClauses.takeVector ();
331-
332- // Walk the function to find `acc.declare_enter`/`acc.declare_exit` pairs that
333- // dominate and post-dominate the compute construct and add their data
334- // clauses to the list.
335- auto &domInfo = this ->getAnalysis <DominanceInfo>();
336- auto &postDomInfo = this ->getAnalysis <PostDominanceInfo>();
337- funcOp->walk ([&](acc::DeclareEnterOp declareEnterOp) {
338- if (domInfo.dominates (declareEnterOp.getOperation (), computeConstructOp)) {
339- // Collect all `acc.declare_exit` ops for this token.
340- SmallVector<acc::DeclareExitOp> exits;
341- for (auto *user : declareEnterOp.getToken ().getUsers ())
342- if (auto declareExit = dyn_cast<acc::DeclareExitOp>(user))
343- exits.push_back (declareExit);
344-
345- // Only add clauses if every `acc.declare_exit` op post-dominates the
346- // compute construct.
347- if (!exits.empty () && llvm::all_of (exits, [&](acc::DeclareExitOp exitOp) {
348- return postDomInfo.postDominates (exitOp, computeConstructOp);
349- })) {
350- for (auto dataClause : declareEnterOp.getDataClauseOperands ())
351- dominatingDataClauses.insert (dataClause);
352- }
353- }
354- });
355-
356- return dominatingDataClauses.takeVector ();
357- }
358-
359298template <typename OpT>
360299Operation *ACCImplicitData::getOriginalDataClauseOpForAlias (
361300 Value var, OpBuilder &builder, OpT computeConstructOp,
@@ -775,7 +714,10 @@ void ACCImplicitData::generateImplicitDataOps(
775714 LLVM_DEBUG (llvm::dbgs () << " == Generating clauses for ==\n "
776715 << computeConstructOp << " \n " );
777716 }
778- auto dominatingDataClauses = getDominatingDataClauses (computeConstructOp);
717+ auto &domInfo = this ->getAnalysis <DominanceInfo>();
718+ auto &postDomInfo = this ->getAnalysis <PostDominanceInfo>();
719+ auto dominatingDataClauses =
720+ acc::getDominatingDataClauses (computeConstructOp, domInfo, postDomInfo);
779721 for (auto var : candidateVars) {
780722 auto newDataClauseOp = generateDataClauseOpForCandidate (
781723 var, module , builder, computeConstructOp, dominatingDataClauses,
0 commit comments