If you're real lucky it's just the thermostat. And before it outright dies it's sticking or only opening part of the way. At hi revs the engine runs hotter and since its not open all the way the engine isn't cooling enough. More likely - the water pump is failing. Look for antifreeze leaks under the car.