Skip to content

[flang] Construct SmallVector with ArrayRef (NFC) #101901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Aug 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2024

@llvm/pr-subscribers-flang-fir-hlfir

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/101901.diff

8 Files Affected:

  • (modified) flang/include/flang/Lower/CallInterface.h (+1-1)
  • (modified) flang/include/flang/Lower/IterationSpace.h (+1-1)
  • (modified) flang/include/flang/Optimizer/Builder/BoxValue.h (+2-3)
  • (modified) flang/include/flang/Optimizer/Support/InternalNames.h (+2-3)
  • (modified) flang/lib/Lower/ConvertArrayConstructor.cpp (+2-4)
  • (modified) flang/lib/Lower/IterationSpace.cpp (+1-1)
  • (modified) flang/lib/Optimizer/Transforms/AffineDemotion.cpp (+2-3)
  • (modified) flang/unittests/Optimizer/InternalNamesTest.cpp (+2-3)
diff --git a/flang/include/flang/Lower/CallInterface.h b/flang/include/flang/Lower/CallInterface.h
index a11e81b6593de..9a688330e8bd2 100644
--- a/flang/include/flang/Lower/CallInterface.h
+++ b/flang/include/flang/Lower/CallInterface.h
@@ -138,7 +138,7 @@ class CallInterface {
     FirPlaceHolder(mlir::Type t, int passedPosition, Property p,
                    llvm::ArrayRef<mlir::NamedAttribute> attrs)
         : type{t}, passedEntityPosition{passedPosition}, property{p},
-          attributes{attrs.begin(), attrs.end()} {}
+          attributes{attrs} {}
     /// Type for this input/output
     mlir::Type type;
     /// Position of related passedEntity in passedArguments.
diff --git a/flang/include/flang/Lower/IterationSpace.h b/flang/include/flang/Lower/IterationSpace.h
index 1359e22e23edd..ab52821432fb6 100644
--- a/flang/include/flang/Lower/IterationSpace.h
+++ b/flang/include/flang/Lower/IterationSpace.h
@@ -56,7 +56,7 @@ class IterationSpace {
   explicit IterationSpace(const IterationSpace &from,
                           llvm::ArrayRef<mlir::Value> idxs)
       : inArg(from.inArg), outRes(from.outRes), element(from.element),
-        indices(idxs.begin(), idxs.end()) {}
+        indices(idxs) {}
 
   /// Create a copy of the \p from IterationSpace and prepend the \p prefix
   /// values and append the \p suffix values, respectively.
diff --git a/flang/include/flang/Optimizer/Builder/BoxValue.h b/flang/include/flang/Optimizer/Builder/BoxValue.h
index 9fdaa0b197179..5f9834bfb8ec9 100644
--- a/flang/include/flang/Optimizer/Builder/BoxValue.h
+++ b/flang/include/flang/Optimizer/Builder/BoxValue.h
@@ -127,8 +127,7 @@ class AbstractArrayBox {
   AbstractArrayBox() = default;
   AbstractArrayBox(llvm::ArrayRef<mlir::Value> extents,
                    llvm::ArrayRef<mlir::Value> lbounds)
-      : extents{extents.begin(), extents.end()}, lbounds{lbounds.begin(),
-                                                         lbounds.end()} {}
+      : extents{extents}, lbounds{lbounds} {}
 
   // Every array has extents that describe its shape.
   const llvm::SmallVectorImpl<mlir::Value> &getExtents() const {
@@ -296,7 +295,7 @@ class BoxValue : public AbstractIrBox {
            llvm::ArrayRef<mlir::Value> explicitParams,
            llvm::ArrayRef<mlir::Value> explicitExtents = {})
       : AbstractIrBox{addr, lbounds, explicitExtents},
-        explicitParams{explicitParams.begin(), explicitParams.end()} {
+        explicitParams{explicitParams} {
     assert(verify());
   }
   // TODO: check contiguous attribute of addr
diff --git a/flang/include/flang/Optimizer/Support/InternalNames.h b/flang/include/flang/Optimizer/Support/InternalNames.h
index ff23510922372..9e13b4a7668b7 100644
--- a/flang/include/flang/Optimizer/Support/InternalNames.h
+++ b/flang/include/flang/Optimizer/Support/InternalNames.h
@@ -56,9 +56,8 @@ struct NameUniquer {
     DeconstructedName(llvm::ArrayRef<std::string> modules,
                       llvm::ArrayRef<std::string> procs, std::int64_t blockId,
                       llvm::StringRef name, llvm::ArrayRef<std::int64_t> kinds)
-        : modules{modules.begin(), modules.end()}, procs{procs.begin(),
-                                                         procs.end()},
-          blockId{blockId}, name{name}, kinds{kinds.begin(), kinds.end()} {}
+        : modules{modules}, procs{procs}, blockId{blockId}, name{name},
+          kinds{kinds} {}
 
     llvm::SmallVector<std::string> modules;
     llvm::SmallVector<std::string> procs;
diff --git a/flang/lib/Lower/ConvertArrayConstructor.cpp b/flang/lib/Lower/ConvertArrayConstructor.cpp
index 3c43cd20eb080..7e2142693eac5 100644
--- a/flang/lib/Lower/ConvertArrayConstructor.cpp
+++ b/flang/lib/Lower/ConvertArrayConstructor.cpp
@@ -194,8 +194,7 @@ class AsElementalStrategy : public StrategyBase {
                       fir::SequenceType declaredType, mlir::Value extent,
                       llvm::ArrayRef<mlir::Value> lengths)
       : StrategyBase{stmtCtx, symMap}, shape{builder.genShape(loc, {extent})},
-        lengthParams{lengths.begin(), lengths.end()},
-        exprType{getExprType(declaredType)} {}
+        lengthParams{lengths}, exprType{getExprType(declaredType)} {}
 
   static hlfir::ExprType getExprType(fir::SequenceType declaredType) {
     // Note: 7.8 point 4: the dynamic type of an array constructor is its static
@@ -331,8 +330,7 @@ class RuntimeTempStrategy : public StrategyBase {
       // Prepare the initial state of the allocatable descriptor with a
       // deallocated status and all the available knowledge about the extent
       // and length parameters.
-      llvm::SmallVector<mlir::Value> emboxLengths(lengths.begin(),
-                                                  lengths.end());
+      llvm::SmallVector<mlir::Value> emboxLengths(lengths);
       if (!extent)
         extent = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
       if (missingLengthParameters) {
diff --git a/flang/lib/Lower/IterationSpace.cpp b/flang/lib/Lower/IterationSpace.cpp
index 9303536403837..63011483022b7 100644
--- a/flang/lib/Lower/IterationSpace.cpp
+++ b/flang/lib/Lower/IterationSpace.cpp
@@ -59,7 +59,7 @@ class ArrayBaseFinder {
   using RT = bool;
 
   ArrayBaseFinder(llvm::ArrayRef<Fortran::lower::FrontEndSymbol> syms)
-      : controlVars(syms.begin(), syms.end()) {}
+      : controlVars(syms) {}
 
   template <typename T>
   void operator()(const T &x) {
diff --git a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp
index c416302d671eb..d45f855c9078e 100644
--- a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp
+++ b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp
@@ -125,9 +125,8 @@ class ConvertConversion : public mlir::OpRewritePattern<fir::ConvertOp> {
 };
 
 mlir::Type convertMemRef(mlir::MemRefType type) {
-  return fir::SequenceType::get(
-      SmallVector<int64_t>(type.getShape().begin(), type.getShape().end()),
-      type.getElementType());
+  return fir::SequenceType::get(SmallVector<int64_t>(type.getShape()),
+                                type.getElementType());
 }
 
 class StdAllocConversion : public mlir::OpRewritePattern<memref::AllocOp> {
diff --git a/flang/unittests/Optimizer/InternalNamesTest.cpp b/flang/unittests/Optimizer/InternalNamesTest.cpp
index 058bbeef9b007..ab0b91622980a 100644
--- a/flang/unittests/Optimizer/InternalNamesTest.cpp
+++ b/flang/unittests/Optimizer/InternalNamesTest.cpp
@@ -19,9 +19,8 @@ struct DeconstructedName {
   DeconstructedName(llvm::ArrayRef<std::string> modules,
       llvm::ArrayRef<std::string> procs, std::int64_t blockId,
       llvm::StringRef name, llvm::ArrayRef<std::int64_t> kinds)
-      : modules{modules.begin(), modules.end()}, procs{procs.begin(),
-                                                     procs.end()},
-        blockId{blockId}, name{name}, kinds{kinds.begin(), kinds.end()} {}
+      : modules{modules}, procs{procs}, blockId{blockId}, name{name},
+        kinds{kinds} {}
 
   bool isObjEqual(const NameUniquer::DeconstructedName &actualObj) {
     return actualObj.modules == modules && actualObj.procs == procs &&

@dwblaikie
Copy link
Collaborator

Since this is flang-specific, might want to find a flang code owner/contributor to sign off on this. But it looks fine to me.

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from the flang side. Thanks!

@kazutakahirata kazutakahirata merged commit 6f8ef5a into llvm:main Aug 5, 2024
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_SmallVector_ctor_range_flang branch August 5, 2024 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants