High-performance backpropagation for structured-grid solvers