LLVM-based C++ Interpreter For ROOT Axel Naumann, CERN Lukasz Janyst, CERN Philippe Canal, Fermilab.

Slides:



Advertisements
Similar presentations
C++ Language Fundamentals. 2 Contents 1. Introduction to C++ 2. Basic syntax rules 3. Declaring and using variables.
Advertisements

Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
Linking & Loading CS-502 Operating Systems
Chapter FourModern Programming Languages1 Language Systems.
Reflex Dictionary Generator Antti Hahto
Status and Future of CINT Reflex as Reflection Database Object-Oriented CINT Multi-Threading Masaharu Goto, Agilent Philippe Canal, Fermilab Stefan Roiser,
ROOT TOOLKIT (I) Técnicas Fundamentales de Simulación, Reconstrucción y Análisis de Datos en Física Experimental de Partículas Isidro González Caballero.
COSC 120 Computer Programming
JETT 2003 Java.compareTo(C++). JAVA Java Platform consists of 4 parts: –Java Language –Java API –Java class format –Java Virtual Machine.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Guide To UNIX Using Linux Third Edition
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
LLVM Developed by University of Illinois at Urbana-Champaign CIS dept Cisc 471 Matthew Warner.
Using the Clang Integrated Assembler to Compile the Linux Kernel Bryce Adelstein-Lelbach, Louisiana State University.
SEAL V1 Status 12 February 2003 P. Mato / CERN Shared Environment for Applications at LHC.
Language Systems Chapter FourModern Programming Languages 1.
CINT Retrospect ROOT Workshop Mar 2013 Agilent Technologies Masaharu Goto.
M.Frank CERN/LHCb - Persistency Workshop, Dec.2004 Agenda: 2 separate talks! Don’t mangle together what does not belong together 1.Schema Evolution Tests.
JIT in webkit. What’s JIT See time_compilation for more info. time_compilation.
Copyright 2001 Oxford Consulting, Ltd1 January Storage Classes, Scope and Linkage Overview Focus is on the structure of a C++ program with –Multiple.
Lecture 10 : Introduction to Java Virtual Machine
CINT & Reflex: New Reflection Data Structures Masa(haru) Goto Agilent Philippe Canal Fermilab/CD Stefan Roiser, Axel Naumann PH/SFT.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
CST320 - Lec 11 Why study compilers? n n Ties lots of things you know together: –Theory (finite automata, grammars) –Data structures –Modularization –Utilization.
Axel Naumann University of Nijmegen / NIKHEF, NL ROOT 2004 Users Workshop The Future of THtml Plans and Status of ROOT’s documentation facility.
MD – Object Model Domain eSales Checker Presentation Régis Elling 26 th October 2005.
Axel Naumann. Outline  Static Code Analysis  Coverity  Reporting Tools, Report Quality  "Demo": Examples Axel Naumann Application Area Meeting2.
CINT C++ Interpreter update ROOT2001 at Fermi-Lab Masaharu Goto.
LANGUAGE SYSTEMS Chapter Four Modern Programming Languages 1.
Presentation Name / 1 Visual C++ Builds and External Dependencies NAME.
THtml  THtml will generate >=1 doc.root file .html pages generated from doc.root files by April (Feb doesn't exist)  Bertrand: extract doc for online.
Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo.
Cling – The New C++ Interpreter for ROOT 6
Java: An Overview John R Durrett Texas Tech University.
LLVM Compiler Katie Dew. Lectures High-level overview of LLVM (Katie) Walkthrough of LLVM in context of our project (Jason) –Input requirements –Configuration.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
Low-Level Virtual Machine support for Eclipse C/C++ Development Tooling Petri Tuononen - 17/5/2011.
A. Valassi – Python bindings for C++ in PyCool ROOT Workshop – 16 th Sep Python bindings for C++ via PyRoot User experience from PyCool in COOL.
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
ROOT Team Meeting Axel Naumann CERN PH/SFT Crienftlex Extended Version. And also Director’s Cut. Crienftlex.
C Programming Chapters 11, . . .
CINT & Reflex – The Future CINT’s Future Layout Reflex API Work In Progress: Use Reflex to store dictionary data Smaller memory footprint First step to.
Axel Naumann. Nada FTE  LLVM + cling would take 4 years  when done, move to next hot-spot in ROOT Axel Naumann ROOT Team Meeting2.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
G.Govi CERN/IT-DB 1GridPP7 June30 - July 2, 2003 Data Storage with the POOL persistency framework Motivation Strategy Storage model Storage operation Summary.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
CINT/Reflex workshop 1 Rene Brun 4 May 2005 Summary of the CINT/Reflex workshop 2-6 May 2005
Hello world !!! ASCII representation of hello.c.
What is New in Core Fons Rademakers 1. Library Reorganization Split off from libCore: libRIO libNet libMath (soon) These libraries are now loaded at run-
2001 ROOT Workshop The Summary. Content Most Requested Request already satisfied Build and Distribution Web Page Information and Documentation.
ACAT 2008 Axel Naumann (CERN), Philippe Canal (Fermilab) The Role of Interpreters in High Performance Computing.
Optimization of Python-bindings Wim T.L.P. Lavrijsen, LBNL ROOT Meeting, CERN; 01/15/10 C O M P U T A T I O N A L R E S E A R C H D I V I S I O N.
Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 root.cern.ch ROOT 6 Vassil Vassilev CERN, PH-SFT.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
ROOT / Reflex ‘07+ Stefan Roiser Missed last team meeting b/c.
Computer System Structures
Dictionary generation for the Experiments
Compiler Construction (CS-636)
Linking & Loading.
-by Nisarg Vasavada (Compiled*)
CS-3013 Operating Systems C-term 2008
National Energy Research Scientific Computing Center (NERSC)
The HP OpenVMS Itanium® Calling Standard
Overview of Compilation The Compiler BACK End
Linking & Loading CS-502 Operating Systems
Chapter 1 Introduction.
Linking & Loading CS-502 Operating Systems
ROOT Support and Developments at FNAL
SPL – PS1 Introduction to C++.
Presentation transcript:

LLVM-based C++ Interpreter For ROOT Axel Naumann, CERN Lukasz Janyst, CERN Philippe Canal, Fermilab

Prompt: same as compiled language! I/O: type database, members, object from type name Signal/slot, Plugins: call function given a string Interest even outside HEP Main items: Reflection (types, members, sizes…) Calling compiled functions Why Interpreter? CHEP'09 Axel Naumann, Philippe Canal

CHEP'09 Axel Naumann, Philippe Canal3 Overview Of Reflection Data Dictionary Parser Headers I/O Structure G__My.cxx rootcint MyClass.h ROOT I/O Example

CHEP'09 Axel Naumann, Philippe Canal4 Overview Of Reflection Data Dictionary Parser Headers I/O Structure My_rflx.cxx genreflex [GCCXML] MyClass.h ROOT I/O Example

Current Reflection Gathering CINT Limited parser (templates, operators, overloading, lookup, file handling, STL / sys headers) GCCXML/ genreflex Inhomogeneous: GCC / XML / Python / C++ Slow Extremely difficult to influence / fix; involves three parties (GCC, GCCXML, us), different interests CHEP'09 Axel Naumann, Philippe Canal

Function Calls From String, Current Maintain table Stubs generated as part of dictionary: Given call function stub, pass arguments. Needs one stub per function: 40% of dictionaries’ size! [Disclaimer: code is paraphrased] CHEP'09 Axel Naumann, Philippe Canal Func_stub(vector args) { function_name((int)args[0]); } "function_name"&Func_stub "func(0)" funcmap["func"](make_vector(0))

LLVM Open Source project with Uni Illinois Urbana- Champaign, started around 2002 Sponsored by Apple, Adobe, Cray,… Features: drop-in, faster alternative to GCC modular design with C++ API liberal NCSA open source license just-in-time compiler very active mailing list, very responsive developers CHEP'09 Axel Naumann, Philippe Canal

LLVM C++ front-end clang (alternative: GCC front-end) bytecode layer with optimizers and execution engine back-end for all major platforms: Windows, Linux, MacOS, PS3, Solaris, … Can already build e.g. ROOT (with GCC front-end) CHEP'09 Axel Naumann, Philippe Canal Source clang or GCC C++ front-end LLVM bytecode LLVM back-end native binaries LLVM bytecode exec optimizer

clang LLVM C[++] front-end: preprocessor etc, result: AST Clean C++ API: analyze, generate, manipulate code! Already used for C and ObjC C++ still in development: contribute and influence! Apple: “production quality in 2011” approx 200 commits / week, by far most for C CHEP'09 Axel Naumann, Philippe Canal

LLVM + clang + X = cling Requirements: all CINT features, no user level changes (prompt, ACLiC, gInterpreter etc) Benefits of cling: Interpreter is based on production-grade parser and optimizers; benefit from compiler improvements ACLiC (.L file.C+) will use JIT instead of native compiler / linker / loader: in-memory compilation! Modularity eases maintenance Apply >10 years of C++ interpreter to new design CHEP'09 Axel Naumann, Philippe Canal10

Auto-dlopen, -#include, -Declaration CINT CINT: loads lib for class on first usage (rootmap) clang clang: analyze AST, extract types, load needed libraries CINT CINT: needs no #include for types with dictionary clang clang: intercept parser errors on unknown type; inject type's header into AST and re-parse CINT CINT: auto-declares variables in assignment clang clang: patch in "auto" keyword as error handling CHEP'09 Axel Naumann, Philippe Canal auto h=new TH1F()h=new TH1F() transform

Function Calls With clang / LLVM LLVM resolves missing symbols in memory from: shared libraries code already compiled in memory code not yet compiled: just-in-time (JIT) compile it! JIT already available on X86, PowerPC, ARM, Alpha with Linux (32 / 64 bit), MacOS X, Win32. No stubs anymore, 40% smaller dictionaries! Also speeds up performance critical interpreted code! CHEP'09 Axel Naumann, Philippe Canal

The Challenges As compiler, LLVM expects all code to be available. cling on the other hand: 1.must allow iterative loading Compilers parse all, then compile, then link. Solution: iterative linking of tiny translation units 13 cling[0].L func0.C cling[1] int i = func0(); cling[2].L func1.C cling[3] i = func1(); CHEP'09 Axel Naumann, Philippe Canal

The Challenges As compiler, LLVM expects all code to be available. cling on the other hand: 1.must allow iterative loading 2.must keep stack Stack not even set up for compiler. Solution: need interpreter context to survive incremental linking 14 cling[0] int i = 12; cling[1].L times2.C cling[2] times2(&i); cling[3] printf("%d\n",i); CHEP'09 Axel Naumann, Philippe Canal

The Challenges As compiler, LLVM expects all code to be available. cling on the other hand: 1.must allow iterative loading 2.must keep stack 3.must support unloading Unthinkable for compilers. Solution: need to modify AST, re-link, track dependencies,… 15 cling[0].L func0.C cling[1] func0(); cling[2].U func0.C cling[3] int func0 = 0; CHEP'09 Axel Naumann, Philippe Canal

More Challenges Prompt: use prompt namespace, incremental linking Dynamic scope: automatic variable names “Multithreading” (multiple interpreter objects): make LLVM thread-safe where needed (rare), use new, thread-safe Reflex as reflection database PyROOT, ROOT’s python interpreter interface : "llvm-py provides Python bindings for LLVM" 16 new TFile("f.root"); cling.delay("hist->Draw()"); new TFile("f.root"); hist->Draw(); transform CHEP'09 Axel Naumann, Philippe Canal

Objective Aim at full-blown replacement for existing solutions: parser replaces CINT, GCCXML type info from clang replaces rootcint, genreflex interpreter replaces CINT JIT replaces ACLiC (.L MyCode.C+) Works with GCC / MSVC / … as native compiler No need to switch to LLVM as compiler! CHEP'09 Axel Naumann, Philippe Canal

Summary LLVM and clang: exciting and promising! Compile a list of ingredients for a C++ interpreter and code parser for reflection extraction: clang + LLVM is an incredibly good match. Proof-of-concept exists, first steps in prompt, JIT, unloading, calling into shared libraries: CINT will have a competitor! CHEP'09 Axel Naumann, Philippe Canal

cling: C++ Interpreter Demo CHEP'09 Axel Naumann, Philippe Canal19 #include "/usr/include/expat.h" #include int xml() { printf("%s\n", XML_ExpatVersion()); return 0; } xml.h [cling]$ auto s = "hello"; printf("%s\n", s); cling errors.h [cling]$.L /usr/lib64/libexpat.so [cling]$.x xml.h