AnyDSL / thorin

The Higher-Order Intermediate Representation
https://anydsl.github.io
GNU Lesser General Public License v3.0
150 stars 15 forks source link

Fix several PE-related issues: #94

Closed madmann91 closed 6 years ago

madmann91 commented 6 years ago
richardmembarth commented 6 years ago

aobench fails to build (cpu backend): impala: anydsl/thorin/src/thorin/be/llvm/llvm.cpp:1112: llvm::Type* thorin::CodeGen::convert(const Type*): Assertion `ret' failed.

madmann91 commented 6 years ago

I forgot to put a loop that iterates until fix point is reached for lower2cff. I have a commit that fixes this.

richardmembarth commented 6 years ago

Did you push?

richardmembarth commented 6 years ago

Stincilla looks fine with this. I'll send you information with some regressions on other codes.

leissa commented 6 years ago

@madmann91 Great work :+1: I'm fine with the changes

madmann91 commented 6 years ago

Apparently there are still some regressions on other code bases (fasis I believe?), so I need to look into that before merging.

madmann91 commented 6 years ago

I have added a new feature to this pull request. It is now possible to perform PE on mutable variables. The following Impala code:

fn @(?a & ?b) range(a: i32, b: i32, body: fn(i32) -> ()) -> () {
    if a < b {
        @@body(a);
        range(a + 1, b, body, return)
    }
}

fn @sort(p: &mut [i32], n: i32) -> () {
    for i in range(1, n) {
        let tmp = p(i);
        fn @(?j) inner_loop(j: i32) -> () {
            if j > 0 && tmp < p(j - 1) {
                p(j) = p(j - 1);
                inner_loop(j - 1);
            } else {
                p(j) = tmp;
            }
        }
        inner_loop(i, continue)
    }
}

extern fn main() -> [i32 * 10] {
    let mut p = [1, 3, 4, 6, 7, 5, 8, 2, 9, 0];
    sort(&mut p, 10);
    [p(0), p(1), p(2), p(3), p(4), p(5), p(6), p(7), p(8), p(9)]
}

Now produces the following IR:

module 'test_mut'

main_15922(mem mem_15923, fn(mem, [10 x qs32]) return_15924) extern 
    return_15924(mem_15923, ([10 x qs32] definite_array qs32 0, qs32 1, qs32 2, qs32 3, qs32 4, qs32 5, qs32 6, qs32 7, qs32 8, qs32 9))
leissa commented 6 years ago

Great work :+1: