clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the...
Transcript of clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the...
![Page 1: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/1.jpg)
OCL OMP
clangreinven&ng the compiler
C Obj-C
���1
C++
Alp Toker h3p://www.nuan&.com
![Page 2: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/2.jpg)
Overview
• What can we achieve going beyond compilation?
• Why are we compelled to invent a better wheel?
• How can we make everyday life better for coders?
• Could the compiler itself become an instrument for wider social change?
���2
![Page 3: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/3.jpg)
Clang in a Nutshell
LLVM backend
clang frontend
lld linker
clang driver
clang-cl driver
���3
![Page 4: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/4.jpg)
CodeGen to LLVM IR
Analysis ARCMigrate AST ASTMatchers Basic CodeGen Driver Edit Format Frontend FrontendTool Headers Index Lex Parse Rewrite Sema Serialization StaticAnalyzer Tooling
Sema semantic analysis
Parse semantic analysis
Lex tokenization and preprocessing
AST syntax tree
Analyzer static analysis
���4
clang frontend “lowering”
![Page 5: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/5.jpg)
Plugins & frontend
passesRewrite
& other utilities
Tooling build-your-own
CIndex indexing engine
libclang stable C API
���5
![Page 6: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/6.jpg)
Why invent a be;er wheel?
���6
![Page 7: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/7.jpg)
MSVC support is coming. But why are we even doing this?
���7
![Page 8: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/8.jpg)
���8
![Page 9: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/9.jpg)
���9
ISO CObjec&ve C
ISO C++
a kind of geekyRose;a stone
MicrosoE Visual C++
OpenCL
OpenMP
![Page 10: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/10.jpg)
3.5: MSVC CompaJbility
• More significant than just Windows support
• Unusual parsing
• Name mangling
• Built-in types
• Delayed template parsing���10
![Page 11: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/11.jpg)
clang-‐cl.exe
• A cl.exe drop-in replacement driver
• Visual Studio integration
���11
![Page 12: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/12.jpg)
���12
![Page 13: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/13.jpg)
���13
![Page 14: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/14.jpg)
How?
���14
![Page 15: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/15.jpg)
The Clang Parser
• Hand-written recursive-descent parser.
• A single unified parser for C/C++/ObjC
• (Mostly) decoupled from the AST representation
���15
![Page 16: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/16.jpg)
Clang SemanJc Analysis
• Sema: The brains of the operation.
• Builds the AST and computes types, linkage etc.
• Some problems here too.
���16
![Page 17: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/17.jpg)
What next?
���17
![Page 18: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/18.jpg)
The road to Faster CompilaJon
• In-process execution currently under investigation
• Multi-TU compilation supporting modules
• Cached resources across invocations
• Use MCJIT for constexpr compile-time evaluation?
���18
![Page 19: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/19.jpg)
Spot the problem in this code…
���19
bool ProcessingFailed = for (unsigned std::string // FIXME: chdir is thread hostile; on the other hand, creating the same // behavior as chdir is complex: chdir resolves the path once, thus // guaranteeing that all subsequent relative path operations work // on the same path the original chdir resulted in. This makes a difference // for example on network filesystems, where symlinks might be switched // during runtime of the tool. Fixing this depends on having a file system // abstraction that allows openat() style interactions. if (chdir llvm:: std::vector for (unsigned CommandLine = assert(!CommandLine. CommandLine[ // FIXME: We need a callback mechanism for the tool writer to output a // customized message for each file. DEBUG({ llvm:: });
![Page 20: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/20.jpg)
Time for Compiler Accessibility?• Vision and motion impaired users code too.
• Hierarchical documents lend themselves to universal access:
• The AST is a natural representation here to get started.
• Code completion machinery can help select inputs and refactoring will enable edits out of scope.
• Diagnostics can be annotated for voice output.
• We have all the technology today, yet no a11y story to speak of.���20
![Page 21: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/21.jpg)
Clang & the Linux Kernel
• clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode.
• Integrated ASM parser support imminent for all .S files
• Users & developers joining the LLVM community to fulfil their needs.
���21
LLVMLinux 11:00 AM
![Page 22: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/22.jpg)
The Clang AST• Abstract Syntax Tree represented as a C++ class hierarchy
• Uses LLVM’s casting system, not RTTI
• Informal representation, some problems here:
• Objective-C duplication. Function/Method, Interface/Record/Class…
• Some semantic analysis still “performed” by AST
• Type system omits linkage & other details, time to address this?���22
![Page 23: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/23.jpg)
���23
LLVM and Clang are defending your SoEware Freedom. Here’s how…
![Page 24: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/24.jpg)
���24
!
(That’s called defending your Software Freedom.)
Vendors are switching:
From 100% proprietary toolchains to 90%-100% Free Software compiler stacks built around clang.
(Freedom #1)
the freedom to innovate
![Page 25: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/25.jpg)
���25
(Freedom #2)
![Page 26: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/26.jpg)
LLVM Community 2.0
• Do we approach controversial issues effectively?
• What makes a patch acceptable?
• Do we welcome new contributors or is there an initiation by fire?
• How should we handle non-code contributions?���26
![Page 27: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/27.jpg)
1.5m LoC30 active developers 500 commits per month
Clang Zeitgeist 2014
���27
![Page 28: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/28.jpg)
Some introspecJve quesJons…
• Where does our infrastructure come from?
• Is there a framework to deal with emergencies and existential threats to our project?
• Do we have transparent oversight?
• How about…���28
![Page 29: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/29.jpg)
���29
LLVM Founda&oncompilers for everyone
[ proposal ] [ draft ] [ please-‐review ]
![Page 30: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/30.jpg)
Planet Clang http://planet.clang.org
LLVM Weekly http://llvmweekly.org
���30
![Page 31: clang - LLVM · 2019-10-30 · Clang&theLinuxKernel • clang -m16: Code generation to support the x86 boot loader appropriate for a CPU running in 16-bit mode." • Integrated ASM](https://reader034.fdocuments.in/reader034/viewer/2022042612/5f52f45ab9ba5a5f923a0a98/html5/thumbnails/31.jpg)
OpJmizer pragmas & a;ributes
• A desire to offer hands-on control over the LLVM code generation and optimizer.
• Vectorization attributes
• optnone — or more granularity?
���31
Auto-vectorization 11:00 AM