SlideShare a Scribd company logo
Vassil VassilevVassil Vassilev
Cling – The LLVM-basedCling – The LLVM-based
InterpreterInterpreter
Why Do We Need Cling?
Cling's advantages:
 Full C++ support
 STL + templates
 Path to C++0x
 Planned massive reduction of dictionaries
 Easier and smoother transition between
interpreted and compiled code
 Easy maintenance
What Is Cling?
 An interpreter – looks like an interpreter and
behaves like an interpreter
Cling follows the read-evaluate-print-loop (repl) concept.
 More than interpreter – built on top of a compiler
(clang) and compiler framework (LLVM)
Contains interpreter parts and compiler parts. More of an interactive
compiler or an interactive compiler interface for clang
What Cling Depends On?
 LLVM
“The LLVM Project is a collection of modular and reusable compiler
and toolchain technologies...”
 More than 120 active contributors
Apple, ARM, Google, Qualcomm, QuIC, NVidia, AMD and more
 ~250 commits/week
 Clang
“The goal of the Clang project is to create a new C, C++, Objective C
and Objective C++ front-end for the LLVM compiler.“
 More than 100 active contributors
Apple, ARM, AMD and more
 ~150 commits/week
* Stats from last year until 14.10.2011
Cling's Codebase
LLVM – 430K SLOC*
Clang – 333K SLOC*
Cling – 7K SLOC*
* By 12.10.2011. No testsuites included. C and C++ only.
Credits: generated using David A. Wheeler's 'SLOCCount'
Cling's Codebase
LLVM
Clang
Cling
Other ROOT – 1400K SLOC*
CINT+Reflex – 230K SLOC*
Cling – 7K SLOC*
Cling's Codebase
ROOT
CINT
Cling
Additional Features
 Just-in-time compiler (JIT)
 Extra platform support
 World class performance and optimizations
 OpenCL
 Expressive diagnostics
 ...
Expressive Diagnostics
 Column numbers and caret diagnostics
CaretDiagnostics.C:4:13: warning: '.*' specified field precision is missing a
matching 'int' argument
printf("%.*d");
~~^~
 Range highlighting
RangeHighlight.C:14:39: error: invalid operands to binary expression ('int' and 'A')
return y + func(y ? ((SomeA.X + 40) + SomeA) / 42 + SomeA.X : SomeA.X);
~~~~~~~~~~~~ ^ ~~~~~~~
 Fix-it hints
FixItHints.C:7:27: warning: use of GNU old-style field designator extension
struct point origin = { x: 0.0, y: 0.0 };
^~
.x =
Improving Cling Step-By-Step
Cling prototype in 2010:
 Shortcomings of the existing prototype were
analyzed
Source-to-source manipulations, variable initializers not managed
correctly, redundant re-parsing, low efficiency, ...
 Redesign almost from scratch
 Resulted in complete rewrite
Advantages of the New Design
 Rely on the compiler libraries where possible
instead of custom implementations
Reduces the maintenance load. If the implementation is not too
specific and makes sense for a compiler we prefer putting it into the
compiler codebase and delegate the maintenance...
 More language independent
The necessary code injections and rewrites are directly in the internal
structures of the underlying compiler
 Stability
The new design enables the implementation of stable error recovery
 Better performance
Re-parsing only in very few cases
Challenges
 How to combine incompatible concepts like
compilation and interpretation
Many tasks that are trivial for an interpreter become a nightmare for a
compiler.
 How to make it user-friendly
First step should be to adopt the successful usability extensions from
CINT.
Challenges
How to make it user-friendly
First step should be to adopt the successful usability extensions from
CINT.
 Value printer
The interactive mode obeys the repl concept and there should be
easy, interactive and user-extensible access to types and values
 Expressions and statements
CINT-specific C++ extension improving the user interaction with the
interpreter from the terminal...
[cling]$ sin(1)
(double const) 0.841471
void wrapper() {
sin(1);
}
[cling]$
[cling]$
int i = 12; printf("%dn",i);
printf("%fn",sin(i));
Expressions and Statements
 Wrap the input
 Scan for declarations
 Extract the declarations one level up, as global
declarations
void wrapper1() {
int i = 12;
printf("%dn",i);
}
void wrapper2() {
printf("%fn", sin(i));
}
int i = 12;
Challenges
How to combine incompatible concepts like
compilation and interpretation
Many tasks that are trivial for an interpreter become a nightmare for a compiler.
 Initialization of global variables
