[llvm] [llvm] Construct SmallVector with ArrayRef (NFC) (PR #136063)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 16 17:43:50 PDT 2025


https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/136063

>From 280c4bd8b7882d47793000b74b2c93b8fe3dacc4 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 16 Apr 2025 12:35:38 -0700
Subject: [PATCH 1/2] [llvm] Construct SmallVector with ArrayRef (NFC)

---
 llvm/lib/IR/IRBuilder.cpp                           | 13 ++++---------
 .../llvm-reduce/deltas/ReduceOperandsToArgs.cpp     |  3 +--
 llvm/tools/lto/lto.cpp                              |  3 +--
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp
index e5a2f08c393c9..a195945c9cadb 100644
--- a/llvm/lib/IR/IRBuilder.cpp
+++ b/llvm/lib/IR/IRBuilder.cpp
@@ -748,18 +748,15 @@ getStatepointBundles(std::optional<ArrayRef<T1>> TransitionArgs,
                      ArrayRef<T3> GCArgs) {
   std::vector<OperandBundleDef> Rval;
   if (DeoptArgs) {
-    SmallVector<Value*, 16> DeoptValues;
-    llvm::append_range(DeoptValues, *DeoptArgs);
+    SmallVector<Value *, 16> DeoptValues(*DeoptArgs);
     Rval.emplace_back("deopt", DeoptValues);
   }
   if (TransitionArgs) {
-    SmallVector<Value*, 16> TransitionValues;
-    llvm::append_range(TransitionValues, *TransitionArgs);
+    SmallVector<Value *, 16> TransitionValues(*TransitionArgs);
     Rval.emplace_back("gc-transition", TransitionValues);
   }
   if (GCArgs.size()) {
-    SmallVector<Value*, 16> LiveValues;
-    llvm::append_range(LiveValues, GCArgs);
+    SmallVector<Value *, 16> LiveValues(GCArgs);
     Rval.emplace_back("gc-live", LiveValues);
   }
   return Rval;
@@ -1091,9 +1088,7 @@ CallInst *IRBuilderBase::CreateConstrainedFPCall(
     Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
     std::optional<RoundingMode> Rounding,
     std::optional<fp::ExceptionBehavior> Except) {
-  llvm::SmallVector<Value *, 6> UseArgs;
-
-  append_range(UseArgs, Args);
+  llvm::SmallVector<Value *, 6> UseArgs(Args);
 
   if (Intrinsic::hasConstrainedFPRoundingModeOperand(Callee->getIntrinsicID()))
     UseArgs.push_back(getConstrainedFPRounding(Rounding));
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
index 3f877b525549f..cb27d5473fd73 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp
@@ -129,8 +129,7 @@ static void substituteOperandWithArgument(Function *OldF,
     UniqueValues.insert(Op->get());
 
   // Determine the new function's signature.
-  SmallVector<Type *> NewArgTypes;
-  llvm::append_range(NewArgTypes, OldF->getFunctionType()->params());
+  SmallVector<Type *> NewArgTypes(OldF->getFunctionType()->params());
   size_t ArgOffset = NewArgTypes.size();
   for (Value *V : UniqueValues)
     NewArgTypes.push_back(V->getType());
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index 29219c9114522..bb64d42ccced1 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -496,8 +496,7 @@ void lto_codegen_debug_options_array(lto_code_gen_t cg,
                                      const char *const *options, int number) {
   assert(optionParsingState != OptParsingState::Early &&
          "early option processing already happened");
-  SmallVector<StringRef, 4> Options;
-  llvm::append_range(Options, ArrayRef(options, number));
+  SmallVector<StringRef, 4> Options(ArrayRef(options, number));
   unwrap(cg)->setCodeGenDebugOptions(ArrayRef(Options));
 }
 

>From 4189c603bd5ca6ca2070f3565224d4203cdfc50d Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 16 Apr 2025 17:43:12 -0700
Subject: [PATCH 2/2] Address a comment.

---
 llvm/lib/IR/IRBuilder.cpp | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp
index a195945c9cadb..b448c0372eb0e 100644
--- a/llvm/lib/IR/IRBuilder.cpp
+++ b/llvm/lib/IR/IRBuilder.cpp
@@ -747,18 +747,13 @@ getStatepointBundles(std::optional<ArrayRef<T1>> TransitionArgs,
                      std::optional<ArrayRef<T2>> DeoptArgs,
                      ArrayRef<T3> GCArgs) {
   std::vector<OperandBundleDef> Rval;
-  if (DeoptArgs) {
-    SmallVector<Value *, 16> DeoptValues(*DeoptArgs);
-    Rval.emplace_back("deopt", DeoptValues);
-  }
-  if (TransitionArgs) {
-    SmallVector<Value *, 16> TransitionValues(*TransitionArgs);
-    Rval.emplace_back("gc-transition", TransitionValues);
-  }
-  if (GCArgs.size()) {
-    SmallVector<Value *, 16> LiveValues(GCArgs);
-    Rval.emplace_back("gc-live", LiveValues);
-  }
+  if (DeoptArgs)
+    Rval.emplace_back("deopt", SmallVector<Value *, 16>(*DeoptArgs));
+  if (TransitionArgs)
+    Rval.emplace_back("gc-transition",
+                      SmallVector<Value *, 16>(*TransitionArgs));
+  if (GCArgs.size())
+    Rval.emplace_back("gc-live", SmallVector<Value *, 16>(GCArgs));
   return Rval;
 }
 



More information about the llvm-commits mailing list