The literary device presented in Ophelia's song is "simile".
Simile is a figure of speech that compares to things with no necessity of a huge explanation. This happens when you compare two things.
In Shakespeare's masterpiece, Ophelia's song was considered to be very revealing because at that time, the way she spoke or what she said throughout the song was socially unacceptable due to the fact that she was an unmarried women and talking so openly was an issue.