Cling depends on global variables, which need to be initialized. However,
the global variables continue to be added (potentially) with every input line...
 Error recovery
Even though the user has typed wrong input at the prompt cling must
survive, i.e issue an error and continue to work...
 Late binding
Cling needs to provide a way for symbols unavailable at compile-time a
second chance to be provided at runtime...
Error Recovery
 Filled input-by-input from the command line
 Incorrect inputs must be discarded as a whole
Late Binding
{
TFile F;
if (is_day_of_month_even())
F.setName("even.root");
else
F.setName("odd.root");
F.Open();
hist->Draw();
hist->Fill(1.5);
hist->SetFillColor(46);
}
hist->Draw();
 Defined in the
root file
 The root file is gone.
Issue an error.
 Opens a dynamic scope. It
tells the compiler that cling
will take over the resolution
of possible unknown
symbols
Late Binding
 Tell the compiler the symbol will be resolved at
runtime
 Wrap it into valid C++ code
 Partially recompile at runtime
{
TFile F;
if (is_day_of_month_even())
F.setName("even.root");
else
F.setName("odd.root");
F.Open();
gCling->EvaluateT<void>("hist->Draw()", ...);
...
}
hist->Draw();
Challenges
 Error recovery
Even though the user has typed wrong input at the prompt cling must survive, i.e
issue an error and continue to work...
 Initialization of global variables
Cling depends on global variables, which need to be initialized. However, the global
variables continue to be added (potentially) with every input line...
 Late binding
Cling needs to provide a way for symbols unavailable at compile-time a second
chance to be provided at runtime...
 Value printer
The interactive mode obeys the repl concept and there should be way of easy print
value and type of expression in a user-extensible way...
 Expressions and statements
CINT-specific C++ extension improving the user interaction with the interpreter from
the terminal...
Dictionaries
 No reflection information in C++
There is no way a C++ interpreter could know what are the detailed
contents of a compiled program
 CINT and Reflex dictionaries:
 Take large fraction
of libraries
 Multiple copies of
the dictionary
data in the memory
Dictionaries in Cling
 Now the compiler is an interpreter as well!
 JIT enables native calls into libraries
 Query the reflection data from compiler libraries
 Compiled dictionaries should be no longer
needed
 Middle term: Everything but ClassDef goes away!
 Long term: No dictionaries at all
Library Calls in Cling
 Load the lib
 #include the header containing the function
definition
 Make the call
Can we repackage a
library's headers?
Can we avoid re-
parsing again and
again?
Cling @ the LLVM Community
 On 25.07.2011 cling was announced on clang's
mailing list as a working C++ interpreter
 People were thrilled and enthusiastic about it
 Lots of excellent comment and suggestions
The Road Ahead
Integration into ROOT
Ongoing and continuous process that needs:
Experience with ROOT
Knowledge about cling and clang
interfaces
Future: Code Unloading
[cling]$
[cling]$
[cling]$
[cling]$
[cling]$
[cling]$
[cling]$
[cling]$
[cling]$
.L Calculator.h
Calculator calc;
calc.Add(3, 1)
2
.U Calculator.h
.L Calculator.h
Calculator calc;
calc.Add(3, 1)
4
// Calculator.h
class Calculator {
int Add(int a, int b) {
return a + b;
}
...
};
// Calculator.h
class Calculator {
int Add(int a, int b) {
return a - b;
}
...
};
Future: Code Unloading
 Fundamental requirement for ROOT
This is what drives the rapid development in ROOT...
 Extremely difficult for a compiler
Teaching an elephant to dance...
 Requires in-depth knowledge of clang internals
Different phases in the compiler, advanced AST manipulations, inter-
procedural analysis, knowledge about LLVM intermediate representation
(bitcode), JIT internals, bitcode recompilation...
 Thinking out-of-the-box
Not often seen problem needs novel way of understanding the compiler
libraries...
 We know how to do it!
Watermarks, dependency analysis, annotation of the corresponding
bitcode, generated for the high-level internal structures,...
Cling in ROOT
Lots of interest from experiments and
physicists
The prototype will be included in the
source package of ROOT (the November
release)
The prototype will be an optional
interpreter for ROOT
Demo:Demo:
C N GC N G
Thank you!Thank you!
Backup slidesBackup slides
Pre-Compiled Headers
Carefully crafted data structures designed to
improve translator's performance:
 Reduce lexical, syntax and semantic analysis
 Loaded “lazily” on demand
