AnyDSL / MimIR

MimIR is my Intermediate Representation
https://anydsl.github.io/MimIR/
MIT License
46 stars 9 forks source link

Matrix map_reduce: missing token for extractvalue in generated llvm code #223

Closed betzinger closed 1 year ago

betzinger commented 1 year ago

When trying to compile the llvm code generated from the program below, clang will abort with the error

error: expected value token
    %acc_132593 = extractvalue {i32, i32, i32, [2 x [2 x float]]*} , 3
                                                                   ^
.plugin mem;
.plugin core;
.plugin matrix;

.let M1 = %matrix.Mat(2, (2, 3), %math.F32);
.let M2 = %matrix.Mat(2, (3, 2), %math.F32);
.let M3 = %matrix.Mat(2, (2, 2), %math.F32);

.con .extern map_reduce_test [mem : %mem.M,a: M1, b: M2, c: %mem.Ptr(M3, 0), return : .Cn %mem.M] = {
    .ret (`mem, prod) = internal_mapRed_matrix_prod(2,3,2, %math.f32) $(mem, a, b); 
    .let `mem : %mem.M = %mem.store(mem, c, prod);
    return mem
};
NeuralCoder3 commented 1 year ago

This looks like an extract on type level (although I am unable to match up the code with the thorin code without further investigation).

However, the simple solution seems to be to lower everything correctly (move mems, reshape types, ...). This is all done by the closure plugin (and the closure conversion phase for higher order functions):

./build/bin/thorin -p clos [file] -o - --output-ll T.ll

Or adding

.plugin clos;
betzinger commented 1 year ago

Adding .plugin clos; produces valid llvm code, however, the generated llvm-code doesn't define the function map_reduce_test. Is there an easy fix for that or should I open another issue?

NeuralCoder3 commented 1 year ago

Adding .plugin clos; produces valid llvm code, however, the generated llvm-code doesn't define the function map_reduce_test. Is there an easy fix for that or should I open another issue?

The function is named map_reduce_test _reshape. This is a relict from when reshape renamed every function. I changed it to not rename externals. But somehow I forgot to merge the change into master.

Solutions:

Note: There are a few other things that appear weird (the three higher-order Pis without usage). But if they do not make the compiler crash/produce incorrect code, they can be ignored for now.

betzinger commented 1 year ago

Alright, thanks a lot!