[flang-commits] [flang] [flang][OpenMP] Avoid unnecessary init loop, use constructor instead,… (PR #75482)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Thu Dec 14 07:19:25 PST 2023


https://github.com/kparzysz created https://github.com/llvm/llvm-project/pull/75482

… NFC

SmallVector has a constructor that fills it with a number of copies of a given value. Use it instead of a loop that does the same thing.

>From 92b545374bd93d755b0649cec48926dc38c21c90 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 14 Dec 2023 09:14:38 -0600
Subject: [PATCH] [flang][OpenMP] Avoid unnecessary init loop, use constructor
 instead, NFC

SmallVector has a constructor that fills it with a number of copies of a
given value. Use it instead of a loop that does the same thing.
---
 flang/lib/Lower/OpenMP.cpp | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index eeba87fcd15116..12b8ea82884d9d 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2117,12 +2117,8 @@ static void createBodyOfOp(
     for (const Fortran::semantics::Symbol *arg : args)
       loopVarTypeSize = std::max(loopVarTypeSize, arg->GetUltimate().size());
     mlir::Type loopVarType = getLoopVarType(converter, loopVarTypeSize);
-    llvm::SmallVector<mlir::Type> tiv;
-    llvm::SmallVector<mlir::Location> locs;
-    for (int i = 0; i < (int)args.size(); i++) {
-      tiv.push_back(loopVarType);
-      locs.push_back(loc);
-    }
+    llvm::SmallVector<mlir::Type> tiv(args.size(), loopVarType);
+    llvm::SmallVector<mlir::Location> locs(args.size(), loc);
     firOpBuilder.createBlock(&op.getRegion(), {}, tiv, locs);
     int argIndex = 0;
     // The argument is not currently in memory, so make a temporary for the



More information about the flang-commits mailing list