Pre-Compiled Headers
Design advantages:
 Loading PCH is significantly faster
than re-parsing
 Minimize the cost of reading
 Read times don't depend on PCH
size
 Cost of generating PCH isn't large

More Related Content

What's hot

C vs c++
C vs c++C vs c++
C vs c++
Gaurav Badhan
 
2. data, operators, io
2. data, operators, io2. data, operators, io
2. data, operators, io
Srichandan Sobhanayak
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
Jitendra Ahir
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
sudipv
 
C language introduction
C language introduction C language introduction
C language introduction
musrath mohammad
 
Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
starlit electronics
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
Syed Zaid Irshad
 
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTREC & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
jatin batra
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-sem
Kavita Dagar
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
Vincenzo De Florio
 
Std 10 Chapter 10 Introduction to C Language Important MCQs
Std 10 Chapter 10 Introduction to C Language Important MCQsStd 10 Chapter 10 Introduction to C Language Important MCQs
Std 10 Chapter 10 Introduction to C Language Important MCQs
Nuzhat Memon
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#
Sireesh K
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
educationfront
 
C vs c++
C vs c++C vs c++
C vs c++
ZTE Nepal
 
C language
C languageC language
C language
Rohit Singh
 
C language programming
C language programmingC language programming
C language programming
pullarao29
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
jatin batra
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
Leandro Schenone
 
C programming interview questions
C programming interview questionsC programming interview questions
C programming interview questions
adarshynl
 
Deep C
Deep CDeep C
Deep C
Olve Maudal
 

What's hot (20)

C vs c++
C vs c++C vs c++
C vs c++
 
2. data, operators, io
2. data, operators, io2. data, operators, io
2. data, operators, io
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
 
C language introduction
C language introduction C language introduction
C language introduction
 
Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTREC & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-sem
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
Std 10 Chapter 10 Introduction to C Language Important MCQs
Std 10 Chapter 10 Introduction to C Language Important MCQsStd 10 Chapter 10 Introduction to C Language Important MCQs
Std 10 Chapter 10 Introduction to C Language Important MCQs
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
 
C vs c++
C vs c++C vs c++
C vs c++
 
C language
C languageC language
C language
 
C language programming
C language programmingC language programming
C language programming
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
C programming interview questions
C programming interview questionsC programming interview questions
C programming interview questions
 
Deep C
Deep CDeep C
Deep C
 

Similar to Cling the llvm based interpreter

Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flattening
CAFxX
 
LLVM
LLVMLLVM
c.ppt
c.pptc.ppt
Legacy of Void*
Legacy of Void*Legacy of Void*
Legacy of Void*
Adam Crain
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
SRamadossbiher
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
SRamadossbiher
 
Programming in c
Programming in cProgramming in c
Programming in c
Ashutosh Srivasatava
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
oggyrao
 
A Crash Course in C Part-1
A Crash Course in C Part-1A Crash Course in C Part-1
A Crash Course in C Part-1
MD SAMIR UDDIN
 
00 C hello world.pptx
00 C hello world.pptx00 C hello world.pptx
00 C hello world.pptx
Carla227537
 
Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Reactive Qt - Ivan Čukić (Qt World Summit 2015)Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Ivan Čukić
 
Oops index
Oops indexOops index
Oops index
Hitesh Wagle
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
Mohamed Fawzy
 
C tutorials
C tutorialsC tutorials
C tutorials
Amit Kapoor
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Chris Adamson
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
Eelco Visser
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Alpana Gupta
 
Basic c
Basic cBasic c
Basic c
Veera Karthi
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Ovidiu Farauanu
 

Similar to Cling the llvm based interpreter (20)

Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flattening
 
LLVM
LLVMLLVM
LLVM
 
c.ppt
c.pptc.ppt
c.ppt
 
Legacy of Void*
Legacy of Void*Legacy of Void*
Legacy of Void*
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
A Crash Course in C Part-1
A Crash Course in C Part-1A Crash Course in C Part-1
A Crash Course in C Part-1
 
00 C hello world.pptx
00 C hello world.pptx00 C hello world.pptx
00 C hello world.pptx
 
Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Reactive Qt - Ivan Čukić (Qt World Summit 2015)Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Reactive Qt - Ivan Čukić (Qt World Summit 2015)
 
