Skip to content
/ latte Public

Latte compiler for llvm - compilers construction 2nd assignment

Notifications You must be signed in to change notification settings

stiepan/latte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compilers construction 2nd assignment

Compiler of simple imperative language for llvm

Optimizations:
1. constants propagation
2. copy propagation
3. expressions folding
4. local common subexpression elimination
4a. there's a variant of simple global common subexpression elimination but
at this point it's inefficient and doesn't handle cycles in flow graph very well
5. some peepholes optimizations

For instance:

    string a = "aaa";
    string b = "aaa";
    string c = a + "bb";
    string d = b + "bb";
    if (c == d) {
        printString(a + b);
    }
    if (a + "bb" == "aaa" + "bb") {
        printString(b + a);
    }
    return 0;

results in the following llvm code
define i32 @main() {
    %t1 = getelementptr [4 x i8], [4 x i8]* @.str.0, i32 0, i32 0
    %t2 = getelementptr [3 x i8], [3 x i8]* @.str.1, i32 0, i32 0
    %t3 = call i8* @__concat(i8* %t1, i8* %t2)
    %t6 = call i8* @__concat(i8* %t1, i8* %t1)
    call void @printString(i8* %t6)
    call void @printString(i8* %t6)
    ret i32 0
}

------------------------------------------
Compiled with ghc 8.6.4
Uses llvm-as and llvm-link (6.0)

About

Latte compiler for llvm - compilers construction 2nd assignment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published