//===--- examples/Fibonacci/fibonacci.cpp - An example use of the JIT -----===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This small program provides an example of how to build quickly a small module // with function Fibonacci and execute it with the JIT. // // The goal of this snippet is to create in the memory the LLVM module // consisting of one function as follow: // // int fib(int x) { // if(x<=2) return 1; // return fib(x-1)+fib(x-2); // } // // Once we have this, we compile the module via JIT, then execute the `fib' // function and return result to a driver, i.e. to a "host program". // //===----------------------------------------------------------------------===// #include "llvm/ADT/APInt.h" #include "llvm/IR/Verifier.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/ExecutionEngine/MCJIT.h" #include "llvm/IR/Argument.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/Support/Casting.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> #include <cstdlib> #include <memory> #include <string> #include <vector> usingnamespacellvm; static Function *CreateFibFunction(Module *M, LLVMContext &Context) { … } int main(int argc, char **argv) { … }