[LLVMdev] Applying different Optimizations for different Functions - Questions?

Devang Patel dpatel at apple.com
Mon Aug 11 14:25:01 PDT 2008

On Aug 10, 2008, at 9:50 PM, Murat wrote:

> Hi!
> I am trying to develop an LLVM tool which can apply different  
> optimizations
> for selected functions. For example, I want to apply an optimization  
> onto one
> function but not for another one.
> I am using the standard optimizations available in LLVM.

You are required to "add" passes, before running them, so that the  
pass manager can schedule required analysis information properly.

In your case, you could try...

bool ComplNewBBFuncs::runOnModule(Module &M)
  Function *Main = M.getFunction("main");
  if (Main == 0)
      cerr << "!!! No Main Function" << std::endl;
      return false;

  //Determine each Function
  Function *CurFunc1 = M.getFunction("NewFunction1");
  Function &Current1 = (*CurFunc1);
  Function *CurFunc2 = M.getFunction("NewFunction2");
  Function &Current2 = (*CurFunc2);

  FunctionPassManager FPM1;

  FunctionPassManager FPM2;
  FPM2.add(createLoopUnrollPass());  /* This will setup loop pass  
manager appropriately */



More information about the llvm-dev mailing list