Path: csiph.com!au2pb.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end From: Hans-Peter Diettrich Newsgroups: comp.compilers Subject: Re: IR Representation Date: Sat, 12 Sep 2015 19:45:09 +0200 Organization: Compilers Central Lines: 28 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <15-09-014@comp.compilers> References: <15-09-005@comp.compilers> <15-09-006@comp.compilers> <15-09-010@comp.compilers> <15-09-011@comp.compilers> <15-09-013@comp.compilers> NNTP-Posting-Host: news.iecc.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: miucha.iecc.com 1442086989 95853 2001:470:1f07:1126:0:676f:7373:6970 (12 Sep 2015 19:43:09 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sat, 12 Sep 2015 19:43:09 +0000 (UTC) Keywords: optimize, analysis Posted-Date: 12 Sep 2015 15:43:08 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1609 CC)sar schrieb: > Now I am wondering, how do you usually represent conditional nodes and > looping structures using trees? > > Eg.: > > c = a + b; > if c > 10 goto L1 else goto L2 > L1: a = 10; > goto L3; > L2: a = 20; > L3: The general representation of control flow forms *graphs*, not *trees*. In your example control flow branches off in the "if" statement, into two branches starting at L1 and L2 respectively, which happen to join again at L3. You can consider each GOTO as a leaf in a tree, so that you can convert the graph into trees. Then, in the case of well structured code, L1 and L2 become child nodes of the "if" statement, and L3 will become its sequential successor (right sibling), as L3 is the common target reachable by both branches. The compiler can eliminate a GOTO leaf and replace it by the tree of the GOTO target label, which then indicates the next instruction during sequential execution. This process continues until all trees have been merged into one big tree. DoDi