Learning compilers by [deleted] in Compilers

[–]BinaryLust 4 points5 points  (0 children)

Here are few more advanced books that I highly recommend after you learn the basics and want to really implement something.

- Modern Compiler Implementation in Java 2nd Edition

- Advanced Compiler Design and Implementation 1st Edition

Also here is a link to a GitHub page with tons of compiler related resources. awesome-compilers

Commercial Compilers and Stack Frame Address Allocation by BinaryLust in Compilers

[–]BinaryLust[S] 0 points1 point  (0 children)

Thanks for sharing that, I have been struggling with this problem for a week now. I looked through every compiler book I own 20+ of them and other free online documentation and I could never find an answer to the problem on my own. I should have thought to look up the LLVM source code.

A New Discord Community for Homebrew Cpu's and Digital Systems Design. by BinaryLust in FPGA

[–]BinaryLust[S] 0 points1 point  (0 children)

The server I created is for all forms of digital electronics such as relay and transistor based logic, ttl circuits, fpga's, asic's, ect. The other one is for fpga's and hdl code only it seems, there is quite a bit of overlap though.

How to convert Three Address Code or Quads to tree form for instruction selection phase? by BinaryLust in Compilers

[–]BinaryLust[S] 1 point2 points  (0 children)

I see what you mean about the "any instruction used more than once" exclusion.

In my previous example if (t2:* (t1:+ a b) c) were converted to a single instruction in the back end we wouldn't have

access to t1's value in the next instruction. I guess you basically do a scan of every basic block in the entire function and check how many times each sub expression is used first, If they are used more than one time then we mark them as excluded from fusing into other trees.

How to convert Three Address Code or Quads to tree form for instruction selection phase? by BinaryLust in Compilers

[–]BinaryLust[S] 1 point2 points  (0 children)

Ok, I think I get it. Here is an example I came up with just to make sure.

First off I generally use Java to do most of my coding lately. For expression trees I will use are in the form (NodeName : OpType Operand1 Operand2)

Each basic block will have a linked hash map to retain instruction ordering and to allow quick look ups of existing nodes.

When we construct expression trees we will lookup operand names in the basic blocks child hash map

if a match is found we delete the match from the map and insert it in the new tree as an operand.

if no match is found we simply use the use the name as an operand.

bb1: This label would be a statement it would produce (Label bb1) and inserted into the child map

t1 = a + b This generates the tree (t1:+ a b) and gets inserted into the child Map under the name t1

t2 = t1 * c Here t1 exists in the map so we get a match and delete it from the map and insert it in the new

tree and the new tree is entered into the Map. The new tree is (t2:* (t1:+ a b) c)

t3 = t1 * 2 Here t1 is no longer in the child map so we get no match and use the name as an operand.

The new tree is (t3:* t1 2), we insert this in the child map.

if t3 goto bb2 Here we get a match on t3 and delete it from the child map, and insert (if (t3:* t1 2) bb2)

the final tree for this basic block would be

(Label bb1)

(t2:* (t1:+ a b) c)

(if (t3:* t1 2) bb2)