fold_offsets_1 takes two booleans (analyze, do_recursion) that encode
three valid states, with the fourth combination asserted against.
Replace them with a fold_mode enum (FOLD_RECOGNIZE, FOLD_ANALYZE,
FOLD_COMPUTE) that directly expresses the three operating modes:
FOLD_RECOGNIZE: only check if INSN is understood (no recursion)
FOLD_ANALYZE: recognize and recurse, marking defs in can_fold_insns
FOLD_COMPUTE: recurse and calculate the actual folded offset
This makes the call sites self-documenting and eliminates the
assertion for the invalid boolean combination.
gcc/ChangeLog:
* fold-mem-offsets.cc (enum fold_mode): Define/declare.
(fold_offsets_1): Use fold_mode enum.
(fold_offsets): Use fold_mode enum.
---
gcc/fold-mem-offsets.cc | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/gcc/fold-mem-offsets.cc b/gcc/fold-mem-offsets.cc
index 1cd2dc036c2f..feb2914c7b41 100644
--- a/gcc/fold-mem-offsets.cc
+++ b/gcc/fold-mem-offsets.cc
@@ -256,24 +256,28 @@ get_uses (rtx_insn *insn, rtx reg, bool *success)
static HOST_WIDE_INT
fold_offsets (rtx_insn *insn, rtx reg, bool analyze, bitmap foldable_insns);
-/* Helper function for fold_offsets.
-
- If DO_RECURSION is false and ANALYZE is true this function returns true iff
- it understands the structure of INSN and knows how to propagate constants
- through it. In this case OFFSET_OUT and FOLDABLE_INSNS are unused.
-
- If DO_RECURSION is true then it also calls fold_offsets for each recognized
- part of INSN with the appropriate arguments.
+/* The mode of operation for fold_offsets_1. */
+enum fold_mode {
+ /* Only check if INSN is recognized (can we propagate through it?).
+ Does not recurse. OFFSET_OUT and FOLDABLE_INSNS are unused. */
+ FOLD_RECOGNIZE,
+ /* Analyze: check recognition AND recurse through fold_offsets to mark
+ definitions in CAN_FOLD_INSNS. OFFSET_OUT and FOLDABLE_INSNS are
+ unused. */
+ FOLD_ANALYZE,
+ /* Compute: recurse and calculate the actual folded offset. The result
+ is returned through OFFSET_OUT and the instructions that can be folded
+ are recorded in FOLDABLE_INSNS. */
+ FOLD_COMPUTE
+};
- If DO_RECURSION is true and ANALYZE is false then offset that would result
- from folding is computed and is returned through the pointer OFFSET_OUT.
- The instructions that can be folded are recorded in FOLDABLE_INSNS. */
+/* Helper function for fold_offsets. See fold_mode for description. */
static bool
-fold_offsets_1 (rtx_insn *insn, bool analyze, bool do_recursion,
+fold_offsets_1 (rtx_insn *insn, fold_mode mode,
HOST_WIDE_INT *offset_out, bitmap foldable_insns)
{
- /* Doesn't make sense if both DO_RECURSION and ANALYZE are false. */
- gcc_checking_assert (do_recursion || analyze);
+ bool do_recursion = (mode != FOLD_RECOGNIZE);
+ bool analyze = (mode != FOLD_COMPUTE);
gcc_checking_assert (GET_CODE (PATTERN (insn)) == SET);
rtx src = SET_SRC (PATTERN (insn));
@@ -475,7 +479,7 @@ fold_offsets_1 (rtx_insn *insn, bool analyze, bool
do_recursion,
return false;
}
- if (do_recursion && !analyze)
+ if (mode == FOLD_COMPUTE)
*offset_out = offset;
return true;
@@ -509,7 +513,7 @@ fold_offsets (rtx_insn *insn, rtx reg, bool analyze, bitmap
foldable_insns)
if (analyze)
{
/* Check if we know how to handle DEF. */
- if (!fold_offsets_1 (def, true, false, NULL, NULL))
+ if (!fold_offsets_1 (def, FOLD_RECOGNIZE, NULL, NULL))
return 0;
/* We only fold through instructions that are transitively used as
@@ -563,8 +567,8 @@ fold_offsets (rtx_insn *insn, rtx reg, bool analyze, bitmap
foldable_insns)
}
HOST_WIDE_INT offset = 0;
- bool recognized = fold_offsets_1 (def, analyze, true, &offset,
- foldable_insns);
+ bool recognized = fold_offsets_1 (def, analyze ? FOLD_ANALYZE : FOLD_COMPUTE,
+ &offset, foldable_insns);
if (!recognized)
return 0;
--
2.34.1