SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#sudipv
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xiiSyed 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 CENTREjatin batra
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semKavita 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 LanguageVincenzo 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 MCQsNuzhat 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 Ceducationfront
 
C language programming
C language programmingC language programming
C language programmingpullarao29
 
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 CENTREjatin batra
 
C programming interview questions
C programming interview questionsC programming interview questions
C programming interview questionsadarshynl
 

Tendances (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
 

Similaire à 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 flatteningCAFxX
 
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.pptxSRamadossbiher
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxSRamadossbiher
 
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-1MD SAMIR UDDIN
 
00 C hello world.pptx
00 C hello world.pptx00 C hello world.pptx
00 C hello world.pptxCarla227537
 
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ć
 
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 programmingAlpana Gupta
 
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
 

Similaire à 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)
 

Dernier

GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 

Dernier (20)

GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 

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