[flang-commits] [flang] [flang][MLIR] Hoist `do concurrent` nest bounds/steps outside the nest (PR #114020)
Kareem Ergawy via flang-commits
flang-commits at lists.llvm.org
Wed Oct 30 00:47:30 PDT 2024
================
@@ -2131,18 +2131,33 @@ class FirConverter : public Fortran::lower::AbstractConverter {
llvm::SmallVectorImpl<const Fortran::parser::CompilerDirective *> &dirs) {
assert(!incrementLoopNestInfo.empty() && "empty loop nest");
mlir::Location loc = toLocation();
+
for (IncrementLoopInfo &info : incrementLoopNestInfo) {
- info.loopVariable =
- genLoopVariableAddress(loc, *info.loopVariableSym, info.isUnordered);
- mlir::Value lowerValue = genControlValue(info.lowerExpr, info);
- mlir::Value upperValue = genControlValue(info.upperExpr, info);
- bool isConst = true;
- mlir::Value stepValue = genControlValue(
- info.stepExpr, info, info.isStructured() ? nullptr : &isConst);
- // Use a temp variable for unstructured loops with non-const step.
- if (!isConst) {
- info.stepVariable = builder->createTemporary(loc, stepValue.getType());
- builder->create<fir::StoreOp>(loc, stepValue, info.stepVariable);
+ mlir::Value lowerValue;
+ mlir::Value upperValue;
+ mlir::Value stepValue;
+
+ {
+ mlir::OpBuilder::InsertionGuard guard(*builder);
+
+ // Set the IP before the first loop in the nest so that all nest bounds
+ // and step values are created outside the nest.
+ if (incrementLoopNestInfo[0].doLoop)
+ builder->setInsertionPoint(incrementLoopNestInfo[0].doLoop);
----------------
ergawy wrote:
Thanks for pointing that out. Done.
https://github.com/llvm/llvm-project/pull/114020
More information about the flang-commits
mailing list