diff options
author | Andrew Pinski <quic_apinski@quicinc.com> | 2024-11-15 20:22:02 -0800 |
---|---|---|
committer | Tamar Christina <tamar.christina@arm.com> | 2025-01-07 14:47:44 +0000 |
commit | 4b1a2878ba3241ec5c0a1bf05ff47bfcd09c3711 (patch) | |
tree | e911139daae75a57e0cd0de9f5b34fc1c2d4d7a5 /gcc | |
parent | a856b4d97b8d328fdcb169b792ac5456e40f8c00 (diff) | |
download | gcc-4b1a2878ba3241ec5c0a1bf05ff47bfcd09c3711.zip gcc-4b1a2878ba3241ec5c0a1bf05ff47bfcd09c3711.tar.gz gcc-4b1a2878ba3241ec5c0a1bf05ff47bfcd09c3711.tar.bz2 |
cfgexpand: Factor out getting the stack decl index
This is the first patch in improving this code.
Since there are a few places which get the index and they
check the same thing, let's factor that out into one function.
Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
* cfgexpand.cc (INVALID_STACK_INDEX): New defined.
(decl_stack_index): New function.
(visit_op): Use decl_stack_index.
(visit_conflict): Likewise.
(add_scope_conflicts_1): Likewise.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cfgexpand.cc | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc index abab385..cdebb00 100644 --- a/gcc/cfgexpand.cc +++ b/gcc/cfgexpand.cc @@ -337,6 +337,8 @@ static unsigned stack_vars_alloc; static unsigned stack_vars_num; static hash_map<tree, unsigned> *decl_to_stack_part; +#define INVALID_STACK_INDEX ((unsigned)-1) + /* Conflict bitmaps go on this obstack. This allows us to destroy all of them in one big sweep. */ static bitmap_obstack stack_var_bitmap_obstack; @@ -525,6 +527,27 @@ stack_var_conflict_p (unsigned x, unsigned y) return bitmap_bit_p (a->conflicts, y); } +/* Returns the DECL's index into the stack_vars array. + If the DECL does not exist return INVALID_STACK_INDEX. */ +static unsigned +decl_stack_index (tree decl) +{ + if (!decl) + return INVALID_STACK_INDEX; + if (!DECL_P (decl)) + return INVALID_STACK_INDEX; + if (DECL_RTL_IF_SET (decl) != pc_rtx) + return INVALID_STACK_INDEX; + unsigned *v = decl_to_stack_part->get (decl); + if (!v) + return INVALID_STACK_INDEX; + + unsigned indx = *v; + gcc_checking_assert (indx != INVALID_STACK_INDEX); + gcc_checking_assert (indx < stack_vars_num); + return indx; +} + /* Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var enter its partition number into bitmap DATA. */ @@ -533,14 +556,9 @@ visit_op (gimple *, tree op, tree, void *data) { bitmap active = (bitmap)data; op = get_base_address (op); - if (op - && DECL_P (op) - && DECL_RTL_IF_SET (op) == pc_rtx) - { - unsigned *v = decl_to_stack_part->get (op); - if (v) - bitmap_set_bit (active, *v); - } + unsigned idx = decl_stack_index (op); + if (idx != INVALID_STACK_INDEX) + bitmap_set_bit (active, idx); return false; } @@ -553,20 +571,15 @@ visit_conflict (gimple *, tree op, tree, void *data) { bitmap active = (bitmap)data; op = get_base_address (op); - if (op - && DECL_P (op) - && DECL_RTL_IF_SET (op) == pc_rtx) + unsigned num = decl_stack_index (op); + if (num != INVALID_STACK_INDEX + && bitmap_set_bit (active, num)) { - unsigned *v = decl_to_stack_part->get (op); - if (v && bitmap_set_bit (active, *v)) - { - unsigned num = *v; - bitmap_iterator bi; - unsigned i; - gcc_assert (num < stack_vars_num); - EXECUTE_IF_SET_IN_BITMAP (active, 0, i, bi) - add_stack_var_conflict (num, i); - } + bitmap_iterator bi; + unsigned i; + gcc_assert (num < stack_vars_num); + EXECUTE_IF_SET_IN_BITMAP (active, 0, i, bi) + add_stack_var_conflict (num, i); } return false; } @@ -638,15 +651,14 @@ add_scope_conflicts_1 (basic_block bb, bitmap work, bool for_conflict) if (gimple_clobber_p (stmt)) { tree lhs = gimple_assign_lhs (stmt); - unsigned *v; /* Handle only plain var clobbers. Nested functions lowering and C++ front-end inserts clobbers which are not just plain variables. */ if (!VAR_P (lhs)) continue; - if (DECL_RTL_IF_SET (lhs) == pc_rtx - && (v = decl_to_stack_part->get (lhs))) - bitmap_clear_bit (work, *v); + unsigned indx = decl_stack_index (lhs); + if (indx != INVALID_STACK_INDEX) + bitmap_clear_bit (work, indx); } else if (!is_gimple_debug (stmt)) { |