cobol: Improved GENERIC for conditionals and comparisons.
After several years, I am finally developing some understanding of
GENERIC and how the middle-end processes it. These wide-ranging changes
improve the execution speed of conditional logic and numeric-numeric,
numeric-alpha, and alpha-alpha comparisons.
I started with refining the way GENERIC for "IF <conditional statement>"
is created, and then I moved on to numerous individual cases. Some
all-purpose routines in libgcobol.so have been broken out into special-
purpose routines implemented in GENERIC.
gcc/cobol/ChangeLog:
* Make-lang.in: Incorporate new gcc/cobol/compare.cc file.
* cobol1.cc (ATTR_CONST_NOTHROW_LEAF): Incorporate __builtin_swap16,
__builtin_swap32, __builtin_swap64, and __builtin_swap128.
(cobol_langhook_init): Likewise.
* genapi.cc (treeplet_fill_source): Improve speed.
(get_binary_value_from_float): Spelling.
(normal_normal_compare): Eliminate.
(compare_binary_binary): Eliminate.
(DEBUG_COMPARE): Eliminate.
(cobol_compare): Eliminate.
(parser_enter_file): Eliminate obsolete variables.
(data_decl_type_for): New function.
(parser_alphabet_use): Flag altered alphabets for speed.
(parser_display): Environment switch for putting comments into
the assembly language.
(program_end_stuff): Change "hijack" to "hijack_h".
(parser_division): Repair RETURN-CODE logic.
(parser_logop): Improve GENERIC for logical operations.
(parser_relop): Use new cobol_compare_relop() routine.
(parser_relop_long): Elminate unnecessary static variable.
(inspect_tally): Improve parameter passing to library routine.
(inspect_replacing): Likewise.
(parser_intrinsic_subst): Likewise.
(parser_intrinsic_callv): Likewise.
(parser_intrinsic_call_1): Likewise.
(parser_bsearch_start): Likewise.
(parser_bsearch_when): Use new comparison routine; simplify logic.
(parser_unstring): Improve parameter passing to library routine.
(parser_string): Likewise.
(create_and_call): Repair RETURN-CODE logic.
(parser_call): Adjust exception processing when the target cannot be
found.
(build_temporaryN): Constructor for cblc_field_t::data.
(hijack_for_development): Change hijacking name to "dubner_h".
(hijacker): Change hijacking name to "hijack_h".
(get_reference_to_data): New function.
(mh_identical): Improve speed when sender and receiver have the same
structure.
(mh_source_is_literalN): Eliminate leading plus/minus when moving a
numeric to an alphanumeric.
(move_helper): Adjust logic for mh_identical and mh_source_is_group.
(actually_create_the_static_field): Use constructor for data member.
(psa_new_var_decl): Typo in comment.
(parser_symbol_add): Make the generated data type more consistent
with the COBOL variable type.
* genapi.h (parser_bsearch_when): Change declaration.
(parser_bsearch_start): Formatting.
(parser_sort): Formatting.
* gengen.cc (gg_show_type): Expand for ARRAY_TYPE and ARRAY_REF.
(gg_define_from_declaration): Use void type for DECL_EXPR.
(gg_define_volatile_variable): New function.
(gg_get_address): New function.
(gg_array_value): Use fold_convert().
(gg_bswap): New function.
(gg_memcmp): New function.
* gengen.h (SCHAR_P): New and changed declarations.
(struct gg_function_t): Add alphabet_in_use flag.
(gg_define_volatile_variable): New declaration.
(gg_get_address_of): Comment.
(gg_pointer_to_array): Comment.
(gg_get_address): New declaration.
(gg_bswap): New declaration.
(gg_memcmp): New declaration.
(gg_insert_into_assemblerf): Formatting.
* genmath.cc (arithmetic_operation): Improved handling of
parameters.
(fast_add): Improved handling of locations.
(parser_add): Formatting.
* genutil.cc (tree_type_from_digits): Correct parameter.
(get_data_offset): Correct exception handling.
(get_binary_value_tree): Improve location handling.
(tree_type_from_field): Correct logic.
(tree_type_from_size): Correct signs for returned type.
(build_array_of_treeplets): Eliminated.
(build_array_of_referlets): New function.
(build_array_of_fourplets): Eliminated.
(build_array_of_refers): New function.
(refer_is_clean): Improved logic.
(refer_is_super_clean): New function.
(refer_is_working_storage): New function.
(refer_offset): Formatting.
(binary_from_FldNumericBin5): New function.
(binary_from_FldNumericBinary): New function.
(d_and_q_num_disp): New function.
(binary_from_FldNumericDisplay): New function.
(make_dp2bin_decl): New function.
(d_and_q_packed): New function.
(binary_from_comp_3): New function.
(binary_from_comp_6): New function.
(binary_from_FldPacked): New function.
(binary_from_FldFloat): New function.
(get_binary_value): New function.
(get_location): New function.
(get_length): New function.
* genutil.h (tree_type_from_digits): New declaration.
(tree_type_from_size): Changed declaration.
(refer_is_super_clean): New declaration.
(refer_is_working_storage): New declaration.
(refer_offset): Changed declaration.
(build_array_of_treeplets): Remove declaration.
(build_array_of_referlets): New declaration.
(build_array_of_fourplets): Remove declaration.
(build_array_of_refers): New declaration.
(tree_type_from_field): New declaration.
(get_binary_value): New declaration.
(get_location): New declaration.
(get_length): New declaration.
* parse.y: Mysterious changes. All changes to YACC rules are
mysterious.
* parse_ante.h (class log_expr_t): Changes to logop() invocation.
* scan_post.h (yylex): Remove unnecessary trailing semicolon.
* structs.cc (create_cblc_file_t): Change cblc_file_t declaration.
(create_referlet_t): New function.
(create_refer_t): New function.
(create_our_type_nodes): Add cblc_referlet_type_node and
cblc_refer_type_node.
* structs.h (member2): New declaration.
(GTY): Type for cblc_referlet_type_node and cblc_refer_type_node.
* symbols.cc (temporaries_t::add): Remove unnecessary trailing
semicolon.
* symbols.h (struct cbl_bsearch_t): Remove obsolete member.
(ENABLE_HIJACKING): Compilation switch for enabling dubner_h and
hijack_h code-generation hijacking.
* util.cc (symbol_field_type_update): Comment.
* compare.cc: New file.
* compare.h: New file.
libgcobol/ChangeLog:
* charmaps.h (class charmap_t): Remove an abort().
* common-defs.h (SUPERTYPE): Pairs integers for complex switch().
(cbl_file_mode_str): Remove unnecessary trailing semicolon.
* gcobolio.h: New cblc_referlet_t and cblc_refer_t structures;
eliminate obsolete structures.
* gmath.cc (__gg__pow): Improved parameter handling.
(__gg__add_fixed_phase1): Likewise.
(__gg__addf1_fixed_phase2): Likewise.
(__gg__fixed_phase2_assign_to_c): Likewise.
(__gg__add_float_phase1): Likewise.
(__gg__addf1_float_phase2): Likewise.
(__gg__float_phase2_assign_to_c): Likewise.
(__gg__addf3): Likewise.
(__gg__subtractf1_fixed_phase2): Likewise.
(__gg__subtractf2_fixed_phase1): Likewise.
(__gg__subtractf1_float_phase2): Likewise.
(__gg__subtractf2_float_phase1): Likewise.
(__gg__subtractf3): Likewise.
(__gg__multiplyf1_phase1): Likewise.
(__gg__multiplyf1_phase2): Likewise.
(__gg__multiplyf2): Likewise.
(__gg__dividef1_phase2): Likewise.
(__gg__dividef23): Likewise.
(__gg__dividef45): Likewise.
* inspect.cc (inspect_backward_format_1): Likewise.
(__gg__inspect_format_1): Likewise.
(inspect_backward_format_2): Likewise.
(__gg__inspect_format_2): Likewise.
(__gg__inspect_format_1_sbc): Likewise.
* intrinsic.cc (kahan_summation): Likewise.
(variance): Likewise.
(__gg__concat): Likewise.
(__gg__max): Likewise.
(__gg__mean): Likewise.
(__gg__median): Likewise.
(__gg__midrange): Likewise.
(__gg__min): Likewise.
(__gg__ord_min): Likewise.
(__gg__ord_max): Likewise.
(__gg__present_value): Likewise.
(__gg__range): Likewise.
(__gg__standard_deviation): Likewise.
(__gg__sum): Likewise.
(__gg__variance): Likewise.
(__gg__substitute): Likewise.
* libgcobol.cc (__gg__resize_int_p): Eliminate.
(__gg__resize_treeplet): Eliminate.
(initialize_program_state): Eliminate the use of obsolete variables.
(format_for_display_internal): Handle FldLiteralN; display up to
38 digits for __int128.
(compare_field_class): Rename to __gg__compare_field_class.
(__gg__compare_field_class): Likewise.
(interconvert): Correct codeset correction logic.
(__gg__compare_2): Use __gg__compare_field_class.
(__gg__move): Handle FldNumericBin5 correction.
(__gg__string): Improved parameter handling.
(display_both): Cope with missing codeset parameter.
(__gg__literaln_alpha_compare): Eliminate.
(__gg__unstring): Improved parameter handling.
(__gg__just_mangle_name): Improved codeset handling.
(__gg__convert): Formatting.
(__gg__set_data_member): Eliminate.
(__gg__show_int128): New function.
(__gg__compare_string_all): New function.
(__gg__compare_string_1): New function.
(ASCII_16): Abuse of the preprocessor to create a 1024-byte string
of ASCII spaces.
(ASCII_64): Likewise.
(ASCII_256): Likewise.
(ASCII_1024): Likewise.
(EBCDIC_16): Abuse of the preprocessor to create a 1024-byte string
of EBCDIC spaces.
(EBCDIC_64): Likewise.
(EBCDIC_256): Likewise.
(EBCDIC_1024): Likewise.
(__gg__compare_string_1a): New function.
(__gg__compare_string_1e): New function.
(__gg__compare_string_2): New function.
(__gg__compare_string_2a): New function.
(__gg__compare_string_4): New function.
(__gg__compare_string_4a): New function.
(__gg_compare_string_different): New function.
(__gg__compare_numeric_all): New function.
(__gg__compare_binary_to_string): New function.
* stringbin.cc (__gg__binary_to_string_ascii): Improved algorithm.
gcc/testsuite/ChangeLog:
* cobol.dg/group2/Check_for_equality_of_COMP-1___COMP-2.cob:
Corrected logic.
* cobol.dg/group2/ENTRY_statement.cob: Expanded test.
* cobol.dg/group2/ENTRY_statement.out: Likewise.
* cobol.dg/group2/FUNCTION_DATE___TIME_OMNIBUS.cob: Automated
generation of run-time environment variable.
* cobol.dg/group2/Intrinsic_Function_ABS.cob: Corrected.
* cobol.dg/group2/RETURN-CODE_moving.cob: Requires "dialect ibm".
* cobol.dg/group2/FUNCTION_TRIM_with_NATIONAL_characters.cob: New test.
* cobol.dg/group2/FUNCTION_TRIM_with_NATIONAL_characters.out: New test.
* cobol.dg/group2/Large_PIC_10000000_.cob: New test.
* cobol.dg/group2/Large_PIC_10000000_.out: New test.
* cobol.dg/group2/Nested_PERFORM.cob: New test.
* cobol.dg/group2/Nested_PERFORM.out: New test.
* cobol.dg/group2/Overlapping_MOVE.cob: New test.
* cobol.dg/group2/Overlapping_MOVE.out: New test.
* cobol.dg/group2/PERFORM_TIMES_subscripted.cob: New test.
* cobol.dg/group2/PERFORM_TIMES_subscripted.out: New test.
* cobol.dg/group2/PERFORM_VARYING_BY_-0.2.cob: New test.
* cobol.dg/group2/PERFORM_VARYING_BY_-0.2.out: New test.
* cobol.dg/group2/REDEFINES__chained.cob: New test.
* cobol.dg/group2/REDEFINES__chained.out: New test.
* cobol.dg/group2/RETURN-CODE_with_INITIAL_and_RECURSIVE.cob: New test.
* cobol.dg/group2/RETURN-CODE_with_INITIAL_and_RECURSIVE.out: New test.
* cobol.dg/group2/Sanity_check_for_ENTRY.cob: New test.
* cobol.dg/group2/Sanity_check_for_ENTRY.out: New test.
* cobol.dg/group2/Simple_COMP-X.cob: New test.
* cobol.dg/group2/Simple_COMP-X.out: New test.
* cobol.dg/group2/compare_alpha_to_all__literal_.cob: New test.
* cobol.dg/group2/compare_alpha_to_all__literal_.out: New test.
* cobol.dg/group2/compare_national_to_display.cob: New test.
* cobol.dg/group2/compare_national_to_display.out: New test.
* cobol.dg/group2/comprensive_compare_comp-1_comp-5.cob: New test.
* cobol.dg/group2/comprensive_compare_comp-1_comp-5.out: New test.
* cobol.dg/group2/refmod_with_nested_parentheses.cob: New test.
* cobol.dg/group2/refmod_with_nested_parentheses.out: New test.
* cobol.dg/group2/signed_unsigned_compare.cob: New test.
* cobol.dg/group2/signed_unsigned_compare.out: New test.