Oops index
Oops indexOops index
Oops index
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
C tutorials
C tutorialsC tutorials
C tutorials
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Basic c
Basic cBasic c
Basic c
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 

Recently uploaded

E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 

Recently uploaded (20)

E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 

Cling the llvm based interpreter

  • 1. Vassil VassilevVassil Vassilev Cling – The LLVM-basedCling – The LLVM-based InterpreterInterpreter
  • 2. Why Do We Need Cling? Cling's advantages:  Full C++ support  STL + templates  Path to C++0x  Planned massive reduction of dictionaries  Easier and smoother transition between interpreted and compiled code  Easy maintenance
  • 3. What Is Cling?  An interpreter – looks like an interpreter and behaves like an interpreter Cling follows the read-evaluate-print-loop (repl) concept.  More than interpreter – built on top of a compiler (clang) and compiler framework (LLVM) Contains interpreter parts and compiler parts. More of an interactive compiler or an interactive compiler interface for clang
  • 4. What Cling Depends On?  LLVM “The LLVM Project is a collection of modular and reusable compiler and toolchain technologies...”  More than 120 active contributors Apple, ARM, Google, Qualcomm, QuIC, NVidia, AMD and more  ~250 commits/week  Clang “The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler.“  More than 100 active contributors Apple, ARM, AMD and more  ~150 commits/week * Stats from last year until 14.10.2011
  • 5. Cling's Codebase LLVM – 430K SLOC* Clang – 333K SLOC* Cling – 7K SLOC* * By 12.10.2011. No testsuites included. C and C++ only. Credits: generated using David A. Wheeler's 'SLOCCount' Cling's Codebase LLVM Clang Cling Other ROOT – 1400K SLOC* CINT+Reflex – 230K SLOC* Cling – 7K SLOC* Cling's Codebase ROOT CINT Cling
  • 6. Additional Features  Just-in-time compiler (JIT)  Extra platform support  World class performance and optimizations  OpenCL  Expressive diagnostics  ...
  • 7. Expressive Diagnostics  Column numbers and caret diagnostics CaretDiagnostics.C:4:13: warning: '.*' specified field precision is missing a matching 'int' argument printf("%.*d"); ~~^~  Range highlighting RangeHighlight.C:14:39: error: invalid operands to binary expression ('int' and 'A') return y + func(y ? ((SomeA.X + 40) + SomeA) / 42 + SomeA.X : SomeA.X); ~~~~~~~~~~~~ ^ ~~~~~~~  Fix-it hints FixItHints.C:7:27: warning: use of GNU old-style field designator extension struct point origin = { x: 0.0, y: 0.0 }; ^~ .x =
  • 8. Improving Cling Step-By-Step Cling prototype in 2010:  Shortcomings of the existing prototype were analyzed Source-to-source manipulations, variable initializers not managed correctly, redundant re-parsing, low efficiency, ...  Redesign almost from scratch  Resulted in complete rewrite
  • 9. Advantages of the New Design  Rely on the compiler libraries where possible instead of custom implementations Reduces the maintenance load. If the implementation is not too specific and makes sense for a compiler we prefer putting it into the compiler codebase and delegate the maintenance...  More language independent The necessary code injections and rewrites are directly in the internal structures of the underlying compiler  Stability The new design enables the implementation of stable error recovery  Better performance Re-parsing only in very few cases
  • 10. Challenges  How to combine incompatible concepts like compilation and interpretation Many tasks that are trivial for an interpreter become a nightmare for a compiler.  How to make it user-friendly First step should be to adopt the successful usability extensions from CINT.
  • 11. Challenges How to make it user-friendly First step should be to adopt the successful usability extensions from CINT.  Value printer The interactive mode obeys the repl concept and there should be easy, interactive and user-extensible access to types and values  Expressions and statements CINT-specific C++ extension improving the user interaction with the interpreter from the terminal... [cling]$ sin(1) (double const) 0.841471 void wrapper() { sin(1); }
  • 12. [cling]$ [cling]$ int i = 12; printf("%dn",i); printf("%fn",sin(i)); Expressions and Statements  Wrap the input  Scan for declarations  Extract the declarations one level up, as global declarations void wrapper1() { int i = 12; printf("%dn",i); } void wrapper2() { printf("%fn", sin(i)); } int i = 12;
  • 13. Challenges How to combine incompatible concepts like compilation and interpretation Many tasks that are trivial for an interpreter become a nightmare for a compiler.  Initialization of global variables Cling depends on global variables, which need to be initialized. However, the global variables continue to be added (potentially) with every input line...  Error recovery Even though the user has typed wrong input at the prompt cling must survive, i.e issue an error and continue to work...  Late binding Cling needs to provide a way for symbols unavailable at compile-time a second chance to be provided at runtime...
  • 14. Error Recovery  Filled input-by-input from the command line  Incorrect inputs must be discarded as a whole
  • 15. Late Binding { TFile F; if (is_day_of_month_even()) F.setName("even.root"); else F.setName("odd.root"); F.Open(); hist->Draw(); hist->Fill(1.5); hist->SetFillColor(46); } hist->Draw();  Defined in the root file  The root file is gone. Issue an error.  Opens a dynamic scope. It tells the compiler that cling will take over the resolution of possible unknown symbols
  • 16. Late Binding  Tell the compiler the symbol will be resolved at runtime  Wrap it into valid C++ code  Partially recompile at runtime { TFile F; if (is_day_of_month_even()) F.setName("even.root"); else F.setName("odd.root"); F.Open(); gCling->EvaluateT<void>("hist->Draw()", ...); ... } hist->Draw();
  • 17. Challenges  Error recovery Even though the user has typed wrong input at the prompt cling must survive, i.e issue an error and continue to work...  Initialization of global variables Cling depends on global variables, which need to be initialized. However, the global variables continue to be added (potentially) with every input line...  Late binding Cling needs to provide a way for symbols unavailable at compile-time a second chance to be provided at runtime...  Value printer The interactive mode obeys the repl concept and there should be way of easy print value and type of expression in a user-extensible way...  Expressions and statements CINT-specific C++ extension improving the user interaction with the interpreter from the terminal...
  • 18. Dictionaries  No reflection information in C++ There is no way a C++ interpreter could know what are the detailed contents of a compiled program  CINT and Reflex dictionaries:  Take large fraction of libraries  Multiple copies of the dictionary data in the memory
  • 19. Dictionaries in Cling  Now the compiler is an interpreter as well!  JIT enables native calls into libraries  Query the reflection data from compiler libraries  Compiled dictionaries should be no longer needed  Middle term: Everything but ClassDef goes away!  Long term: No dictionaries at all
  • 20. Library Calls in Cling  Load the lib  #include the header containing the function definition  Make the call Can we repackage a library's headers? Can we avoid re- parsing again and again?
  • 21. Cling @ the LLVM Community  On 25.07.2011 cling was announced on clang's mailing list as a working C++ interpreter  People were thrilled and enthusiastic about it  Lots of excellent comment and suggestions
  • 23. Integration into ROOT Ongoing and continuous process that needs: Experience with ROOT Knowledge about cling and clang interfaces
  • 24. Future: Code Unloading [cling]$ [cling]$ [cling]$ [cling]$ [cling]$ [cling]$ [cling]$ [cling]$ [cling]$ .L Calculator.h Calculator calc; calc.Add(3, 1) 2 .U Calculator.h .L Calculator.h Calculator calc; calc.Add(3, 1) 4 // Calculator.h class Calculator { int Add(int a, int b) { return a + b; } ... }; // Calculator.h class Calculator { int Add(int a, int b) { return a - b; } ... };
  • 25. Future: Code Unloading  Fundamental requirement for ROOT This is what drives the rapid development in ROOT...  Extremely difficult for a compiler Teaching an elephant to dance...  Requires in-depth knowledge of clang internals Different phases in the compiler, advanced AST manipulations, inter- procedural analysis, knowledge about LLVM intermediate representation (bitcode), JIT internals, bitcode recompilation...  Thinking out-of-the-box Not often seen problem needs novel way of understanding the compiler libraries...  We know how to do it! Watermarks, dependency analysis, annotation of the corresponding bitcode, generated for the high-level internal structures,...
  • 26. Cling in ROOT Lots of interest from experiments and physicists The prototype will be included in the source package of ROOT (the November release) The prototype will be an optional interpreter for ROOT
  • 30. Pre-Compiled Headers Carefully crafted data structures designed to improve translator's performance:  Reduce lexical, syntax and semantic analysis  Loaded “lazily” on demand
  • 31. Pre-Compiled Headers Design advantages:  Loading PCH is significantly faster than re-parsing  Minimize the cost of reading  Read times don't depend on PCH size  Cost of generating PCH isn't large