CS255/455 Spring 2009 Discussion Board

Last year's discussion page was a success for people to discuss and share the project experience, especially their experience with GCC. So this year, we are going to continue with the discussion tradition. This page is intended for anyone to post questions and everyone to answer them. Please insert questions at the beginning and separate each question with a horizontal rule separator. For other formatting instructions read the answer to this question.


Q: Not having access to a nodes children array can be annoying. If nothing else, and method that returns an iterator or children's length should be added in the next version.

A: The children array is readable through the clone. One can get the size by using node.children_copy.length and the index of a child by node.children_copy.index(child).


Q: In Project Part2, Tasks 2 and 3 would have been much easier if I could have directly modified the id field.

A: The id and children fields are read-only so to protect the integrity of the Ast node. By design the way to change a node is to create a new node and replace the old node.


Q: In the intermediate language, can we assume that in an OpExpr, the operands are always either VarAcc or Const, i.e. expressions are not arbitrarily nested?

A: Based on the form of gimplified statements, yes, you can make that assumption to simplify your implementation.


Q: How do you convert an int back into an INTEGER_CST? I couldn't find any reference in the documentation.

A: Try build_int_cst, which is in tree.c


Q: I had several questions that Bin answered via e-mail. He asked me to summarize them here. It was never really detailed in class exactly what you do when you find a redundant statement. My initial thought was to simply replace the right hand side of a redundant statement with the left hand side of the statement which it was repeating. I then noticed that the success benchmark in this class how many statements we could remove from a program, and this method didn't remove any, it optimized the program by decreasing the number of operations executed, but didn't change the statement count. My next thought was that you needed to delete the statement and replace subsequent instances of the left hand side with what you would have replaced the right hand side with, but that has issues since we're only doing local value numbering, and deleting a statement could have wide spread effects in other basic blocks. So the question is what action should we take when we find a redundant statement?

A: This question reveals a very important issue in compiler design, interaction among various compiler optimizations. It is true that we can not simply remove a redundant assignment during value numbering. But the later dead code elimination phase should be able to handle this properly. Here is an example to illustrate this.

a = b + c;
d = b + c;
e = b + d;
f = b + a;
should be transformed (by LVN) into
a = b + c;
d = a;
e = b + a; // here d get replaced with a.
f = e;
We also replaced d in e = b + d here, because that can eliminate a use to d. Then if there is no use to d after d = a, dead code elimination can remove d = a. However, in a real compiler, such a replacement is not always beneficial, because it will increase the lifetime of variable a, which might cause trouble to later register allocation phase. Again, here you can see the interaction among optimization phases. For our project, the metric of your compiler performance is the number of executed statements, so you don't need to worry about register allocation here.


URCC problems

  • Insert Ast::Const nodes with the same numeric value will cause problem. Thus we have slightly changed the loop.c for Project Part 2. We will provide a solution soon.
  • If the end of the string is "\n", sometimes we will lose it during the transformation. This might cause problem for scanf. E.g. run ab we generated from ab.c will require any extra input after providing two numbers. Under fixing.
  • Array supporting will come soon.

A: Each Ast node can have at most one parent. If a program has the same constants used in multiple places, each use will be represented by a different Ast::Const object. This differs from GCC implementation, in which the same constant is represented by the same Ast node.


#StyleQ Q: How do we format a question and an answer?

A: A question and an answer start with the bold letter Q and A respectively followed by a colon. Use italic text for the question and normal text for the answer. Use a separator (a horizontal rule) after each question. Add new questions to the beginning of the list.

-- BinBao - 05 Feb 2009

Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r7 - 2009-02-26 - BinBao
 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding URCS? Send feedback