@@ -334,54 +334,6 @@ convertOmpCritical(Operation &opInst, llvm::IRBuilderBase &builder,
334334 return success ();
335335}
336336
337- // / Returns a reduction declaration that corresponds to the given reduction
338- // / operation in the given container. Currently only supports reductions inside
339- // / WsloopOp and ParallelOp but can be easily extended as long as the given
340- // / construct implements getNumReductionVars.
341- template <typename T>
342- static std::optional<omp::DeclareReductionOp>
343- findReductionDeclInContainer (T container, omp::ReductionOp reduction) {
344- for (unsigned i = 0 , e = container.getNumReductionVars (); i < e; ++i) {
345- if (container.getReductionVars ()[i] != reduction.getAccumulator ())
346- continue ;
347-
348- SymbolRefAttr reductionSymbol =
349- cast<SymbolRefAttr>((*container.getReductions ())[i]);
350- auto declareOp =
351- SymbolTable::lookupNearestSymbolFrom<omp::DeclareReductionOp>(
352- container, reductionSymbol);
353- return declareOp;
354- }
355- return std::nullopt ;
356- }
357-
358- // / Searches for a reduction in a provided region and the regions
359- // / it is nested in
360- static omp::DeclareReductionOp findReductionDecl (Operation &containerOp,
361- omp::ReductionOp reduction) {
362- std::optional<omp::DeclareReductionOp> declareOp = std::nullopt ;
363- Operation *container = &containerOp;
364-
365- while (!declareOp.has_value () && container) {
366- // Check if current container is supported for reductions searches
367- if (auto par = dyn_cast<omp::ParallelOp>(*container)) {
368- declareOp = findReductionDeclInContainer (par, reduction);
369- } else if (auto loop = dyn_cast<omp::WsloopOp>(*container)) {
370- declareOp = findReductionDeclInContainer (loop, reduction);
371- } else {
372- break ;
373- }
374-
375- // See if we can search parent for reductions as well
376- container = containerOp.getParentOp ();
377- }
378-
379- assert (declareOp.has_value () &&
380- " reduction operation must be associated with a declaration" );
381-
382- return *declareOp;
383- }
384-
385337// / Populates `reductions` with reduction declarations used in the given loop.
386338template <typename T>
387339static void
@@ -1786,62 +1738,6 @@ convertOmpAtomicCapture(omp::AtomicCaptureOp atomicCaptureOp,
17861738 return updateGenStatus;
17871739}
17881740
1789- // / Converts an OpenMP reduction operation using OpenMPIRBuilder. Expects the
1790- // / mapping between reduction variables and their private equivalents to have
1791- // / been stored on the ModuleTranslation stack. Currently only supports
1792- // / reduction within WsloopOp and ParallelOp, but can be easily extended.
1793- static LogicalResult
1794- convertOmpReductionOp (omp::ReductionOp reductionOp,
1795- llvm::IRBuilderBase &builder,
1796- LLVM::ModuleTranslation &moduleTranslation) {
1797- // Find the declaration that corresponds to the reduction op.
1798- omp::DeclareReductionOp declaration;
1799- Operation *reductionParent = reductionOp->getParentOp ();
1800- if (dyn_cast<omp::ParallelOp>(reductionParent) ||
1801- dyn_cast<omp::WsloopOp>(reductionParent)) {
1802- declaration = findReductionDecl (*reductionParent, reductionOp);
1803- } else {
1804- llvm_unreachable (" Unhandled reduction container" );
1805- }
1806- assert (declaration && " could not find reduction declaration" );
1807-
1808- // Retrieve the mapping between reduction variables and their private
1809- // equivalents.
1810- const DenseMap<Value, llvm::Value *> *reductionVariableMap = nullptr ;
1811- moduleTranslation.stackWalk <OpenMPVarMappingStackFrame>(
1812- [&](const OpenMPVarMappingStackFrame &frame) {
1813- if (frame.mapping .contains (reductionOp.getAccumulator ())) {
1814- reductionVariableMap = &frame.mapping ;
1815- return WalkResult::interrupt ();
1816- }
1817- return WalkResult::advance ();
1818- });
1819- assert (reductionVariableMap && " couldn't find private reduction variables" );
1820- // Translate the reduction operation by emitting the body of the corresponding
1821- // reduction declaration.
1822- Region &reductionRegion = declaration.getReductionRegion ();
1823- llvm::Value *privateReductionVar =
1824- reductionVariableMap->lookup (reductionOp.getAccumulator ());
1825- llvm::Value *reductionVal = builder.CreateLoad (
1826- moduleTranslation.convertType (reductionOp.getOperand ().getType ()),
1827- privateReductionVar);
1828-
1829- moduleTranslation.mapValue (reductionRegion.front ().getArgument (0 ),
1830- reductionVal);
1831- moduleTranslation.mapValue (
1832- reductionRegion.front ().getArgument (1 ),
1833- moduleTranslation.lookupValue (reductionOp.getOperand ()));
1834-
1835- SmallVector<llvm::Value *> phis;
1836- if (failed (inlineConvertOmpRegions (reductionRegion, " omp.reduction.body" ,
1837- builder, moduleTranslation, &phis)))
1838- return failure ();
1839- assert (phis.size () == 1 && " expected one value to be yielded from "
1840- " the reduction body declaration region" );
1841- builder.CreateStore (phis[0 ], privateReductionVar);
1842- return success ();
1843- }
1844-
18451741// / Converts an OpenMP Threadprivate operation into LLVM IR using
18461742// / OpenMPIRBuilder.
18471743static LogicalResult
@@ -3350,9 +3246,6 @@ convertHostOrTargetOperation(Operation *op, llvm::IRBuilderBase &builder,
33503246 .Case ([&](omp::ParallelOp op) {
33513247 return convertOmpParallel (op, builder, moduleTranslation);
33523248 })
3353- .Case ([&](omp::ReductionOp reductionOp) {
3354- return convertOmpReductionOp (reductionOp, builder, moduleTranslation);
3355- })
33563249 .Case ([&](omp::MasterOp) {
33573250 return convertOmpMaster (*op, builder, moduleTranslation);
33583251 })
0 commit comments