[csa][cleanup] Remove ParameterMode from CalculateNewElementsCapacity

Drive-by: Also from WordOrSmiShr

Bug: v8:9708, v8:6949
Change-Id: Ic00b91988abf2120b433809dac3871eb887b8484
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2339614
Reviewed-by: Dan Elphick <delphick@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69295}
diff --git a/src/codegen/code-stub-assembler.cc b/src/codegen/code-stub-assembler.cc
index c912979..b0a24f0 100644
--- a/src/codegen/code-stub-assembler.cc
+++ b/src/codegen/code-stub-assembler.cc
@@ -4821,16 +4821,25 @@
   }
 }
 
-Node* CodeStubAssembler::CalculateNewElementsCapacity(Node* old_capacity,
-                                                      ParameterMode mode) {
-  CSA_SLOW_ASSERT(this, MatchesParameterMode(old_capacity, mode));
-  Node* half_old_capacity = WordOrSmiShr(old_capacity, 1, mode);
-  Node* new_capacity = IntPtrOrSmiAdd(half_old_capacity, old_capacity, mode);
-  Node* padding =
-      IntPtrOrSmiConstant(JSObject::kMinAddedElementsCapacity, mode);
-  return IntPtrOrSmiAdd(new_capacity, padding, mode);
+template <typename TIndex>
+TNode<TIndex> CodeStubAssembler::CalculateNewElementsCapacity(
+    TNode<TIndex> old_capacity) {
+  static_assert(
+      std::is_same<TIndex, Smi>::value || std::is_same<TIndex, IntPtrT>::value,
+      "Only Smi or IntPtrT old_capacity is allowed");
+  Comment("TryGrowElementsCapacity");
+  TNode<TIndex> half_old_capacity = WordOrSmiShr(old_capacity, 1);
+  TNode<TIndex> new_capacity = IntPtrOrSmiAdd(half_old_capacity, old_capacity);
+  TNode<TIndex> padding =
+      IntPtrOrSmiConstant<TIndex>(JSObject::kMinAddedElementsCapacity);
+  return IntPtrOrSmiAdd(new_capacity, padding);
 }
 
+template V8_EXPORT_PRIVATE TNode<IntPtrT>
+    CodeStubAssembler::CalculateNewElementsCapacity<IntPtrT>(TNode<IntPtrT>);
+template V8_EXPORT_PRIVATE TNode<Smi>
+    CodeStubAssembler::CalculateNewElementsCapacity<Smi>(TNode<Smi>);
+
 TNode<FixedArrayBase> CodeStubAssembler::TryGrowElementsCapacity(
     TNode<HeapObject> object, TNode<FixedArrayBase> elements, ElementsKind kind,
     TNode<Smi> key, Label* bailout) {
@@ -4858,7 +4867,7 @@
   GotoIf(UintPtrOrSmiGreaterThanOrEqual(key, max_capacity), bailout);
 
   // Calculate the capacity of the new backing store.
-  Node* new_capacity = CalculateNewElementsCapacity(
+  TNode<TIndex> new_capacity = CalculateNewElementsCapacity(
       IntPtrOrSmiAdd(key, IntPtrOrSmiConstant<TIndex>(1)));
 
   ParameterMode mode =
diff --git a/src/codegen/code-stub-assembler.h b/src/codegen/code-stub-assembler.h
index a584b96..3f8dcbb 100644
--- a/src/codegen/code-stub-assembler.h
+++ b/src/codegen/code-stub-assembler.h
@@ -695,13 +695,10 @@
     }
   }
 
-  Node* WordOrSmiShr(Node* a, int shift, ParameterMode mode) {
-    if (mode == SMI_PARAMETERS) {
-      return SmiShr(CAST(a), shift);
-    } else {
-      DCHECK_EQ(INTPTR_PARAMETERS, mode);
-      return WordShr(a, shift);
-    }
+  TNode<Smi> WordOrSmiShr(TNode<Smi> a, int shift) { return SmiShr(a, shift); }
+
+  TNode<IntPtrT> WordOrSmiShr(TNode<IntPtrT> a, int shift) {
+    return WordShr(a, shift);
   }
 
 #define SMI_COMPARISON_OP(SmiOpName, IntPtrOpName, Int32OpName)           \
@@ -2229,15 +2226,8 @@
                                       ElementsKind from_kind,
                                       ElementsKind to_kind, Label* if_hole);
 
-  Node* CalculateNewElementsCapacity(Node* old_capacity, ParameterMode mode);
-
-  TNode<Smi> CalculateNewElementsCapacity(TNode<Smi> old_capacity) {
-    return CAST(CalculateNewElementsCapacity(old_capacity, SMI_PARAMETERS));
-  }
-  TNode<IntPtrT> CalculateNewElementsCapacity(TNode<IntPtrT> old_capacity) {
-    return UncheckedCast<IntPtrT>(
-        CalculateNewElementsCapacity(old_capacity, INTPTR_PARAMETERS));
-  }
+  template <typename TIndex>
+  TNode<TIndex> CalculateNewElementsCapacity(TNode<TIndex> old_capacity);
 
   // Tries to grow the |elements| array of given |object| to store the |key|
   // or bails out if the growing gap is too big. Returns new elements.