Code Monkey home page Code Monkey logo

getting-started-llvm-c-api's Introduction

Getting started LLVM C API

Started from Pauladam Smith's blog how to get started with llvm c api, then try to make it a comprehensive code guide about llvm c api

Build

Typical cmake project, make sure LLVM in cmake search path

MCJIT

  1. simple function -- create_sum_fn: Adopted Paladam's sum code to LLVM 14 and C++
  2. call function in libc -- create_out_fn: Call functions from libc, puts
  3. recursive calls and TCE -- create_factorial_fn: Recursive function factorial(n) with LLVMAddTailCallEliminationPass to eliminate recursive calls in IR
  4. more complicated recursive calls and TCE -- create_fib_fn: Naive recursive implementation of fib(n), clearly only the last fib call in fib(n-1) + fib(n-2) got TCE optimized
  5. if-the-else with PHI -- create_is_odd_fn: if then else pattern
  6. while-do without PHI -- create_factorial_loop_fn: while-do without PHI. For factorial, this version and the recursive one optimized down to the same IR code.
  7. array access with GEP -- create_ap_sum_fn: Sum of an array of arithmetic progression numbers, I really hoped LLVM can do it in the way of (f + l) * n / 2, but sadly no, still loops
  8. Niubi LLVM optimization -- create_ap_simple_sum_fn: Sum of an array of a sequence of arithmetic progression numbers, still not using that formula, maybe because of some optimization are missing, unlike pure -O3, maybe it is being done during re-write

ORC V2 JIT

In orcv2jit.cpp file

  1. Found memory leaks in llvm official example, filed a bug report, fixed in 4246269
  2. In the same bug report, I mentioned LLVMOrcIRTransformLayerSetTransform causes memory leaks, fixed in bc062e0
  3. cal_fact_4: call to another function in a different module

getting-started-llvm-c-api's People

Contributors

mo-xiaoming avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

liuqi123123

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.