Functional constraints in the evolution of brain circuits