From 80dea726c896e558ffee4036534f56698a2d412f Mon Sep 17 00:00:00 2001 From: Michal Jires Date: Mon, 25 Aug 2025 17:58:03 +0200 Subject: [PATCH] lto: Simplify control variable in loop of balanced partitioning Minor simplification as preparation for next patch. gcc/lto/ChangeLog: * lto-partition.cc (lto_balanced_map): Simplify. --- gcc/lto/lto-partition.cc | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/gcc/lto/lto-partition.cc b/gcc/lto/lto-partition.cc index c53471173de..650bf638162 100644 --- a/gcc/lto/lto-partition.cc +++ b/gcc/lto/lto-partition.cc @@ -1167,7 +1167,8 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) callgraph or IPA reference edge leaving the partition contributes into COST. Every edge inside partition was earlier computed as one leaving it and thus we need to subtract it from COST. */ - while (last_visited_node < lto_symtab_encoder_size (partition->encoder)) + for (; last_visited_node < lto_symtab_encoder_size (partition->encoder); + last_visited_node++) { int j; struct ipa_ref *ref = NULL; @@ -1178,9 +1179,6 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) { struct cgraph_edge *edge; - - last_visited_node++; - gcc_assert (node->definition || node->weakref); /* Compute boundary cost of callgraph edges. */ @@ -1197,8 +1195,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) gcc_assert (edge_cost > 0); index = lto_symtab_encoder_lookup (partition->encoder, edge->callee); - if (index != LCC_NOT_FOUND - && index < last_visited_node - 1) + if (index != LCC_NOT_FOUND && index < last_visited_node) cost -= edge_cost, internal += edge_cost; else cost += edge_cost; @@ -1216,15 +1213,12 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) gcc_assert (edge_cost > 0); index = lto_symtab_encoder_lookup (partition->encoder, edge->caller); - if (index != LCC_NOT_FOUND - && index < last_visited_node - 1) + if (index != LCC_NOT_FOUND && index < last_visited_node) cost -= edge_cost, internal += edge_cost; else cost += edge_cost; } } - else - last_visited_node++; /* Compute boundary cost of IPA REF edges and at the same time look into variables referenced from current partition and try to add them. */ @@ -1242,8 +1236,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) add_symbol_to_partition (partition, vnode); index = lto_symtab_encoder_lookup (partition->encoder, vnode); - if (index != LCC_NOT_FOUND - && index < last_visited_node - 1) + if (index != LCC_NOT_FOUND && index < last_visited_node) cost--, internal++; else cost++; @@ -1255,8 +1248,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) node = dyn_cast (ref->referred); index = lto_symtab_encoder_lookup (partition->encoder, node); - if (index != LCC_NOT_FOUND - && index < last_visited_node - 1) + if (index != LCC_NOT_FOUND && index < last_visited_node) cost--, internal++; else cost++; @@ -1281,8 +1273,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) add_symbol_to_partition (partition, vnode); index = lto_symtab_encoder_lookup (partition->encoder, vnode); - if (index != LCC_NOT_FOUND - && index < last_visited_node - 1) + if (index != LCC_NOT_FOUND && index < last_visited_node) cost--, internal++; else cost++; @@ -1295,8 +1286,7 @@ lto_balanced_map (int n_lto_partitions, int max_partition_size) gcc_assert (node->definition); index = lto_symtab_encoder_lookup (partition->encoder, node); - if (index != LCC_NOT_FOUND - && index < last_visited_node - 1) + if (index != LCC_NOT_FOUND && index < last_visited_node) cost--, internal++; else cost++; -- 2.47.3