程序代写案例-LLVM 12

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
Part 1: Warm up (learning LLVM basics)
● Objectives
○ Install and set up the LLVM 12 environments.
○ Get familiar with its basic toolchains.
https://clang.llvm.org/get_started.html
■ https://llvm.org/docs/CommandGuide/index.html
○ Learn how to write LLVM passes.
● Tasks:
○ Install LLVM (from source code).
○ Figure out commands to translate between different code representations (step 2-b).
○ Modify the HelloPass to print number of predecessors and successors (step 3).
Part 1: Warm up (learning LLVM basics)
C code:
c = a + 1;
LLVM IR:
%0 = load i32, i32* %a, align 4
%add = add nsw i32 %0, 1
store i32 %add, i32* %c, align 4
Part 2: Implementing liveness analysis pass
● Backward May Problem
○ IN[B]: Variables live at B’s entry.
○ OUT[B]:Variables live at B’s exit.
○ GEN[B], KILL[B]: …
● Your implementation finds out OUT[B] for each basic block.
○ Using iterative algorithm or the worklist one.
Part 2: liveness analysis pass
● Implementation:
○ Finish Pass/LivenessAnalysis.cpp
○ Only basic scenarios
■ +, -, *, /, Load/Store, etc.
○ In C++, set, union operation …
● Testing:
○ Scripts provided in test folder
■ bash create_input.sh Test: transform Test.c to Test.ll
■ bash test.sh Test: run the pass and save output to Test.out
● Compiling:
mkdir build
cd build
cmake ..
make
Part 3: Implementing available expression analysis
● Forward Must Problem
○ IN[B]: expressions available at B’s entry
○ OUT[B]: expressions available at B’s exit
○ GEN[B], KILL[B]: …
● Your implementation should:
○ Output all available expressions at the end of each
basic block

欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468