Skip to content

Commit b2fc1fa

Browse files
committed
fixup! fixup! arcv: apex: Add LTO support for APEX intrinsics.
Signed-off-by: Luis Silva <[email protected]>
1 parent 8240ed7 commit b2fc1fa

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

gcc/config/riscv/riscv-apex-lto.cc

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ arcv_apex_lto_write_section (void)
8989
if (apex_count == 0)
9090
return;
9191

92-
/* First pass: count how many intrinsics are actually used and not
93-
optimized away. */
94-
int used_count = 0;
92+
/* Collect indices of intrinsics that are actually used and not optimized
93+
away. Use an auto_vec to avoid manual memory management. */
94+
auto_vec<int> used_indices;
9595
for (int i = 0; i < apex_count; i++)
9696
{
9797
const char *fn_name = arcv_apex_get_fn_name (i);
@@ -101,14 +101,14 @@ arcv_apex_lto_write_section (void)
101101
symtab_node *snode = symtab_node::get_for_asmname (
102102
get_identifier (fn_name));
103103

104-
/* Only count intrinsics that exist and are actually used.
104+
/* Only keep intrinsics that exist and are actually used.
105105
Check if the symbol is referred to anywhere in the program. */
106106
if (snode && snode->referred_to_p ())
107-
used_count++;
107+
used_indices.safe_push (i);
108108
}
109109

110110
/* If all intrinsics were optimized away, skip section creation. */
111-
if (used_count == 0)
111+
if (used_indices.is_empty ())
112112
return;
113113

114114
/* Create a new LTO section for APEX intrinsics. */
@@ -120,11 +120,12 @@ arcv_apex_lto_write_section (void)
120120

121121
/* Write the number of used APEX builtins so the reader knows
122122
how many to expect. */
123-
streamer_write_uhwi_stream (ob->main_stream, used_count);
123+
streamer_write_uhwi_stream (ob->main_stream, used_indices.length ());
124124

125-
/* Second pass: serialize only the intrinsics that are still used. */
126-
for (int i = 0; i < apex_count; i++)
125+
/* Serialize only the intrinsics that are still used. */
126+
for (unsigned int idx = 0; idx < used_indices.length (); idx++)
127127
{
128+
int i = used_indices[idx];
128129
const char *fn_name = NULL;
129130
const char *insn_name = NULL;
130131
unsigned int opcode = 0;
@@ -137,14 +138,6 @@ arcv_apex_lto_write_section (void)
137138
/* Function and instruction names must exist. */
138139
gcc_assert (fn_name && insn_name);
139140

140-
/* Check if the intrinsic is still referenced in the program. */
141-
symtab_node *snode = symtab_node::get_for_asmname (
142-
get_identifier (fn_name));
143-
144-
/* Skip intrinsics that were optimized away. */
145-
if (!snode || !snode->referred_to_p ())
146-
continue;
147-
148141
/* Write function name as length-prefixed string. */
149142
size_t name_len = strlen (fn_name);
150143
streamer_write_uhwi_stream (ob->main_stream, name_len);

0 commit comments

Comments
 (0)