[llvm-branch-commits] [mlir] [mlir][OpenMP] Convert reduction alloc region to LLVMIR (PR #102524)

2024-08-20 Thread Mats Petersson via llvm-branch-commits


@@ -594,45 +594,85 @@ convertOmpOrderedRegion(Operation &opInst, 
llvm::IRBuilderBase &builder,
 
 /// Allocate space for privatized reduction variables.
 template 
-static void allocByValReductionVars(
-T loop, ArrayRef reductionArgs, llvm::IRBuilderBase 
&builder,
-LLVM::ModuleTranslation &moduleTranslation,
-llvm::OpenMPIRBuilder::InsertPointTy &allocaIP,
-SmallVectorImpl &reductionDecls,
-SmallVectorImpl &privateReductionVariables,
-DenseMap &reductionVariableMap,
-llvm::ArrayRef isByRefs) {
+static LogicalResult
+allocReductionVars(T loop, ArrayRef reductionArgs,
+   llvm::IRBuilderBase &builder,
+   LLVM::ModuleTranslation &moduleTranslation,
+   llvm::OpenMPIRBuilder::InsertPointTy &allocaIP,
+   SmallVectorImpl &reductionDecls,
+   SmallVectorImpl &privateReductionVariables,
+   DenseMap &reductionVariableMap,
+   llvm::ArrayRef isByRefs) {
   llvm::IRBuilderBase::InsertPointGuard guard(builder);
   builder.SetInsertPoint(allocaIP.getBlock()->getTerminator());
 
+  // delay creating stores until after all allocas
+  SmallVector> storesToCreate;
+  storesToCreate.reserve(loop.getNumReductionVars());
+
   for (std::size_t i = 0; i < loop.getNumReductionVars(); ++i) {
-if (isByRefs[i])
-  continue;
-llvm::Value *var = builder.CreateAlloca(
-moduleTranslation.convertType(reductionDecls[i].getType()));
-moduleTranslation.mapValue(reductionArgs[i], var);
-privateReductionVariables[i] = var;
-reductionVariableMap.try_emplace(loop.getReductionVars()[i], var);
+Region &allocRegion = reductionDecls[i].getAllocRegion();
+if (isByRefs[i]) {
+  if (allocRegion.empty())

Leporacanthicus wrote:

What does allocRegion empty mean here? It's not been created? If so, where does 
the alloca go?

https://github.com/llvm/llvm-project/pull/102524
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][OpenMP] Convert reduction alloc region to LLVMIR (PR #102524)

2024-08-20 Thread Mats Petersson via llvm-branch-commits

https://github.com/Leporacanthicus edited 
https://github.com/llvm/llvm-project/pull/102524
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [mlir][OpenMP] Convert reduction alloc region to LLVMIR (PR #102524)

2024-08-20 Thread Mats Petersson via llvm-branch-commits

https://github.com/Leporacanthicus edited 
https://github.com/llvm/llvm-project/pull/102524
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] use reduction alloc region (PR #102525)

2024-08-20 Thread Mats Petersson via llvm-branch-commits

https://github.com/Leporacanthicus approved this pull request.

LGTM. Probably good to have a second approval tho'.

https://github.com/llvm/llvm-project/pull/102525
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [flang] [Flang][Lower] Attach target_cpu and target_features attributes to MLIR functions (PR #78289)

2024-01-17 Thread Mats Petersson via llvm-branch-commits


@@ -4290,6 +4291,18 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
 assert(blockId == 0 && "invalid blockId");
 assert(activeConstructStack.empty() && "invalid construct stack state");
 
+// Set target_cpu and target_features attributes to be passed through to 
the
+// llvm.func operation during lowering.
+const llvm::TargetMachine &targetMachine = bridge.getTargetMachine();
+if (auto targetCPU = targetMachine.getTargetCPU(); !targetCPU.empty())
+  func->setAttr("target_cpu",
+mlir::StringAttr::get(func.getContext(), targetCPU));
+
+if (auto targetFeatures = targetMachine.getTargetFeatureString();
+!targetFeatures.empty())
+  func->setAttr("target_features", mlir::LLVM::TargetFeaturesAttr::get(
+   func.getContext(), targetFeatures));

Leporacanthicus wrote:

I _think_ this doesn't set the target info for function declarations 
(interfaces that are in a different source), which I  need. I'm happy to add 
that as an addition on top. l

Are we getting the target CPU and target features for every function? Or just 
the once? I'm sure it's not a "heavy" operaiton, but seems a bit unnecessary to 
do repeatedly. Should be the same for ALL functions in a module... 

https://github.com/llvm/llvm-project/pull/78289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] Use OmpDirectiveSpecification in standalone directives (PR #131163)

2025-04-05 Thread Mats Petersson via llvm-branch-commits

https://github.com/Leporacanthicus approved this pull request.

LGTM, thanks for the work!

https://github.com/llvm/llvm-project/pull/131163
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits