[LLVMdev] Adding a module in a pass

Bjorn Reese breese at mail1.stofanet.dk
Tue Aug 9 06:49:36 PDT 2011


I have an optimization pass (FunctionPass) where I need to add global
constructors.

For cleaness sake I decided to add these in my own module. My module
is created in my FunctionPass constructor:

   MyPass()
     : FunctionPass(ID),
       myModule("my_module", getGlobalContext())
   {}

I generate an llvm.global_ctor global variable in my module, and I add
my global constructors there. This appears to be correct. Here is a
dump of the module after the pass:

   ; ModuleID = 'my_module'

   @my_literal = internal constant [6 x i8] c"Hello\00"
   @llvm.global_ctors = appending global [1 x { i32, void ()* }] [void 
() { i32 65535, void ()* @my_global_constructor }]

   define void @my_global_constructor() {
     %puts = call i32 @puts(i8* getelementptr inbounds ([6 x i8]* 
@my_literal, i32 0, i32 0))
   }

   declare i32 @puts(i8* nocapture) nounwind

My problem is that this module is not linked into the executable.

Do I need to insert the module somewhere?



More information about the llvm-dev mailing list