SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Downloaden Sie, um offline zu lesen
Welcome to my short presentation with a long title :)
I'm currently working for Nokia where we're moving part of software from base station into cloud –
hence the name of our team – Miotacze Piorunów.
I think that direct translation would be “lighting throwers”, but I'm not sure.
We even have a flag! :)
How do we perceive compilers?
Most of the time when we think about them we have similar picture in our minds.
There's a back box, which is being feed with C++ in order to produce some binary - presumably for
x86 machines.
Besides the fact the picture is oversimplified, there's nothing wrong with it. However, if we make a
little step towards reality...
… we get something like this.
Not only C and C++ are supported by C++ compilers.
Other languages like Google Go or Objective-C are also supported.
Afaik GCC support 9 languages out of the box.
And of course you can provide an implementation for your own (custom) language.
Same thing can be said about possible targets..
It's kind of insane, but GCC supports more than 60 targets! That's just amazing.
Cheerp is an interesting example of how flexible compilers can be.
It's modified clang and it allows you to write isomorphic web apps in C++!
The funny thing is that instead of producing a binary it produces… JavaScript.
How it's even possible? Mainly because modular architecture.
The picture is of course oversimplified, as almost everything in the presentation.
There's clear split between the front-end and the back-end.
Front-end responsibility is to convert input language into “an internal representation”.
The IR is an interface between the two guys.
Most of the things happen in the backend – optimizations, code generation, more optimizations etc.
Frontent is relatively simple, when compared to the backend.
Lots of problems (NP-hard, NP-complete) are solved by compilers. They're huge and complex.
How do we control their behavior, then?
With command line switches!
When we're learning C++ we are simultaneously learning how to use our favorite compiler. We start
with knowing little things like -o.
Then we discover how to do much more: static libs, shared libs.
Then how to control verbosity, optimizations and so on.
Eventually we become ninjas. Detaching STD lib or preprocessor? Why not :)
I have made small research to see how customizable GCC is compared to other common tools.
There's huge gap between GCC and other Linux tools.
The only two players that are close are Google Chrome (which is like a virtual machine btw) and git. I
wasn't surprised about git :)
I know it's not a perfect measure, but it definitely tells us something – compilers are highly
customizable.
Similarly to previous image, the relation between C++ standard and compilers seems to be simple.
There's one international specification which is being implemented by multiple vendors.
Hence we have different compilers.
Easy, isn't it?
If you look for implementation-defined stuff in the standard, you're going to find more than 100 items.
This leaves room for compilers to differ.
However, there's one more evil thing out there.
Yes, you're right.
C++ standard (C++14 working draft to be precise) contains over 100 occurrences of “is undefined”
phrase. Crazy.
Even if you're seasoned programmer you are likely to introduce bugs to applications. The worst thing is
that you're not gonna notice that until something breaks in production.
Programming in C++ used to be like going into dark cave without a flashlight, knowing that you may
be bitten by a snake.
Fortunately, the situation is getting better.
Modern compilers are shipped with tools that help to find different kind of problems.
One of these tools is undefined behavior sanitizer.
The idea behind UBSan is that the compiler instruments the code so that in runtime it can detect Ubs.
This isn't without cost. It slows down execution ~ 2-3x. It is definitely good to give it a try in tests,
though.
Programmer, for different kinds of UB can choose the behavior – trap instruction, print & continue, or
print & exit.
With UBSan there's simply more control.
Optimizations are everywhere.
They do start in the fronend (AST), then they are apparent at IR phase, GEN phase. Even after creating
object files we have optimizations.
Special information is encoded within object files so the link time optimizer can kick in and optimize at
the top level.
There are also run-time optimizations, like profile guided optimization or recently announced
efficiency sanitizer which hopefully will join C++ world.
Other important thing about optimizing is that we tend to underestimate the compiler. We also try to
outsmart compiler sometimes.
E.g. instead of traditional approach to swapping one can use three XOR assignments.
Looks hacky, but is it faster indeed?
Apparently not.
A lot of knowledge has been put into compilers by smart people.
They know about CPU caches and extensions (like e.g. SIMD).
Also, not all CPUs are perfect. There may be a performance in some revision of some CPU. It's likely
that the compiler will already know about it and will avoid this instruction whilst generating code.
What about us? Do we know? Not necessarily.
Compilers look at the code generations from multiple perspectives. It's simply hard to outsmart them.
And even if you can, then why wouldn't you improve them in a first place anyway?
I've already mentioned UBSan.
We have more than that.
AddressSanitizer and MemorySanitizer allows us to spot errors related to memory (e.g. reading
uninitialized memory or ordinary memory leak).
Our apps can be subject of cracking. Some bad people can try to hijack the flow so the program does
unintended things. For protection we can use ControlFlowSanitizer. It will look for situations that could
possibly be used by hacker to take control over execution (e.g. return-oriented programming).
If our application is multi-threaded we can use ThreadSanitizer to find deadlocks, data races, etc.
And finally, recently annoucned EfficiencySanitizer will look how the performance can be improved.
E.g. it will look for write-after-write, possible reordering of fields in struct to improve cache
friendliness etc...
All of the sanitizers are likely to slow down the program.
Modern compilers are also shipped with auxiliary tools, like presented on the slide.
• Reformatting the code → clang-format
• C++ linter → clang-tidy
• Suggestions in IDE → clang-complete
• Static analysis tool → clang-analyzer
All of these tools have common part – they're using compiler as a library.
No C++ parsing is done by these tools (that was always tricky part). All of the information is obtained
from the compiler so 100% accuracy is achieved.
The list is not complete! Go read your compiler's documentation :)
It's both funny and sad that we've been having runtime debuggers for years without single compile-time
debugger.
Now we have two.
They can be used to see how templates are instantiated and memoized.
Can be quite useful in case we want to e.g. decrease compilation time or see with 100% accuracy how
templates are instantiated in our project.
Other example of how compiler can be used as libraries is Synth tool which was announced few weeks
ago.
Purpose of the tool is to convert C++ code into hyper-linked colorful HTML.
Hyperlinks of standard containers, classes, etc. redirect to C++ reference page.
And finally a tool that isn't actually strictly related to compilers, but it lives near by.
STOKE is a tool that can possibly improve performance of single functions (10, 11 instructions).
Functions' codes (little programs in fact) are treated as if they were single points in multi-dimensional
space.
Changing instruction order, adding instructions, removing them, or changing order of arguments – it's
all a move in such a space.
Compilers start in some area where instruction set composes a valid program. Then they optimize the
code within the area.
It's likely than they won't be able to jump to other (distant) areas where the code is still valid and has
better performance.
And that's the niche STOKE is focused on… maybe it's not mature now but who knows – maybe it's a
future of code optimization?
What every C++ programmer should know about modern compilers (w/ comments, ACCU 2016)

