Where `add_int` is defined

I am curious how some basic operations are mapped to llvm instructions. I am looking on an addition of two integers, but I cannot find the source of julia, where add_int is defined. I have located in boot.jl that mul_int is imported from .Intrinsics, but I cannot find, where module Intrinsics is located. Can someone point me to this or explain to me, what I do not uderstand?

Thanks in advance.

Best wishes,
Tomas

1 Like

https://github.com/JuliaLang/julia/blob/master/src/intrinsics.cpp

The macros used in that .cpp file can be found in intrinsics.h, which defines the enum in question.

2 Likes

Thanks a lot, I was afraid of this (in a good sense). My knowledge of C++ is from late 90s.

May I ask, what do you need the intrinsic for? How did you arrive at this question?

2 Likes

It was really a pure curiosity.
We are introducing a Julia course and I like to know as many details as possible.

2 Likes

Ah, gotcha :smiley: Be aware that the existence of intrinsics.cpp is really just an implementation detail of the compiler - it shouldn’t concern julia semantics and syntax at all.

1 Like

My intuition (after your answer) is that intrinsics.cpp defines julia function / structures that are
mapped to specific llvm calls. Many thanks for clarification.

Welllll… that’s the stuff the compiler itself needs, as I understand it. Since the julia compiler is not (fully) bootstrapped, a limited amount is done like this in C++. There’s other packages talking directly to LLVM, e.g. LoopVectorization has as few things it uses llvmcall for.

2 Likes

That makes a lot of sense. I have thought that Julia is bootstrapped similarly as LoopVectorization, as I have peeking at some point to LoopVectorization as well and I have thought this is the way to do it. Bootstrapping of complers always seems to me like a chicken and egg problem.

Again, big thanks for swift answers.

Tomas

LoopVectorization has the advantage of already running in a context that handles the LLVM infrastructure setup, namely julia. You’re right in that fully bootstrapping is a chicken and egg problem!

There’s also some bits in this JuliaCon talk by jeff from 2 years ago about where julia has this sort of distinction between “the compiler needs it” and “well how do we make it available in the regular language?”. It’s sort of related to the bootstrapping part, but orthogonal to the LLVM specific bits.

2 Likes

I remember that talk and Jeff talking he does not like Core part of the language, but I did not know he is talking about this case. This talk was one of my favorite from Juliacon 2019.