Git Product home page Git Product logo

Comments (9)

vnmakarov avatar vnmakarov commented on May 6, 2024

Ok. Thank you for informing me.

I had MIR_T_V for some time but got rid of it.

I'll correct the documentation on this weekend. Thanks again.

from mir.

sletz avatar sletz commented on May 6, 2024

So what is the way to express the "void" type concept?

from mir.

vnmakarov avatar vnmakarov commented on May 6, 2024

So what is the way to express the "void" type concept?

This type was necessary once to express a MIR function w/o result in MIR textual representation. Since then the syntax was changed and void result function is a function with zero number of results.

So you don't need this type as for other assembler-level languages.

from mir.

sletz avatar sletz commented on May 6, 2024
extern MIR_item_t MIR_new_func (MIR_context_t ctx, const char *name, size_t nres,
                                MIR_type_t *res_types, size_t nargs, ...);

So how do I describe a function returning "void"? Is the following one correct ?

 MIR_type_t res_type = MIR_T_I64; // What type should be used for "res_type" ?
 fCompute = MIR_new_func(fContext, "compute", 0, &res_type, 2, MIR_T_P, "inputs",  MIR_T_P, "outputs");

from mir.

vnmakarov avatar vnmakarov commented on May 6, 2024

So how do I describe a function returning "void"? Is the following one correct ?

Yes. nres should be zero. You can pass NULL for res_types in this case.

In MIR textual representation, void function looks like

foo: func i32:arg

and the same function returning i64 value

foo: func i64, i32:arg

from mir.

sletz avatar sletz commented on May 6, 2024

OK thanks !
My project with MIR it to recode this class https://github.com/grame-cncm/faust/blob/master-dev/compiler/generator/interpreter/fbc_llvm_compiler.hh, which generates LLVM IR, to directly generate MIR, in the context of the Faust language.

from mir.

vnmakarov avatar vnmakarov commented on May 6, 2024

It is an interesting project. But I guess you need a very optimized code for your language domain, including auto-vectorization. LLVM optimization pipeline can do auto-vectorization. Vectorized code vs unvectorized code can be 2-3 times faster. Although it is hard to say what real performance difference between MIR and LLVM generated code will be for your language applications (although it is definitely less than 2-3 times).

I don't think MIR will ever support vector insns. My plans concerning optimizations is to implement loop-invariant motion additionally and add new speculative insns (it is mostly for easy implementation of dynamic type languages). Although MIR could be used as tier1 JIT compiler and LLVM as tier 2 JIT compiler. LLVM is complicated and LLVM IR interface unstable (e.g. fedora distribution has a tendency to have several versions of LLVM as different LLVM versions are required for different components), MIR is much simpler but its interface can be changed too as it is not ready yet for a release.

In any case good luck with your project and I hope you share any your experience with MIR usage for your project.

from mir.

sletz avatar sletz commented on May 6, 2024

Yes I know all of that.
My hope is to have a reasonable fast JIT (like for testing the code), easier to deploy on smaller devices (like Android, possible ARM based embedded devices at some point ?) than the big LLVM chain.

from mir.

sletz avatar sletz commented on May 6, 2024

This simple program (a function that does nothing for now, and just returns):

#include "/Documents/JIT-compilation/mir/mir.h"
#include "/Documents/JIT-compilation/mir/mir-gen.h"

typedef void (*compiledFun)(int* int_heap, float* real_heap, float** inputs, float** outputs);

int main(int argc, char* argv[])
{
    MIR_context_t fContext = MIR_init();
    MIR_module_t fModule = MIR_new_module(fContext, "Faust");
    
    // Create 'compute' function
    MIR_item_t fCompute = MIR_new_func(fContext, "compute", 0,
                            NULL, 4,
                            MIR_T_P, "int_heap",
                            MIR_T_P, "real_heap",
                            MIR_T_P, "inputs",
                            MIR_T_P, "outputs");
    
    MIR_append_insn(fContext, fCompute, MIR_new_ret_insn(fContext, 0));
    
    // Finish function
    MIR_finish_func(fContext);
    
    // Finish module
    MIR_finish_module(fContext);
    
    // Output MIR file
    FILE* file = fopen("log_mir.txt", "w");
    MIR_output_module(fContext, file, fModule);
    fclose(file);
    
    // Code generation and link
    MIR_gen_init(fContext);
    MIR_gen_set_debug_file(fContext, stderr);
    compiledFun fCompiledFun = (compiledFun)MIR_gen(fContext, fCompute);
    MIR_gen_finish(fContext);
    
    MIR_finish(fContext);
    return 0;
}

crash with:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_platform.dylib      	0x00007fff7215ffd0 _platform_memmove$VARIANT$Haswell + 176
1   libsystem_c.dylib             	0x00007fff71f1f101 __memcpy_chk + 22
2   mir-test                      	0x0000000107745120 _MIR_update_code + 1072 (mir.c:3335)
3   mir-test                      	0x0000000107739b68 _MIR_redirect_thunk + 56 (mir-x86_64.c:70)
4   mir-test                      	0x000000010776d562 MIR_gen + 1794 (mir-gen.c:4641)
5   mir-test                      	0x0000000107732a84 main + 356 (mir-test.c:36)
6   libdyld.dylib                 	0x00007
fff71e4e015 start + 1

I could not find why...

from mir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.