Repository navigation
Optimizer: code generator's CPU for the cost model, --size_level at every level, inlining of functions with a try off Windows - #804
Merged
Conversation
…at every level, inlining of functions with a try off Windows - The LLVM optimizer is handed the TargetMachine the code is generated with (the JIT's host machine, the object file's) instead of building one from -mcpu/-mattr, which under the JIT described a generic CPU while the code was generated for the host. - --size_level selects -Os/-Oz at any --opt_level above 0 (it was read only beside --opt_level=2, and the default is 3), marks functions optsize / minsize as clang does, and generates code at the -O2 level. - A function with a personality is noinline only on Windows, where Win32ExceptionPass rewrites its landing pads into funclets. - The MLIR loop-invariant code motion pass is no longer scheduled: loops are lowered to branches before it ran, so it had nothing to act on. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J8KRfVk4FT2FALW47Ux2Fp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four fixes from a review of how the MLIR and LLVM optimization passes are scheduled.
This has not been compiled or run locally (no LLVM 22 build was available where it was written), so CI is the first build and test of it.
Changes
The optimizer uses the code generator's target machine.
getTransformertakes aTargetMachine. The JIT, the JIT cache and object emission pass the one they generate code with;--emit=llvm/--emit=bcstill build one from the module triple and-mcpu/-mattr. Before, every caller passed null, and under the JIT the cost model described a generic CPU while the code was generated for the host.A function with a personality is
noinlineonly on Windows. That is whereWin32ExceptionPassrewrites landing pads into funclets. Elsewhere a function with atryor ausingcan now be inlined by LLVM. The MLIR inliner still refuses these functions.--size_levelworks at any--opt_levelabove 0. 1 selects-Os, 2 selects-Oz; functions are markedoptsize/minsizeas clang does, and object code is generated at the-O2level. It was read only beside--opt_level=2, and the default level is 3.The MLIR loop-invariant code motion pass is no longer scheduled.
While,DoWhileandForare lowered to branches before it ran, so it had nothing to act on. LLVM's LICM is unaffected.What to look at
try/catch/finally,using, the rc/own cleanup cases) under--opton Linux are the ones that would show a problem. Reverting it is the oneifinlib/TypeScript/LowerToLLVM.cpp.--opt_level=1 --size_level=1meant-O1and now means-Os; a size level above 2 is now an error at every opt level.Generated by Claude Code