> Hi Honza,
>
> Thanks for the review.
>
> >> +/* Assign discriminators to all statements in a basic block. This
> >> + function updates the multiplicity and/or copyid discriminator
> >> components for
> >> + all statements in the given basic block, while preserving the base
> >> + discriminator. */
> >> +
> >> +void
> >> +assign_discriminators_to_bb (basic_block bb,
> >> + unsigned int multiplicity_value,
> >> + unsigned int copyid_value,
> >> + bool update_multiplicity,
> >> + bool update_copyid)
> >
> > I would also add stmt version....
>
> How do we want to use the version?
I meant that it would be useful to have
assign_disctimainators_to_stmt which is called from
assign_discriminators_to_bb since similar logic is needed for normal
statements and PHIs and I believe we will eventually also need it when
moving individual statements around as opposed copying the whole basic
blocks.
>
> gcc/ChangeLog:
>
> * Makefile.in: Add hierarchical_discriminator.o to OBJS.
> * hierarchical_discriminator.cc: New file.
> * hierarchical_discriminator.h: New file.
> * input.cc (location_with_discriminator_components): New function.
> (get_discriminator_components_from_loc): Likewise.
> * input.h (DISCR_BASE_BITS): New constant.
> (DISCR_MULTIPLICITY_BITS): Likewise.
> (DISCR_COPYID_BITS): Likewise.
> (DISCR_UNUSED_BITS): Likewise.
> (DISCR_BASE_MASK): Likewise.
> (DISCR_MULTIPLICITY_MASK): Likewise.
> (DISCR_COPYID_MASK): Likewise.
> (DISCR_BASE_SHIFT): Likewise.
> (DISCR_MULTIPLICITY_SHIFT): Likewise.
> (DISCR_COPYID_SHIFT): Likewise.
> (DISCR_BASE_MAX): Likewise.
> (DISCR_MULTIPLICITY_MAX): Likewise.
> (DISCR_COPYID_MAX): Likewise.
> (location_with_discriminator_components): New function declaration.
> (get_discriminator_components_from_loc): Likewise.
>
> +
> +/* Assign discriminators to all statements in a basic block. This
> + function updates the multiplicity and/or copyid discriminator components
> for
> + all statements in the given basic block, while preserving the base
> + discriminator.
> +
> + If multiplicity_factor > 0, multiply existing multiplicity by this factor.
> + If copyid > 0, set it to this value. */
> +
> +void
> +assign_discriminators_to_bb (basic_block bb,
> + unsigned int multiplicity_factor,
> + unsigned int copyid)
> +{
> + gimple_stmt_iterator gsi;
> + gphi_iterator phi_gsi;
> + edge e;
> + edge_iterator ei;
> +
> + /* Update PHI statements. */
> + for (phi_gsi = gsi_start_phis (bb); !gsi_end_p (phi_gsi);
> + gsi_next (&phi_gsi))
> + {
> + gphi *phi = phi_gsi.phi ();
> + location_t loc = gimple_location (phi);
> +
> + if (loc != UNKNOWN_LOCATION)
> + {
> + location_t new_loc
> + = update_location_discriminator (loc,
> + multiplicity_factor,
> + copyid);
> + gimple_set_location (phi, new_loc);
> + }
> +
> + /* Update PHI argument locations. */
> + for (unsigned i = 0; i < gimple_phi_num_args (phi); i++)
> + {
> + loc = gimple_phi_arg_location (phi, i);
> + if (loc != UNKNOWN_LOCATION)
> + {
> + location_t new_loc
> + = update_location_discriminator (loc,
> + multiplicity_factor,
> + copyid);
> + gimple_phi_arg_set_location (phi, i, new_loc);
> + }
> + }
> + }
I am not sure updating location of PHI will work as intended, since the
operation really belongs to the edge it is associated with that is
copied if the source basic block is copied, so perhaps for most of
common cases we want to update locations of PHI arguments of PHIs
located in the sucessors of BB?
I.e. when duplicating blocks for loop unrolling, you want to update
discriminators of PHI args on destination of loop exit edges.
Honza
>