Weitere ähnliche Inhalte

Was ist angesagt?

Go language presentation
Go language presentationGo language presentation
Go language presentationparamisoft
 
Anton Kasyanov, Introduction to Python, Lecture1
Anton Kasyanov, Introduction to Python, Lecture1Anton Kasyanov, Introduction to Python, Lecture1
Anton Kasyanov, Introduction to Python, Lecture1Anton Kasyanov
 
Bridging Ousterhout's Dichotomy
Bridging Ousterhout's DichotomyBridging Ousterhout's Dichotomy
Bridging Ousterhout's Dichotomyguest2838a0
 
Are 64-bit errors real?
Are  64-bit errors real?Are  64-bit errors real?
Are 64-bit errors real?PVS-Studio
 
C plus plus for hackers it security
C plus plus for hackers it securityC plus plus for hackers it security
C plus plus for hackers it securityCESAR A. RUIZ C
 
Why you should care about Go (Golang)
Why you should care about Go (Golang)Why you should care about Go (Golang)
Why you should care about Go (Golang)Aaron Schlesinger
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#Sireesh K
 
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017Codemotion
 
G W T(2)
G W T(2)G W T(2)
G W T(2)tomcoh
 
Building a high-performance, scalable ML & NLP platform with Python, Sheer El...
Building a high-performance, scalable ML & NLP platform with Python, Sheer El...Building a high-performance, scalable ML & NLP platform with Python, Sheer El...
Building a high-performance, scalable ML & NLP platform with Python, Sheer El...Pôle Systematic Paris-Region
 
Algorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notesAlgorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notesArghodeepPaul
 
Python vs MATLAB: Which one is the best language
Python vs MATLAB:  Which one is the best languagePython vs MATLAB:  Which one is the best language
Python vs MATLAB: Which one is the best languageStat Analytica
 
Harmonic Stack for Speed
Harmonic Stack for SpeedHarmonic Stack for Speed
Harmonic Stack for SpeedYung-Yu Chen
 
