Datapath and memory co-optimization for FPGA-based computation