Skip to content

Commit 07a2b1a

Browse files
rguenthRichard Biener
authored andcommitted
Add gather_imm_use_stmts helper
The following adds a helper function to gather SSA use stmts without duplicates. It steals the only padding bit in gimple to be a "infrastructure local flag" which should be used only temporarily and kept cleared. I did not add accessor functions for the flag to not encourage (ab-)uses. I have used an auto_vec<gimple *, 2> in the API to avoid heap allocations for most cases (without doing statistics). I have verified GCC 7 performs NRV optimization on the copy but I'll note while auto_vec<gimple *> has copy and assign deleted, auto_vec<gimple *, N> does not. Adding them breaks pair-fusion.cc compile. Without using 'auto' or range-for the API use is a bit awkward as that exposes the number of auto-allocated elements. The helper can be used in a range-for, see the followup for an example. * gimple.h (gimple::pad): Rename to ... (gimple::ilf): ... this. * ssa-iterators.h (gather_imm_use_stmts): Declare. * tree-ssa-operands.cc (gather_imm_use_stmts): New function.
1 parent b9457ed commit 07a2b1a

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

gcc/gimple.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ struct GTY((desc ("gimple_statement_structure (&%h)"), tag ("GSS_BASE"),
250250
/* Nonzero if this statement contains volatile operands. */
251251
unsigned has_volatile_ops : 1;
252252

253-
/* Padding to get subcode to 16 bit alignment. */
254-
unsigned pad : 1;
253+
/* Infrastructure local flag. Always clear. */
254+
unsigned ilf : 1;
255255

256256
/* The SUBCODE field can be used for tuple-specific flags for tuples
257257
that do not require subcodes. Note that SUBCODE should be at

gcc/ssa-iterators.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ struct auto_end_imm_use_stmt_traverse
114114
(void) ((DEST) = next_imm_use_on_stmt (&(ITER))))
115115

116116

117+
/* Use this to get a vector of all gimple stmts using SSAVAR without
118+
duplicates. It's cheaper than FOR_EACH_IMM_USE_STMT and has no
119+
constraints on what you are allowed to do inside an iteration
120+
over the vector. */
121+
extern auto_vec<gimple *, 2> gather_imm_use_stmts (tree ssavar);
117122

118123
extern bool single_imm_use_1 (const ssa_use_operand_t *head,
119124
use_operand_p *use_p, gimple **stmt);

gcc/tree-ssa-operands.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,3 +1416,23 @@ single_imm_use_1 (const ssa_use_operand_t *head,
14161416
return single_use;
14171417
}
14181418

1419+
/* Gather all stmts SSAVAR is used on, eliminating duplicates. */
1420+
1421+
auto_vec<gimple *, 2>
1422+
gather_imm_use_stmts (tree ssavar)
1423+
{
1424+
auto_vec<gimple *, 2> stmts;
1425+
imm_use_iterator iter;
1426+
use_operand_p use_p;
1427+
FOR_EACH_IMM_USE_FAST (use_p, iter, ssavar)
1428+
{
1429+
gimple *use_stmt = USE_STMT (use_p);
1430+
if (use_stmt->ilf)
1431+
continue;
1432+
use_stmt->ilf = 1;
1433+
stmts.safe_push (use_stmt);
1434+
}
1435+
for (gimple *use_stmt : stmts)
1436+
use_stmt->ilf = 0;
1437+
return stmts;
1438+
}

0 commit comments

Comments
 (0)