4 ms·
Is there a name for duplicating function calls such that different optimizations for the same function can be compiled, but they are not fully duplicated at eve
by jayd16 9mo ago
Is there a name for duplicating function calls such that different optimizations for the same function can be compiled, but they are not fully duplicated at every call site?
- Someone 9mo agoI think that is called specialization (https://www.linkedin.com/posts/compilers-lab_compiler-programming-research-activity-7364732010130554882-B_ty https://www.linkedin.com/posts/compilers-lab_compiler-progra...). Even if the compiler doesn’t explicitly do it, it can happen when doing subsequent optimization steps after inlining such as constant folding and dead code elimination.
- hinkley 9mo agoSpecialization is one of the reasons my call trees are just a little bit deeper than what one would expect given my loud but moderate stance on function splitting. Uncle Bob is nuts for espousing one line functions. But the answer to Bob being a lunatic is not two page functions. I think you can say a lot in five to six lines, and not overshoot meaningful names into word salad because you’ve run out of ideas. That’s still small enough for branch prediction, inlining, and specialization to kick in per call site, particularly if some callers follow one conditional branch and the others favors the other.
- taeric 9mo agoI think this is what the C++ world calls template specialization?
- khuey 9mo agoIf I understand what you're asking for correctly, function cloning. If you have f(x, y) and the compiler realizes the function optimizes nicely when y == 2 it can create a clone of f with a fixed argument y == 2, optimize that, and rewrite the appropriate call sites to call the clone.
- deleted 9mo ago[deleted]
- mgaunard 9mo agoCompilers aren't as good at doing that one unfortunately.
- fweimer 9mo agoI think GCC calls the IPA (inter-procedural analysis) clones. https://gcc.gnu.org/onlinedocs/gccint/IPA-passes.html https://gcc.gnu.org/onlinedocs/gccint/IPA-passes.html https://gcc.gnu.org/onlinedocs/gccint/Regular-IPA-passes.html https://gcc.gnu.org/onlinedocs/gccint/Regular-IPA-passes.htm... https://gcc.gnu.org/onlinedocs/gccint/Late-IPA-passes.html https://gcc.gnu.org/onlinedocs/gccint/Late-IPA-passes.html
- mathisfun123 9mo agospecialization - i don't know if general purpose compilers do this but ML compilers specialize the hell out of kernels (based on constants, types, tensor dimensions, etc). EDIT: i'm le dumb - this is the whole point of JIT compilers.