SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Downloaden Sie, um offline zu lesen
LLVM Compiler
LinkTimeOptimization
Wednesday, 16 October 13
Introduction To LLVM
• collection of modular and reusable compiler and tools
• formerly Low Level Virtual Machine
• spawned a wide variety of front ends like ActionScript,
Ada, D, Fortran, GLSL, Haskell, Java bytecode, Julia,
Objective-C, Python, Ruby, Rust, Scala and C#.
• supports several backends like ARM, Hexagon,
MBlaze, MIPS, Nvidia PTX ,PowerPC, SPARC, z/
Architecture , x86/x86-64, XCore
Wednesday, 16 October 13
Overview of tools
• bugpoint is the automatic test case reduction tool.
• clang is the Clang C, C++, and Objective-C compiler.
• llc iis the LLVM static compiler
• llvm-as is the LLVM assembler
• llvm-bcanalyzer is the LLVM bitcode analyzer.
• llvm-dis is the LLVM disassembler.
• llvm-link is the LLVM linker.
• llvm-nm is used to list LLVM bitcode and object file's
symbol table
Wednesday, 16 October 13
LLVM Feature
Link Time Optimization
• intermodular optimizations which can be used at link
time
• treates LLVM bitcode files like native object files and
allows mixing and matching
• let the developer take advantage of intermodular
optimizations without making any significant changes
to the developer’s makefiles or build system
• libLTO, a shared object, to handle LLVM bitcode files
Wednesday, 16 October 13
Example
--- a.h ---
extern int foo1(void);
extern void foo2(void);
extern void foo4(void);
--- a.c ---
#include "a.h"
static signed int i = 0;
void foo2(void) {
i = -1;
}
static int foo3() {
foo4();
return 10;
}
int foo1(void) {
int data = 0;
if (i < 0)
data = foo3();
data = data + 42;
return data;
}
--- main.c ---
#include <stdio.h>
#include "a.h"
void foo4(void) {
printf("Hin");
}
int main() {
return foo1();
}
% clang -emit-llvm -c a.c -o a.o # <-- a.o is LLVM bitcode file
% clang -c main.c -o main.o # <-- main.o is native object file
% clang a.o main.o -o main # <-- link command without modifications
Wednesday, 16 October 13
How it works?
Phase 1 : Read LLVM Bit code Files
The linker first reads all object files.
the linker calls lto_module_create()for non native object file.
If object file is LLVM bit code then lto_module_get_symbol_name() and
lto_module_get_symbol_attribute() are used.
result --> linker’s global table.
The lto* -> libLTO. This allows the LLVM LTO code to be updated independently of the linker tool. lazy loading.
Phase 2 : Symbol Resolution
The linker resolves symbols using global symbol table.
Reports Error.
The linker is able to do this seamlessly even though it does not know the exact content of input
LLVM bit code files.
Wednesday, 16 October 13
continue...
Phase 3 : Optimize Bit code Files
the linker tells the LTO shared object which symbols are needed by native object files
using lto_codegen_add_must_preserve_symbol().
Next the linker invokes the LLVM optimizer and code generators using
lto_codegen_compile() which returns a native object file creating by merging the
LLVM bit code files and applying various optimization passes.
Phase 4 : Symbol Resolution after optimization
The linker reads optimized a native object file and updates the internal global symbol table.
The linker also collects information about any changes in use of external symbols by LLVM bitcode
files. In the example above, the linker notes that foo4() is not used any more.
So performs dead code stripping.
After this phase, the linker continues linking as if it never saw LLVM bit code files.
Wednesday, 16 October 13
libLTO
libLTO is a shared object that is part of the LLVM tools, and is intended for use by a linker.
A non-native object file is handled via an lto_module_t. The following functions allow the linker to check
if a file (on disk or in a memory buffer) is a file which libLTO can process:
lto_module_is_object_file(const char*)
lto_module_is_object_file_for_target(const char*, const char*)
lto_module_is_object_file_in_memory(const void*, size_t)
lto_module_is_object_file_in_memory_for_target(const void*, size_t, const char*)
If the object file can be processed by libLTO, the linker creates a lto_module_t by using one of:
lto_module_create(const char*)
lto_module_create_from_memory(const void*, size_t)
and when done, the handle is released via
lto_module_dispose(lto_module_t)
The linker can introspect the non-native object file by getting the number of symbols and getting the
name and attributes of each symbol via:
lto_module_get_num_symbols(lto_module_t)
lto_module_get_symbol_name(lto_module_t, unsigned int)
lto_module_get_symbol_attribute(lto_module_t, unsigned int)
The attributes of a symbol include the alignment, visibility, and kind.
Wednesday, 16 October 13
lto_code_gen_t
Once the linker has loaded each non-native object files into an lto_module_t, it can request libLTO to process
them all and generate a native object file. This is done in a couple of steps. First, a code generator is created
with:
lto_codegen_create()
Then, each non-native object file is added to the code generator with:
lto_codegen_add_module(lto_code_gen_t, lto_module_t)
The linker then has the option of setting some codegen options. Whether or not to generate DWARF debug
info is set with:
lto_codegen_set_debug_model(lto_code_gen_t)
Which kind of position independence is set with:
lto_codegen_set_pic_model(lto_code_gen_t)
And each symbol that is referenced by a native object file or otherwise must not be optimized away is set with:
lto_codegen_add_must_preserve_symbol(lto_code_gen_t, const char*)
After all these settings are done, the linker requests that a native object file be created from the modules with
the settings using:
lto_codegen_compile(lto_code_gen_t, size*)
which returns a pointer to a buffer containing the generated native object file. The linker then parses that and
links it with the rest of the native object files.
Wednesday, 16 October 13
Reference
• http://llvm.org/docs/LinkTimeOptimization.html
• http://llvm.org/releases/download.html#3.3
• http://en.wikipedia.org/wiki/Llvm
Wednesday, 16 October 13

