[LLVMdev] write a transformation pass

Alexandru Ionut Diaconescu alexandruionutdiaconescu at gmail.com
Wed Feb 13 01:45:12 PST 2013


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) {
      //initializeMemDepPrinterPass(*PassRegistry::getPassRegistry());
    }
    virtual bool runOnFunction(Function &F);
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
    }

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

char metadata::ID = 0;

static RegisterPass<metadata> X("my-metadata", "Adding metadata", false, true);

Thank you !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130213/b56ebbb4/attachment.html>


More information about the llvm-dev mailing list