Simplifying training deep and serving learning models with big data in python...
Simplifying training deep and serving learning models with big data in python...Simplifying training deep and serving learning models with big data in python...
Simplifying training deep and serving learning models with big data in python...Holden Karau
 

Was ist angesagt? (19)

Go language presentation
Go language presentationGo language presentation
Go language presentation
 
Anton Kasyanov, Introduction to Python, Lecture1
Anton Kasyanov, Introduction to Python, Lecture1Anton Kasyanov, Introduction to Python, Lecture1
Anton Kasyanov, Introduction to Python, Lecture1
 
Python and data analytics
Python and data analyticsPython and data analytics
Python and data analytics
 
Bridging Ousterhout's Dichotomy
Bridging Ousterhout's DichotomyBridging Ousterhout's Dichotomy
Bridging Ousterhout's Dichotomy
 
Are 64-bit errors real?
Are  64-bit errors real?Are  64-bit errors real?
Are 64-bit errors real?
 
Research paper on python by Rj
Research paper on python by RjResearch paper on python by Rj
Research paper on python by Rj
 
C plus plus for hackers it security
C plus plus for hackers it securityC plus plus for hackers it security
C plus plus for hackers it security
 
Why you should care about Go (Golang)
Why you should care about Go (Golang)Why you should care about Go (Golang)
Why you should care about Go (Golang)
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#
 
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
 
Beginning development in go
Beginning development in goBeginning development in go
Beginning development in go
 
G W T(2)
G W T(2)G W T(2)
G W T(2)
 
Building a high-performance, scalable ML & NLP platform with Python, Sheer El...
Building a high-performance, scalable ML & NLP platform with Python, Sheer El...Building a high-performance, scalable ML & NLP platform with Python, Sheer El...
Building a high-performance, scalable ML & NLP platform with Python, Sheer El...
 
Algorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notesAlgorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notes
 
Ruby
RubyRuby
Ruby
 
Python vs MATLAB: Which one is the best language
Python vs MATLAB:  Which one is the best languagePython vs MATLAB:  Which one is the best language
Python vs MATLAB: Which one is the best language
 
F# for Scala developers
F# for Scala developersF# for Scala developers
F# for Scala developers
 
Harmonic Stack for Speed
Harmonic Stack for SpeedHarmonic Stack for Speed
Harmonic Stack for Speed
 
Simplifying training deep and serving learning models with big data in python...
Simplifying training deep and serving learning models with big data in python...Simplifying training deep and serving learning models with big data in python...
Simplifying training deep and serving learning models with big data in python...
 

Ähnlich wie What every C++ programmer should know about modern compilers (w/ comments, ACCU 2016)

His162013 140529214456-phpapp01
His162013 140529214456-phpapp01His162013 140529214456-phpapp01
His162013 140529214456-phpapp01Getachew Ganfur
 
The Development History of PVS-Studio for Linux
The Development History of PVS-Studio for LinuxThe Development History of PVS-Studio for Linux
The Development History of PVS-Studio for LinuxPVS-Studio
 
Compilers programmingembedded
Compilers programmingembeddedCompilers programmingembedded
Compilers programmingembeddedManish Pandey
 
Possibility of arbitrary code execution by Step-Oriented Programming by Hiroa...
Possibility of arbitrary code execution by Step-Oriented Programming by Hiroa...Possibility of arbitrary code execution by Step-Oriented Programming by Hiroa...
Possibility of arbitrary code execution by Step-Oriented Programming by Hiroa...CODE BLUE
 
Possibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented ProgrammingPossibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented Programmingkozossakai
 
C++ In One Day_Nho Vĩnh Share
C++ In One Day_Nho Vĩnh ShareC++ In One Day_Nho Vĩnh Share
C++ In One Day_Nho Vĩnh ShareNho Vĩnh
 
The pragmatic programmer
The pragmatic programmerThe pragmatic programmer
The pragmatic programmerLeylimYaln
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionAKR Education
 
The Nightmare Fuzzing Suite and Blind Code Coverage Fuzzer
The Nightmare Fuzzing Suite and Blind Code Coverage FuzzerThe Nightmare Fuzzing Suite and Blind Code Coverage Fuzzer
The Nightmare Fuzzing Suite and Blind Code Coverage FuzzerJoxean Koret
 
