generated frommo-xiaoming/cpp-vcpkg-template
- Notifications
You must be signed in to change notification settings - Fork0
Getting started LLVM 14 C API
License
NotificationsYou must be signed in to change notification settings
mo-xiaoming/getting-started-llvm-c-api
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Started from Pauladam Smith's bloghow to get started with llvm c api, then try to make it a comprehensive code guide about llvm c api
Typical cmake project, make sure LLVM in cmake search path
- simple function --
create_sum_fn
: Adopted Paladam'ssum
code to LLVM 14 and C++ - call function in libc --
create_out_fn
: Call functions from libc,puts
- recursive calls and TCE --
create_factorial_fn
: Recursive functionfactorial(n)
withLLVMAddTailCallEliminationPass
to eliminate recursive calls in IR - more complicated recursive calls and TCE --
create_fib_fn
: Naive recursive implementation offib(n)
, clearly only the lastfib
call infib(n-1) + fib(n-2)
got TCE optimized - if-the-else with PHI --
create_is_odd_fn
:if then else
pattern - 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. - 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 - Niubi LLVM optimization --
create_ap_simple_sum_fn
: Sum ofan array ofa 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
Inorcv2jit.cpp
file
- Found memory leaks inllvm official example, filed abug report, fixed in4246269
- In the same bug report, I mentioned
LLVMOrcIRTransformLayerSetTransform
causesmemory leaks, fixed inbc062e0 cal_fact_4
: call to another function in a different module
About
Getting started LLVM 14 C API