Weitere ähnliche Inhalte

Was ist angesagt?

Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
Thesis - LLVM toolchain support as a plug-in for Eclipse CDTThesis - LLVM toolchain support as a plug-in for Eclipse CDT
Thesis - LLVM toolchain support as a plug-in for Eclipse CDTTuononenP
 
不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)Douglas Chen
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_ivNico Ludwig
 
llvm-py: Writing Compilers In Python
llvm-py: Writing Compilers In Pythonllvm-py: Writing Compilers In Python
llvm-py: Writing Compilers In Pythonmdevan
 
Clang Analyzer Tool Review
Clang Analyzer Tool ReviewClang Analyzer Tool Review
Clang Analyzer Tool ReviewDoug Schuster
 
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...AboutYouGmbH
 
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....AboutYouGmbH
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005Saleem Ansari
 
GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?Saket Pathak
 
LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723Iftach Ian Amit
 
Turbo C Compiler Reports
Turbo C Compiler Reports Turbo C Compiler Reports
Turbo C Compiler Reports Sunil Kumar R
 
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...Mickael Istria
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux Mohammad Golyani
 

Was ist angesagt? (20)

Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
Thesis - LLVM toolchain support as a plug-in for Eclipse CDTThesis - LLVM toolchain support as a plug-in for Eclipse CDT
Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
 
不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)
 
LLVM Compiler
LLVM CompilerLLVM Compiler
LLVM Compiler
 
MinGw Compiler
MinGw CompilerMinGw Compiler
MinGw Compiler
 
GCC, GNU compiler collection
GCC, GNU compiler collectionGCC, GNU compiler collection
GCC, GNU compiler collection
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
 
llvm-py: Writing Compilers In Python
llvm-py: Writing Compilers In Pythonllvm-py: Writing Compilers In Python
llvm-py: Writing Compilers In Python
 
Clang Analyzer Tool Review
Clang Analyzer Tool ReviewClang Analyzer Tool Review
Clang Analyzer Tool Review
 
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
 
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005
 
GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?
 
LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723
 
C#unit4
C#unit4C#unit4
C#unit4
 
