Skip to content

[llvm] Migrate away from ArrayRef(std::nullopt) (NFC) #144967

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

Merged

Conversation

kazutakahirata
Copy link
Contributor

ArrayRef has a constructor that accepts std::nullopt. This
constructor dates back to the days when we still had llvm::Optional.

Since the use of std::nullopt outside the context of std::optional is
kind of abuse and not intuitive to new comers, I would like to move
away from the constructor and eventually remove it.

This patch takes care of the llvm side of the migration.

ArrayRef has a constructor that accepts std::nullopt.  This
constructor dates back to the days when we still had llvm::Optional.

Since the use of std::nullopt outside the context of std::optional is
kind of abuse and not intuitive to new comers, I would like to move
away from the constructor and eventually remove it.

This patch takes care of the llvm side of the migration.
@llvmbot
Copy link
Member

llvmbot commented Jun 20, 2025

@llvm/pr-subscribers-vectorizers

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

ArrayRef has a constructor that accepts std::nullopt. This
constructor dates back to the days when we still had llvm::Optional.

Since the use of std::nullopt outside the context of std::optional is
kind of abuse and not intuitive to new comers, I would like to move
away from the constructor and eventually remove it.

This patch takes care of the llvm side of the migration.


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

3 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/BasicTTIImpl.h (+2-2)
  • (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+5-5)
  • (modified) llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp (+1-2)
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 3b87978fe3fab..90a75c3d352e4 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -2376,8 +2376,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
                                           CostKind, 1, nullptr, nullptr);
       Cost += thisT()->getVectorInstrCost(Instruction::InsertElement, SearchTy,
                                           CostKind, 0, nullptr, nullptr);
