write a transformation pass

Hello everyone,

I am trying to write a trivial adding metadata transformation pass. I have Test.bc the target on which I want to perform transformations.

First, I compile with clang++ my target program and I have my resulting Test.bc. I save it under Test1.bc.
As a particular example, I have " %myDimension = alloca %class.ThreeDimension, align 4 ".

Second, I apply my pass :
//…/llvm/Release+Asserts/bin/opt -load //home/alex/llvm/Release+Asserts/lib/my_test_metadata.so -my-metadata //…/llvm/tools/clang/woRKSPACE/Test.bc

Test1.bc and Test.bc are the same. In Test.bc no metadata is added. However, if in my transformation pass I debug with errs(), metadata is displayed ( " %myDimension = alloca %class.ThreeDimension, align 4, !sensitive !0, !md !1 " ), but the Test.bc file is not modified (still have " %myDimension = alloca %class.ThreeDimension, align 4 ").

Can you tell me how can I make the transformations persistent?

I have :

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<metadata> X("my-metadata", "Adding metadata", false, true);

Thank you !

Thank you ! I will now redirect the output .bc when dealing with transformation passes