Skip to content

Commit

Permalink
+11-ir-expr
Browse files Browse the repository at this point in the history
  • Loading branch information
hengxin committed May 9, 2024
1 parent f11c7b2 commit 0ef8395
Show file tree
Hide file tree
Showing 55 changed files with 364 additions and 81 deletions.
Binary file modified 2024/10-llvm-ir/10-llvm-ir.pdf
Binary file not shown.
Binary file modified 2024/10-llvm-ir/figs/f2-opt1-factorial-cfg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/10-llvm-ir/figs/factorial2-o1-ll-code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/10-llvm-ir/figs/figs.pptx
Binary file not shown.
Binary file added 2024/10-llvm-ir/figs/instruction-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/10-llvm-ir/figs/llvm-ir-animation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 21 additions & 26 deletions 2024/10-llvm-ir/parts/llvm-ir-api.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{}
\begin{center}
\href{https://llvm.org/docs/LangRef.html}{LLVM Language Reference Manual}
\fig{width = 0.80\textwidth}{figs/llvm-lang-ref}
\href{https://llvm.org/docs/ProgrammersManual.html}{LLVM Programmer's Manual}

\vspace{0.30cm}
\fig{width = 0.80\textwidth}{figs/llvm-programmer-manual}

\vspace{0.50cm}
如何用编程的方式生成 LLVM IR?
Expand Down Expand Up @@ -37,6 +39,10 @@
\vspace{0.30cm}

主打一个 \red{``课上不讲, 课后自学''}吗?

\pause
\vspace{0.60cm}
课程实验可以使用 \texttt{\teal{load, store}} 指令, 不需要采用 \teal{$\phi$} 指令格式
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
Expand All @@ -55,18 +61,7 @@
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{}
\begin{center}
\href{https://llvm.org/docs/ProgrammersManual.html}{LLVM Programmer's Manual}

\vspace{0.30cm}
\fig{width = 0.80\textwidth}{figs/llvm-programmer-manual}
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{}
\begin{center}
\href{https://llvm.org/docs/tutorial/}{Kaleidoscope: Implementing a Language with LLVM}
\href{https://llvm.org/docs/tutorial/}{Kaleidoscope: Implementing a Language with LLVM (in C++)}
\end{center}

\begin{columns}
Expand All @@ -78,21 +73,21 @@

\vspace{0.20cm}
\begin{center}
\href{https://github.com/courses-at-nju-by-hfwei/kaleidoscope-in-java}{kaleidoscope-in-java@github}
\href{https://github.com/courses-at-nju-by-hfwei/kaleidoscope-in-java}{kaleidoscope-in-java @ GitHub}
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{}
\begin{center}
\blue{强烈\red{\bf 不}推荐, 严重挫伤初学者的学习热情}
\end{center}
\begin{columns}
\column{0.50\textwidth}
\fig{width = 0.80\textwidth}{figs/llvm-cookbook-book}
\column{0.50\textwidth}
\fig{width = 0.80\textwidth}{figs/llvm-core-book}
\end{columns}
\end{frame}
% \begin{frame}{}
% \begin{center}
% \blue{强烈\red{\bf 不}推荐, 严重挫伤初学者的学习热情}
% \end{center}
% \begin{columns}
% \column{0.50\textwidth}
% \fig{width = 0.80\textwidth}{figs/llvm-cookbook-book}
% \column{0.50\textwidth}
% \fig{width = 0.80\textwidth}{figs/llvm-core-book}
% \end{columns}
% \end{frame}
%%%%%%%%%%%%%%%%%%%%
101 changes: 47 additions & 54 deletions 2024/10-llvm-ir/parts/llvm-ir.tex
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@
\uncover<2->{\blue {Three Address Code (TAC)}}
\uncover<3->{\qquad \red{Static Single Assignment (SSA)}}

\vspace{0.20cm}
\fig{width = 0.95\textwidth}{figs/f0-opt0}
\vspace{0.30cm}
\fig{width = 0.95\textwidth}{figs/f0-opt1}
\vspace{0.30cm}

\teal{\texttt{clang}} \red{\texttt{-S -emit-llvm}} \blue{\texttt{-fno-discard-value-names}}

\teal{\texttt{factorial0.c -o f0-opt0.ll}}
\teal{\texttt{factorial0.c -o f0-opt0.ll \violet{-O1} \purple{-g0}}}

% \pause
% \vspace{0.10cm}
Expand All @@ -66,17 +67,17 @@
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{}
\begin{center}
\blue{mem2reg}
\vspace{0.30cm}
% \begin{frame}{}
% \begin{center}
% \blue{mem2reg}
% \vspace{0.30cm}

\fig{width = 0.95\textwidth}{figs/f0-opt1}
% \fig{width = 0.95\textwidth}{figs/f0-opt1}

\vspace{0.30cm}
\teal{\texttt{clang -S -emit-llvm factorial0.c -o f0-opt1.ll \red{-O1} -g0}}
\end{center}
\end{frame}
% \vspace{0.30cm}
% \teal{\texttt{clang -S -emit-llvm factorial0.c -o f0-opt1.ll \red{-O1} -g0}}
% \end{center}
% \end{frame}
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -282,14 +283,14 @@
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{}
\begin{center}
\fig{width = 0.20\textwidth}{figs/f1-opt3-factorial-cfg-only}
% \begin{frame}{}
% \begin{center}
% \fig{width = 0.20\textwidth}{figs/f1-opt3-factorial-cfg-only}

\vspace{-0.30cm}
\texttt{factorial1 (opt3)}
\end{center}
\end{frame}
% \vspace{-0.30cm}
% \texttt{factorial1 (opt3)}
% \end{center}
% \end{frame}
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -336,41 +337,45 @@

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{}
\vspace{-0.50cm}
\fig{width = 0.70\textwidth}{figs/f2-opt1-factorial-cfg.pdf}
\fig{width = 0.85\textwidth}{figs/factorial2-o1-ll-code}
% \fig{width = 0.70\textwidth}{figs/f2-opt1-factorial-cfg.pdf}
\end{frame}
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{}
\begin{center}
\fig{width = 0.20\textwidth}{figs/f2-opt3-factorial-cfg-only}
% \begin{frame}{}
% \begin{center}
% \fig{width = 0.20\textwidth}{figs/f2-opt3-factorial-cfg-only}

\vspace{-0.30cm}
\texttt{factorial2 (opt3)}
\end{center}
\end{frame}
% \vspace{-0.30cm}
% \texttt{factorial2 (opt3)}
% \end{center}
% \end{frame}
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{}
\begin{center}
\href{https://blog.piovezan.ca/compilers/llvm\_ir\_animation/llvm\_ir.html}{LLVM IR Animation}

\vspace{0.30cm}
\fig{width = 0.60\textwidth}{figs/llvm-ir-tutorial}
\vspace{0.30cm}

\href{https://www.bilibili.com/video/BV1mE421g7BA/?share\_source=copy\_web\&vd\_source=afddc1f6e07c3046ed07519aa34370fd}{LLVM IR Tutorial @ Bilibili}
\end{center}
\begin{columns}
\column{0.50\textwidth}
\begin{center}
\fig{width = 0.80\textwidth}{figs/llvm-ir-animation}
\href{https://blog.piovezan.ca/compilers/llvm\_ir\_animation/llvm\_ir.html}{LLVM IR Animation}
\end{center}
\column{0.50\textwidth}
\begin{center}
\fig{width = 0.80\textwidth}{figs/llvm-ir-tutorial}
\href{https://www.bilibili.com/video/BV1mE421g7BA/?share\_source=copy\_web\&vd\_source=afddc1f6e07c3046ed07519aa34370fd}{LLVM IR Tutorial @ Bilibili}
\end{center}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{}
\begin{center}
\href{https://llvm.org/docs/LangRef.html}{LLVM Language Reference Manual}
\fig{width = 0.80\textwidth}{figs/llvm-lang-ref}
\href{https://llvm.org/docs/LangRef.html\#instruction-reference}{Instruction Reference @ LLVM Language Reference Manual}
\fig{width = 0.60\textwidth}{figs/llvm-lang-ref}
\fig{width = 0.60\textwidth}{figs/instruction-ref}
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
Expand All @@ -382,21 +387,9 @@

\vspace{0.30cm}
\fig{width = 0.60\textwidth}{figs/prog-visual}
\vspace{0.30cm}

使用命令行生成 LLVM IR 与控制流图 (Control Flow Graph)
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
% \begin{frame}{}
% \begin{center}
% \fig{width = 0.25\textwidth}{figs/qa}
% \end{center}

% \pause
% \begin{itemize}[<+->]
% \setlength{\itemsep}{10pt}
% \item 一个函数里可以包含多个含有 \texttt{ret} 指令的基本块吗?
% \item 如果可以, 那不就可以解决 $\phi$ 指令相关的问题了吗?
% \end{itemize}
% \end{frame}
%%%%%%%%%%%%%%%%%%%%
Binary file added 2024/11-ir-expr/11-ir-expr-handout.pdf
Binary file not shown.
Binary file added 2024/11-ir-expr/11-ir-expr.pdf
Binary file not shown.
27 changes: 27 additions & 0 deletions 2024/11-ir-expr/11-ir-expr.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
% 11-ir-expr.tex

% !TEX program = xelatex
%%%%%%%%%%%%%%%%%%%%
\documentclass[]{beamer}
\input{../preamble}
%%%%%%%%%%%%%%%%%%%%
\title[语义分析]{四、中间代码生成 \\ (11. 表达式的翻译)}

\author[魏恒峰]{\large 魏恒峰}
\titlegraphic{\includegraphics[height = 2.0cm]{figs/welcome}}
\institute{hfwei@nju.edu.cn}
\date{2024年05月10日}
%%%%%%%%%%%%%%%%%%%%
\begin{document}

\maketitle
%%%%%%%%%%%%%%%%%%%%
\input{parts/overview}
\input{parts/expr}
\input{parts/array}

\thankyou{}
\input{parts/suggestion}
%%%%%%%%%%%%%%%%%%%%
\end{document}
%%%%%%%%%%%%%%%%%%%%
10 changes: 10 additions & 0 deletions 2024/11-ir-expr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 11-ir-expr-control

## TODO

- [ ] (Java) generate code for array-ref, if-else, while, etc.
- [ ] codegen in the way of attributed grammars
- [ ] codegen in LLVM IR
- [ ] generate .dot files for illustration of code blocks
- more beautiful
- layout: tree
Binary file added 2024/11-ir-expr/figs/12-ir-expr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDD-P.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDD-assign.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDD-expr-ast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDD-expr-tac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDD-lnot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDT-L-L-addr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDT-L-L-array.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDT-L-L-type.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDT-array-reference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDT-array.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/SDT-expr-tac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/anno-array.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/anno-type-width.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/array-c-ll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/array-c-type.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/array-c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/array-code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/cfg-S-L.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/cfg-S.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/cfg-array.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2024/11-ir-expr/figs/codegen-logo.png
Binary file added 2024/11-ir-expr/figs/expr-c.png
Binary file added 2024/11-ir-expr/figs/expr-ll.png
Binary file added 2024/11-ir-expr/figs/expr-tac.png
Binary file added 2024/11-ir-expr/figs/figs.pptx
Binary file not shown.
Binary file added 2024/11-ir-expr/figs/gep-overview.png
Binary file added 2024/11-ir-expr/figs/grammar-assign-expr.png
Binary file added 2024/11-ir-expr/figs/grammar-bool-expr.png
Binary file added 2024/11-ir-expr/figs/grammar-control.png
Binary file added 2024/11-ir-expr/figs/grammar-expr-array.png
Binary file added 2024/11-ir-expr/figs/grammars.png
Binary file added 2024/11-ir-expr/figs/llvm-ir-tutorial.png
Binary file added 2024/11-ir-expr/figs/matters.png
Binary file added 2024/11-ir-expr/figs/tac-array.png
Binary file added 2024/11-ir-expr/figs/thankyou.png
Binary file added 2024/11-ir-expr/figs/welcome.jpg
Loading

0 comments on commit 0ef8395

Please sign in to comment.