Cross-Layer Optimization for Multilevel Cell STT-RAM Caches