DyCL: Dynamic Neural Network Compilation Via Program Rewriting and Graph Optimization