Top 10 web development tools in 2022
Top 10 web development tools in 2022Top 10 web development tools in 2022
Top 10 web development tools in 2022intouchgroup2
 
PVS-Studio Has Finally Got to Boost
PVS-Studio Has Finally Got to BoostPVS-Studio Has Finally Got to Boost
PVS-Studio Has Finally Got to BoostAndrey Karpov
 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1benDesigning
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java ProgrammingKaty Allen
 
Makefile
MakefileMakefile
MakefileIonela
 
Cs121 Unit Test
Cs121 Unit TestCs121 Unit Test
Cs121 Unit TestJill Bell
 
Creating a compiler for your own language
Creating a compiler for your own languageCreating a compiler for your own language
Creating a compiler for your own languageAndrea Tino
 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithmshccit
 

Ähnlich wie What every C++ programmer should know about modern compilers (w/ comments, ACCU 2016) (20)

Programming in C++
Programming in C++Programming in C++
Programming in C++
 
C++ for hackers
C++ for hackersC++ for hackers
C++ for hackers
 
His162013 140529214456-phpapp01
His162013 140529214456-phpapp01His162013 140529214456-phpapp01
His162013 140529214456-phpapp01
 
The Development History of PVS-Studio for Linux
The Development History of PVS-Studio for LinuxThe Development History of PVS-Studio for Linux
The Development History of PVS-Studio for Linux
 
Compilers programmingembedded
Compilers programmingembeddedCompilers programmingembedded
Compilers programmingembedded
 
Possibility of arbitrary code execution by Step-Oriented Programming by Hiroa...
Possibility of arbitrary code execution by Step-Oriented Programming by Hiroa...Possibility of arbitrary code execution by Step-Oriented Programming by Hiroa...
Possibility of arbitrary code execution by Step-Oriented Programming by Hiroa...
 
Possibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented ProgrammingPossibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented Programming
 
C++ In One Day_Nho Vĩnh Share
C++ In One Day_Nho Vĩnh ShareC++ In One Day_Nho Vĩnh Share
C++ In One Day_Nho Vĩnh Share
 
Java
JavaJava
Java
 
The pragmatic programmer
The pragmatic programmerThe pragmatic programmer
The pragmatic programmer
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introduction
 
The Nightmare Fuzzing Suite and Blind Code Coverage Fuzzer
The Nightmare Fuzzing Suite and Blind Code Coverage FuzzerThe Nightmare Fuzzing Suite and Blind Code Coverage Fuzzer
The Nightmare Fuzzing Suite and Blind Code Coverage Fuzzer
 
Top 10 web development tools in 2022
Top 10 web development tools in 2022Top 10 web development tools in 2022
Top 10 web development tools in 2022
 
PVS-Studio Has Finally Got to Boost
PVS-Studio Has Finally Got to BoostPVS-Studio Has Finally Got to Boost
PVS-Studio Has Finally Got to Boost
 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
 
Makefile
MakefileMakefile
Makefile
 
Cs121 Unit Test
Cs121 Unit TestCs121 Unit Test
Cs121 Unit Test
 
Creating a compiler for your own language
Creating a compiler for your own languageCreating a compiler for your own language
Creating a compiler for your own language
 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithms
 

Mehr von Sławomir Zborowski

C++ Undefined Behavior (Code::Dive 2016)
C++ Undefined Behavior (Code::Dive 2016)C++ Undefined Behavior (Code::Dive 2016)
C++ Undefined Behavior (Code::Dive 2016)Sławomir Zborowski
 
