willi19 / swpp202301-compiler-team6

MIT License
0 stars 0 forks source link

[Wrap-Up] Add Add2SumPass #44

Closed germanium32 closed 1 year ago

germanium32 commented 1 year ago

Overview

Implement Add2Sum. Traverse over add instructions, and check whether if it is chained to a simple addition operation. That is:

res = a + b + c + d + e

will be transformed into ll by iterated additions, such as the form:

%0 = add %a, %b
%1 = add %0, %c
%2 = add %1, %d
%res = add %2, %e

which then can be optimized in the form:

%res = call sum(%a, %b, %c, %d, %e, 0, 0, 0)

Implementation

Reverse traverse all instructions, and find propagating tree of add instructions. Since the internal nodes will be all removed, other uses of such instructions must exist.