962 Commits

Author SHA1 Message Date
Nikita Popov
e5a41f0afc Revert "[IR] Lazily initialize the class to pass name mapping (NFC) (#96321)"
My attempt to fix the Windows build made things worse,
revert entirely for now.

This reverts commit e7137f2fed5cfee822ae3c4c6d39188adb59a16c.
This reverts commit 6eaf204dbb0a6a81cddfd02f625c130f7bb1aae5.
This reverts commit 957dc4366dd2ce9d5d2991c3ad76bbf438e9954e.
2024-06-24 10:32:03 +02:00
Nikita Popov
957dc4366d
[IR] Lazily initialize the class to pass name mapping (NFC) (#96321)
Initializing this map is somewhat expensive (especially for O0), so we
currently only do it if certain flags are used. I would like to make use
of it for crash dumps (#96078), where we don't know in advance whether
it will be needed or not.

This patch changes the initialization to a lazy approach, where a
callback is registered that does the actual initialization. The
callbacks will be run the first time the pass name is requested.

This way there is no compile-time impact if the mapping is not used.
2024-06-24 09:40:09 +02:00
paperchalice
8e9c6bfb50
[CodeGen][NewPM] Extract MachineFunctionProperties modification part to an RAII class (#94854)
Modify MachineFunctionProperties in PassModel makes `PassT P;
P.run(...);` not work properly. This is a necessary compromise.
2024-06-22 17:34:03 +08:00
paperchalice
a41a46c665
[CodeGen][NewPM] Port machine dominator tree analysis to new pass manager (#95879)
- Add `MachineDominatorTreeAnalysis`
- Add `MachineDominatorTreePrinterPass` There is no test for this
analysis in codebase.

Also, the pass name is renamed to `machine-dom-tree` instead of
`machinedomtree`.
2024-06-22 10:24:44 +08:00
Alexis Engelke
739a960567
[RegAlloc] Don't call always-true ShouldAllocClass (#96296)
Previously, there was at least one virtual function call for every
allocated register. The only users of this feature are AMDGPU and RISC-V
(RVV), other targets don't use this. To easily identify these cases,
change the default functor to nullptr and don't call it for every
allocated register.
2024-06-21 13:18:35 +02:00
Nikita Popov
6cea40400d
[IR] Remove RepeatedPass (#96211)
This pass is not used in any pipeline, barely used in tests and not
really useful, so drop it. The only place where we "repeat" passes is
devirt repetition, and that is done using a separate pass.
2024-06-20 19:39:19 +02:00
Min-Yih Hsu
37e309f163
[AArch64][LoopIdiom] Generalize AArch64LoopIdiomTransform into LoopIdiomVectorize (#94081)
To facilitate sharing LoopIdiomTransform between AArch64 and RISC-V,
this first patch moves AArch64LoopIdiomTransform from lib/Target/AArch64
to lib/Transforms/Vectorize and renames it to LoopIdiomVectorize. The
following patch (#94082) will teach LoopIdiomVectorize how to generate VP
intrinsics (in addition to the current masked vector style) in favor of
RVV.
2024-06-07 14:06:11 -07:00
paperchalice
1bc8b3258e
[NewPM][CodeGen] Port regallocfast to new pass manager (#94426)
This pull request port `regallocfast` to new pass manager. It exposes
the parameter `filter` to handle different register classes for AMDGPU.
IIUC AMDGPU need to allocate different register classes separately so it
need implement its own `--<reg-class>-regalloc`. Now users can use e.g.
`-passe=regallocfast<filter=sgpr>` to allocate specific register class.
The command line option `--regalloc-npm` is still in work progress, plan
to reuse the syntax of passes, e.g. use
`--regalloc-npm=regallocfast<filter=sgpr>,greedy<filter=vgpr>` to
replace `--sgpr-regalloc` and `--vgpr-regalloc`.
2024-06-07 12:22:42 +08:00
Jon Chesterfield
8516f54e6a
[AMDGPU] Implement variadic functions by IR lowering (#93362)
This is a mostly-target-independent variadic function optimisation and
lowering pass. It is only enabled for AMDGPU in this initial commit.

The purpose is to make C style variadic functions a zero cost
abstraction. They are lowered to equivalent IR which is then amenable to
other optimisations. This is inherently slightly target specific but
much less so than one might expect - the C varargs interface heavily
constrains the ABI design divergence.

The pass is primarily tested from webassembly. This is because wasm has
a straightforward variadic lowering strategy which coincides exactly
with what this pass transforms code into and a struct passing convention
with few cases to check. Adding further targets conventions is
straightforward and elided from this patch primarily to simplify the
review. Implemented in other branches are Linux X86, AMD64, AArch64 and
NVPTX.

Testing for targets that have existing lowering for va_arg from clang is
most efficiently done by checking that clang | opt completely elides the
variadic syntax from test cases. The lowering produces a struct for each
call site which can be inspected to check the various alignment and
indirections are correct.

AMDGPU presently has no variadic support other than some ad hoc printf
handling. Combined with the pass being inactive on all other targets
landing this represents strict increase in capability with zero risk.
Testing and refining will continue post commit.

In addition to the compiler tests included here, a self contained x64
clang/musl toolchain was constructed using the "lowering" instead of the
systemv ABI and used to build various C programs like lua and libxml2.
2024-06-06 10:44:53 +01:00
paperchalice
d4d3239d98
[NewPM][CodeGen] Port localstackalloc to new pass manager (#94303)
There are two AArch64 tests use `-start-before` and `-print-after`. Rest tests uses `--passes` to test this pass.
2024-06-05 19:24:19 +08:00
paperchalice
9b0e1c2ca2
[NewPM][CodeGen] Port finalize-isel to new pass manager (#94214)
It should preserve more analysis results, but it happens immediately
after instruction selection.
2024-06-04 09:23:52 +08:00
Tim Besard
e8692b88be
[NewPM] Add pass options for InternalizePass to preserve GVs (reland) (#92383)
Reland of https://github.com/llvm/llvm-project/pull/91334, which broke
the gcc7 buildbot and was reverted in
https://github.com/llvm/llvm-project/pull/92321.
Work around the failure by being explicit about returning an `Expected`.

cc @joker-eph
2024-05-16 09:18:37 -07:00
Mehdi Amini
537a94b2ef
Revert "[NewPM] Add pass options for InternalizePass to preserve GVs." (#92321)
Reverts llvm/llvm-project#91334

This broke the gcc7 build.
I suspect the issue is a mismatch on user-defined move constructor on
the return: `return PreservedGVs;` does not match the return type of the
function.
2024-05-15 15:06:08 -07:00
Tim Besard
ee765b0c94
[NewPM] Add pass options for InternalizePass to preserve GVs. (#91334)
This PR adds a string interface to `InternalizePass`' `MustPreserveGV`
option, which is a callback function to indicate if a GV is not to be
internalized. This is for use in LLVM.jl, the Julia wrapper for LLVM,
which uses the C API and is thus required to use the PassBuilder string
API for building NewPM pipelines.
2024-05-15 13:17:29 -07:00
Mircea Trofin
96568f3539
[llvm][ctx_profile] Add instrumentation lowering (#90821)
This adds the instrumentation lowering pass.

(Tracking Issue: #89287, RFC referenced there)
2024-05-08 16:49:08 -07:00
paperchalice
e7939d0df6
[Instrumentation] Support verifying machine function (#90931)
We need it to test isel related passes. Currently
`verifyMachineFunction` is incomplete (no LiveIntervals support), but is
enough for testing isel pass, will migrate to complete
`MachineVerifierPass` in future.
2024-05-04 09:00:59 +08:00
paperchalice
3fe282a83d
[Pass] Add pre-isel-intrinsic-lowering to pass registry (#90851)
This was removed due to avoid circular dependency between `CodeGen` and
`Passes`, but now I realized this is no longer a problem since
`CodeGenPassBuilder` is moved into `Passes`.
2024-05-02 21:57:46 +08:00
paperchalice
6ea0c0a283
[NewPM][CodeGen] Add MachineFunctionAnalysis (#88610)
In new pass system, `MachineFunction` could be an analysis result again,
machine module pass can now fetch them from analysis manager.
`MachineModuleInfo` no longer owns them.
Remove `FreeMachineFunctionPass`, replaced by
`InvalidateAnalysisPass<MachineFunctionAnalysis>`.

Now `FreeMachineFunction` is replaced by
`InvalidateAnalysisPass<MachineFunctionAnalysis>`, the workaround in
`MachineFunctionPassManager` is no longer needed, there is no difference
between `unittests/MIR/PassBuilderCallbacksTest.cpp` and
`unittests/IR/PassBuilderCallbacksTest.cpp`.
2024-04-30 09:54:48 +08:00
paperchalice
496de32ee2
[NewPM] Remove MachinePassInfoMixin (#88243)
Unify the inheritance paths of IR and machine function.
2024-04-11 19:13:06 +08:00
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 5538853f9abb559ff4bb7ff598535041d91d97d7. #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](2663d2cb9c/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp (L288)) to have external linkage; and with
[full](2663d2cb9c/llvm/lib/LTO/LTO.cpp (L1328))
or
[thin](2663d2cb9c/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