================ @@ -102,6 +105,47 @@ mlir::Operation *findLoopIterationVarMemDecl(fir::DoLoopOp doLoop) { return result.getDefiningOp(); } +/// Collects the op(s) responsible for updating a loop's iteration variable with +/// the current iteration number. For example, for the input IR: +/// ``` +/// %i = fir.alloca i32 {bindc_name = "i"} +/// %i_decl:2 = hlfir.declare %i ... +/// ... +/// fir.do_loop %i_iv = %lb to %ub step %step unordered { +/// %1 = fir.convert %i_iv : (index) -> i32 +/// fir.store %1 to %i_decl#1 : !fir.ref<i32> +/// ... +/// } +/// ``` +/// this function would return the first 2 ops in the `fir.do_loop`'s region. +llvm::SetVector<mlir::Operation *> +extractIndVarUpdateOps(fir::DoLoopOp doLoop) { + mlir::Value indVar = doLoop.getInductionVar(); + llvm::SetVector<mlir::Operation *> indVarUpdateOps; + + llvm::SmallVector<mlir::Value> toProcess; + toProcess.push_back(indVar); + + llvm::DenseSet<mlir::Value> done; + + while (!toProcess.empty()) { + mlir::Value val = toProcess.back(); + toProcess.pop_back(); ---------------- skatrak wrote:
```suggestion mlir::Value val = toProcess.pop_back_val(); ``` https://github.com/llvm/llvm-project/pull/127634 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits