Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create new Function in llvm

Tags:

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

like image 835
R.Omar Avatar asked Jun 25 '13 12:06

R.Omar


People also ask

What is intrinsics in LLVM?

An intrinsic function is a function built in to the compiler. The compiler knows how to best implement the functionality in the most optimized way for these functions and replaces with a set of machine instruction for a particular backend.

What is module in LLVM?

The first segment is pretty simple: it creates an LLVM “module.” In LLVM, a module represents a single unit of code that is to be processed together. A module contains things like global variables and function declarations and implementations.


1 Answers

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);
like image 83
Eli Bendersky Avatar answered Sep 28 '22 09:09

Eli Bendersky