[LLVMdev] Adding a module in a pass

Bjorn Reese breese at mail1.stofanet.dk
Wed Aug 10 01:16:57 PDT 2011


On 2011-08-09 20:59, John Criswell wrote:
> On 8/9/11 9:15 AM, Bjorn Reese wrote:
>> I only want to generate my global constructors once for the whole
>> program. They are generated from a scripting language, which is parsed
>> in the optimization pass.
>
> I'm not familiar with how your languages organizes compilation units,
> but from the sounds of it, it seems like you're saying that you want to
> add the global ctor once after the compilation units are linked into a
> single LLVM bitcode file.

I guess that what I am after is the ability to add a translation unit
during the optimization phase. This translation unit does not itself
have to be optimized.

I am using the optimization pass to instrument another C/C++ program
with debugging code (think "DTrace for programs", except that the
instrumentation is static, not dynamic.) The instrumentation is
controlled by a script. For example:

   @begin
   {
     print("This is executed before main()");
   }

   @enter:Foo
   {
     print("This is executed when entering Foo()");
   }

The @enter code is injected at the beginning of Foo(), so this code is
put into the current module. My own module contains the @begin code,
along with all global functions, global variables, and build-in
functions that are generated from the script.

> In that case, you either delay running your FunctionPass until you have
> the whole bitcode file, or you create a ModulePass that is only executed
> once the whole-program bitcode is generated.

I have considered adding a ModulePass but got confused by the
description of analysis groups (which I assume I need to use in order
to make sure that my ModulePass and FunctionPass are run together.)

I am currently generating my code in the FunctionPass constructor, which
works just fine, except I do not know how to get my module passed on to
the linker.



More information about the llvm-dev mailing list