SJTU ACM Class Compiler Design and Implementation 2022 Assignment ( MS208 Course Project )
An Mx* Compiler which abandoned SSA-based optimizations in favor of self-designed magic optimizations. (Because I won't take that compiler optimization course next semester.)
Violet IR is an IR simplified from LLVM IR without guaranteeing SSA in order to achieve some magical optimizations.
@ global
% local
void
iN
<type> * pointer
<type> (<parameter list>) function
{<type list>} class
@global_string = global i8* "Hello world\00"
define i32 @foo(i32 %a)
{
ret i32 0
}
%MyStruct = type
{
i32,
i8
}
@global_variable = global i32 0
%local_variable = add %a, %b
add
sub
mul
div
rem
shl
shr
and
or
xor
%1 = load @global_variable
store 1, @global_variable
%1 = get %my_structs, 1
Type of %a, %b
must be i32
.
Return an i1
value.
%comparison_result = cmp uge %a, %b
eq, ne, sgt, sge, slt, sle
Type of %comparison_result
must be i1
.
br %comparison_result, A, B
jp start
%1 = call @foo(%variable, 1)
move %a, %b
ret 0