Using metadata with codegen

Hi everyone !
I am adding metadata to some type of loops using a pass. I would like to emit machine instructions before a loop begins if it has been marked with metadata.
From what I can see, metadata are stripped after instruction selection, so I would need to create a new DAG node in SelectionDAG.cpp.
That being said, I have no idea how to check for metadata, where that code should live, and how to insert the new node. Any hint on where I should start ?