-      Cost += thisT()->getShuffleCost(TTI::SK_Broadcast, SearchTy, std::nullopt,
-                                      CostKind, 0, nullptr);
+      Cost += thisT()->getShuffleCost(TTI::SK_Broadcast, SearchTy, {}, CostKind,
+                                      0, nullptr);
       Cost += thisT()->getCmpSelInstrCost(BinaryOperator::ICmp, SearchTy, RetTy,
                                           CmpInst::ICMP_EQ, CostKind);
       Cost +=
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 4551a365a6967..5eef2497cf90b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -5994,7 +5994,7 @@ static bool isMaskedLoadCompress(
       InstructionCost InterleavedCost =
           VectorGEPCost + TTI.getInterleavedMemoryOpCost(
                               Instruction::Load, AlignedLoadVecTy,
-                              CompressMask[1], std::nullopt, CommonAlignment,
+                              CompressMask[1], {}, CommonAlignment,
                               LI->getPointerAddressSpace(), CostKind, IsMasked);
       if (InterleavedCost < GatherCost) {
         InterleaveFactor = CompressMask[1];
@@ -13561,7 +13561,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
       case TreeEntry::Vectorize:
         if (unsigned Factor = E->getInterleaveFactor()) {
           VecLdCost = TTI->getInterleavedMemoryOpCost(
-              Instruction::Load, VecTy, Factor, std::nullopt, LI0->getAlign(),
+              Instruction::Load, VecTy, Factor, {}, LI0->getAlign(),
               LI0->getPointerAddressSpace(), CostKind);
 
         } else {
@@ -13602,7 +13602,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
         Align CommonAlignment = LI0->getAlign();
         if (InterleaveFactor) {
           VecLdCost = TTI->getInterleavedMemoryOpCost(
-              Instruction::Load, LoadVecTy, InterleaveFactor, std::nullopt,
+              Instruction::Load, LoadVecTy, InterleaveFactor, {},
               CommonAlignment, LI0->getPointerAddressSpace(), CostKind);
         } else if (IsMasked) {
           VecLdCost = TTI->getMaskedMemoryOpCost(
@@ -13677,8 +13677,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
                  "No reused shuffles expected");
           CommonCost = 0;
           VecStCost = TTI->getInterleavedMemoryOpCost(
-              Instruction::Store, VecTy, Factor, std::nullopt,
-              BaseSI->getAlign(), BaseSI->getPointerAddressSpace(), CostKind);
+              Instruction::Store, VecTy, Factor, {}, BaseSI->getAlign(),
+              BaseSI->getPointerAddressSpace(), CostKind);
         } else {
           TTI::OperandValueInfo OpInfo = getOperandInfo(E->getOperand(0));
           VecStCost = TTI->getMemoryOpCost(
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 22861eb1c7dfc..f45ce46763c57 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -3478,8 +3478,7 @@ InstructionCost VPInterleaveRecipe::computeCost(ElementCount VF,
 
   return Cost + IG->getNumMembers() *
                     Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Reverse,
-                                           VectorTy, std::nullopt, Ctx.CostKind,
-                                           0);
+                                           VectorTy, {}, Ctx.CostKind, 0);
 }
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

@kazutakahirata kazutakahirata merged commit 64fe323 into llvm:main Jun 20, 2025
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250619_nullopt_llvm branch June 20, 2025 04:31
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 20, 2025

LLVM Buildbot has detected a new failure on builder flang-aarch64-latest-gcc running on linaro-flang-aarch64-latest-gcc while building llvm at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/130/builds/13831

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
476.302 [729/118/6629] Building CXX object tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/parse-tree.cpp.o
477.020 [729/117/6630] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/openmp-modifiers.cpp.o
480.211 [729/116/6631] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-stop.cpp.o
480.331 [729/115/6632] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/openmp-dsa.cpp.o
481.243 [729/114/6633] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-purity.cpp.o
482.545 [729/113/6634] Building CXX object tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/expr-parsers.cpp.o
485.141 [729/112/6635] Building CXX object tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/real.cpp.o
492.390 [729/111/6636] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/compute-offsets.cpp.o
848.671 [729/110/6637] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/dump-expr.cpp.o
1744.235 [729/109/6638] Building CXX object tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/shape.cpp.o
FAILED: tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/shape.cpp.o 
/usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/flang/lib/Evaluate -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/lib/Evaluate -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/../mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/clang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/../clang/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-ctad-maybe-unsupported -fno-strict-aliasing -fno-semantic-interposition -fpch-preprocess -O3 -DNDEBUG -fno-semantic-interposition -std=c++17 -fPIC  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -Winvalid-pch -include /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/cmake_pch.hxx -MD -MT tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/shape.cpp.o -MF tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/shape.cpp.o.d -o tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/shape.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/lib/Evaluate/shape.cpp
g++-latest: fatal error: Killed signal terminated program cc1plus
compilation terminated.
1752.825 [729/108/6639] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-select-rank.cpp.o
1753.261 [729/107/6640] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-namelist.cpp.o
1753.750 [729/106/6641] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/attr.cpp.o
1762.895 [729/105/6642] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-if-stmt.cpp.o
1763.271 [729/104/6643] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-arithmeticif.cpp.o
1787.400 [729/103/6644] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-nullify.cpp.o
1792.613 [729/102/6645] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-select-type.cpp.o
1799.170 [729/101/6646] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/definable.cpp.o
1801.328 [729/100/6647] Building CXX object tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/initial-image.cpp.o
1801.417 [729/99/6648] Building CXX object tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/fold-designator.cpp.o
1801.903 [729/98/6649] Building CXX object tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/TextDiagnosticPrinter.cpp.o
1802.167 [729/97/6650] Building CXX object tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/intrinsics-library.cpp.o
1804.785 [729/96/6651] Building CXX object tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/openacc-parsers.cpp.o
1806.115 [729/95/6652] Building CXX object tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/TextDiagnosticBuffer.cpp.o
1810.622 [729/94/6653] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/pointer-assignment.cpp.o
1811.086 [729/93/6654] Building CXX object tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/variable.cpp.o
1811.463 [729/92/6655] Building CXX object tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/program-parsers.cpp.o
1811.710 [729/91/6656] Building CXX object tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/FrontendOptions.cpp.o
1813.841 [729/90/6657] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/tools.cpp.o
1814.410 [729/89/6658] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/type.cpp.o
1815.588 [729/88/6659] Building CXX object tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/type.cpp.o
1816.622 [729/87/6660] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-deallocate.cpp.o
1817.286 [729/86/6661] Building CXX object tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/io-parsers.cpp.o
1818.712 [729/85/6662] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/LoweringOptions.cpp.o
1819.825 [729/84/6663] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ComponentPath.cpp.o
1822.159 [729/83/6664] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/canonicalize-directives.cpp.o
1823.167 [729/82/6665] Building CXX object tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/fold-reduction.cpp.o
1824.821 [729/81/6666] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/rewrite-parse-tree.cpp.o
1824.831 [729/80/6667] Building CXX object tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CodeGenOptions.cpp.o
1825.231 [729/79/6668] Building CXX object tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInvocation.cpp.o
1826.062 [729/78/6669] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/check-acc-structure.cpp.o
1826.423 [729/77/6670] Building CXX object tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/formatting.cpp.o
1827.996 [729/76/6671] Building CXX object tools/flang/lib/Evaluate/CMakeFiles/FortranEvaluate.dir/intrinsics.cpp.o
1829.419 [729/75/6672] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/IterationSpace.cpp.o
1829.905 [729/74/6673] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/assignment.cpp.o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants