summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
AgeCommit message (Collapse)Author
2025-05-17[ICP] Use a block with LLVM_DEBUG (NFC) (#140387)Kazu Hirata
Using a block inside LLVM_DEBUG allows us to simplify the code with a single LLVM_DEBUG and remove maybe_unused.
2025-03-23[Transforms] Use *Set::insert_range (NFC) (#132652)Kazu Hirata
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E); down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration.
2024-11-06[Instrumentation] Remove unused includes (NFC) (#115117)Kazu Hirata
Identified with misc-include-cleaner.
2024-10-16[LLVM] Add `Intrinsic::getDeclarationIfExists` (#112428)Rahul Joshi
Add `Intrinsic::getDeclarationIfExists` to lookup an existing declaration of an intrinsic in a `Module`.
2024-10-02[TypeProf][PGO]Support skipping vtable comparisons for a class and its ↵Mingming Liu
derived ones (#110575) Performance critical core libraries could be highly-optimized for arch or micro-arch features. For instance, the absl crc library specializes different templated classes among different hardwares [1]. In a practical setting, it's likely that instrumented profiles are collected on one type of machine and used to optimize binaries that run on multiple types of hardwares. While this kind of specialization is rare in terms of lines of code, compiler can do a better job to skip vtable-based ICP. * The per-class `Extend` implementation is arch-specific as well. If an instrumented profile is collected on one arch and applied to another arch where `Extend` implementation is different, `Extend` might be regarded as unlikely function in the latter case. `ABSL_ATTRIBUTE_HOT` annotation alleviates the problem by putting all `Extend` implementation into the hot text section [2] This change introduces a comma-separated list to specify the mangled vtable names, and ICP pass will skip vtable-based comparison if a vtable variable definition is shown to be in its class hierarchy (per LLVM type metadata). [1] https://github.com/abseil/abseil-cpp/blob/c6b27359c3d27438b1313dddd7598914c1274a50/absl/crc/internal/crc_x86_arm_combined.cc#L621-L650 [2] https://github.com/abseil/abseil-cpp/blame/c6b27359c3d27438b1313dddd7598914c1274a50/absl/crc/internal/crc_x86_arm_combined.cc#L370C3-L370C21
2024-09-15[Instrumentation] Move out to Utils (NFC) (#108532)Antonio Frighetto
Utility functions have been moved out to Utils. Minor opportunity to drop the header where not needed.
2024-08-27[ICP] Fix warningsKazu Hirata
This patch fixes: llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp:845:12: error: variable 'RemainingVTableCount' set but not used [-Werror,-Wunused-but-set-variable] llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp:306:23: error: private field 'PSI' is not used [-Werror,-Wunused-private-field] Here are a couple of domino effects: - Once I remove PSI, I need to update the contructor and its caller. - Once I remove RemainingVTableCount, I don't need TotalCount, so I am updating the caller as well.
2024-08-27[TypeProf][ICP]Allow vtable-comparison as long as vtable count is comparable ↵Mingming Liu
with function count for each candidate (#106260) The current cost-benefit analysis between vtable comparison and function comparison require the indirect fallback branch to be cold. This is too conservative. This change allows vtable-comparison as long as vtable count is comparable with function count for each function candidate and removes the cold indirect fallback requirement. Tested: 1. Testing this on benchmarks uplifts the measurable performance wins. Counting the (possibly-duplicated) remarks (because of linkonce_odr functions, cross-module import of functions) show the number of vtable remarks increases from ~30k-ish to 50k-ish. 2. https://gcc.godbolt.org/z/sbGK7Pacn shows vtable-comparison doesn't happen today (using the same IR input)
2024-07-01[IndirectCallPromotion] Migrate to a new version of getValueProfDataFromInst ↵Kazu Hirata
(#97357)
2024-07-01[IndirectCallPromotion] Use ArrayRef<PromotionCandidate> (NFC) (#97236)Kazu Hirata
Aside from the fact that LLVM Programmer's Manual prefers ArrayRef to const std::vector &, ArrayRef<PromotionCandidate> here makes it easier to switch the underlying type to something like SmallVector. Note that we typically do not have a lot of candidates.
2024-06-30[TypeProf] Include unordered_map after #81442Fangrui Song
Needed by VTableAddressPointOffsetValMap.
2024-06-29[TypeProf][InstrFDO]Implement more efficient comparison sequence for ↵Mingming Liu
indirect-call-promotion with vtable profiles. (#81442) Clang's `-fwhole-program-vtables` is required for this optimization to take place. If `-fwhole-program-vtables` is not enabled, this change is no-op. * Function-comparison (before): ``` %vtable = load ptr, ptr %obj %vfn = getelementptr inbounds ptr, ptr %vtable, i64 1 %func = load ptr, ptr %vfn %cond = icmp eq ptr %func, @callee br i1 %cond, label bb1, label bb2: bb1: call @callee bb2: call %func ``` * VTable-comparison (after): ``` %vtable = load ptr, ptr %obj %cond = icmp eq ptr %vtable, @vtable-address-point br i1 %cond, label bb1, label bb2: bb1: call @callee bb2: %vfn = getelementptr inbounds ptr, ptr %vtable, i64 1 %func = load ptr, ptr %vfn call %func ``` Key changes: 1. Find out virtual calls and the vtables they come from. - The ICP relies on type intrinsic `llvm.type.test` to find out virtual calls and the compatible vtables, and relies on type metadata to find the address point for comparison. 2. ICP pass does cost-benefit analysis and compares vtable only when the number of vtables for a function candidate is within (option specified) threshold. 3. Sink the function addressing and vtable load instruction to indirect fallback. - The sink helper functions are simplified versions of `InstCombinerImpl::tryToSinkInstruction`. Currently debug intrinsics are not handled. Ideally `InstCombinerImpl::tryToSinkInstructionDbgValues` and `InstCombinerImpl::tryToSinkInstructionDbgVariableRecords` could be moved into Transforms/Utils/Local.cpp (or another util cpp file) to handle debug intrinsics when moving instructions across basic blocks. 4. Keep value profiles updated 1) Update vtable value profiles after inline 2) For either function-based comparison or vtable-based comparison, update both vtable and indirect call value profiles.
2024-06-28[IndirectCallPromotion] Use ArrayRef consistently (NFC) (#96412)Kazu Hirata
2024-06-17[Analysis] Clean up getPromotionCandidatesForInstruction (NFC) (#95624)Kazu Hirata
Callers of getPromotionCandidatesForInstruction pass NumVals as an out parameter for the number of value-count pairs of the value profiling data, but nobody uses the out parameter. This patch removes the parameter and updates the callers. Note that the number of value-count pairs is still available via getPromotionCandidatesForInstruction(...).size().
2024-06-12Reapply "[llvm][IR] Extend BranchWeightMetadata to track provenance o… ↵Paul Kirth
(#95281) …f weights" #95136 Reverts #95060, and relands #86609, with the unintended code generation changes addressed. This patch implements the changes to LLVM IR discussed in https://discourse.llvm.org/t/rfc-update-branch-weights-metadata-to-allow-tracking-branch-weight-origins/75032 In this patch, we add an optional field to MD_prof meatdata nodes for branch weights, which can be used to distinguish weights added from llvm.expect* intrinsics from those added via other methods, e.g. from profiles or inserted by the compiler. One of the major motivations, is for use with MisExpect diagnostics, which need to know if branch_weight metadata originates from an llvm.expect intrinsic. Without that information, we end up checking branch weights multiple times in the case if ThinLTO + SampleProfiling, leading to some inaccuracy in how we report MisExpect related diagnostics to users. Since we change the format of MD_prof metadata in a fundamental way, we need to update code handling branch weights in a number of places. We also update the lang ref for branch weights to reflect the change.
2024-06-11Revert "[llvm][IR] Extend BranchWeightMetadata to track provenance of ↵Paul Kirth
weights" (#95060) Reverts llvm/llvm-project#86609 This change causes compile-time regressions for stage2 builds (https://llvm-compile-time-tracker.com/compare.php?from=3254f31a66263ea9647c9547f1531c3123444fcd&to=c5978f1eb5eeca8610b9dfce1fcbf1f473911cd8&stat=instructions:u). It also introduced unintended changes to `.text` which should be addressed before relanding.
2024-06-10[llvm][IR] Extend BranchWeightMetadata to track provenance of weights (#86609)Paul Kirth
This patch implements the changes to LLVM IR discussed in https://discourse.llvm.org/t/rfc-update-branch-weights-metadata-to-allow-tracking-branch-weight-origins/75032 In this patch, we add an optional field to MD_prof metadata nodes for branch weights, which can be used to distinguish weights added from `llvm.expect*` intrinsics from those added via other methods, e.g. from profiles or inserted by the compiler. One of the major motivations, is for use with MisExpect diagnostics, which need to know if branch_weight metadata originates from an llvm.expect intrinsic. Without that information, we end up checking branch weights multiple times in the case if ThinLTO + SampleProfiling, leading to some inaccuracy in how we report MisExpect related diagnostics to users. Since we change the format of MD_prof metadata in a fundamental way, we need to update code handling branch weights in a number of places. We also update the lang ref for branch weights to reflect the change.
2024-04-11[NFC][IndirectCallProm] Refactor function-based conditional devirtualization ↵Mingming Liu
and indirect call value profile update into one helper function (#80762) * The motivation is to move indirect callee profile update inside the function-based speculative indirect-call promotion, so that there are fewer diffs the vtable-based transformation and profile update is implemented in a follow-up patch. * The Parent patch is https://github.com/llvm/llvm-project/pull/79381
2023-11-16Add setBranchWeigths convenience function. NFC (#72446)Matthias Braun
Add `setBranchWeights` convenience function to ProfDataUtils.h and use it where appropriate.
2023-07-20[nfc] Renamed ICallPromotionFunc to InidrectCallPromoterMircea Trofin
For (subjectively) more clarity; also updated the comment describing it. Differential Revision: https://reviews.llvm.org/D155888
2023-07-20[nfc] small maintainability IndirectCallPromotion changesMircea Trofin
- we can remove the `Module` field, it's obtainable from `F` and used in only one place - a few fields can be `const`-ed, thus enforcing compile-time initialization checking (and we don't need to support `operator=`) Differential Revision: https://reviews.llvm.org/D155212
2023-07-12[nfc] rename `AM` to `MAM` in PGOInstrumentationMircea Trofin
Consistency with how we tend to name `ModuleAnalysisManager` parameters.
2023-07-12[nfc] simplify promoteIndirectCallsMircea Trofin
There's no caller to `promoteIndirectCalls` that would pass a nullptr `ModuleAnalysisManager`, so passing it by reference does away with a bunch of nullptr tests, and also removes the need for a "OwnedORE". Differential Revision: https://reviews.llvm.org/D155027
2022-08-07[llvm] Qualify auto (NFC)Kazu Hirata
Identified with readability-qualified-auto.
2022-06-03[llvm] Remove unneeded cl::ZeroOrMore for cl::opt options. NFCFangrui Song
Some cl::ZeroOrMore were added to avoid the `may only occur zero or one times!` error. More were added due to cargo cult. Since the error has been removed, cl::ZeroOrMore is unneeded. Also remove cl::init(false) while touching the lines.
2022-05-04[iwyu] Handle regressions in libLLVM header includeserge-sans-paille
Running iwyu-diff on LLVM codebase since fa5a4e1b95c8f37796 detected a few regressions, fixing them. Differential Revision: https://reviews.llvm.org/D124847
2022-04-15[PGO] Remove legacy PM passesFangrui Song
Legacy PM for optimization pipeline was deprecated in 13.0.0 and Clang dropped legacy PM support in D123609. This change removes legacy PM passes for PGO so that downstream projects won't be able to use it. It seems appropriate to start removing such "add-on" features like instrumentations, before we remove more stuff after 15.x is branched. I have checked many LLVM users and only ldc[1] uses the legacy PGO pass. [1]: https://github.com/ldc-developers/ldc/issues/3961 Reviewed By: davidxl Differential Revision: https://reviews.llvm.org/D123834
2022-03-12Cleanup includes: DebugInfo & CodeGenserge-sans-paille
Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121332
2021-06-04Fix some -Wunused-but-set-variable in -DLLVM_ENABLE_ASSERTIONS=off buildFangrui Song
2021-03-12[IndirectCallPromotion] Recommit "Don't strip ".__uniq." suffix when it stripsWei Mi
".llvm." suffix". The recommit fixed a bug that symbols with "." at the beginning is not properly handled in the last commit. Original commit message: Currently IndirectCallPromotion simply strip everything after the first "." in LTO mode, in order to match the symbol name and the name with ".llvm." suffix in the value profile. However, if -funique-internal-linkage-names and thinlto are both enabled, the name may have both ".__uniq." suffix and ".llvm." suffix, and the current mechanism will strip them both, which is unexpected. The patch fixes the problem. Differential Revision: https://reviews.llvm.org/D98389
2020-12-08[ICP] Don't promote when target not defined in moduleTeresa Johnson
This guards against cases where the symbol was dead code eliminated in the binary by ThinLTO, and we have a sample profile collected for one binary but used to optimize another. Most of the benefit from ICP comes from inlining the target, which we can't do with only a declaration anyway. If this is in the pre-ThinLTO link step (e.g. for instrumentation based PGO), we will attempt the promotion again in the ThinLTO backend after importing anyway, and we don't need the early promotion to facilitate that. Differential Revision: https://reviews.llvm.org/D92804
2020-04-29[llvm][NFC] Change parameter type to more specific CallBase in ↵Mircea Trofin
IndirectCallPromotion Reviewers: dblaikie, craig.topper, wmi Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79047
2020-04-28[llvm][NFC] Refactor APIs operating on CallBaseMircea Trofin
Summary: Refactored the parameter and return type where they are too generally typed as Instruction. Reviewers: dblaikie, wmi, craig.topper Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79027
2020-04-12[llvm][NFC] Refactor uses of CallSite to CallBase - call promotionMircea Trofin
Summary: Updated CallPromotionUtils and impacted sites. Parameters that are expected to be non-null, and return values that are guranteed non-null, were replaced with CallBase references rather than pointers. Left FIXME in places where more changes are facilitated by CallBase, but aren't CallSites: Instruction* parameters or return values, for example, where the contract that they are actually CallBase values. Reviewers: davidxl, dblaikie, wmi Reviewed By: dblaikie Subscribers: arsenm, jvesely, nhaehnle, eraman, hiraditya, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77930
2019-11-13Sink all InitializePasses.h includesReid Kleckner
This file lists every pass in LLVM, and is included by Pass.h, which is very popular. Every time we add, remove, or rename a pass in LLVM, it caused lots of recompilation. I found this fact by looking at this table, which is sorted by the number of times a file was changed over the last 100,000 git commits multiplied by the number of object files that depend on it in the current checkout: recompiles touches affected_files header 342380 95 3604 llvm/include/llvm/ADT/STLExtras.h 314730 234 1345 llvm/include/llvm/InitializePasses.h 307036 118 2602 llvm/include/llvm/ADT/APInt.h 213049 59 3611 llvm/include/llvm/Support/MathExtras.h 170422 47 3626 llvm/include/llvm/Support/Compiler.h 162225 45 3605 llvm/include/llvm/ADT/Optional.h 158319 63 2513 llvm/include/llvm/ADT/Triple.h 140322 39 3598 llvm/include/llvm/ADT/StringRef.h 137647 59 2333 llvm/include/llvm/Support/Error.h 131619 73 1803 llvm/include/llvm/Support/FileSystem.h Before this change, touching InitializePasses.h would cause 1345 files to recompile. After this change, touching it only causes 550 compiles in an incremental rebuild. Reviewers: bkramer, asbirlea, bollu, jdoerfert Differential Revision: https://reviews.llvm.org/D70211
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
2019-04-05Change some dyn_cast to more apropriate isa. NFCFangrui Song
llvm-svn: 357773
2019-04-04[IR] Refactor attribute methods in Function class (NFC)Evandro Menezes
Rename the functions that query the optimization kind attributes. Differential revision: https://reviews.llvm.org/D60287 llvm-svn: 357731
2019-04-03[IR] Create new method in `Function` class (NFC)Evandro Menezes
Create method `optForNone()` testing for the function level equivalent of `-O0` and refactor appropriately. Differential revision: https://reviews.llvm.org/D59852 llvm-svn: 357638
2019-02-05[SamplePGO] Minor efficiency improvement in samplePGO ICPTeresa Johnson
Summary: When attaching prof metadata to promoted direct calls in SamplePGO mode, no need to construct and use a SmallVector to pass a single count to the ArrayRef parameter, we can simply use a brace-enclosed init list. This made a small but consistent improvement for a ThinLTO backend compile I was measuring. Reviewers: wmi Subscribers: mehdi_amini, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57706 llvm-svn: 353123
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2019-01-07[CallSite removal] Port `IndirectCallSiteVisitor` to use `CallBase` andChandler Carruth
update client code. Also rename it to use the more generic term `call` instead of something that could be confused with a praticular type. Differential Revision: https://reviews.llvm.org/D56183 llvm-svn: 350508
2018-11-19[ProfileSummary] Standardize methods and fix commentVedant Kumar
Every Analysis pass has a get method that returns a reference of the Result of the Analysis, for example, BlockFrequencyInfo &BlockFrequencyInfoWrapperPass::getBFI(). I believe that ProfileSummaryInfo::getPSI() is the only exception to that, as it was returning a pointer. Another change is renaming isHotBB and isColdBB to isHotBlock and isColdBlock, respectively. Most methods use BB as the argument of variable names while methods usually refer to Basic Blocks as Blocks, instead of BB. For example, Function::getEntryBlock, Loop:getExitBlock, etc. I also fixed one of the comments. Patch by Rodrigo Caetano Rocha! Differential Revision: https://reviews.llvm.org/D54669 llvm-svn: 347182
2018-08-24[PGO] add target md5sum in warning message for icallXinliang David Li
Differential revision: http://reviews.llvm.org/D51193 llvm-svn: 340657
2018-05-14Rename DEBUG macro to LLVM_DEBUG.Nicola Zaghen
The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM - Manual change to APInt - Manually chage DOCS as regex doesn't match it. In the transition period the DEBUG() macro is still present and aliased to the LLVM_DEBUG() one. Differential Revision: https://reviews.llvm.org/D43624 llvm-svn: 332240
2018-03-23Fix Layering, move instrumentation transform headers into Instrumentation ↵David Blaikie
subdirectory llvm-svn: 328379
2017-12-06[PGO] Make indirect call promotion a utilityMatthew Simpson
This patch factors out the main code transformation utilities in the pgo-driven indirect call promotion pass and places them in Transforms/Utils. The change is intended to be a non-functional change, letting non-pgo-driven passes share a common implementation with the existing pgo-driven pass. The common utilities are used to conditionally promote indirect call sites to direct call sites. They perform the underlying transformation, and do not consider profile information. The pgo-specific details (e.g., the computation of branch weight metadata) have been left in the indirect call promotion pass. Differential Revision: https://reviews.llvm.org/D40658 llvm-svn: 319963
2017-10-21[Transforms] Fix some Clang-tidy modernize and Include What You Use ↵Eugene Zelenko
warnings; other minor fixes (NFC). llvm-svn: 316253
2017-10-11[NFC] Convert OptimizationRemarkEmitter old emit() calls to new closureVivek Pandya
parameterized emit() calls Summary: This is not functional change to adopt new emit() API added in r313691. Reviewed By: anemet Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38285 llvm-svn: 315476
2017-10-09Rename OptimizationDiagnosticInfo.* to OptimizationRemarkEmitter.*Adam Nemet
Sync it up with the name of the class actually defined here. This has been bothering me for a while... llvm-svn: 315249