Comments (1)
Since MIR can interpret code I was wondering if it is possible to have 2 phase compilation: interpret first, gather some profiling data and then generate machine code in second phase.
No. I don't think it is important to gather and use profile data automatically for MIR. It would be important for tracing JIT to form the right trace. But MIR is a method compiler. If you look at GCC benchmarks with and without feedback-directed optimization, the difference is not big (about 5-7%). More correctly it is big for compilers like GCC but not for simple MIR compiler.
I recently implemented a loop analysis which is used in RA to get BB frequency estimation. It is good enough although GCC uses another more sophisticated static frequency estimation algorithm.
What can be done is a decision when to JIT. It can be achieved through usage of a new interface. At the end of mir-gen.c there is simple implementation of lazy code generation of function (code generation by the 1st function call). It is only 5-10 lines of C code. It is easy to modify to generate and use code on n-th call.
The interface can be extended to collect also caller function which could be collected and used to generate code of the caller with inlining the calling functions (by using MIR_INLINE insn instead of MIR_CALL).
But I think it should be achieved by generation MIR code which will collect this info during execution (by interpreter and JITTed code). IMHO collecting and using frequency or call info is a simple case of speculation/deoptimization. For inlining we assume small number of calls and use MIR_CALL insn, if we found that there are many calls we use MIR_INLINE insn instead during generation of a new version of MIR. Dynamic languages will require more than this. For example, in CRuby JIT we can assume that Ruby VM plus insn works only with integer and generate a specialized MIR code for this with check. If the check failed, we generate new version of MIR code with general Ruby VM plus insn. We could start from opposite direction. In any case additional MIR insns should be generated to collect this info. There could be many ways of speculation (calling Ruby function, used object layout etc). MIR was designed to conveniently change version of MIR function numerous times. All function calls in MIR are implemented through a small code (thunk) which can redirect calls to different versions.
That is how I see the way currently to improve code by using a profile information.
from mir.
Related Issues (20)
- heap-buffer-overflow in `def_symbol` HOT 1
- heap-buffer-overflow in `VARR_token_tpush` and `VARR_token_tpop` HOT 3
- Assertion failed: (0), function out_op, file mir2c.c, line 65 HOT 8
- Supplying custom allocation/deallocation routines HOT 2
- Building with zig and failing at runtime on `mir_hash_1`
- Support for system calls? HOT 11
- Issue 361 test case failed HOT 2
- Shebang support for Mir files? HOT 13
- Awk has a syntax error in the benchmarks HOT 16
- Allow MIR text to be mixed in with C API
- Bug in mir-gen-x86_64.c on bbv branch HOT 3
- Add Apple Silicon CI support HOT 2
- Assertion error in 'process_aggregate_arg' for anonymous struct/union HOT 2
- Assertion error in 'get_uptodate_def_insn' relating to division by `sizeof(char)` HOT 3
- Please implement _Thread_local HOT 1
- CMake build broken with 9b7aa03 HOT 2
- Feature request: add debug info support?
- v1.0.0 Undefined function _MIR_name_char_p when #MIR_NO_SCAN is used HOT 2
- v1.0.0 Fails to compile C code HOT 6
- v1.0.0 causes crashes during execution HOT 30
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mir.