]> git.ipfire.org Git - thirdparty/gcc.git/commit
Error handling for hard register constraints
authorStefan Schulze Frielinghaus <stefansf@gcc.gnu.org>
Mon, 21 Jul 2025 11:05:26 +0000 (13:05 +0200)
committerStefan Schulze Frielinghaus <stefansf@gcc.gnu.org>
Mon, 21 Jul 2025 11:05:26 +0000 (13:05 +0200)
commitcbf17db978c663817e4cd3337bbc80f59fa05bb6
tree18241ae07554e9237b20ffc4daf032bffd2b4e14
parenta51c146ebce41b5e4326b222f2d9e04bb22d276f
Error handling for hard register constraints

This implements error handling for hard register constraints including
potential conflicts with register asm operands.

In contrast to register asm operands, hard register constraints allow
more than just one register per operand.  Even more than just one
register per alternative.  For example, a valid constraint for an
operand is "{r0}{r1}m,{r2}".  However, this also means that we have to
make sure that each register is used at most once in each alternative
over all outputs and likewise over all inputs.  For asm statements this
is done by this patch during gimplification.  For hard register
constraints used in machine description, error handling is still a todo
and I haven't investigated this so far and consider this rather a low
priority.

gcc/ada/ChangeLog:

* gcc-interface/trans.cc (gnat_to_gnu): Pass null pointer to
parse_{input,output}_constraint().

gcc/analyzer/ChangeLog:

* region-model-asm.cc (region_model::on_asm_stmt): Pass null
pointer to parse_{input,output}_constraint().

gcc/c/ChangeLog:

* c-typeck.cc (build_asm_expr): Pass null pointer to
parse_{input,output}_constraint().

gcc/ChangeLog:

* cfgexpand.cc (n_occurrences): Move this ...
(check_operand_nalternatives): and this ...
(expand_asm_stmt): and the call to gimplify.cc.
* config/s390/s390.cc (s390_md_asm_adjust): Pass null pointer to
parse_{input,output}_constraint().
* gimple-walk.cc (walk_gimple_asm): Pass null pointer to
parse_{input,output}_constraint().
(walk_stmt_load_store_addr_ops): Ditto.
* gimplify-me.cc (gimple_regimplify_operands): Ditto.
* gimplify.cc (num_occurrences): Moved from cfgexpand.cc.
(num_alternatives): Ditto.
(gimplify_asm_expr): Deal with hard register constraints.
* stmt.cc (eliminable_regno_p): New helper.
(hardreg_ok_p): Perform a similar check as done in
make_decl_rtl().
(parse_output_constraint): Add parameter for gimplify_reg_info
and validate hard register constrained operands.
(parse_input_constraint): Ditto.
* stmt.h (class gimplify_reg_info): Forward declaration.
(parse_output_constraint): Add parameter.
(parse_input_constraint): Ditto.
* tree-ssa-operands.cc
(operands_scanner::get_asm_stmt_operands): Pass null pointer
to parse_{input,output}_constraint().
* tree-ssa-structalias.cc (find_func_aliases): Pass null pointer
to parse_{input,output}_constraint().
* varasm.cc (assemble_asm): Pass null pointer to
parse_{input,output}_constraint().
* gimplify_reg_info.h: New file.

gcc/cp/ChangeLog:

* semantics.cc (finish_asm_stmt): Pass null pointer to
parse_{input,output}_constraint().

gcc/d/ChangeLog:

* toir.cc: Pass null pointer to
parse_{input,output}_constraint().

gcc/testsuite/ChangeLog:

* gcc.dg/pr87600-2.c: Split test into two files since errors for
functions test{0,1} are thrown during expand, and for
test{2,3} during gimplification.
* lib/scanasm.exp: On s390, skip lines beginning with #.
* gcc.dg/asm-hard-reg-error-1.c: New test.
* gcc.dg/asm-hard-reg-error-2.c: New test.
* gcc.dg/asm-hard-reg-error-3.c: New test.
* gcc.dg/asm-hard-reg-error-4.c: New test.
* gcc.dg/asm-hard-reg-error-5.c: New test.
* gcc.dg/pr87600-3.c: New test.
* gcc.target/aarch64/asm-hard-reg-2.c: New test.
* gcc.target/s390/asm-hard-reg-7.c: New test.
26 files changed:
gcc/ada/gcc-interface/trans.cc
gcc/analyzer/region-model-asm.cc
gcc/c/c-typeck.cc
gcc/cfgexpand.cc
gcc/config/s390/s390.cc
gcc/cp/semantics.cc
gcc/d/toir.cc
gcc/gimple-walk.cc
gcc/gimplify-me.cc
gcc/gimplify.cc
gcc/gimplify_reg_info.h [new file with mode: 0644]
gcc/stmt.cc
gcc/stmt.h
gcc/testsuite/gcc.dg/asm-hard-reg-error-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/asm-hard-reg-error-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/asm-hard-reg-error-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/asm-hard-reg-error-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/asm-hard-reg-error-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr87600-2.c
gcc/testsuite/gcc.dg/pr87600-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/asm-hard-reg-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/s390/asm-hard-reg-7.c [new file with mode: 0644]
gcc/testsuite/lib/scanasm.exp
gcc/tree-ssa-operands.cc
gcc/tree-ssa-structalias.cc
gcc/varasm.cc