This is the same setback I had during my senior year of cross. Alot of which was associated with lactate-based foods and acid-reflux (do you have this). What I would general discover is that I would be well into a hard tempo or race and then phlegm would hit my gaga reflex and would cause me to dry heave. Though most of the time I would continue to race/run the workout, dry heaving takes so much energy out of you that you are ultimately forced to a much slower pace.
Here is how I combated this. If acid reflux is a problem, what happens is you will feel a burp coming, followed by an intense burn in your throat, followed by phlegm buildup. Its the phlegm buildup that is the antagonist. Try to avoid lactate-rich foods such as milk, yogurt, cheese etc on days of races and workouts. However, to combat acid reflux, yogurt and milk are great staples to a diet, so implement them into your diet on non hard days. This is only IF you have an acid reflux problem. On race days, eat a tum before racing, they will buffer your stomach and cause it to settle.
More important measures to combat gagging and dry heaving are making sure you stay well-hydrated throughout each and every day. During races and workouts if you feel this coming on just try your best to relax and not panic. Another step, if you have a phlegm problem, is to practice hacking and spitting phlegm out of your throat during normal easy days. This may sound gross but it really helps. If you can get down the art of hacking the phlegm up and immediately spitting it out, you are in good shape because then nothing will get stuck near your gag reflex.