Error in Kaleidoscope Chapter3

I am working on understand Chapter 3 of the Kaleidoscope example. While doing so I tried the example code; i.e.,

I compiled this program using
clang++ toy.cpp -o toy -g -lLLVM-11

I fed the example Kaleidoscope source code from Chapter one
in to the corresponding program; i.e.

# Compute the x'th fibonacci number.
def fib(x)
  if x < 3 then

# This expression will compute the 40th number.

I called the example program toy.kal. When I run
toy < toy.kal
I get the output below which has unexpected errors in it; i.e., it is as if the example toy.kal is not a valid Kaleidoscope program ?

./toy < tol.kal
ready> ready> Error: Unknown variable name
ready> Error: Unknown variable name
ready> Error: Unknown variable name
ready> Read top-level expression:define double @__anon_expr() {
  ret double 1.000000e+00

ready> Error: Unknown variable name
ready> Error: Unknown function referenced
Error: Unknown function referenced
ready> Error: Unknown function referenced
ready> ; ModuleID = 'my cool jit'
source_filename = "my cool jit"

Chapter 5 will add the control flow support. So if you compile chapter 5 source code with “clang++ -g toy.cpp llvm-config --cxxflags --ldflags --system-libs --libs core orcjit native -O3 -o toy” and then run that toy.kal, it should work fine.

I have tried to switch to the Chapter5 vrersion of toy.cpp and get the following error:

KaleidoscopeJIT.h:24:10: fatal error: 'llvm/ExecutionEngine/Orc/TargetProcessControl.h' file not found

It appears that the required include file is not installed on my Fedora 33 system. Here is my investigation into this:

The commands
ls /usr/include/llvm/ExecutionEngine/Orc | grep 'Taget'
Results in the following output:


The command
sudo dnf install llvm-devel
Results in …
Nothing to do.

The command
dnf info llvm | grep Version
results in
Version 11.0.0

There is only llvm-12 have TargetProcessControl.h file. and you can install llvm-12 or find correct tutorial match with llvm-11.x in this

The code file in this:


The easiest thing for me to do was
git checkout release/11.x
and then copy the Kaleidoscope directory to my testing directory.

Once I did that, I get to the following result for toy.kal (using my installed version of llvm):

/toy < toy.kal
ready> ready> Read function definition:define double @fib(double %x) {
  %cmptmp = fcmp ult double %x, 3.000000e+00
  br i1 %cmptmp, label %ifcont, label %else

else:                                             ; preds = %entry
  %subtmp = fadd double %x, -1.000000e+00
  %calltmp = call double @fib(double %subtmp)
  %subtmp1 = fadd double %x, -2.000000e+00
  %calltmp2 = call double @fib(double %subtmp1)
  %addtmp = fadd double %calltmp, %calltmp2
  br label %ifcont

ifcont:                                           ; preds = %entry, %else
  %iftmp = phi double [ %addtmp, %else ], [ 1.000000e+00, %entry ]
  ret double %iftmp

ready> Evaluated to 102334155.000000

I notice the following in the Kaleidoscope 11.x source code

static std::unique_ptr<legacy::FunctionPassManager> TheFPM;

Does legacy this mean that this class has been deprecated and one should use a different one going forward ?

I have another quesiton about this example. It uses the Function class defined by the following include in toy.cpp:

#include "llvm/IR/Function.h`"

and used as a codegen return value; e.g.

  Function *codegen();

When I search for the documentaiotn for this class I do not find it, not even in the doxygen. Looking in llvm/IR/Function.h I do not see documentation there either. Is this class part of the llvm API and if so, where can I find documentation for what will be supported by future releases ?

Yes, LegacyPassManager was the default pass manager. I think LLVM now switches to NewPassManager. And in the last week, Sjoerd Meijer announced that in this mailing thread. Some documentation is available here: Writing an LLVM Pass — LLVM 12 documentation or you can try llvm-tutor which show creating passes with both PassManagers.

Kaleidoscope codegen documented here:

Function and Value class are documentaed here:

With every new release of LLVM, a release note is also publish which mentions significant changes to LLVM APIs.

For LLVM 11.0.0 Release it is here.

My further posts to this discussion were suddenly removed as spam and I do not know why or how to recover them.

Maybe you were at trust level 0, few things you can’t do, like sending more than two hyperlinks in a post, more than 10 replies etc.

To remove these restrictions you need to reach at trust level 1 by…

  • Entering at least 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading posts