From 0cd001d570b11ca924e5f1ce41815a6b86f5c73f Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 23 Nov 2025 10:38:13 -0800 Subject: [PATCH] [AST] Construct iterator_range with the conversion constructor (NFC) This patch simplifies iterator_range construction with the conversion constructor. --- clang/include/clang/AST/OpenMPClause.h | 328 ++++++------------------- 1 file changed, 79 insertions(+), 249 deletions(-) diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index 7972d05bedbf7..72c5efde7449b 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -313,12 +313,8 @@ template class OMPVarListClause : public OMPClause { unsigned varlist_size() const { return NumVars; } bool varlist_empty() const { return NumVars == 0; } - varlist_range varlist() { - return varlist_range(varlist_begin(), varlist_end()); - } - varlist_const_range varlist() const { - return varlist_const_range(varlist_begin(), varlist_end()); - } + varlist_range varlist() { return getVarRefs(); } + varlist_const_range varlist() const { return getVarRefs(); } varlist_iterator varlist_begin() { return getVarRefs().begin(); } varlist_iterator varlist_end() { return getVarRefs().end(); } @@ -3404,14 +3400,10 @@ class OMPPrivateClause final using private_copies_const_range = llvm::iterator_range; - private_copies_range private_copies() { - return private_copies_range(getPrivateCopies().begin(), - getPrivateCopies().end()); - } + private_copies_range private_copies() { return getPrivateCopies(); } private_copies_const_range private_copies() const { - return private_copies_const_range(getPrivateCopies().begin(), - getPrivateCopies().end()); + return getPrivateCopies(); } child_range children() { @@ -3531,13 +3523,9 @@ class OMPFirstprivateClause final using private_copies_const_range = llvm::iterator_range; - private_copies_range private_copies() { - return private_copies_range(getPrivateCopies().begin(), - getPrivateCopies().end()); - } + private_copies_range private_copies() { return getPrivateCopies(); } private_copies_const_range private_copies() const { - return private_copies_const_range(getPrivateCopies().begin(), - getPrivateCopies().end()); + return getPrivateCopies(); } using inits_iterator = MutableArrayRef::iterator; @@ -3545,12 +3533,8 @@ class OMPFirstprivateClause final using inits_range = llvm::iterator_range; using inits_const_range = llvm::iterator_range; - inits_range inits() { - return inits_range(getInits().begin(), getInits().end()); - } - inits_const_range inits() const { - return inits_const_range(getInits().begin(), getInits().end()); - } + inits_range inits() { return getInits(); } + inits_const_range inits() const { return getInits(); } child_range children() { return child_range(reinterpret_cast(varlist_begin()), @@ -3752,44 +3736,23 @@ class OMPLastprivateClause final /// copies of original lastprivate variables. void setPrivateCopies(ArrayRef PrivateCopies); - helper_expr_const_range private_copies() const { - return helper_expr_const_range(getPrivateCopies().begin(), - getPrivateCopies().end()); - } + helper_expr_const_range private_copies() const { return getPrivateCopies(); } - helper_expr_range private_copies() { - return helper_expr_range(getPrivateCopies().begin(), - getPrivateCopies().end()); - } + helper_expr_range private_copies() { return getPrivateCopies(); } - helper_expr_const_range source_exprs() const { - return helper_expr_const_range(getSourceExprs().begin(), - getSourceExprs().end()); - } + helper_expr_const_range source_exprs() const { return getSourceExprs(); } - helper_expr_range source_exprs() { - return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end()); - } + helper_expr_range source_exprs() { return getSourceExprs(); } helper_expr_const_range destination_exprs() const { - return helper_expr_const_range(getDestinationExprs().begin(), - getDestinationExprs().end()); + return getDestinationExprs(); } - helper_expr_range destination_exprs() { - return helper_expr_range(getDestinationExprs().begin(), - getDestinationExprs().end()); - } + helper_expr_range destination_exprs() { return getDestinationExprs(); } - helper_expr_const_range assignment_ops() const { - return helper_expr_const_range(getAssignmentOps().begin(), - getAssignmentOps().end()); - } + helper_expr_const_range assignment_ops() const { return getAssignmentOps(); } - helper_expr_range assignment_ops() { - return helper_expr_range(getAssignmentOps().begin(), - getAssignmentOps().end()); - } + helper_expr_range assignment_ops() { return getAssignmentOps(); } child_range children() { return child_range(reinterpret_cast(varlist_begin()), @@ -4178,79 +4141,45 @@ class OMPReductionClause final using helper_flag_const_range = llvm::iterator_range; - helper_expr_const_range privates() const { - return helper_expr_const_range(getPrivates().begin(), getPrivates().end()); - } + helper_expr_const_range privates() const { return getPrivates(); } - helper_expr_range privates() { - return helper_expr_range(getPrivates().begin(), getPrivates().end()); - } + helper_expr_range privates() { return getPrivates(); } - helper_expr_const_range lhs_exprs() const { - return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end()); - } + helper_expr_const_range lhs_exprs() const { return getLHSExprs(); } - helper_expr_range lhs_exprs() { - return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end()); - } + helper_expr_range lhs_exprs() { return getLHSExprs(); } - helper_expr_const_range rhs_exprs() const { - return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end()); - } + helper_expr_const_range rhs_exprs() const { return getRHSExprs(); } - helper_expr_range rhs_exprs() { - return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end()); - } + helper_expr_range rhs_exprs() { return getRHSExprs(); } helper_flag_const_range private_var_reduction_flags() const { - return helper_flag_const_range(getPrivateVariableReductionFlags().begin(), - getPrivateVariableReductionFlags().end()); + return getPrivateVariableReductionFlags(); } helper_flag_range private_var_reduction_flags() { - return helper_flag_range(getPrivateVariableReductionFlags().begin(), - getPrivateVariableReductionFlags().end()); + return getPrivateVariableReductionFlags(); } - helper_expr_const_range reduction_ops() const { - return helper_expr_const_range(getReductionOps().begin(), - getReductionOps().end()); - } + helper_expr_const_range reduction_ops() const { return getReductionOps(); } - helper_expr_range reduction_ops() { - return helper_expr_range(getReductionOps().begin(), - getReductionOps().end()); - } + helper_expr_range reduction_ops() { return getReductionOps(); } - helper_expr_const_range copy_ops() const { - return helper_expr_const_range(getInscanCopyOps().begin(), - getInscanCopyOps().end()); - } + helper_expr_const_range copy_ops() const { return getInscanCopyOps(); } - helper_expr_range copy_ops() { - return helper_expr_range(getInscanCopyOps().begin(), - getInscanCopyOps().end()); - } + helper_expr_range copy_ops() { return getInscanCopyOps(); } helper_expr_const_range copy_array_temps() const { - return helper_expr_const_range(getInscanCopyArrayTemps().begin(), - getInscanCopyArrayTemps().end()); + return getInscanCopyArrayTemps(); } - helper_expr_range copy_array_temps() { - return helper_expr_range(getInscanCopyArrayTemps().begin(), - getInscanCopyArrayTemps().end()); - } + helper_expr_range copy_array_temps() { return getInscanCopyArrayTemps(); } helper_expr_const_range copy_array_elems() const { - return helper_expr_const_range(getInscanCopyArrayElems().begin(), - getInscanCopyArrayElems().end()); + return getInscanCopyArrayElems(); } - helper_expr_range copy_array_elems() { - return helper_expr_range(getInscanCopyArrayElems().begin(), - getInscanCopyArrayElems().end()); - } + helper_expr_range copy_array_elems() { return getInscanCopyArrayElems(); } child_range children() { return child_range(reinterpret_cast(varlist_begin()), @@ -4450,39 +4379,21 @@ class OMPTaskReductionClause final using helper_expr_const_range = llvm::iterator_range; - helper_expr_const_range privates() const { - return helper_expr_const_range(getPrivates().begin(), getPrivates().end()); - } + helper_expr_const_range privates() const { return getPrivates(); } - helper_expr_range privates() { - return helper_expr_range(getPrivates().begin(), getPrivates().end()); - } + helper_expr_range privates() { return getPrivates(); } - helper_expr_const_range lhs_exprs() const { - return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end()); - } + helper_expr_const_range lhs_exprs() const { return getLHSExprs(); } - helper_expr_range lhs_exprs() { - return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end()); - } + helper_expr_range lhs_exprs() { return getLHSExprs(); } - helper_expr_const_range rhs_exprs() const { - return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end()); - } + helper_expr_const_range rhs_exprs() const { return getRHSExprs(); } - helper_expr_range rhs_exprs() { - return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end()); - } + helper_expr_range rhs_exprs() { return getRHSExprs(); } - helper_expr_const_range reduction_ops() const { - return helper_expr_const_range(getReductionOps().begin(), - getReductionOps().end()); - } + helper_expr_const_range reduction_ops() const { return getReductionOps(); } - helper_expr_range reduction_ops() { - return helper_expr_range(getReductionOps().begin(), - getReductionOps().end()); - } + helper_expr_range reduction_ops() { return getReductionOps(); } child_range children() { return child_range(reinterpret_cast(varlist_begin()), @@ -4694,48 +4605,28 @@ class OMPInReductionClause final using helper_expr_const_range = llvm::iterator_range; - helper_expr_const_range privates() const { - return helper_expr_const_range(getPrivates().begin(), getPrivates().end()); - } + helper_expr_const_range privates() const { return getPrivates(); } - helper_expr_range privates() { - return helper_expr_range(getPrivates().begin(), getPrivates().end()); - } + helper_expr_range privates() { return getPrivates(); } - helper_expr_const_range lhs_exprs() const { - return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end()); - } + helper_expr_const_range lhs_exprs() const { return getLHSExprs(); } - helper_expr_range lhs_exprs() { - return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end()); - } + helper_expr_range lhs_exprs() { return getLHSExprs(); } - helper_expr_const_range rhs_exprs() const { - return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end()); - } + helper_expr_const_range rhs_exprs() const { return getRHSExprs(); } - helper_expr_range rhs_exprs() { - return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end()); - } + helper_expr_range rhs_exprs() { return getRHSExprs(); } - helper_expr_const_range reduction_ops() const { - return helper_expr_const_range(getReductionOps().begin(), - getReductionOps().end()); - } + helper_expr_const_range reduction_ops() const { return getReductionOps(); } - helper_expr_range reduction_ops() { - return helper_expr_range(getReductionOps().begin(), - getReductionOps().end()); - } + helper_expr_range reduction_ops() { return getReductionOps(); } helper_expr_const_range taskgroup_descriptors() const { - return helper_expr_const_range(getTaskgroupDescriptors().begin(), - getTaskgroupDescriptors().end()); + return getTaskgroupDescriptors(); } helper_expr_range taskgroup_descriptors() { - return helper_expr_range(getTaskgroupDescriptors().begin(), - getTaskgroupDescriptors().end()); + return getTaskgroupDescriptors(); } child_range children() { @@ -4965,52 +4856,36 @@ class OMPLinearClause final using privates_range = llvm::iterator_range; using privates_const_range = llvm::iterator_range; - privates_range privates() { - return privates_range(getPrivates().begin(), getPrivates().end()); - } + privates_range privates() { return getPrivates(); } - privates_const_range privates() const { - return privates_const_range(getPrivates().begin(), getPrivates().end()); - } + privates_const_range privates() const { return getPrivates(); } using inits_iterator = MutableArrayRef::iterator; using inits_const_iterator = ArrayRef::iterator; using inits_range = llvm::iterator_range; using inits_const_range = llvm::iterator_range; - inits_range inits() { - return inits_range(getInits().begin(), getInits().end()); - } + inits_range inits() { return getInits(); } - inits_const_range inits() const { - return inits_const_range(getInits().begin(), getInits().end()); - } + inits_const_range inits() const { return getInits(); } using updates_iterator = MutableArrayRef::iterator; using updates_const_iterator = ArrayRef::iterator; using updates_range = llvm::iterator_range; using updates_const_range = llvm::iterator_range; - updates_range updates() { - return updates_range(getUpdates().begin(), getUpdates().end()); - } + updates_range updates() { return getUpdates(); } - updates_const_range updates() const { - return updates_const_range(getUpdates().begin(), getUpdates().end()); - } + updates_const_range updates() const { return getUpdates(); } using finals_iterator = MutableArrayRef::iterator; using finals_const_iterator = ArrayRef::iterator; using finals_range = llvm::iterator_range; using finals_const_range = llvm::iterator_range; - finals_range finals() { - return finals_range(getFinals().begin(), getFinals().end()); - } + finals_range finals() { return getFinals(); } - finals_const_range finals() const { - return finals_const_range(getFinals().begin(), getFinals().end()); - } + finals_const_range finals() const { return getFinals(); } using used_expressions_iterator = MutableArrayRef::iterator; using used_expressions_const_iterator = ArrayRef::iterator; @@ -5270,34 +5145,19 @@ class OMPCopyinClause final using helper_expr_const_range = llvm::iterator_range; - helper_expr_const_range source_exprs() const { - return helper_expr_const_range(getSourceExprs().begin(), - getSourceExprs().end()); - } + helper_expr_const_range source_exprs() const { return getSourceExprs(); } - helper_expr_range source_exprs() { - return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end()); - } + helper_expr_range source_exprs() { return getSourceExprs(); } helper_expr_const_range destination_exprs() const { - return helper_expr_const_range(getDestinationExprs().begin(), - getDestinationExprs().end()); + return getDestinationExprs(); } - helper_expr_range destination_exprs() { - return helper_expr_range(getDestinationExprs().begin(), - getDestinationExprs().end()); - } + helper_expr_range destination_exprs() { return getDestinationExprs(); } - helper_expr_const_range assignment_ops() const { - return helper_expr_const_range(getAssignmentOps().begin(), - getAssignmentOps().end()); - } + helper_expr_const_range assignment_ops() const { return getAssignmentOps(); } - helper_expr_range assignment_ops() { - return helper_expr_range(getAssignmentOps().begin(), - getAssignmentOps().end()); - } + helper_expr_range assignment_ops() { return getAssignmentOps(); } child_range children() { return child_range(reinterpret_cast(varlist_begin()), @@ -5433,34 +5293,19 @@ class OMPCopyprivateClause final using helper_expr_const_range = llvm::iterator_range; - helper_expr_const_range source_exprs() const { - return helper_expr_const_range(getSourceExprs().begin(), - getSourceExprs().end()); - } + helper_expr_const_range source_exprs() const { return getSourceExprs(); } - helper_expr_range source_exprs() { - return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end()); - } + helper_expr_range source_exprs() { return getSourceExprs(); } helper_expr_const_range destination_exprs() const { - return helper_expr_const_range(getDestinationExprs().begin(), - getDestinationExprs().end()); + return getDestinationExprs(); } - helper_expr_range destination_exprs() { - return helper_expr_range(getDestinationExprs().begin(), - getDestinationExprs().end()); - } + helper_expr_range destination_exprs() { return getDestinationExprs(); } - helper_expr_const_range assignment_ops() const { - return helper_expr_const_range(getAssignmentOps().begin(), - getAssignmentOps().end()); - } + helper_expr_const_range assignment_ops() const { return getAssignmentOps(); } - helper_expr_range assignment_ops() { - return helper_expr_range(getAssignmentOps().begin(), - getAssignmentOps().end()); - } + helper_expr_range assignment_ops() { return getAssignmentOps(); } child_range children() { return child_range(reinterpret_cast(varlist_begin()), @@ -6632,18 +6477,14 @@ class OMPMappableExprListClause : public OMPVarListClause, using const_all_decls_iterator = ArrayRef::iterator; using const_all_decls_range = llvm::iterator_range; - const_all_decls_range all_decls() const { - auto A = getUniqueDeclsRef(); - return const_all_decls_range(A.begin(), A.end()); - } + const_all_decls_range all_decls() const { return getUniqueDeclsRef(); } using const_all_num_lists_iterator = ArrayRef::iterator; using const_all_num_lists_range = llvm::iterator_range; const_all_num_lists_range all_num_lists() const { - auto A = getDeclNumListsRef(); - return const_all_num_lists_range(A.begin(), A.end()); + return getDeclNumListsRef(); } using const_all_lists_sizes_iterator = ArrayRef::iterator; @@ -6651,8 +6492,7 @@ class OMPMappableExprListClause : public OMPVarListClause, llvm::iterator_range; const_all_lists_sizes_range all_lists_sizes() const { - auto A = getComponentListSizesRef(); - return const_all_lists_sizes_range(A.begin(), A.end()); + return getComponentListSizesRef(); } using const_all_components_iterator = ArrayRef::iterator; @@ -6660,8 +6500,7 @@ class OMPMappableExprListClause : public OMPVarListClause, llvm::iterator_range; const_all_components_range all_components() const { - auto A = getComponentsRef(); - return const_all_components_range(A.begin(), A.end()); + return getComponentsRef(); } using mapperlist_iterator = MutableArrayRef::iterator; @@ -8241,14 +8080,10 @@ class OMPUseDevicePtrClause final using private_copies_const_range = llvm::iterator_range; - private_copies_range private_copies() { - return private_copies_range(getPrivateCopies().begin(), - getPrivateCopies().end()); - } + private_copies_range private_copies() { return getPrivateCopies(); } private_copies_const_range private_copies() const { - return private_copies_const_range(getPrivateCopies().begin(), - getPrivateCopies().end()); + return getPrivateCopies(); } using inits_iterator = MutableArrayRef::iterator; @@ -8256,13 +8091,9 @@ class OMPUseDevicePtrClause final using inits_range = llvm::iterator_range; using inits_const_range = llvm::iterator_range; - inits_range inits() { - return inits_range(getInits().begin(), getInits().end()); - } + inits_range inits() { return getInits(); } - inits_const_range inits() const { - return inits_const_range(getInits().begin(), getInits().end()); - } + inits_const_range inits() const { return getInits(); } child_range children() { return child_range(reinterpret_cast(varlist_begin()), @@ -8904,8 +8735,7 @@ class OMPInitClause final } const_prefs_range prefs() const { - auto Prefs = const_cast(this)->prefs(); - return const_prefs_range(Prefs.begin(), Prefs.end()); + return const_prefs_range(const_cast(this)->prefs()); } static bool classof(const OMPClause *T) {