Turbo C Compiler Reports
Turbo C Compiler Reports Turbo C Compiler Reports
Turbo C Compiler Reports
 
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
 
Mini-Training: TypeScript
Mini-Training: TypeScriptMini-Training: TypeScript
Mini-Training: TypeScript
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux
 
C under Linux
C under LinuxC under Linux
C under Linux
 
JAVA BYTE CODE
JAVA BYTE CODEJAVA BYTE CODE
JAVA BYTE CODE
 

Ähnlich wie LLVM Compiler - Link Time Optimization

An Overview of LLVM Link Time Optimization
An Overview of LLVM Link Time Optimization An Overview of LLVM Link Time Optimization
An Overview of LLVM Link Time Optimization Vivek Pandya
 
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotoolsThierry Gayet
 
Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerGonçalo Gomes
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain艾鍗科技
 
DLL Design with Building Blocks
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building BlocksMax Kleiner
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3aminmesbahi
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkAnne Nicolas
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckAndrey Karpov
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxoscars29
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
 
Legacy of Void*
Legacy of Void*Legacy of Void*
Legacy of Void*Adam Crain
 
ROS Based Programming and Visualization of Quadrotor Helicopters
ROS Based Programming and Visualization of Quadrotor HelicoptersROS Based Programming and Visualization of Quadrotor Helicopters
ROS Based Programming and Visualization of Quadrotor HelicoptersAtılay Mayadağ
 

Ähnlich wie LLVM Compiler - Link Time Optimization (20)

An Overview of LLVM Link Time Optimization
An Overview of LLVM Link Time Optimization An Overview of LLVM Link Time Optimization
An Overview of LLVM Link Time Optimization
 
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotools
 
64-bit Loki
64-bit Loki64-bit Loki
64-bit Loki
 
COM Introduction
COM IntroductionCOM Introduction
COM Introduction
 
Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic Linker
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 
Libraries
LibrariesLibraries
Libraries
 
DLL Design with Building Blocks
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building Blocks
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver framework
 
Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
COM
COMCOM
COM
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd Check
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docx
 
interview questions.docx
interview questions.docxinterview questions.docx
interview questions.docx
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 
Legacy of Void*
Legacy of Void*Legacy of Void*
Legacy of Void*
 
ROS Based Programming and Visualization of Quadrotor Helicopters
ROS Based Programming and Visualization of Quadrotor HelicoptersROS Based Programming and Visualization of Quadrotor Helicopters
ROS Based Programming and Visualization of Quadrotor Helicopters
 

