How to output a color ramp node in a material to it's own compositor pass? (2.79b)
You could try duplicating the entire scene. (Full copy) Then in the new scene change the material duplicate to an emission type, with the output being the grayscale of the color ramp. The new scene is also set to only render an emission pass.



Then in compositing output you can use the main scene for the render, and the duplicate scene's emission output as the masking pass. Not exactly what it's intended for (likely to need some adjustment), but I think this may be workable.

Also on the new scene, you can turn samples way down to speed it up a bit, since it's only being used as a mask.