R.Omar
R.Omar

Reputation: 655

Create new Function in llvm

If I have a set of basic blocks and edges and I need to create for them a new function with new entry and end points.

Could I create this directly in LLVM , just like createFunction(F) then F.insert(bb, edges) which bb is a basic block and edges is the new edges for the new function.

Thanks

Upvotes: 6

Views: 8793

Answers (2)

Eli Bendersky
Eli Bendersky

Reputation: 273716

You can create a new function with Function::Create. See this snippet from the LLVM tutorial for example:

Function *PrototypeAST::Codegen() {
  // Make the function type:  double(double,double) etc.
  std::vector<Type*> Doubles(Args.size(),
                             Type::getDoubleTy(getGlobalContext()));
  FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
                                       Doubles, false);

  Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);

Upvotes: 6

Related Questions