Memory and Communication Optimizations for Macro-dataflow Programs