What every C++ programmer should know about modern compilers (w/o comments, A...
What every C++ programmer should know about modern compilers (w/o comments, A...What every C++ programmer should know about modern compilers (w/o comments, A...
What every C++ programmer should know about modern compilers (w/o comments, A...Sławomir Zborowski
 
C++17 - the upcoming revolution (Code::Dive 2015)/
C++17 - the upcoming revolution (Code::Dive 2015)/C++17 - the upcoming revolution (Code::Dive 2015)/
C++17 - the upcoming revolution (Code::Dive 2015)/Sławomir Zborowski
 
Boost.Python - domesticating the snake
Boost.Python - domesticating the snakeBoost.Python - domesticating the snake
Boost.Python - domesticating the snakeSławomir Zborowski
 
Metaprogramming in C++ - from 70's to C++17
Metaprogramming in C++ - from 70's to C++17Metaprogramming in C++ - from 70's to C++17
Metaprogramming in C++ - from 70's to C++17Sławomir Zborowski
 
How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)Sławomir Zborowski
 

Mehr von Sławomir Zborowski (9)

C++ Undefined Behavior (Code::Dive 2016)
C++ Undefined Behavior (Code::Dive 2016)C++ Undefined Behavior (Code::Dive 2016)
C++ Undefined Behavior (Code::Dive 2016)
 
What every C++ programmer should know about modern compilers (w/o comments, A...
What every C++ programmer should know about modern compilers (w/o comments, A...What every C++ programmer should know about modern compilers (w/o comments, A...
What every C++ programmer should know about modern compilers (w/o comments, A...
 
Algorithms for Cloud Computing
Algorithms for Cloud ComputingAlgorithms for Cloud Computing
Algorithms for Cloud Computing
 
C++17 - the upcoming revolution (Code::Dive 2015)/
C++17 - the upcoming revolution (Code::Dive 2015)/C++17 - the upcoming revolution (Code::Dive 2015)/
C++17 - the upcoming revolution (Code::Dive 2015)/
 
More functional C++14
More functional C++14More functional C++14
More functional C++14
 
Boost.Python - domesticating the snake
Boost.Python - domesticating the snakeBoost.Python - domesticating the snake
Boost.Python - domesticating the snake
 
Metaprogramming in C++ - from 70's to C++17
Metaprogramming in C++ - from 70's to C++17Metaprogramming in C++ - from 70's to C++17
Metaprogramming in C++ - from 70's to C++17
 
Boost Multi Index
Boost Multi IndexBoost Multi Index
Boost Multi Index
 
How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)
 

Kürzlich hochgeladen

result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Kürzlich hochgeladen (20)

result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 

What every C++ programmer should know about modern compilers (w/ comments, ACCU 2016)

  • 1. Welcome to my short presentation with a long title :)
  • 2. I'm currently working for Nokia where we're moving part of software from base station into cloud – hence the name of our team – Miotacze Piorunów. I think that direct translation would be “lighting throwers”, but I'm not sure. We even have a flag! :)
  • 3.
  • 4.
  • 5. How do we perceive compilers? Most of the time when we think about them we have similar picture in our minds. There's a back box, which is being feed with C++ in order to produce some binary - presumably for x86 machines. Besides the fact the picture is oversimplified, there's nothing wrong with it. However, if we make a little step towards reality...
  • 6. … we get something like this.
  • 7. Not only C and C++ are supported by C++ compilers.
  • 8. Other languages like Google Go or Objective-C are also supported.
  • 9. Afaik GCC support 9 languages out of the box. And of course you can provide an implementation for your own (custom) language.
  • 10. Same thing can be said about possible targets..
  • 11.
  • 12. It's kind of insane, but GCC supports more than 60 targets! That's just amazing.
  • 13. Cheerp is an interesting example of how flexible compilers can be. It's modified clang and it allows you to write isomorphic web apps in C++! The funny thing is that instead of producing a binary it produces… JavaScript.
  • 14. How it's even possible? Mainly because modular architecture. The picture is of course oversimplified, as almost everything in the presentation. There's clear split between the front-end and the back-end. Front-end responsibility is to convert input language into “an internal representation”. The IR is an interface between the two guys.
  • 15. Most of the things happen in the backend – optimizations, code generation, more optimizations etc. Frontent is relatively simple, when compared to the backend. Lots of problems (NP-hard, NP-complete) are solved by compilers. They're huge and complex. How do we control their behavior, then?
  • 16. With command line switches! When we're learning C++ we are simultaneously learning how to use our favorite compiler. We start with knowing little things like -o. Then we discover how to do much more: static libs, shared libs. Then how to control verbosity, optimizations and so on. Eventually we become ninjas. Detaching STD lib or preprocessor? Why not :)
  • 17. I have made small research to see how customizable GCC is compared to other common tools. There's huge gap between GCC and other Linux tools. The only two players that are close are Google Chrome (which is like a virtual machine btw) and git. I wasn't surprised about git :) I know it's not a perfect measure, but it definitely tells us something – compilers are highly customizable.
  • 18.
  • 19. Similarly to previous image, the relation between C++ standard and compilers seems to be simple. There's one international specification which is being implemented by multiple vendors. Hence we have different compilers. Easy, isn't it?
  • 20.
  • 21. If you look for implementation-defined stuff in the standard, you're going to find more than 100 items. This leaves room for compilers to differ. However, there's one more evil thing out there. Yes, you're right.
  • 22. C++ standard (C++14 working draft to be precise) contains over 100 occurrences of “is undefined” phrase. Crazy.
  • 23. Even if you're seasoned programmer you are likely to introduce bugs to applications. The worst thing is that you're not gonna notice that until something breaks in production. Programming in C++ used to be like going into dark cave without a flashlight, knowing that you may be bitten by a snake. Fortunately, the situation is getting better.
  • 24. Modern compilers are shipped with tools that help to find different kind of problems. One of these tools is undefined behavior sanitizer. The idea behind UBSan is that the compiler instruments the code so that in runtime it can detect Ubs. This isn't without cost. It slows down execution ~ 2-3x. It is definitely good to give it a try in tests, though. Programmer, for different kinds of UB can choose the behavior – trap instruction, print & continue, or print & exit.
  • 25. With UBSan there's simply more control.
  • 26.
  • 27. Optimizations are everywhere. They do start in the fronend (AST), then they are apparent at IR phase, GEN phase. Even after creating object files we have optimizations. Special information is encoded within object files so the link time optimizer can kick in and optimize at the top level. There are also run-time optimizations, like profile guided optimization or recently announced efficiency sanitizer which hopefully will join C++ world.
  • 28. Other important thing about optimizing is that we tend to underestimate the compiler. We also try to outsmart compiler sometimes. E.g. instead of traditional approach to swapping one can use three XOR assignments. Looks hacky, but is it faster indeed?
  • 30. A lot of knowledge has been put into compilers by smart people. They know about CPU caches and extensions (like e.g. SIMD). Also, not all CPUs are perfect. There may be a performance in some revision of some CPU. It's likely that the compiler will already know about it and will avoid this instruction whilst generating code. What about us? Do we know? Not necessarily. Compilers look at the code generations from multiple perspectives. It's simply hard to outsmart them. And even if you can, then why wouldn't you improve them in a first place anyway?
  • 31.
  • 32. I've already mentioned UBSan. We have more than that. AddressSanitizer and MemorySanitizer allows us to spot errors related to memory (e.g. reading uninitialized memory or ordinary memory leak). Our apps can be subject of cracking. Some bad people can try to hijack the flow so the program does unintended things. For protection we can use ControlFlowSanitizer. It will look for situations that could possibly be used by hacker to take control over execution (e.g. return-oriented programming). If our application is multi-threaded we can use ThreadSanitizer to find deadlocks, data races, etc. And finally, recently annoucned EfficiencySanitizer will look how the performance can be improved. E.g. it will look for write-after-write, possible reordering of fields in struct to improve cache friendliness etc... All of the sanitizers are likely to slow down the program.
  • 33. Modern compilers are also shipped with auxiliary tools, like presented on the slide. • Reformatting the code → clang-format • C++ linter → clang-tidy • Suggestions in IDE → clang-complete • Static analysis tool → clang-analyzer All of these tools have common part – they're using compiler as a library. No C++ parsing is done by these tools (that was always tricky part). All of the information is obtained from the compiler so 100% accuracy is achieved. The list is not complete! Go read your compiler's documentation :)
  • 34. It's both funny and sad that we've been having runtime debuggers for years without single compile-time debugger. Now we have two. They can be used to see how templates are instantiated and memoized. Can be quite useful in case we want to e.g. decrease compilation time or see with 100% accuracy how templates are instantiated in our project.
  • 35. Other example of how compiler can be used as libraries is Synth tool which was announced few weeks ago. Purpose of the tool is to convert C++ code into hyper-linked colorful HTML. Hyperlinks of standard containers, classes, etc. redirect to C++ reference page.
  • 36. And finally a tool that isn't actually strictly related to compilers, but it lives near by. STOKE is a tool that can possibly improve performance of single functions (10, 11 instructions). Functions' codes (little programs in fact) are treated as if they were single points in multi-dimensional space. Changing instruction order, adding instructions, removing them, or changing order of arguments – it's all a move in such a space. Compilers start in some area where instruction set composes a valid program. Then they optimize the code within the area. It's likely than they won't be able to jump to other (distant) areas where the code is still valid and has better performance. And that's the niche STOKE is focused on… maybe it's not mature now but who knows – maybe it's a future of code optimization?