Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Misaki-Wang committed Nov 2, 2023
1 parent a02865a commit bccce45
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 27 deletions.
51 changes: 51 additions & 0 deletions docs/Static-Analysis/0-LLVM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## LLVM

[19_LLVM.pdf (xiongyingfei.github.io)](https://xiongyingfei.github.io/SA/2017/19_LLVM.pdf)

### LLVM Basic

LLVM is **a compiler infrastructure** designed as a set of reusable libraries with well-defined interfaces.

Big pictures of LLVM:

- LLVM implements the entire compilation flow
<img src="https://picgo-wbyz.oss-cn-nanjing.aliyuncs.com/202310311432785.png" alt="compilation" style="zoom:50%;" />
- off-the-shell optimizations
- Virtual Register Allocation
- Constant Propagation



### LLVM IR

LLVM Core Hierarchy
<img src="https://picgo-wbyz.oss-cn-nanjing.aliyuncs.com/202310311448380.png" alt="LLVM-core-hierarchy" style="zoom:50%;" />

- Module
- Function
- Value
- local start with `%`, global with $@$
- Type
- Basic & Instruction



### LLVM Pass

[LLVM: llvm::Pass Class Reference](https://llvm.org/doxygen/classllvm_1_1Pass.html)

- Passes perform the **transformations and optimizations** that make up the compiler,
they **build the analysis results** that are used by these transformations,
and they are, above all, **a structuring technique** for compiler code.
- One of the main features of the LLVM Pass Framework is that it schedules passes to run in an efficient way based on the constraints that your pass meets (which are indicated by which class they derive from).

- LLVM applies a chain of analyses and transformations on the target program.
Each of these analyses or transformations is called a **pass**.
Some passes, which are machine independent, are invoked by *opt*.
A pass may require information provided by other passes. Such dependencies must be explicitly stated.

- A pass is an instance of the LLVM class `Pass`, `Pass` is the **base class** of all the pass
<img src="https://picgo-wbyz.oss-cn-nanjing.aliyuncs.com/202310311524152.png" alt="Pass Class" style="zoom:50%;" />



53 changes: 26 additions & 27 deletions docs/Static-Analysis/5-Interprocedural Analysis.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
# Interprocedural An
# Interprocedural Analysis

**阅读提示:使用屏幕较大的设备能够看到自带的Sticky Table of Contents,更有利于理清阅读思路。**
## 过程间分析简介

对应视频在:
本小节通过四个部分介绍过程间分析。

* [第七课-过程间分析](https://www.bilibili.com/video/BV1GQ4y1T7zm)
* [第八课-指针分析](https://www.bilibili.com/video/BV1gg4y1z78p)
Motivation
* **为什么** 要引入过程间分析?

## 过程间分析简介
Call Graph Construction \(CHA\)
* 介绍一个过程间分析 **必要的数据结构Call Graph**
* 当前有数种方法来**构建Call Graph**,本节介绍其中**速度最快的一种(Class hierarchy analysis,简称CHA)**

本小节通过四个部分介绍过程间分析。
Interprocedural Control-Flow Graph
* 之前的章节关注CFG,引入过程间分析后,我们向CFG中**添加相应的元素**,得到过程间的控制流图(ICFG)
* 讨论由于添加了新元素而需要**增加的操作**

1. Motivation
* **为什么** 要引入过程间分析?
2. Call Graph Construction \(CHA\)
* 介绍一个过程间分析 **必要的数据结构Call Graph**
* 当前有数种方法来**构建Call Graph**,本节介绍其中**速度最快的一种(Class hierarchy analysis,简称CHA)**
3. Interprocedural Control-Flow Graph
* 之前的章节关注CFG,引入过程间分析后,我们向CFG中**添加相应的元素**,得到过程间的控制流图(ICFG)
* 讨论由于添加了新元素而需要**增加的操作**
4. Interprocedural Data-Flow Analysis
* 通过一个例子(也就是实验一中做的常量传播分析)来**总结**过程间分析。
Interprocedural Data-Flow Analysis
* 通过一个例子(也就是实验一中做的常量传播分析)来**总结**过程间分析。

## Motivation

之前的章节中都没有考虑方法调用,然而在实际的程序中方法调用非常常见,那么我们如何分析带方法调用的程序呢?最简单的处理方式是(这里仍然以常量传播作为一个例子):做最保守的假设,即**为函数调用返回NAC**。而这种情况会**丢失精度****引入过程间分析能够提高精度。**如果使用最简单的处理方式,下图中的n和y分析结果都不是常量,尽管我们能够一眼看出他们的运行时值是n=10,y=43。

![](https://picgo-wbyz.oss-cn-nanjing.aliyuncs.com/202311011954944.png)

## Call Graph Construction \(CHA\)
## Call Graph Construction

接下来我们讨论一个必要的数据结构Call Graph,中文可以理解为调用关系图。

Expand Down Expand Up @@ -85,7 +81,7 @@ A:分别调用A和C中定义的foo方法。

![](https://picgo-wbyz.oss-cn-nanjing.aliyuncs.com/202311011954575.png)

## Class Hierarchy Analysis \(CHA\)
## Class Hierarchy Analysis

### Definition of CHA

Expand Down Expand Up @@ -267,12 +263,15 @@ Edge transfer处理引入的call & return edge。为此,我们需要**在之

## Key points

1. How to build call graph via class hierarchy analysis
* 如何利用CHA构建调用关系图\(call graph\)
2. Concept of interprocedural control-flow graph
* 过程间控制流图\(ICFG\)的概念
3. Concept of interprocedural data-flow analysis
* 过程间数据流分析的概念
4. Interprocedural constant propagation
* 例子——引入过程间分析的常量分析
How to build call graph via class hierarchy analysis
* 如何利用CHA构建调用关系图\(call graph\)

Concept of interprocedural control-flow graph
* 过程间控制流图\(ICFG\)的概念

Concept of interprocedural data-flow analysis
* 过程间数据流分析的概念

Interprocedural constant propagation
* 例子——引入过程间分析的常量分析

0 comments on commit bccce45

Please sign in to comment.