writing, registerng and running a machine function pass

​​Hello everybody.

I write and run some llvm regular passes with opt with these simple commands:

clang++ -c mypass.cpp llvm-config --cxxflags
clang++ -shared -o mypass.so mypass.o llvm-config --ldflags
opt -load ./mypass.so -mypass < sample.bc > /dev/null

But I would like to write, register and run machine function pass. I know these passes cannot generally be run from the opt or bugpoint commands. What do I do and how? I didn’t find any example.

I am newbie on llvm.

Thanks.