summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineFunctionSplitter.cpp
AgeCommit message (Collapse)Author
2024-11-22[BasicBlockSections] Allow mixing of -basic-block-sections with MFS. (#117076)Rahman Lavaee
This PR allows mixing `-basic-block-sections` with `-enable-machine-function-splitter`. The strategy is to let `-basic-block-sections` take precedence over functions with profiles.
2024-11-12[CodeGen] Remove unused includes (NFC) (#115996)Kazu Hirata
Identified with misc-include-cleaner.
2024-07-12[CodeGen][NewPM] Port `machine-block-freq` to new pass manager (#98317)paperchalice
- Add `MachineBlockFrequencyAnalysis`. - Add `MachineBlockFrequencyPrinterPass`. - Use `MachineBlockFrequencyInfoWrapperPass` in legacy pass manager. - `LazyMachineBlockFrequencyInfo::print` is empty, drop it due to new pass manager migration.
2024-02-22[CodeGen] Clean up MachineFunctionSplitter MBB safety checking (NFC)Daniel Hoekwater
Move the "is MBB safe to split" check out of `isColdBlock` and update the comment since we're no longer using a temporary hack.
2023-08-28[CodeGen][AArch64] Don't split jump table basic blocksDaniel Hoekwater
Jump tables on AArch64 are label-relative rather than table-relative, so having jump table destinations that are in different sections causes problems with relocation. Jump table lookups have a max range of 1MB, so all destinations must be in the same section as the lookup code. Both of these restrictions can be mitigated with some careful and complex logic, but doing so doesn't gain a huge performance benefit. Efficiently ensuring jump tables are correct and can be compressed on AArch64 is a TODO item. In the meantime, don't split blocks that can cause problems. Differential Revision: https://reviews.llvm.org/D157124
2023-08-25[CodeGen] Remove unused option in MachineFunctionSplitter.Snehasish Kumar
The option was added in github.com/llvm/llvm-project/commit/90ab85a but it doesn't seem to be used. The triple check has been removed so this shouldn't be required going forward. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D158885
2023-08-24[CodeGen][AArch64] Don't split functions with a red zone on AArch64Daniel Hoekwater
Because unconditional branch relaxation on AArch64 grows the stack to spill a register, splitting a function would cause the red zone to be overwritten. Explicitly disable MFS for such functions. Differential Revision: https://reviews.llvm.org/D157127
2023-08-22Reland "[CodeGen][AArch64] Make MFS testable on AArch64"Daniel Hoekwater
Reverted by 3d22dac6c3b97d7bb92f243886dfb0d32a5c42e9 because it depended on b9d079d6188b50730e0a67267b7fee36008435ce, which broke some tests.
2023-08-21Revert D157750 "[Driver][CodeGen] Properly handle -fsplit-machine-functions ↵Fangrui Song
for fatbinary compilation." This reverts commit 317a0fe5bd7113c0ac9d30b2de58ca409e5ff754. This reverts commit 30c4b97aec60895a6905816670f493cdd1d7c546. See post-commit discussions on https://reviews.llvm.org/D157750 that we should use a different mechanism to handle the error with --cuda-gpu-arch= The IR/DiagnosticInfo.cpp, warn_drv_for_elf_only, codegne tests in clang/test/Driver, and the following driver behavior (downgrading error to warning) changes are undesired. ``` % clang --target=riscv64 -fsplit-machine-functions -c a.c warning: -fsplit-machine-functions is not valid for riscv64 [-Wbackend-plugin] ```
2023-08-16[Driver][CodeGen] Properly handle -fsplit-machine-functions for fatbinary ↵Han Shen
compilation. When building a fatbinary, the driver invokes the compiler multiple times with different "--target". (For example, with "-x cuda --cuda-gpu-arch=sm_70" flags, clang will be invoded twice, once with --target=x86_64_...., once with --target=sm_70) If we use -fsplit-machine-functions or -fno-split-machine-functions for such invocation, the driver reports an error. This CL changes the behavior so: - "-fsplit-machine-functions" is now passed to all targets, for non-X86 targets, the flag is a NOOP and causes a warning. - "-fno-split-machine-functions" now negates -fsplit-machine-functions (if -fno-split-machine-functions appears after any -fsplit-machine-functions) for any target triple, previously, it causes an error. - "-fsplit-machine-functions -Xarch_device -fno-split-machine-functions" enables MFS on host but disables MFS for GPUS without warnings/errors. - "-Xarch_host -fsplit-machine-functions" enables MFS on host but disables MFS for GPUS without warnings/errors. Reviewed by: xur, dhoekwater Differential Revision: https://reviews.llvm.org/D157750
2023-07-18[CodeGen] Separate MachineFunctionSplitter logic for different profile types.Han Shen
In D152577 @xur has a post-submit comment regarding to an awkward usage of MFS for Autofdo - instead of just using -fsplit-machine-function, the user needs to add "-mllvm -mfs-psi-cutoff=0" to choose the right logic for AutoFDO. The compiler should choose the right default values for such case. This CL separate MFS logic for different profile types. Reviewed By: xur, wenlei Differential Revision: https://reviews.llvm.org/D155253
2023-07-10[CodeGen] Fine tune MachineFunctionSplitPass (MFS) for FSAFDO.Han Shen
The original MFS work D85368 shows good performance improvement with Instrumented FDO. However, AutoFDO or Flow-Sensitive AutoFDO (FSAFDO) does not show performance gain. This is mainly caused by a less accurate profile compared to the iFDO profile. For the past few months, we have been working to improve FSAFDO quality, like in D145171. Taking advantage of this improvement, MFS now shows performance improvements over FSAFDO profiles. That being said, 2 minor changes need to be made, 1) An FS-AutoFDO profile generation pass needs to be added right before MFS pass and an FSAFDO profile load pass is needed when FS-AutoFDO is enabled and the MFS flag is present. 2) MFS only applies to hot functions, because we believe (and experiment also shows) FS-AutoFDO is more accurate about functions that have plenty of samples than those with no or very few samples. With this improvement, we see a 1.2% performance improvement in clang benchmark, 0.9% QPS improvement in our internal search benchmark, and 3%-5% improvement in internal storage benchmark. This is #1 of the two patches that enables the improvement. Reviewed By: wenlei, snehasish, xur Differential Revision: https://reviews.llvm.org/D152399
2023-01-30[Pseudo Probe] Do not instrument EH blocks.Hongtao Yu
This change avoids inserting probes to EH blocks. Pseudo probe can prevent block merging when probes in the blocks look different. This has a chained effect to passes incurring exponential IR growth (such as jump threading) and as a consequence the compilation may time out. Not inserting probes to EH blocks could mitigate the issue. Another benefit is that both IR size and binary size are smaller. Since EH blocks are usually cold, the change should have minimal impact to profile quality. Testing: Out of two internal large benchmarks, no perf impact seen. 1% size savings to both the `text` and the `pseudo_probe` section. Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D142747
2022-12-16[Transforms,CodeGen] std::optional::value => operator*/operator->Fangrui Song
value() has undesired exception checking semantics and calls __throw_bad_optional_access in libc++. Moreover, the API is unavailable without _LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS).
2022-12-06[YAML] Convert Optional to std::optionalKrzysztof Parzyszek
2022-12-05[IR] llvm::Optional => std::optionalFangrui Song
Many llvm/IR/* files have been migrated by other contributors. This migrates most remaining files.
2022-08-17Split EH code by defaultArchit Saxena
The current machine function splitter is reliant on profile data to do profile summary analysis to split blocks into cold section. This may sometimes limit the usage of machine function splitter especially in cases where we could do some form of static analysis to split out cold blocks if profile data is absent or profile data which may be faulty (Consider Sample PGO). Of all code that could statically be marked cold Exception handling blocks are one of them (In fact BFI framework also tends to mark them as cold), and the most in size contribution. In my experiments I found out Exception handling pads and all code reachable from there account for up to 6-8% of the .text section on modern production binaries. This patch introduces a flag to split out all Exception handling blocks and blocks only reachable from Exceptional Handling pad to cold section. This flag has shown to give a performance win of up to 0.1% in terms of average cycles and instructions executed on internal facebook search service. Reviewed By: snehasish Differential Revision: https://reviews.llvm.org/D131824
2022-07-22Add a nop instruction if a section starts with landing pad for function splitterARCHIT SAXENA
This change adds a nop instruction if section starts with landing pad. This change is like [D73739](https://reviews.llvm.org/D73739) which avoids zero offset landing pad in basic block sections. Detailed description: The current machine functions splitter can create ˜sections which start with a landing pad themselves. This places landing pad at offset zero from LPStart. ``` .section .text.split.foo10,"ax",@progbits foo10.cold: # %lpad .cfi_startproc .cfi_personality 3, __gxx_personality_v0 .cfi_lsda 3, .Lexception5 .cfi_def_cfa %rsp, 16 .Ltmp11: <--- This is a Landing pad and also LP Start as it is start of this section movq %rax, %rdi <--- first instruction is at offest 0 from LPStart callq _Unwind_Resume@PLT ``` This will cause landing pad entries to become zero (.Ltmp11-foo10.cold) ``` .Lcst_begin4: .uleb128 .Ltmp9-.Lfunc_begin2 # >> Call Site 1 << .uleb128 .Ltmp10-.Ltmp9 # Call between .Ltmp9 and .Ltmp10 .uleb128 .Ltmp11-foo10.cold <---This is zero # jumps to .Ltmp11 .byte 3 # On action: 2 .uleb128 .Ltmp10-.Lfunc_begin2 # >> Call Site 2 << .uleb128 .Lfunc_end9-.Ltmp10 # Call between .Ltmp10 and .Lfunc_end9 .byte 0 # has no landing pad .byte 0 # On action: cleanup .p2align 2 ``` The C++ ABI somehow assumes that no landing pads point directly to LPStart (which works in the normal case since the function begin is never a landing pad), and uses LP.offset = 0 to specify no landing pad. This change adds a nop instruction at start of such sections so that such a case could be avoided. Output: ``` .section .text.split.foo10,"ax",@progbits foo10.cold: # %lpad .cfi_startproc .cfi_personality 3, __gxx_personality_v0 .cfi_lsda 3, .Lexception5 .cfi_def_cfa %rsp, 16 nop <--- new instruction that is added .Ltmp11: movq %rax, %rdi callq _Unwind_Resume@PLT ``` Reviewed By: modimo, snehasish, rahmanl Differential Revision: https://reviews.llvm.org/D130133
2022-07-13[llvm] Use value instead of getValue (NFC)Kazu Hirata
2022-06-25[llvm] Don't use Optional::hasValue (NFC)Kazu Hirata
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata
2022-06-20[llvm] Don't use Optional::hasValue (NFC)Kazu Hirata
2022-03-16Cleanup codegen includesserge-sans-paille
This is a (fixed) recommit of https://reviews.llvm.org/D121169 after: 1061034926 before: 1063332844 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121681
2022-03-10Revert "Cleanup codegen includes"Nico Weber
This reverts commit 7f230feeeac8a67b335f52bd2e900a05c6098f20. Breaks CodeGenCUDA/link-device-bitcode.cu in check-clang, and many LLVM tests, see comments on https://reviews.llvm.org/D121169
2022-03-10Cleanup codegen includesserge-sans-paille
after: 1061034926 before: 1063332844 Differential Revision: https://reviews.llvm.org/D121169
2021-04-23[NFC] Use hasSection instead of getSection().empty()Snehasish Kumar
Use the optimized check hasSection() instead of calling getSection().empty(). Originally suggested in D101004, but was dropped in the commit.
2021-04-21[CodeGen] Do not split functions with attr "implicit-section-name".Snehasish Kumar
The #pragma clang section can be used at a coarse granularity to specify the section used for bss/data/text/rodata for global objects. When split functions is enabled, the function may be split into two parts violating user expectations. Reference: https://clang.llvm.org/docs/LanguageExtensions.html#specifying-section-names-for-global-objects-pragma-clang-section Differential Revision: https://reviews.llvm.org/D101004
2021-02-11[CodeGen] Split out cold exception handling pads.Snehasish Kumar
Support for splitting exception handling pads was added in D73739. This change updates the code to split out exception handling pads if profile information indicates that they are cold. For a given function with multiple landind pads, if one of them is hot they are all retained as part of the hot code section. Differential Revision: https://reviews.llvm.org/D96372
2020-12-08[CodeGen] Add text section prefix for COFF object filePan, Tao
Text section prefix is created in CodeGenPrepare, it's file format independent implementation, text section name is written into object file in TargetLoweringObjectFile, it's file format dependent implementation, port code of adding text section prefix to text section name from ELF to COFF. Different with ELF that use '.' as concatenation character, COFF use '$' as concatenation character. That is, concatenation character is variable, so split concatenation character from text section prefix. Text section prefix is existing feature of ELF, it can help to reduce icache and itlb misses, it's also make possible aggregate other compilers e.g. v8 created same prefix sections. Furthermore, the recent feature Machine Function Splitter (basic block level text prefix section) is based on text section prefix. Reviewed By: pengfei, rnk Differential Revision: https://reviews.llvm.org/D92073
2020-10-14[llvm] Update default cutoff threshold for machine function splitter.Snehasish Kumar
Based on internal testing at Google we found that setting the profile summary cutoff threshold to 999950 yields the best results in terms of itlb and icache metrics (as observed on Intel CPUs). *default* = Split out code if no profile count available for block *size-%* = The fraction of bytes split out of .text and .text.hot *itlb* = Misses per kilo instructions (MPKI) for itlb *icache* = Misses per kilo instructions (MPKI) for L1 icache Search1 | cutoff | size-% | itlb | icache | |---------|---------|-----------|---------| | default | 42.5861 | 0.0822151 | 2.46363 | | 999999 | 44.9350 | 0.0767194 | 2.44416 | | 999950 | 50.0660 | 0.075744 | 2.4091 | | 999500 | 56.9158 | 0.082564 | 2.4188 | | 995000 | 63.8625 | 0.0814927 | 2.42832 | | 990000 | 71.7314 | 0.106906 | 2.57785 | Search2 | cutoff | size-% | itlb | icache | |---------|--------|----------|---------| | default | 2.8845 | 0.626712 | 4.73245 | | 999999 | 3.3291 | 0.602309 | 4.70045 | | 999950 | 3.8577 | 0.587842 | 4.71632 | | 999500 | 4.4170 | 0.63577 | 4.68351 | | 995000 | 5.1020 | 0.657969 | 4.82272 | | 990000 | 5.7153 | 0.719122 | 5.39496 | Differential Revision: https://reviews.llvm.org/D89085
2020-08-28[llvm][CodeGen] Machine Function SplitterSnehasish Kumar
We introduce a codegen optimization pass which splits functions into hot and cold parts. This pass leverages the basic block sections feature recently introduced in LLVM from the Propeller project. The pass targets functions with profile coverage, identifies cold blocks and moves them to a separate section. The linker groups all cold blocks across functions together, decreasing fragmentation and improving icache and itlb utilization. We evaluated the Machine Function Splitter pass on clang bootstrap and SPECInt 2017. For clang bootstrap we observe a mean 2.33% runtime improvement with a ~32% reduction in itlb and stlb misses. Additionally, L1 icache misses reduced by 9.5% while L2 instruction misses reduced by 20%. For SPECInt we report the change in IntRate the C/C++ benchmarks. All benchmarks apart from mcf and x264 improve, on average by 0.6% with the max for deepsjeng at 1.6%. Benchmark % Change 500.perlbench_r 0.78 502.gcc_r 0.82 505.mcf_r -0.30 520.omnetpp_r 0.18 523.xalancbmk_r 0.37 525.x264_r -0.46 531.deepsjeng_r 1.61 541.leela_r 0.83 557.xz_r 0.15 Differential Revision: https://reviews.llvm.org/D85368