Hi, I am studying SSA and some time ago I asked on this list how to see the phi nodes in the llvm ir output. I learned then to use this command: opt -mem2reg test.ll -S > test_mem2reg.ll However, if you look at the output (attached to this message) there is something I do not understand. At the end of the function @f at line 18, the function returns the variable %a_addr.0. However, this variable is never defined or set. The variable %a is. Is "_addr.0" a way to get the address of a variable? I could not find anything about this in in LLVM language reference manual. Where does this variable come from? thanks, Maarten Faddegon -------------- next part -------------- ; ModuleID = 'test.ll' target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-unknown-linux-gnu" define i32 @f(i32 %a) nounwind { entry: %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0] %0 = sub nsw i32 %a, 5 ; <i32> [#uses=1] %1 = icmp sgt i32 %0, 10 ; <i1> [#uses=1] br i1 %1, label %bb, label %bb1 bb: ; preds = %entry br label %bb2 bb1: ; preds = %entry br label %bb2 bb2: ; preds = %bb1, %bb %a_addr.0 = phi i32 [ 1, %bb ], [ 0, %bb1 ] ; <i32> [#uses=1] br label %return return: ; preds = %bb2 ret i32 %a_addr.0 } define i32 @main(i32 %argc, i8** %argv) nounwind { entry: %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0] %0 = call i32 @f(i32 %argc) nounwind ; <i32> [#uses=1] br label %return return: ; preds = %entry ret i32 %0 }
Hi Maarten, If you look at the start of basic block 2 (bb2) you'll see the following instruction: %a_addr.0 = phi i32 [ 1, %bb ], [ 0, %bb1 ] ; <i32> [#uses=1] This is an SSA phi node which assigns a value of either 1 or 0 to %a_addr.0 depending on whether control reached the PHI node from basic block bb, or bb1. - Lang. On Thu, Sep 23, 2010 at 11:26 PM, maarten faddegon < m.faddegon at student.tudelft.nl> wrote:> Hi, > > I am studying SSA and some time ago I asked on this list how to see the > phi nodes in the llvm ir output. I learned then to use this command: > opt -mem2reg test.ll -S > test_mem2reg.ll > > However, if you look at the output (attached to this message) there is > something I do not understand. At the end of the function @f at line 18, > the function returns the variable %a_addr.0. However, this variable is > never defined or set. The variable %a is. Is "_addr.0" a way to get the > address of a variable? I could not find anything about this in in LLVM > language reference manual. > Where does this variable come from? > > > thanks, > Maarten Faddegon > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100923/521694dc/attachment.html>
Elaborating slightly - The mem2reg pass hoists values from memory into registers. It was responsible for adding %a_addr.0 and the PHI node which defines it. - Lang. On Thu, Sep 23, 2010 at 11:44 PM, Lang Hames <lhames at gmail.com> wrote:> Hi Maarten, > > If you look at the start of basic block 2 (bb2) you'll see the following instruction: > > %a_addr.0 = phi i32 [ 1, %bb ], [ 0, %bb1 ] ; <i32> [#uses=1] > > This is an SSA phi node which assigns a value of either 1 or 0 to %a_addr.0 > depending on whether control reached the PHI node from basic block bb, or > bb1. > > - Lang. > > On Thu, Sep 23, 2010 at 11:26 PM, maarten faddegon < > m.faddegon at student.tudelft.nl> wrote: > >> Hi, >> >> I am studying SSA and some time ago I asked on this list how to see the >> phi nodes in the llvm ir output. I learned then to use this command: >> opt -mem2reg test.ll -S > test_mem2reg.ll >> >> However, if you look at the output (attached to this message) there is >> something I do not understand. At the end of the function @f at line 18, >> the function returns the variable %a_addr.0. However, this variable is >> never defined or set. The variable %a is. Is "_addr.0" a way to get the >> address of a variable? I could not find anything about this in in LLVM >> language reference manual. >> Where does this variable come from? >> >> >> thanks, >> Maarten Faddegon >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100923/c9818676/attachment.html>
Hi Maarten,> I am studying SSA and some time ago I asked on this list how to see the > phi nodes in the llvm ir output. I learned then to use this command: > opt -mem2reg test.ll -S> test_mem2reg.ll > > However, if you look at the output (attached to this message) there is > something I do not understand. At the end of the function @f at line 18, > the function returns the variable %a_addr.0. However, this variable is > never defined or set.it is defined here: %a_addr.0 = phi i32 [ 1, %bb ], [ 0, %bb1 ] ; <i32> [#uses=1] Ciao, Duncan.