Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. `llvm::LiveVariables` : Live Variable Analysis
  2. ====
  3.  
  4. LiveVariables.cpp implements Live Variable Analysis Pass. For each machine instruction in the function, this pass calculates the set of registers that are immediately dead after the instruction (i.e., the instruction calculates the value, but it is never used) and the set of registers that are used by the instruction, but are never used after the instruction (i.e., they are killed). (Taken from LiveVariables.cpp)
  5.  
  6. -----------------------------------------
  7.  
  8. * **Which analysis/transformation do you consider?**
  9.  
  10. `llvm::LiveVariables` : Live Variable Analysis
  11.  
  12. * **Where is it located in LLVM code base? (Main file or files)**
  13.  
  14. `{LLVM_src}/lib/CodeGen/LiveVariables.cpp`
  15.  
  16. * **Does the analysis take advantage of the SSA form? If so, how?**
  17.  
  18. Yes. This pass takes advantage of the SSA form.
  19.  
  20. This class computes live variable information for virual registers and _register allocatable_ physical register in a function. Physical registers are assumed to be live within a single block and uses dominance properties of SSA form to compute live variables for virtual registers. Live variable information is calculated in depth first order on the CFG of the function. This guarentees that the definition of variables is seen before its use due to dominance properties of SSA form (PHI nodes are handled as special case)
  21.  
  22. * **What data structures are used? Can you say something about the pass efficiency?**
  23.  
  24. The pass uses data structures such as std::vector<MachineBasicBlock*> to maintain information about Worklist. The list contains instructions (predecessors) in the basic block that were marked alive. There are no global data structures used in this pass.
  25.  
  26. I think the pass is efficient since it makes use of dominance properties of SSA form to compute live variables for virtual registers.
  27.  
  28. * **Give an example program and show the steps of the analysis on it.**
  29.  
  30. *C program*
  31. ```
  32. b1: a = 3;
  33. b = 5;
  34. d = 4;
  35. x = 100;
  36. if a > b then
  37. b2: c = a + b;
  38. d = 2;
  39. b3: endif
  40. c = 4;
  41. return b * d + c;
  42. ```
  43.  
  44. *Analysis*
  45. ```
  46. // in: {}
  47. b1: a = 3;
  48. b = 5;
  49. d = 4;
  50. x = 100; //x is never being used later thus not in the out set {a,b,d}
  51. if a > b then
  52. // out: {a,b,d} //union of all (in) successors of b1 => b2: {a,b}, and b3:{b,d}
  53.  
  54. // in: {a,b}
  55. b2: c = a + b;
  56. d = 2;
  57. // out: {b,d}
  58.  
  59. // in: {b,d}
  60. b3: endif
  61. c = 4;
  62. return b * d + c;
  63. // out:{}
  64. ```
  65.  
  66. *Summary*
  67.  
  68. | processing | out-state | old in-state | new in-state | work list |
  69. |---|---|---|---|---|
  70. |b3|{}|{}|{b,d}|(b1,b2)|
  71. |b1|{b,d}|{}|{}|(b2)|
  72. |b2|{b,d}|{}|{a,b}|(b1)|
  73. |b1|{a,b,d}|{}|{}|()|
  74.  
  75.  
  76. * **What transformation in LLVM code can take advantage of the analysis?**
  77. The result obtained from live variable analysis can be used in dead code elimination tranformation (-dce llvm pass) to check if any instructions that were used by removed instructions to see if they are newly dead.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement