From db8ffb402adef529e224cdc4bd73e09a3aa247f2 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 9 Sep 2016 21:22:15 +0000 Subject: Implement P0035R4, C++17 new of over-aligned types. gcc/cp/ * cp-tree.h (enum cp_tree_index): Add CPTI_ALIGN_TYPE. (align_type_node): New macro. * call.c (build_operator_new_call): Handle C++17 aligned new. (second_parm_is_size_t, build_op_delete_call): Likewise. (non_placement_deallocation_fn_p): Likewise. Rename to usual_deallocation_fn_p. (aligned_allocation_fn_p, aligned_deallocation_fn_p): New. * decl.c (cxx_init_decl_processing): Add aligned new support. * init.c (type_has_new_extended_alignment): New. (build_new_1): Handle aligned new. * tree.c (vec_copy_and_insert): New. gcc/c-family/ * c.opt: Add -faligned-new and -Waligned-new. * c-common.c (max_align_t_align): Split out from... (cxx_fundamental_alignment_p): ...here. * c-common.h: Declare it. * c-cppbuiltin.c (c_cpp_builtins): Handle aligned new. libstdc++-v3/ * libsupc++/new: Declare aligned new/delete operators. * config/abi/pre/gnu.ver: Export them. * configure.ac: Check for aligned_alloc, posix_memalign, memalign, _aligned_malloc. * libsupc++/new_opa.cc: New. * libsupc++/new_opant.cc: New. * libsupc++/new_opva.cc: New. * libsupc++/new_opva.cc: New. * libsupc++/del_opa.cc: New. * libsupc++/del_opant.cc: New. * libsupc++/del_opsa.cc: New. * libsupc++/del_opva.cc: New. * libsupc++/del_opvant.cc: New. * libsupc++/del_opvsa.cc: New. * libsupc++/Makefile.am: Build them. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240056 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/decl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'gcc/cp/decl.c') diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 43cf3df36ba..9d91387c7f1 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4132,6 +4132,17 @@ cxx_init_decl_processing (void) /* Now, C++. */ current_lang_name = lang_name_cplusplus; + if (aligned_new_threshhold > 1 + && exact_log2 (aligned_new_threshhold) == -1) + { + error ("-faligned-new=%d is not a power of two", aligned_new_threshhold); + aligned_new_threshhold = 1; + } + if (aligned_new_threshhold == -1) + aligned_new_threshhold = (cxx_dialect >= cxx1z) ? 1 : 0; + if (aligned_new_threshhold == 1) + aligned_new_threshhold = max_align_t_align () / BITS_PER_UNIT; + { tree newattrs, extvisattr; tree newtype, deltype; @@ -4199,6 +4210,47 @@ cxx_init_decl_processing (void) push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW); } + if (aligned_new_threshhold) + { + push_namespace (std_identifier); + tree align_id = get_identifier ("align_val_t"); + align_type_node = start_enum (align_id, NULL_TREE, size_type_node, + NULL_TREE, /*scoped*/true, NULL); + pop_namespace (); + + /* operator new (size_t, align_val_t); */ + newtype = build_function_type_list (ptr_type_node, size_type_node, + align_type_node, NULL_TREE); + newtype = cp_build_type_attribute_variant (newtype, newattrs); + newtype = build_exception_variant (newtype, new_eh_spec); + opnew = push_cp_library_fn (NEW_EXPR, newtype, 0); + DECL_IS_MALLOC (opnew) = 1; + DECL_IS_OPERATOR_NEW (opnew) = 1; + opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0); + DECL_IS_MALLOC (opnew) = 1; + DECL_IS_OPERATOR_NEW (opnew) = 1; + + /* operator delete (void *, align_val_t); */ + deltype = build_function_type_list (void_type_node, ptr_type_node, + align_type_node, NULL_TREE); + deltype = cp_build_type_attribute_variant (deltype, extvisattr); + deltype = build_exception_variant (deltype, empty_except_spec); + push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW); + push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW); + + if (flag_sized_deallocation) + { + /* operator delete (void *, size_t, align_val_t); */ + deltype = build_function_type_list (void_type_node, ptr_type_node, + size_type_node, align_type_node, + NULL_TREE); + deltype = cp_build_type_attribute_variant (deltype, extvisattr); + deltype = build_exception_variant (deltype, empty_except_spec); + push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW); + push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW); + } + } + nullptr_type_node = make_node (NULLPTR_TYPE); TYPE_SIZE (nullptr_type_node) = bitsize_int (GET_MODE_BITSIZE (ptr_mode)); TYPE_SIZE_UNIT (nullptr_type_node) = size_int (GET_MODE_SIZE (ptr_mode)); -- cgit v1.2.1 From ac29ece21d1243ab39f49fd72ef7c171cf1feaee Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 16 Sep 2016 19:20:44 +0000 Subject: Add inline functions for various bitwise operations. * hwint.h (least_bit_hwi, pow2_or_zerop, pow2p_hwi, ctz_or_zero): New. * hwint.c (exact_log2): Use pow2p_hwi. (ctz_hwi, ffs_hwi): Use least_bit_hwi. * alias.c (memrefs_conflict_p): Use pow2_or_zerop. * builtins.c (get_object_alignment_2, get_object_alignment) (get_pointer_alignment, fold_builtin_atomic_always_lock_free): Use least_bit_hwi. * calls.c (compute_argument_addresses, store_one_arg): Use least_bit_hwi. * cfgexpand.c (expand_one_stack_var_at): Use least_bit_hwi. * combine.c (force_to_mode): Use least_bit_hwi. * emit-rtl.c (set_mem_attributes_minus_bitpos, adjust_address_1): Use least_bit_hwi. * expmed.c (synth_mult, expand_divmod): Use ctz_or_zero, ctz_hwi. (init_expmed_one_conv): Use pow2p_hwi. * fold-const.c (round_up_loc, round_down_loc): Use pow2_or_zerop. (fold_binary_loc): Use pow2p_hwi. * function.c (assign_parm_find_stack_rtl): Use least_bit_hwi. * gimple-fold.c (gimple_fold_builtin_memory_op): Use pow2p_hwi. * gimple-ssa-strength-reduction.c (replace_ref): Use least_bit_hwi. * hsa-gen.c (gen_hsa_addr_with_align, hsa_bitmemref_alignment): Use least_bit_hwi. * ipa-cp.c (ipcp_alignment_lattice::meet_with_1): Use least_bit_hwi. * ipa-prop.c (ipa_modify_call_arguments): Use least_bit_hwi. * omp-low.c (oacc_loop_fixed_partitions) (oacc_loop_auto_partitions): Use least_bit_hwi. * rtlanal.c (nonzero_bits1): Use ctz_or_zero. * stor-layout.c (place_field): Use least_bit_hwi. * tree-pretty-print.c (dump_generic_node): Use pow2p_hwi. * tree-sra.c (build_ref_for_offset): Use least_bit_hwi. * tree-ssa-ccp.c (ccp_finalize): Use least_bit_hwi. * tree-ssa-math-opts.c (bswap_replace): Use least_bit_hwi. * tree-ssa-strlen.c (handle_builtin_memcmp): Use pow2p_hwi. * tree-vect-data-refs.c (vect_analyze_group_access_1) (vect_grouped_store_supported, vect_grouped_load_supported) (vect_permute_load_chain, vect_shift_permute_load_chain) (vect_transform_grouped_load): Use pow2p_hwi. * tree-vect-generic.c (expand_vector_divmod): Use ctz_or_zero. * tree-vect-patterns.c (vect_recog_divmod_pattern): Use ctz_or_zero. * tree-vect-stmts.c (vectorizable_mask_load_store): Use least_bit_hwi. * tsan.c (instrument_expr): Use least_bit_hwi. * var-tracking.c (negative_power_of_two_p): Use pow2_or_zerop. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240194 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/decl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/cp/decl.c') diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9d91387c7f1..2f444656842 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4133,7 +4133,7 @@ cxx_init_decl_processing (void) current_lang_name = lang_name_cplusplus; if (aligned_new_threshhold > 1 - && exact_log2 (aligned_new_threshhold) == -1) + && !pow2p_hwi (aligned_new_threshhold)) { error ("-faligned-new=%d is not a power of two", aligned_new_threshhold); aligned_new_threshhold = 1; -- cgit v1.2.1