Commit Graph
793 Commits
Author SHA1 Message Date
Vitaly Buka 49f0b536fd [UBSAN] Rename remove-traps to lower-allow-check (#84853) 2024-04-04 21:29:46 -07:00
paperchalice b361b5369e Reland "[PassManager] Support MachineFunctionProperties (#83668)" (#87141)
Unfortunately GCC 9 rejects code in https://godbolt.org/z/zd9r5GM3e GCC
11 accepts this code.
2024-03-30 20:03:10 +08:00
paperchalice e9e4ab8147 Revert "Reland "[PassManager] Support MachineFunctionProperties (#83668)"" (#87138)
Reverts llvm/llvm-project#87137
It introduces ambiguous template specialization problem. Revert it.
2024-03-30 10:20:59 +08:00
paperchalice 4f71329522 Reland "[PassManager] Support MachineFunctionProperties (#83668)" (#87137)
Fix preprocessor directive.
2024-03-30 10:12:14 +08:00
paperchalice 0be26dbbed Revert "[PassManager] Support MachineFunctionProperties (#83668)" (#87136)
This reverts commit 5538853f9a. #83668
Break some test bots.
2024-03-30 10:02:49 +08:00
paperchalice 5538853f9a [PassManager] Support MachineFunctionProperties (#83668)
This pull request adds `MachineFunctionProperties` support. If a pass
wants to modify machine function properties, it must derive from
`MachinePassInfoMixin` and define some static methods like in legacy
pass manager. A test pass `RequireAllMachineFunctionPropertiesPass` is
also added here, which could be a example.
2024-03-30 09:54:58 +08:00
paperchalice 4d7f28a2c4 [Passes] Expose parseSinglePassOption (#86226)
Reland #86225, adjust the name space.
2024-03-22 10:55:58 +08:00
paperchalice 8d7d581ad2 Revert "[Passes] Expose parseSinglePassOption" (#86225)
Reverts llvm/llvm-project#86117
2024-03-22 08:54:11 +08:00
paperchalice 8cb2d436ca [Passes] Expose parseSinglePassOption (#86117)
BPF and some machine function passes need it.
2024-03-22 08:48:22 +08:00
Jeremy Morse b9d83eff25 [NFC][RemoveDIs] Use iterators for insertion at various call-sites (#84736)
These are the last remaining "trivial" changes to passes that use
Instruction pointers for insertion. All of this should be NFC, it's just
changing the spelling of how we identify a position.

In one or two locations, I'm also switching uses of getNextNode etc to
using std::next with iterators. This too should be NFC.

---------

Merged by: Stephen Tozer <stephen.tozer@sony.com>
2024-03-19 16:36:29 +00:00
paperchalice 5a3cc7ba24 [PassBuilder] Expose parametrized passes related functions (#85357)
Some targets have passes with parameters, e.g. ARM, AMDGPU and MIPS.
For example, AMDGPU has a pass `AMDGPUAtomicOptimizerPass`
which need a `ScanOption`, this commit enables the syntax
like `-passes=amdgpu-atomic-optimizer<strategy=dpp>` for backend passes.
2024-03-16 12:14:30 +08:00
Vitaly Buka a6a6fca791 [ubsan][pgo] Pass to remove ubsan checks based on profile data (#83471)
UBSAN checks can be too expensive to be used
in release binaries. However not all code affect
performace in the same way. Removing small
number of checks in hot code we can performance
loss, preserving most of the checks.
2024-03-07 10:52:43 -08:00
Rishabh Bali fe42e72db2 [CodeGen] Port AtomicExpand to new Pass Manager (#71220)
Port the `atomicexpand` pass to the new Pass Manager. 
Fixes #64559
2024-02-25 18:42:22 +05:30
Arthur Eubanks 91e9e31752 [NewPM/CodeGen] Rewrite pass manager nesting (#81068)
Currently the new PM infra for codegen puts everything into a
MachineFunctionPassManager. The MachineFunctionPassManager owns both
Module passes and MachineFunction passes, and batches adjacent
MachineFunction passes like a typical PassManager.

The current MachineFunctionAnalysisManager also directly references a
module and function analysis manager to get results.

The initial argument was that the codegen pipeline is relatively "flat",
meaning it's mostly machine function passes with a couple of module
passes here and there. However, there are a couple of issues with this
as compared to a more structured nesting more like the optimization
pipeline. For example, it doesn't allow running function passes then
machine function passes on a function and its machine function all at
once. It also currently requires the caller to split out the IR passes
into one pass manager and the MIR passes into another pass manager.

This patch rewrites the new pass manager infra for the codegen pipeline
to be more similar to the nesting in the optimization pipeline.
Basically, a Function contains a MachineFunction. So we can have Module
-> Function -> MachineFunction adaptors. It also rewrites the analysis
managers to have inner/outer proxies like the ones in the optimization
pipeline. The new pass managers/adaptors/analysis managers can be seen
in use in PassManagerTest.cpp.

This allows us to consolidate to just having to add to one
ModulePassManager when using the codegen pipeline.

I haven't added the Function -> MachineFunction adaptor in this patch,
but it should be added when we merge AddIRPass/AddMachinePass so that we
can run IR and MIR passes on a function before proceeding to the next
function.

The MachineFunctionProperties infra for MIR verification is still WIP.
2024-02-22 12:47:36 -08:00
Arthur Eubanks 93cdd1b5cf [PGO] Add ability to mark cold functions as optsize/minsize/optnone (#69030)
The performance of cold functions shouldn't matter too much, so if we
care about binary sizes, add an option to mark cold functions as
optsize/minsize for binary size, or optnone for compile times [1]. Clang
patch will be in a future patch.

This is intended to replace `shouldOptimizeForSize(Function&, ...)`.
We've seen multiple cases where calls to this expensive function, if not
careful, can blow up compile times. I will clean up users of that
function in a followup patch.

Initial version: https://reviews.llvm.org/D149800

[1]
https://discourse.llvm.org/t/rfc-new-feature-proposal-de-optimizing-cold-functions-using-pgo-info/56388
2024-02-12 14:52:08 -08:00
Alexander Shaposhnikov d26b43ff4f Add JumpTableToSwitch pass (#77709)
Add a pass to convert jump tables to switches.
The new pass replaces an indirect call with a switch + direct calls if all the functions in the jump table are smaller than the provided threshold.
The pass is currently disabled by default and can be enabled by -enable-jump-table-to-switch.

Test plan: ninja check-all
2024-02-10 01:12:46 -08:00
Nikita Popov ac3bd2bd53 [LoopReroll] Remove unused and unmaintained pass (#80972)
Remove the LoopReroll pass, which is both unused (in any default
pipeline) and unmaintained, with numerous open correctness issues
(https://github.com/llvm/llvm-project/issues?q=is%3Aissue+is%3Aopen+loop-reroll).
The removal is in line with
https://discourse.llvm.org/t/rfc-disallow-unmaintained-unused-passes/75151.

There is also a defunct `-freroll-loops` option in clang, which I'll
remove separately.

Migrated from https://reviews.llvm.org/D150684.
2024-02-09 11:20:19 +01:00
paperchalice c9fd738388 [CodeGen] Port DeadMachineInstructionElim to new pass manager (#80582)
A simple enough op pass so we can test standard instrumentations in
future.
2024-02-06 17:56:56 +08:00
Arthur Eubanks 942cb2427a [CodeGen][NewPM] Consolidate PASS_NAME and CONSTRUCTOR in MachinePassRegistry.def (#80779)
This matches the optimization pipeline's PassRegistry.def.

I ran into a bug where CONSTRUCTOR wasn't always being used (in
PassBuilder::registerMachineFunctionAnalyses()).

Make DUMMY_* just accept a pass name, there's no point in having proper
constructors if the generated dummy class has a templated constructor
accepting arbitrary arguments.

Remove unused getPassNameFromLegacyName() as it was using this but for
no purpose.

Remove DUMMY_MACHINE_FUNCTION_ANALYSIS, we can just add those as we port
them.

This for some reason exposed missing mock calls in existing unittests.
2024-02-05 20:17:09 -08:00
paperchalice e7ec0c972e [CodeGen] Port PrintMIR to new pass manager (#79440)
The legacy version print machine functions to a string stream, then
output the module and string in `doFinalization`. This patch break
`MIRPrintingPass` into two parts `PrintMIRPreparePass` and
`PrintMIRPass`. `PrintMIRPreparePass` output the original IR in yaml
string, `PrintMIRPass` just print the machine function, so we can avoid
the `doFinalization`.
2024-02-03 16:52:54 +08:00
paperchalice 12a8bc09ca [CodeGen] Port FreeMachineFunction to new pass manager (#79421)
This pass should be the last machine function pass in pipeline, also
ignore `PI.runAfterPass(*P, MF, PassPA);` to avoid accessing a dangling
reference.
2024-01-25 17:24:05 +08:00
paperchalice 7251243315 [CodeGen][Passes] Move CodeGenPassBuilder.h to Passes (#79242)
`CodeGenPassBuilder` is not very tightly coupled to CodeGen, it may need
to reference some method in pass builder in future, so move
`CodeGenPassBuilder.h` to Passes.
2024-01-24 11:29:18 +08:00
Paul Kirth 9d476e1e1a [clang][FatLTO] Avoid UnifiedLTO until it can support WPD/CFI (#79061)
Currently, the UnifiedLTO pipeline seems to have trouble with several
LTO features, like SplitLTO units, which means we cannot use important
optimizations like Whole Program Devirtualization or security hardening
instrumentation like CFI.

This patch reverts FatLTO to using distinct pipelines for Full LTO and
ThinLTO. It still avoids module cloning, since that was error prone.
2024-01-23 14:04:52 -08:00
Mingming Liu 5ce286849a [CGProfile] Use callee's PGO name when caller->callee is an indirect call. (#78610)
- With PGO, indirect call edges are constructed using value profiles, and the profile address is mapped to a function's PGO name. The PGO name is computed using a functions linkage before LTO internalization or global promotion.
- With ThinLTO, local functions [could be
promoted](https://github.com/llvm/llvm-project/blob/2663d2cb9c9361f0b234c40a0f50c7ba0748eb26/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp#L288) to have external linkage; and with
[full](https://github.com/llvm/llvm-project/blob/2663d2cb9c9361f0b234c40a0f50c7ba0748eb26/llvm/lib/LTO/LTO.cpp#L1328)
or
[thin](https://github.com/llvm/llvm-project/blob/2663d2cb9c9361f0b234c40a0f50c7ba0748eb26/llvm/lib/LTO/LTO.cpp#L448)
LTO, global functions could be internalized. Edge construction should use a function's PGO name before its linkage is updated.
2024-01-22 10:36:03 -08:00
paperchalice ab0d8fc4a6 Reland "[CodeGen] Support start/stop in CodeGenPassBuilder (#70912)" (#78570)
Unfortunately the legacy pass system can't recognize `no-op-module` and
`no-op-function` so it causes test failure in `CodeGenTests`. Add a
workaround in function `PassInfo *getPassInfo(StringRef PassName)`,
`TargetPassConfig.cpp`.
2024-01-20 08:38:22 +08:00
paperchalice a48c1bda74 Revert "[CodeGen] Support start/stop in CodeGenPassBuilder" (#78567)
Reverts llvm/llvm-project#70912. This breaks some bazel tests.
2024-01-18 20:09:53 +08:00
paperchalice baaf0c968e [CodeGen] Support start/stop in CodeGenPassBuilder (#70912)
Add `-start/stop-before/after` support for CodeGenPassBuilder.
Part of #69879.
2024-01-18 14:54:56 +08:00
paperchalice bd9e14574a [CodeGen] Port GlobalMerge to new pass manager (#77474) 2024-01-18 12:07:46 +07:00
paperchalice 8566cd6124 [CodeGen] Let PassBuilder support machine passes (#76320)
`PassBuilder` would be a better place to parse MIR pipeline. We can
reuse the code to support parsing pass with parameters and targets can
reuse `registerPassBuilderCallbacks` to register the target specific
passes. `PassBuilder` also has ability to check whether a Pass is a
machine pass.
2024-01-13 11:28:07 +08:00
paperchalice ae1c1ed6af [CodeGen] Allow CodeGenPassBuilder to add module pass after function pass (#77084)
In fact, there are several backends, e.g. AArch64, AMDGPU etc. add
module pass after function pass, this patch removes this constraint.
This patch also adds a simple unit test for `CodeGenPassBuilder`.
2024-01-12 08:37:12 +08:00
paperchalice 7c71a09d5e [CodeGen][NewPM] Port AssignmentTrackingAnalysis to new pass manager (#77550) 2024-01-10 17:49:45 +08:00
paperchalice f9a1d157e5 [CodeGen] Port StackProtector to new pass manager (#75334)
The original `StackProtector` is both transform and analysis pass, break
it into two passes now. `getAnalysis<StackProtector>()` could be now
replaced by `FAM.getResult<SSPLayoutAnalysis>(F)` in new pass system.
2024-01-09 19:13:33 +08:00
Nick AndersonandKrishna-13-cyber f1ec0d12bb Port CodeGenPrepare to new pass manager (and BasicBlockSectionsProfil… (#77182)
Port CodeGenPrepare to new pass manager and dependency
BasicBlockSectionsProfileReader
Fixes: #75380

Co-authored-by: Krishna-13-cyber <84722531+Krishna-13-cyber@users.noreply.github.com>
2024-01-09 13:32:59 +07:00
paperchalice 1c43e64d70 [CodeGen] Port ShadowStackGCLowering to new pass manager (#75324)
IIUC the new pass system was designed with parallelism. This pass needs
to add some global variables into the current module, this is not
allowed by

[WritingAnLLVMPass](https://llvm.org/docs/WritingAnLLVMPass.html#the-functionpass-class),
so convert it to module pass, see FIXME in `GetFrameMap`.

Therefore, this will trigger assertion in `CodeGenPassBuilder`:
https://github.com/llvm/llvm-project/blob/effd47ed45e3badd756103346a7c3b9e1e939e5e/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h#L200-L207
Will fix it in future.
2024-01-06 09:25:15 +08:00
Simon Pilgrim 7648371c25 Revert 4d7c5ad584 "[NewPM] Update CodeGenPreparePass reference in CodeGenPassBuilder (#77054)"
Revert e0c554ad87 "Port CodeGenPrepare to new pass manager (and BasicBlockSectionsProfil… (#75380)"

Revert #75380 and #77054 as they were breaking EXPENSIVE_CHECKS buildbots: https://lab.llvm.org/buildbot/#/builders/104
2024-01-05 12:28:10 +00:00
Nick AndersonandKrishna-13-cyber e0c554ad87 Port CodeGenPrepare to new pass manager (and BasicBlockSectionsProfil… (#75380)
Port CodeGenPrepare to new pass manager and dependency
BasicBlockSectionsProfileReader
Fixes: #64560

Co-authored-by: Krishna-13-cyber <84722531+Krishna-13-cyber@users.noreply.github.com>
2024-01-05 13:47:56 +07:00
paperchalice ffb1f20e0d [CodeGen] Add flag to populate target pass names (#76328)
`print-pipeline-passes` can show target pass names.
2024-01-03 09:07:02 +08:00
paperchalice 72c75501ec [CodeGen] Port LowerEmuTLS to new pass manager (#75171)
In fact, this pass need `llc` to test. `TargetMachine` seems redundant,
because before adding this pass `CodeGenPassBuilder` already checks it:

https://github.com/llvm/llvm-project/blob/ed4194bb8dbca5222628c2cddbc032fff57193b5/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h#L590-L592
2023-12-19 14:44:35 +08:00
paperchalice 60eca674b1 [CodeGen] Port ExpandMemCmp to new pass manager (#74050) 2023-12-13 16:18:24 +08:00
paperchalice 80bb994d2b [CodeGen] Port IndirectBrExpand to new pass manager (#75287) 2023-12-13 16:13:17 +08:00
paperchalice 06aa8b189a [CodeGen] Add analyses to help for porting GC passes (#74972)
- `CollectorMetadataAnalysis` provides `GCStrategyMap`.
- `GCFunctionAnalysis` provides `GCFunctionInfo`.

`GCStrategyMap` owns `GCStrategy` pointers and this
pass is used by `AsmPrinter` to iterate all GC strategies.

Most passes that require `GCModuleInfo` actually require the
`GCFunctionInfo`,
so add `GCFunctionAnalysis` for convenience.
2023-12-13 15:56:12 +08:00
paperchalice a930fec033 [CodeGen] Port InterleavedLoadCombine to new pass manager (#75164) 2023-12-13 12:46:22 +08:00
paperchalice 27259f17e9 [CodeGen] Port CFGuard to new pass manager (#75146)
Port `CFGuard` to new pass manager, add a pass parameter to choose guard
mechanism.
2023-12-13 08:50:22 +08:00
paperchalice b0cc42ae0f [CodeGen] Port SjLjEHPrepare to new pass manager (#75023)
`doInitialization` in `SjLjEHPrepare` is trivial.

This is the last pass suffix with `ehprepare`.
2023-12-12 16:07:26 +08:00
Kazu Hirata 586ecdf205 [llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-11 21:01:36 -08:00
paperchalice ce08c7ee1e [CodeGen] Port SelectOptimize to new pass manager (#74920)
- Use `BlockFrequencyInfoWrapperPass` in legacy pass so member
`std::unique_ptr<BranchProbabilityInfo> BPI` could be removed.
- Member `DominatorTree *DT = nullptr` is unused, remove it.
2023-12-12 12:09:30 +08:00
paperchalice 62b21c6ced [CodeGen] Port JMCInstrumenter to new pass manager (#75049) 2023-12-12 09:00:44 +08:00
paperchalice cd6e462d01 [CodeGen] Port InterleavedAccess to new pass manager (#74904) 2023-12-10 19:15:51 +08:00
paperchalice 5baf66f3c2 [CodeGen] Port WasmEHPrepare to new pass manager (#74435)
Port `WasmEHPrepare` to new pass manager, also rename `wasmehprepare` to
`wasm-eh-prepare`.
2023-12-06 11:11:00 -08:00
paperchalice 8a9bbac662 [CodeGen] Port WinEHPrepare to new pass manager (#74233) 2023-12-04 20:46:51 +07:00