Does the function of REM sleep concern non-REM sleep or waking?

Does the function of REM sleep concern non-REM sleep or waking?