SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Introduction to LLVM
on Program Analysis
Tao He
elfinhe@gmail.com
Department of Computer Science, Sun Yat-Sen University
Department of Computer Science and Engineering, HKUST
Group Discussion
June 2012
HKUST, Hong Kong, China
1/34
Outline
 Objectives
 A quick scenario
 LLVM IR
 ‘opt’ command
 Installation of LLVM
2/34
Objectives -
What do we want to do?
3/34
Objectives
 To implement a symbolic execution engine.
 A expression-based engine [BH07]
different from
most existing implementations (path-based
engines).
 Program analysis on C programs.
 To generate static single assignment (SSA)
representation of C first.
4/34
[BH07] Domagoj Babić and Alan J. Hu. Structural Abstraction of Software Verification Conditions. In Proceedings
of the 19th international conference on Computer aided verification (CAV'07), Lecture Notes in Computer Science,
2007, Volume 4590/2007, 366-378
A Quick Scenario -
What can LLVM do?
5/34
!A Quick Scenario
6/34
 Given a C program:
 #include <stdio.h>
 int branch(int n){
 if (n>0) printf("Positiven");
 else if (n==0) printf("Zeron");
 else if (n<0) printf("Negativen");
 return 0;
 }
 int main() {
 branch(-4); branch(0); branch(6);
 return 0;
 }
!A Quick Scenario
7/34
 Generate immediate representation (IR) of
LLVM – the SSA representation in LLVM
 clang -O3 -emit-llvm hello.c -S -o hello.ll
 define i32 @main() nounwind uwtable {
 %1 = alloca i32, align 4
 store i32 0, i32* %1
 %2 = call i32 @branch(i32 -4)
 %3 = call i32 @branch(i32 0)
 %4 = call i32 @branch(i32 6)
 ret i32 0
 }
 ...
[SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes.
URL: http://llvm.org/docs/Passes.html.
!A Quick Scenario
8/34
 Print call graph
 opt method_para_int_branch.ll -S -dot-
callgraph 2>output_file >/dev/null
 dot -Tsvg in.dot -o out.svg
[SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes.
URL: http://llvm.org/docs/Passes.html.
!A Quick Scenario
9/34
 Print control flow graph (CFG)
 opt method_para_int_branch.ll -S -dot-cfg
2>output_file >/dev/null
[SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes.
URL: http://llvm.org/docs/Passes.html.
# A Quick Scenario
10/34
 More:
 Dead Global Elimination
 Interprocedural Constant Propagation
 Dead Argument Elimination
 Inlining
 Reassociation
 Loop Invariant Code Motion
 Loop Opts
 Memory Promotion
 Dead Store Elimination
 Aggressive Dead Code Elimination
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
What is the SSA representation in LLVM?
- LLVM IR
11/34
LLVM IR
12/34
 “A Static Single Assignment (SSA) based
representation that provides type safety, low-
level operations, flexibility, and the capability
of representing 'all' high-level languages
cleanly.”
[Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
LLVM IR
13/34
 Three address code
 SSA-based
 Three different forms
 An in-memory compiler IR
 An on-disk bitcode representation (suitable for
fast loading by a Just-In-Time compiler)
 A human readable assembly language
representation
[Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
LLVM IR
14/34
 An example
 To multiply the integer variable '%X' by 8
 Syntax:
 <result> = mul <ty> <op1>, <op2>
 IR code:
 %result = mul i32 %X, 8
 More
 For floating point, use fmul
[Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
LLVM IR
15/34
 Another example
 Instruction jump – to change control flow
 Branches or loops
 Syntax:
 br i1 <cond>, label <iftrue>, label <iffalse>
 br label <dest> ; Unconditional branch
[Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
LLVM IR
16/34
 IR code:
 Test:
 %cond = icmp eq i32 %a, %b
 br i1 %cond, label %IfEqual, label %IfUnequal
 IfEqual:
 ret i32 1
 IfUnequal:
[Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
LLVM IR
17/34
 3rd
example
 Function call
 A simplified syntax:
 <result> = call <ty> <fnptrval>(<function args>)
 IR code:
 call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42)
[Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
LLVM IR
18/34
 4th
example
 Function definition
 A simplified syntax:
 define <ResultType> @<FunctionName> ([argument list]) { ... }
 IR code:
 define i32 @main() { … }
 define i32 @test(i32 %X, ...) { … }
[Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
LLVM IR
19/34
 The majority of instructions in C programs:
 Operations (binary/bitwise)
 Jumps
 Function calls
 Function definitions
 Many keywords in LLVM IR will not be
used for C programs. (e.g., invoke)
[Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
How to analyze programs
by using LLVM?
- ‘opt’ command
20/34
‘opt’ command
 Compiler is organized as a series of ‘passes’:
 Each pass is one analysis or transformation
21/34
[SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes.
URL: http://llvm.org/docs/Passes.html.
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
!‘opt’ command
 An example
 -dot-callgraph
22/34
[SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes.
URL: http://llvm.org/docs/Passes.html.
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
!‘opt’ command
23/34
An example
Print call graph: -dot-callgraph
 opt method_para_int_branch.ll -S -dot-
callgraph 2>output_file >/dev/null
 dot -Tsvg in.dot -o out.svg
[SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes.
URL: http://llvm.org/docs/Passes.html.
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
How to write your own pass?
24/34
How to write your own pass?
 Four types of pass:
 ModulePass: general interprocedural pass
 CallGraphSCCPass: bottom-up on the call graph
 FunctionPass: process a function at a time
 BasicBlockPass: process a basic block at a time
25/34
How to write your own pass?
 Two important classes
 User: http://llvm.org/docs/doxygen/html/classllvm_1_1User.html
 This class defines the interface that one who uses a
Value must implement.
 Instructions
 Constants
 Operators
 Value: http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html
 It is the base class of all values computed by a
program that may be used as operands to other
values.
 e.g., instruction and function.
26/34
How to write your own pass?
 An example – print function names
27/34
How to write your own pass?
 An example – print function names
 First generate bytecode:
 clang -emit-llvm hello.c -o hello.bc
 Then
28/34
How to write your own pass?
 Another example – print def-use chain
29/34
How to install LLVM?
30/34
How to install LLVM?
 To compile programs faster and use built-in
transformation and analysis
 Install both ‘llvm’ and ‘clang’ from package
management software
 E.g., Synaptic, yum, apt.
 To write your own pass
 Build from source code and add your own pass
 http://llvm.org/docs/GettingStarted.html#quickstart
 http://llvm.org/docs/WritingAnLLVMPass.html
31/34
LLVM IR
32/34
 The majority of instructions in C programs:
 Operation (binary/bitwise)
 Jump
 Function call
 Function definition
[Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html
[LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini
Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
Q & A
33/34
Thank you!
Contact me via elfinhe@gmail.com
34/34

Weitere ähnliche Inhalte

Was ist angesagt?

Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)Shivang Bajaniya
 
LinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeLinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeAlain Leon
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answersAdenKheire
 
Installation of PC-Lint and its using in Visual Studio 2005
Installation of PC-Lint and its using in Visual Studio 2005Installation of PC-Lint and its using in Visual Studio 2005
Installation of PC-Lint and its using in Visual Studio 2005PVS-Studio
 
Linker and loader upload
Linker and loader   uploadLinker and loader   upload
Linker and loader uploadBin Yang
 
Towards easy program migration using language virtualization
 Towards easy program migration using language virtualization Towards easy program migration using language virtualization
Towards easy program migration using language virtualizationESUG
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Languagezefhemel
 
Nakov dot net-framework-overview-english
Nakov dot net-framework-overview-englishNakov dot net-framework-overview-english
Nakov dot net-framework-overview-englishsrivathsan.10
 
Overview of c++
Overview of c++Overview of c++
Overview of c++geeeeeet
 
Compilation of c
Compilation of cCompilation of c
Compilation of cWay2itech
 
Tail Call Elimination in Open Smalltalk
Tail Call Elimination in Open SmalltalkTail Call Elimination in Open Smalltalk
Tail Call Elimination in Open SmalltalkESUG
 
Net Framework Overview
Net Framework OverviewNet Framework Overview
Net Framework OverviewLuis Goldster
 
In-depth look at the Flex compiler and HFCD
In-depth look at the Flex compiler and HFCDIn-depth look at the Flex compiler and HFCD
In-depth look at the Flex compiler and HFCDStop Coding
 
CORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorialCORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorialRemedy IT
 
OFI libfabric Tutorial
OFI libfabric TutorialOFI libfabric Tutorial
OFI libfabric Tutorialdgoodell
 

Was ist angesagt? (20)

Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)
 
LinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeLinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik Bytecode
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answers
 
Installation of PC-Lint and its using in Visual Studio 2005
Installation of PC-Lint and its using in Visual Studio 2005Installation of PC-Lint and its using in Visual Studio 2005
Installation of PC-Lint and its using in Visual Studio 2005
 
Linker and loader upload
Linker and loader   uploadLinker and loader   upload
Linker and loader upload
 
Towards easy program migration using language virtualization
 Towards easy program migration using language virtualization Towards easy program migration using language virtualization
Towards easy program migration using language virtualization
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Language
 
Nakov dot net-framework-overview-english
Nakov dot net-framework-overview-englishNakov dot net-framework-overview-english
Nakov dot net-framework-overview-english
 
Overview of c++
Overview of c++Overview of c++
Overview of c++
 
C++vs java
C++vs javaC++vs java
C++vs java
 
Compilation of c
Compilation of cCompilation of c
Compilation of c
 
C compilation process
C compilation processC compilation process
C compilation process
 
Tail Call Elimination in Open Smalltalk
Tail Call Elimination in Open SmalltalkTail Call Elimination in Open Smalltalk
Tail Call Elimination in Open Smalltalk
 
Net Framework Overview
Net Framework OverviewNet Framework Overview
Net Framework Overview
 
How a Compiler Works ?
How a Compiler Works ?How a Compiler Works ?
How a Compiler Works ?
 
In-depth look at the Flex compiler and HFCD
In-depth look at the Flex compiler and HFCDIn-depth look at the Flex compiler and HFCD
In-depth look at the Flex compiler and HFCD
 
C Programming - Refresher - Part I
C Programming - Refresher - Part I C Programming - Refresher - Part I
C Programming - Refresher - Part I
 
CORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorialCORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorial
 
OFI libfabric Tutorial
OFI libfabric TutorialOFI libfabric Tutorial
OFI libfabric Tutorial
 
Mixing Python and Java
Mixing Python and JavaMixing Python and Java
Mixing Python and Java
 

Ähnlich wie Introduction to LLVM for Program Analysis Using the 'opt' Command

.NET Profilers and IL Rewriting - DDD Melbourne 2
.NET Profilers and IL Rewriting - DDD Melbourne 2.NET Profilers and IL Rewriting - DDD Melbourne 2
.NET Profilers and IL Rewriting - DDD Melbourne 2Shaun Wilde
 
Eclipse Visualization and Performance Monitoring
Eclipse Visualization and Performance MonitoringEclipse Visualization and Performance Monitoring
Eclipse Visualization and Performance MonitoringChris Laffra
 
Chap_6Lesson02Emsys3EInterruptBasedIOs.pdf
Chap_6Lesson02Emsys3EInterruptBasedIOs.pdfChap_6Lesson02Emsys3EInterruptBasedIOs.pdf
Chap_6Lesson02Emsys3EInterruptBasedIOs.pdfMAHESHV559910
 
torque - Automation Testing Tool for C-C++ on Linux
torque -  Automation Testing Tool for C-C++ on Linuxtorque -  Automation Testing Tool for C-C++ on Linux
torque - Automation Testing Tool for C-C++ on LinuxJITENDRA LENKA
 
Aspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NETAspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NETWaqas Tariq
 
LDTT : A Low Level Driver Unit Testing Tool
LDTT : A Low Level Driver Unit Testing Tool LDTT : A Low Level Driver Unit Testing Tool
LDTT : A Low Level Driver Unit Testing Tool ijseajournal
 
Linaro Connect 2016 (BKK16) - Introduction to LISA
Linaro Connect 2016 (BKK16) - Introduction to LISALinaro Connect 2016 (BKK16) - Introduction to LISA
Linaro Connect 2016 (BKK16) - Introduction to LISAPatrick Bellasi
 
Project_Report (BARC-Jerin)_final
Project_Report (BARC-Jerin)_finalProject_Report (BARC-Jerin)_final
Project_Report (BARC-Jerin)_finalJerin John
 
LIBPF: A LIBRARY FOR PROCESS FLOWSHEETING IN C++
LIBPF: A LIBRARY FOR PROCESS FLOWSHEETING IN C++LIBPF: A LIBRARY FOR PROCESS FLOWSHEETING IN C++
LIBPF: A LIBRARY FOR PROCESS FLOWSHEETING IN C++libpf
 
.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
 
OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysislienhard
 
LIFT: A Legacy InFormation retrieval Tool
LIFT: A Legacy InFormation retrieval ToolLIFT: A Legacy InFormation retrieval Tool
LIFT: A Legacy InFormation retrieval ToolKellyton Brito
 
powershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonpowershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonnettitude_labs
 
Building and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowBuilding and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowKaxil Naik
 

Ähnlich wie Introduction to LLVM for Program Analysis Using the 'opt' Command (20)

Clotho: Saving Programs from Malformed Strings and Incorrect String-handling
Clotho: Saving Programs from Malformed Strings and Incorrect String-handling�Clotho: Saving Programs from Malformed Strings and Incorrect String-handling�
Clotho: Saving Programs from Malformed Strings and Incorrect String-handling
 
SOHIL_RM (1).pptx
SOHIL_RM (1).pptxSOHIL_RM (1).pptx
SOHIL_RM (1).pptx
 
.NET Profilers and IL Rewriting - DDD Melbourne 2
.NET Profilers and IL Rewriting - DDD Melbourne 2.NET Profilers and IL Rewriting - DDD Melbourne 2
.NET Profilers and IL Rewriting - DDD Melbourne 2
 
Codeql Variant Analysis
Codeql Variant AnalysisCodeql Variant Analysis
Codeql Variant Analysis
 
Eclipse Visualization and Performance Monitoring
Eclipse Visualization and Performance MonitoringEclipse Visualization and Performance Monitoring
Eclipse Visualization and Performance Monitoring
 
Chap_6Lesson02Emsys3EInterruptBasedIOs.pdf
Chap_6Lesson02Emsys3EInterruptBasedIOs.pdfChap_6Lesson02Emsys3EInterruptBasedIOs.pdf
Chap_6Lesson02Emsys3EInterruptBasedIOs.pdf
 
torque - Automation Testing Tool for C-C++ on Linux
torque -  Automation Testing Tool for C-C++ on Linuxtorque -  Automation Testing Tool for C-C++ on Linux
torque - Automation Testing Tool for C-C++ on Linux
 
Aspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NETAspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NET
 
LDTT : A Low Level Driver Unit Testing Tool
LDTT : A Low Level Driver Unit Testing Tool LDTT : A Low Level Driver Unit Testing Tool
LDTT : A Low Level Driver Unit Testing Tool
 
Linaro Connect 2016 (BKK16) - Introduction to LISA
Linaro Connect 2016 (BKK16) - Introduction to LISALinaro Connect 2016 (BKK16) - Introduction to LISA
Linaro Connect 2016 (BKK16) - Introduction to LISA
 
Project_Report (BARC-Jerin)_final
Project_Report (BARC-Jerin)_finalProject_Report (BARC-Jerin)_final
Project_Report (BARC-Jerin)_final
 
LIBPF: A LIBRARY FOR PROCESS FLOWSHEETING IN C++
LIBPF: A LIBRARY FOR PROCESS FLOWSHEETING IN C++LIBPF: A LIBRARY FOR PROCESS FLOWSHEETING IN C++
LIBPF: A LIBRARY FOR PROCESS FLOWSHEETING IN C++
 
.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
 
OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysis
 
Intro-Soft-Engg-2.pptx
Intro-Soft-Engg-2.pptxIntro-Soft-Engg-2.pptx
Intro-Soft-Engg-2.pptx
 
LIFT: A Legacy InFormation retrieval Tool
LIFT: A Legacy InFormation retrieval ToolLIFT: A Legacy InFormation retrieval Tool
LIFT: A Legacy InFormation retrieval Tool
 
powershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonpowershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-london
 
Building and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowBuilding and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache Airflow
 
Ch1
Ch1Ch1
Ch1
 
Software Development with PHP & Laravel
Software Development  with PHP & LaravelSoftware Development  with PHP & Laravel
Software Development with PHP & Laravel
 

Mehr von Tao He

Java 并发编程笔记:01. 并行与并发 —— 概念
Java 并发编程笔记:01. 并行与并发 —— 概念Java 并发编程笔记:01. 并行与并发 —— 概念
Java 并发编程笔记:01. 并行与并发 —— 概念Tao He
 
A software fault localization technique based on program mutations
A software fault localization technique based on program mutationsA software fault localization technique based on program mutations
A software fault localization technique based on program mutationsTao He
 
Testing survey
Testing surveyTesting survey
Testing surveyTao He
 
Testing survey by_directions
Testing survey by_directionsTesting survey by_directions
Testing survey by_directionsTao He
 
Smart debugger
Smart debuggerSmart debugger
Smart debuggerTao He
 
Mutation testing
Mutation testingMutation testing
Mutation testingTao He
 
C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4Tao He
 
Django
DjangoDjango
DjangoTao He
 
基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述Tao He
 
Java覆盖信息收集工具比较
Java覆盖信息收集工具比较Java覆盖信息收集工具比较
Java覆盖信息收集工具比较Tao He
 
Testing group’s work on fault localization
Testing group’s work on fault localizationTesting group’s work on fault localization
Testing group’s work on fault localizationTao He
 
Muffler a tool using mutation to facilitate fault localization 2.0
Muffler a tool using mutation to facilitate fault localization 2.0Muffler a tool using mutation to facilitate fault localization 2.0
Muffler a tool using mutation to facilitate fault localization 2.0Tao He
 
Muffler a tool using mutation to facilitate fault localization 2.3
Muffler a tool using mutation to facilitate fault localization 2.3Muffler a tool using mutation to facilitate fault localization 2.3
Muffler a tool using mutation to facilitate fault localization 2.3Tao He
 
Semantic Parsing in Bayesian Anti Spam
Semantic Parsing in Bayesian Anti SpamSemantic Parsing in Bayesian Anti Spam
Semantic Parsing in Bayesian Anti SpamTao He
 
Problems
ProblemsProblems
ProblemsTao He
 
A survey of software testing
A survey of software testingA survey of software testing
A survey of software testingTao He
 
Cleansing test suites from coincidental correctness to enhance falut localiza...
Cleansing test suites from coincidental correctness to enhance falut localiza...Cleansing test suites from coincidental correctness to enhance falut localiza...
Cleansing test suites from coincidental correctness to enhance falut localiza...Tao He
 
Concrete meta research - how to collect, manage, and read papers?
Concrete meta research - how to collect, manage, and read papers?Concrete meta research - how to collect, manage, and read papers?
Concrete meta research - how to collect, manage, and read papers?Tao He
 

Mehr von Tao He (18)

Java 并发编程笔记:01. 并行与并发 —— 概念
Java 并发编程笔记:01. 并行与并发 —— 概念Java 并发编程笔记:01. 并行与并发 —— 概念
Java 并发编程笔记:01. 并行与并发 —— 概念
 
A software fault localization technique based on program mutations
A software fault localization technique based on program mutationsA software fault localization technique based on program mutations
A software fault localization technique based on program mutations
 
Testing survey
Testing surveyTesting survey
Testing survey
 
Testing survey by_directions
Testing survey by_directionsTesting survey by_directions
Testing survey by_directions
 
Smart debugger
Smart debuggerSmart debugger
Smart debugger
 
Mutation testing
Mutation testingMutation testing
Mutation testing
 
C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4
 
Django
DjangoDjango
Django
 
基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述
 
Java覆盖信息收集工具比较
Java覆盖信息收集工具比较Java覆盖信息收集工具比较
Java覆盖信息收集工具比较
 
Testing group’s work on fault localization
Testing group’s work on fault localizationTesting group’s work on fault localization
Testing group’s work on fault localization
 
Muffler a tool using mutation to facilitate fault localization 2.0
Muffler a tool using mutation to facilitate fault localization 2.0Muffler a tool using mutation to facilitate fault localization 2.0
Muffler a tool using mutation to facilitate fault localization 2.0
 
Muffler a tool using mutation to facilitate fault localization 2.3
Muffler a tool using mutation to facilitate fault localization 2.3Muffler a tool using mutation to facilitate fault localization 2.3
Muffler a tool using mutation to facilitate fault localization 2.3
 
Semantic Parsing in Bayesian Anti Spam
Semantic Parsing in Bayesian Anti SpamSemantic Parsing in Bayesian Anti Spam
Semantic Parsing in Bayesian Anti Spam
 
Problems
ProblemsProblems
Problems
 
A survey of software testing
A survey of software testingA survey of software testing
A survey of software testing
 
Cleansing test suites from coincidental correctness to enhance falut localiza...
Cleansing test suites from coincidental correctness to enhance falut localiza...Cleansing test suites from coincidental correctness to enhance falut localiza...
Cleansing test suites from coincidental correctness to enhance falut localiza...
 
Concrete meta research - how to collect, manage, and read papers?
Concrete meta research - how to collect, manage, and read papers?Concrete meta research - how to collect, manage, and read papers?
Concrete meta research - how to collect, manage, and read papers?
 

Kürzlich hochgeladen

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 

Kürzlich hochgeladen (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 

Introduction to LLVM for Program Analysis Using the 'opt' Command

  • 1. Introduction to LLVM on Program Analysis Tao He elfinhe@gmail.com Department of Computer Science, Sun Yat-Sen University Department of Computer Science and Engineering, HKUST Group Discussion June 2012 HKUST, Hong Kong, China 1/34
  • 2. Outline  Objectives  A quick scenario  LLVM IR  ‘opt’ command  Installation of LLVM 2/34
  • 3. Objectives - What do we want to do? 3/34
  • 4. Objectives  To implement a symbolic execution engine.  A expression-based engine [BH07] different from most existing implementations (path-based engines).  Program analysis on C programs.  To generate static single assignment (SSA) representation of C first. 4/34 [BH07] Domagoj Babić and Alan J. Hu. Structural Abstraction of Software Verification Conditions. In Proceedings of the 19th international conference on Computer aided verification (CAV'07), Lecture Notes in Computer Science, 2007, Volume 4590/2007, 366-378
  • 5. A Quick Scenario - What can LLVM do? 5/34
  • 6. !A Quick Scenario 6/34  Given a C program:  #include <stdio.h>  int branch(int n){  if (n>0) printf("Positiven");  else if (n==0) printf("Zeron");  else if (n<0) printf("Negativen");  return 0;  }  int main() {  branch(-4); branch(0); branch(6);  return 0;  }
  • 7. !A Quick Scenario 7/34  Generate immediate representation (IR) of LLVM – the SSA representation in LLVM  clang -O3 -emit-llvm hello.c -S -o hello.ll  define i32 @main() nounwind uwtable {  %1 = alloca i32, align 4  store i32 0, i32* %1  %2 = call i32 @branch(i32 -4)  %3 = call i32 @branch(i32 0)  %4 = call i32 @branch(i32 6)  ret i32 0  }  ... [SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes. URL: http://llvm.org/docs/Passes.html.
  • 8. !A Quick Scenario 8/34  Print call graph  opt method_para_int_branch.ll -S -dot- callgraph 2>output_file >/dev/null  dot -Tsvg in.dot -o out.svg [SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes. URL: http://llvm.org/docs/Passes.html.
  • 9. !A Quick Scenario 9/34  Print control flow graph (CFG)  opt method_para_int_branch.ll -S -dot-cfg 2>output_file >/dev/null [SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes. URL: http://llvm.org/docs/Passes.html.
  • 10. # A Quick Scenario 10/34  More:  Dead Global Elimination  Interprocedural Constant Propagation  Dead Argument Elimination  Inlining  Reassociation  Loop Invariant Code Motion  Loop Opts  Memory Promotion  Dead Store Elimination  Aggressive Dead Code Elimination [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 11. What is the SSA representation in LLVM? - LLVM IR 11/34
  • 12. LLVM IR 12/34  “A Static Single Assignment (SSA) based representation that provides type safety, low- level operations, flexibility, and the capability of representing 'all' high-level languages cleanly.” [Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 13. LLVM IR 13/34  Three address code  SSA-based  Three different forms  An in-memory compiler IR  An on-disk bitcode representation (suitable for fast loading by a Just-In-Time compiler)  A human readable assembly language representation [Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 14. LLVM IR 14/34  An example  To multiply the integer variable '%X' by 8  Syntax:  <result> = mul <ty> <op1>, <op2>  IR code:  %result = mul i32 %X, 8  More  For floating point, use fmul [Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 15. LLVM IR 15/34  Another example  Instruction jump – to change control flow  Branches or loops  Syntax:  br i1 <cond>, label <iftrue>, label <iffalse>  br label <dest> ; Unconditional branch [Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 16. LLVM IR 16/34  IR code:  Test:  %cond = icmp eq i32 %a, %b  br i1 %cond, label %IfEqual, label %IfUnequal  IfEqual:  ret i32 1  IfUnequal: [Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 17. LLVM IR 17/34  3rd example  Function call  A simplified syntax:  <result> = call <ty> <fnptrval>(<function args>)  IR code:  call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) [Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 18. LLVM IR 18/34  4th example  Function definition  A simplified syntax:  define <ResultType> @<FunctionName> ([argument list]) { ... }  IR code:  define i32 @main() { … }  define i32 @test(i32 %X, ...) { … } [Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 19. LLVM IR 19/34  The majority of instructions in C programs:  Operations (binary/bitwise)  Jumps  Function calls  Function definitions  Many keywords in LLVM IR will not be used for C programs. (e.g., invoke) [Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 20. How to analyze programs by using LLVM? - ‘opt’ command 20/34
  • 21. ‘opt’ command  Compiler is organized as a series of ‘passes’:  Each pass is one analysis or transformation 21/34 [SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes. URL: http://llvm.org/docs/Passes.html. [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 22. !‘opt’ command  An example  -dot-callgraph 22/34 [SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes. URL: http://llvm.org/docs/Passes.html. [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 23. !‘opt’ command 23/34 An example Print call graph: -dot-callgraph  opt method_para_int_branch.ll -S -dot- callgraph 2>output_file >/dev/null  dot -Tsvg in.dot -o out.svg [SH] Reid Spencer and Gordon Henriksen. LLVM's Analysis and Transform Passes. URL: http://llvm.org/docs/Passes.html. [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 24. How to write your own pass? 24/34
  • 25. How to write your own pass?  Four types of pass:  ModulePass: general interprocedural pass  CallGraphSCCPass: bottom-up on the call graph  FunctionPass: process a function at a time  BasicBlockPass: process a basic block at a time 25/34
  • 26. How to write your own pass?  Two important classes  User: http://llvm.org/docs/doxygen/html/classllvm_1_1User.html  This class defines the interface that one who uses a Value must implement.  Instructions  Constants  Operators  Value: http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html  It is the base class of all values computed by a program that may be used as operands to other values.  e.g., instruction and function. 26/34
  • 27. How to write your own pass?  An example – print function names 27/34
  • 28. How to write your own pass?  An example – print function names  First generate bytecode:  clang -emit-llvm hello.c -o hello.bc  Then 28/34
  • 29. How to write your own pass?  Another example – print def-use chain 29/34
  • 30. How to install LLVM? 30/34
  • 31. How to install LLVM?  To compile programs faster and use built-in transformation and analysis  Install both ‘llvm’ and ‘clang’ from package management software  E.g., Synaptic, yum, apt.  To write your own pass  Build from source code and add your own pass  http://llvm.org/docs/GettingStarted.html#quickstart  http://llvm.org/docs/WritingAnLLVMPass.html 31/34
  • 32. LLVM IR 32/34  The majority of instructions in C programs:  Operation (binary/bitwise)  Jump  Function call  Function definition [Lat] Chris Lattner. LLVM Language Reference Manual. URL: http://llvm.org/docs/LangRef.html [LA04] Chris Lattner and Vikram Adve. The LLVM Compiler Framework and Infrastructure Tutorial. Mini Workshop on Compiler Research Infrastructures (LCPC'04), West Lafayette, Indiana, Sep. 2004.
  • 34. Thank you! Contact me via elfinhe@gmail.com 34/34