Going to the gym whilst pregnant?

So guys. I'm 8 weeks pregnant I really want to get fit as I'm overweight now at 15 stone, I'm worried that by the time I'm nearly due I'll be 17 maybe even 18 stone :( my question is, is it safe to go to the gym in pregnancy? Or certain trimesters? I need to get fitter before this baby arrives!