Optimization of CNOT circuits under topological constraints