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作业君