[LLVMdev] Adding a module in a pass

Bjorn Reese breese at mail1.stofanet.dk
Tue Aug 9 09:15:46 PDT 2011


On 2011-08-09 16:48, John Criswell wrote:
> On 8/9/11 6:49 AM, Bjorn Reese wrote:
>> 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:
>
> This is not how I would do it.  A FunctionPass has doInitialization()
> and doFinalization() methods that you can implement thatcan operate on
> the whole module.  They are designed for exactly the situation you
> describe: your pass does some sort of local transform, but there's some
> global modifications it needs to do (add global constructors, add
> function prototypes, etc).

Doesn't doIntialization() run once for each translation unit (module)?

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.



More information about the llvm-dev mailing list