So, basically it works like this:
Step 1: Determine the participant's top heavy minimum. If they are a participant in the DB plan, and they worked 1000 hours (assuming the DB plan requires 1000 hours to earn an accrual), then their top heavy minimum is 5%. If not, but if they are a participant in the DC plan, and they were employed on the last day of the year, their top heavy minimum is 3%.
Step 2: Add up all employer allocations from all sources in the DC plan - safe harbor match, discretionary match, QNECs, whatever they've got. If those together satisfy the top heavy minimum (which might be either 3% or 5%, as determined in step 1), then you are done.
Step 3: If the top heavy minimum was not satisfied in step 2, add profit sharing until it is satisfied.
Step 4: If the participant has any non-elective allocations (SHNEC, profit sharing (including whatever was added in step 3), DB accrual, etc) then add whatever additional profit sharing is needed to get them to the gateway minimum.