llvm metadata transformation pass

Hello !

I have a toolchain of two passes. First one, is a transformation pass that should add metadata to some structures (instructions/variables) and the second pass is an analyzing pass which needs to access the added metadata. The problem is with my adding metadata transformation pass. There might be two problems(or both):

First, maybe I don’t add correctly metadata.

LLVMContext& C = myInstruction->getContext();
MDNode* N = MDNode::get(C, MDString::get(C, “add info”));
myInstruction->setMetadata(“important”, N);

However, “add info” is printed after running the pass.

Second, it seems that the transformations are not applied on the .bc of the target program.
The Test1.bc (clean) and Test2.bc (transformation applied) are the same. I just have

using namespace llvm;

namespace {
struct metadata : public FunctionPass {
const Function *F;
static char ID; // Pass identifcation, replacement for typeid
metadata() : FunctionPass(ID) {
virtual bool runOnFunction(Function &F);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {

// virtual void releaseMemory() {
// F = 0;
// }

char metadata::ID = 0;

static RegisterPass X(“my-metadata”, “Adding metadata”, false, true);

at the beginning of my transformation pass. Please tell me how can I add metadata persistently.

Thank you for your answers !