From a3d3e8c362c2d850543eb2e2631128e1efc368f0 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Thu, 5 Aug 2021 19:50:35 -0600 Subject: Adjust by-value function vec arguments to by-reference. gcc/c/ChangeLog: * c-parser.c (c_parser_declaration_or_fndef): Adjust by-value function vec arguments to by-reference. (c_finish_omp_declare_simd): Same. (c_parser_compound_statement_nostart): Same. (c_parser_for_statement): Same. (c_parser_objc_methodprotolist): Same. (c_parser_oacc_routine): Same. (c_parser_omp_for_loop): Same. (c_parser_omp_declare_simd): Same. gcc/ChangeLog: * dominance.c (prune_bbs_to_update_dominators): Adjust by-value vec arguments to by-reference. (iterate_fix_dominators): Same. * dominance.h (iterate_fix_dominators): Same. * ipa-prop.h: Call auto_vec::to_vec_legacy. * tree-data-ref.c (dump_data_dependence_relation): Adjust by-value vec arguments to by-reference. (debug_data_dependence_relation): Same. (dump_data_dependence_relations): Same. * tree-data-ref.h (debug_data_dependence_relation): Same. (dump_data_dependence_relations): Same. * tree-predcom.c (dump_chains): Same. (initialize_root_vars_lm): Same. (determine_unroll_factor): Same. (replace_phis_by_defined_names): Same. (insert_init_seqs): Same. (pcom_worker::tree_predictive_commoning_loop): Call auto_vec::to_vec_legacy. * tree-ssa-pre.c (insert_into_preds_of_block): Adjust by-value vec arguments to by-reference. * tree-ssa-threadbackward.c (populate_worklist): Same. (back_threader::resolve_def): Same. * tree-vect-data-refs.c (vect_check_nonzero_value): Same. (vect_enhance_data_refs_alignment): Same. (vect_check_lower_bound): Same. (vect_prune_runtime_alias_test_list): Same. (vect_permute_store_chain): Same. * tree-vect-slp-patterns.c (vect_normalize_conj_loc): Same. * tree-vect-stmts.c (vect_create_vectorized_demotion_stmts): Same. * tree-vectorizer.h (vect_permute_store_chain): Same. * vec.c (test_init): New function. (vec_c_tests): Call new function. * vec.h (vec): Declare ctors, dtor, and assignment. (auto_vec::vec_to_legacy): New function. (vec::copy): Adjust initialization. --- gcc/vec.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 14 deletions(-) (limited to 'gcc/vec.h') diff --git a/gcc/vec.h b/gcc/vec.h index 30ef9a6..b3f47b1 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -541,18 +541,16 @@ vec_copy_construct (T *dst, const T *src, unsigned n) ::new (static_cast(dst)) T (*src); } -/* Type to provide NULL values for vec. This is used to - provide nil initializers for vec instances. Since vec must be - a POD, we cannot have proper ctor/dtor for it. To initialize - a vec instance, you can assign it the value vNULL. This isn't - needed for file-scope and function-local static vectors, which - are zero-initialized by default. */ -struct vnull -{ - template - CONSTEXPR operator vec () const { return vec(); } -}; -extern vnull vNULL; +/* Type to provide zero-initialized values for vec. This is + used to provide nil initializers for vec instances. Since vec must + be a trivially copyable type that can be copied by memcpy and zeroed + out by memset, it must have defaulted default and copy ctor and copy + assignment. To initialize a vec either use value initialization + (e.g., vec() or vec v{ };) or assign it the value vNULL. This isn't + needed for file-scope and function-local static vectors, which are + zero-initialized by default. */ +struct vnull { }; +constexpr vnull vNULL{ }; /* Embeddable vector. These vectors are suitable to be embedded @@ -1431,10 +1429,34 @@ gt_pch_nx (vec *v, gt_pointer_operator op, void *cookie) As long as we use C++03, we cannot have constructors nor destructors in classes that are stored in unions. */ +template +class auto_vec; + template struct vec { public: + /* Default ctors to ensure triviality. Use value-initialization + (e.g., vec() or vec v{ };) or vNULL to create a zero-initialized + instance. */ + vec () = default; + vec (const vec &) = default; + /* Initialization from the generic vNULL. */ + vec (vnull): m_vec () { } + /* Same as default ctor: vec storage must be released manually. */ + ~vec () = default; + + /* Defaulted same as copy ctor. */ + vec& operator= (const vec &) = default; + + /* Prevent implicit conversion from auto_vec. Use auto_vec::to_vec() + instead. */ + template + vec (auto_vec &) = delete; + + template + void operator= (auto_vec &) = delete; + /* Memory allocation and deallocation for the embedded vector. Needed because we cannot have proper ctors/dtors defined. */ void create (unsigned nelems CXX_MEM_STAT_INFO); @@ -1522,7 +1544,7 @@ public: want to ask for internal storage for vectors on the stack because if the size of the vector is larger than the internal storage that space is wasted. */ -template +template class auto_vec : public vec { public: @@ -1549,6 +1571,14 @@ public: this->release (); } + /* Explicitly convert to the base class. There is no conversion + from a const auto_vec because a copy of the returned vec can + be used to modify *THIS. + This is a legacy function not to be used in new code. */ + vec to_vec_legacy () { + return *static_cast *>(this); + } + private: vec m_auto; T m_data[MAX (N - 1, 1)]; @@ -1602,6 +1632,14 @@ public: return *this; } + /* Explicitly convert to the base class. There is no conversion + from a const auto_vec because a copy of the returned vec can + be used to modify *THIS. + This is a legacy function not to be used in new code. */ + vec to_vec_legacy () { + return *static_cast *>(this); + } + // You probably don't want to copy a vector, so these are deleted to prevent // unintentional use. If you really need a copy of the vectors contents you // can use copy (). @@ -1781,7 +1819,7 @@ template inline vec vec::copy (ALONE_MEM_STAT_DECL) const { - vec new_vec = vNULL; + vec new_vec{ }; if (length ()) new_vec.m_vec = m_vec->copy (ALONE_PASS_MEM_STAT); return new_vec; -- cgit v1.1