Kürzlich hochgeladen

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Kürzlich hochgeladen (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

LLVM Compiler - Link Time Optimization

  • 2. Introduction To LLVM • collection of modular and reusable compiler and tools • formerly Low Level Virtual Machine • spawned a wide variety of front ends like ActionScript, Ada, D, Fortran, GLSL, Haskell, Java bytecode, Julia, Objective-C, Python, Ruby, Rust, Scala and C#. • supports several backends like ARM, Hexagon, MBlaze, MIPS, Nvidia PTX ,PowerPC, SPARC, z/ Architecture , x86/x86-64, XCore Wednesday, 16 October 13
  • 3. Overview of tools • bugpoint is the automatic test case reduction tool. • clang is the Clang C, C++, and Objective-C compiler. • llc iis the LLVM static compiler • llvm-as is the LLVM assembler • llvm-bcanalyzer is the LLVM bitcode analyzer. • llvm-dis is the LLVM disassembler. • llvm-link is the LLVM linker. • llvm-nm is used to list LLVM bitcode and object file's symbol table Wednesday, 16 October 13
  • 4. LLVM Feature Link Time Optimization • intermodular optimizations which can be used at link time • treates LLVM bitcode files like native object files and allows mixing and matching • let the developer take advantage of intermodular optimizations without making any significant changes to the developer’s makefiles or build system • libLTO, a shared object, to handle LLVM bitcode files Wednesday, 16 October 13
  • 5. Example --- a.h --- extern int foo1(void); extern void foo2(void); extern void foo4(void); --- a.c --- #include "a.h" static signed int i = 0; void foo2(void) { i = -1; } static int foo3() { foo4(); return 10; } int foo1(void) { int data = 0; if (i < 0) data = foo3(); data = data + 42; return data; } --- main.c --- #include <stdio.h> #include "a.h" void foo4(void) { printf("Hin"); } int main() { return foo1(); } % clang -emit-llvm -c a.c -o a.o # <-- a.o is LLVM bitcode file % clang -c main.c -o main.o # <-- main.o is native object file % clang a.o main.o -o main # <-- link command without modifications Wednesday, 16 October 13
  • 6. How it works? Phase 1 : Read LLVM Bit code Files The linker first reads all object files. the linker calls lto_module_create()for non native object file. If object file is LLVM bit code then lto_module_get_symbol_name() and lto_module_get_symbol_attribute() are used. result --> linker’s global table. The lto* -> libLTO. This allows the LLVM LTO code to be updated independently of the linker tool. lazy loading. Phase 2 : Symbol Resolution The linker resolves symbols using global symbol table. Reports Error. The linker is able to do this seamlessly even though it does not know the exact content of input LLVM bit code files. Wednesday, 16 October 13
  • 7. continue... Phase 3 : Optimize Bit code Files the linker tells the LTO shared object which symbols are needed by native object files using lto_codegen_add_must_preserve_symbol(). Next the linker invokes the LLVM optimizer and code generators using lto_codegen_compile() which returns a native object file creating by merging the LLVM bit code files and applying various optimization passes. Phase 4 : Symbol Resolution after optimization The linker reads optimized a native object file and updates the internal global symbol table. The linker also collects information about any changes in use of external symbols by LLVM bitcode files. In the example above, the linker notes that foo4() is not used any more. So performs dead code stripping. After this phase, the linker continues linking as if it never saw LLVM bit code files. Wednesday, 16 October 13
  • 8. libLTO libLTO is a shared object that is part of the LLVM tools, and is intended for use by a linker. A non-native object file is handled via an lto_module_t. The following functions allow the linker to check if a file (on disk or in a memory buffer) is a file which libLTO can process: lto_module_is_object_file(const char*) lto_module_is_object_file_for_target(const char*, const char*) lto_module_is_object_file_in_memory(const void*, size_t) lto_module_is_object_file_in_memory_for_target(const void*, size_t, const char*) If the object file can be processed by libLTO, the linker creates a lto_module_t by using one of: lto_module_create(const char*) lto_module_create_from_memory(const void*, size_t) and when done, the handle is released via lto_module_dispose(lto_module_t) The linker can introspect the non-native object file by getting the number of symbols and getting the name and attributes of each symbol via: lto_module_get_num_symbols(lto_module_t) lto_module_get_symbol_name(lto_module_t, unsigned int) lto_module_get_symbol_attribute(lto_module_t, unsigned int) The attributes of a symbol include the alignment, visibility, and kind. Wednesday, 16 October 13
  • 9. lto_code_gen_t Once the linker has loaded each non-native object files into an lto_module_t, it can request libLTO to process them all and generate a native object file. This is done in a couple of steps. First, a code generator is created with: lto_codegen_create() Then, each non-native object file is added to the code generator with: lto_codegen_add_module(lto_code_gen_t, lto_module_t) The linker then has the option of setting some codegen options. Whether or not to generate DWARF debug info is set with: lto_codegen_set_debug_model(lto_code_gen_t) Which kind of position independence is set with: lto_codegen_set_pic_model(lto_code_gen_t) And each symbol that is referenced by a native object file or otherwise must not be optimized away is set with: lto_codegen_add_must_preserve_symbol(lto_code_gen_t, const char*) After all these settings are done, the linker requests that a native object file be created from the modules with the settings using: lto_codegen_compile(lto_code_gen_t, size*) which returns a pointer to a buffer containing the generated native object file. The linker then parses that and links it with the rest of the native object files. Wednesday, 16 October 13