1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00
Commit Graph

77 Commits

Author SHA1 Message Date
Roman Lebedev
237baae3ce [llvm-reduce] ReduceGlobalVarInitializers delta pass: fix handling of globals w/ comdat/non-external linkage
Much like with ReduceFunctionBodies delta pass,
we need to remove comdat and set linkage to external,
else verifier will complain, and our deltas are invalid.
2021-01-07 18:05:03 +03:00
Roman Lebedev
bcf1e6754c [llvm-reduce] Refactor global variable delta pass
The limitation of the current pass that it skips initializer-less GV's
seems arbitrary, in all the reduced cases i (personally) looked at,
the globals weren't needed, yet they were kept.

So let's do two things:
1. allow reducing initializer-less globals
2. before reducing globals, reduce their initializers, much like we do function bodies
2021-01-03 01:45:47 +03:00
Roman Lebedev
36db6ab153 [llvm-reduce] Fix removal of unused llvm intrinsics declarations
ee6e25e4391a6d3ac0a3c89615474e512f44cda6 changed
the delta pass to skip intrinsics, which means we may end up being
left with declarations of intrinsics, that aren't otherwise referenced
in the module. This is obviously unwanted, do drop them.
2021-01-03 01:45:47 +03:00
serge-sans-paille
82b6e6053d llvmbuildectomy - replace llvm-build by plain cmake
No longer rely on an external tool to build the llvm component layout.

Instead, leverage the existing `add_llvm_componentlibrary` cmake function and
introduce `add_llvm_component_group` to accurately describe component behavior.

These function store extra properties in the created targets. These properties
are processed once all components are defined to resolve library dependencies
and produce the header expected by llvm-config.

Differential Revision: https://reviews.llvm.org/D90848
2020-11-13 10:35:24 +01:00
Florian Hahn
2210d6cb66 [llvm-reduce] Add reduction for special globals like llvm.used.
This patch adds a reduction of 'special' globals that lead to further
reductions (e.g. alias or regular globals reduction) being less efficient
because there are special constraints on values referenced in those
special globals. For example, values in @llvm.used and
@llvm.compiler.used need to be named, so replacing all uses of an
alias/global with undef or a different unnamed constant results in
invalid IR.

More details:
https://llvm.org/docs/LangRef.html#intrinsic-global-variables

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D90302
2020-11-11 11:25:05 +00:00
Florian Hahn
b3730ed205 [llvm-reduce] Add reduction for aliases.
This patch adds a new reduction pass that tries to remove aliases.
It runs early, as most of those likely can be removed up-front in
practice.

This substantially improves llvm-reduce for IR generated by the swift
compiler, which can generate a lot of aliases which lead to lots of
invalid reductions.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D90260
2020-10-28 13:11:19 +00:00
Matt Arsenault
09bc15e2ca llvm-reduce: Don't replace intrinsic calls with undef
These don't really have function bodies to try to eliminate. This also
has a good chance of just producing invalid IR since intrinsics can
have special operand constraints (e.g. metadata arguments aren't valid
for an arbitrary call). This was wasting quite a bit of time producing
and failing on invalid IR when replacing dbg.values with undefs.
2020-10-16 10:10:53 -04:00
Matt Arsenault
b288dbc472 llvm-reduce: Fix typo in status message 2020-10-16 09:48:00 -04:00
Florian Hahn
102583c8b4 [llvm-reduce] Create returns with undef values for non-void functions.
Currently replaceBranchTerminator/removeUninterestingBBsFromSwitch
always creates `ret void` instructions if no successor is in the chunk.

This results in invalid IR for functions with non-void return types,
which makes those reductions unfeasible. Instead, create `ret ty undef`
for functions with non-void return types.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D86849
2020-08-31 16:33:46 +01:00
Tyker
b04be3c048 [llvm-reduce] Function body reduction: don't forget to unset comdat
althought the interstingness test should usually fail when the module is invalid
this changes reduces the frequency at which llvm-reduce generate invalid IR.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D86404
2020-08-30 12:17:33 +02:00
Florian Hahn
4cf9e27313 [llvm-reduce] Skip chunks that lead to broken modules.
Some reduction passes may create invalid IR. I am not aware of any use
case where we would like to proceed reducing invalid IR. Various utils
used here, including CloneModule, assume the module to clone is valid
and crash otherwise.

Ideally, no reduction pass would create invalid IR, but some currently
do. ReduceInstructions can be fixed relatively easily (D86210), but
others are harder. For example, ReduceBasicBlocks may remove result in
invalid PHI nodes.

For now, skip the chunks. If we get to the point where all reduction
passes result in valid IR, we may want to turn this into an assertion.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D86212
2020-08-28 09:08:35 +01:00
Florian Hahn
27f75460b8 [llvm-reduce] Skip terminators when reducing instructions.
Removing terminators will result in invalid IR, making further
reductions pointless. I do not think there is any valid use case where
we actually want to create invalid IR as part of a reduction.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D86210
2020-08-23 17:20:34 +01:00
Tyker
d75baa4613 [llvm-reduce] make llvm-reduce save the best reduction it has when it crashes
This helps with both debugging llvm-reduce and sometimes getting usefull result even if llvm-reduce crashes

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D85996
2020-08-22 19:16:43 +02:00
Roman Lebedev
2f56715ea7 [Reduce] Rewrite function body delta pass again
It is not enough to replace all uses of users of the function with undef,
the users, we only drop instruction users, so they may stick around.

Let's try different approach - first drop bodies for all the functions
we will drop, which should take care of blockaddress issue the previous
rewrite was dealing with; then, after dropping *all* such bodies,
replace remaining uses with undef (thus all the uses are either
outside of functions, or are in kept functions)
and then finally drop functions.

This seems to work, and passes the *existing* test coverage,
but it is possible that a new issue will be discovered later :)

A new (previously crashing) test added.
2020-08-08 23:48:44 +03:00
Roman Lebedev
aa265a31e9 [Reduce] Argument reduction: shoe-horn new function into remaining uses of old function
Much like with function reduction, there may be remaining unhandled uses
of function, in particular in blockaddress. And in constants we can't
RAUW it with undef, because undef is not a function.
Instead, let's try to pretent that in the remaining cases, the new
signature didn't change, by bitcasting it.

A new (previously crashing) test case added.
2020-07-27 15:39:03 +03:00
Roman Lebedev
49caf4bfe4 [Reduce] Function reduction: replace all users of function with undef
There may be other users of a function other than CallInsts,
but what's more important, we can't actually replace function pointer
with undef, because for constants, that would not preserve the type
and RAUW would assert.

In particular, that affects blockaddress, however it proves to be
prohibitively complex to come up with a good test involving blockaddress:
we'd need to both ensure that the function body survives until
this pass, and is not interesting in this pass.
2020-07-27 15:39:02 +03:00
Roman Lebedev
eae3e5a494 [Reduce] Argument reduction: do deal with function declarations
We can happily turn function definitions into declarations,
thus obscuring their argument from being elided by this pass.

I don't believe there is a good reason to just ignore declarations.
likely even proper llvm intrinsics ones,
at worst the input becomes uninteresting.

The other question here is that all these transforms are all-or-nothing.
In some cases, should we be treating each use separately?

The main blocker here seemed to be that llvm::CloneFunctionInto()
does `&OldFunc->front()`, which inserts a nullptr into a densemap,
which is not happy about it and asserts.
2020-07-26 01:31:56 +03:00
Roman Lebedev
942c801f82 [Reduce] Argument reduction: do properly handle invoke insts (PR46819)
replaceFunctionCalls() is very non-exhaustive, it only handles
CallInst's. Which means, by the time we drop old function,
there may still be uses of it lurking around.
Let's instead whack-a-mole them by all by replacing with undef.

I'm not sure this is the best handling, especially for calls, but IMO
poorly reduced input is much better than crashing reduction tool.
A (previously-crashing!) test added.

Fixes https://bugs.llvm.org/show_bug.cgi?id=46819
2020-07-26 01:29:00 +03:00
Roman Lebedev
c62f97f67d [Reduce] Basic block reduction: do properly handle invoke insts (PR46818)
Terminator may have returned value, so we need to replace uses,
and in general handle invoke as a branch inst.

I'm not sure this is the best handling, but IMO poorly reduced
input is much better than crashing reduction tool.
A (previously-crashing!) test added.

Fixes https://bugs.llvm.org/show_bug.cgi?id=46818
2020-07-26 01:28:59 +03:00
Roman Lebedev
f9cbb7144f [Reduce] Try turning function definitions into declarations first, NFCI-ish
ReduceFunctions could do it, but it also replaces *all* calls with undef,
so if any of undef replacements makes reduction uninteresting,
it won't work.

ReduceBasicBlocks also could do it, but well, it may take many guesses
for all the blocks of a function to happen to be out-of-chunk,
which is not a very efficient way to go about it.

So let's just do this first.
2020-07-25 21:43:36 +03:00
Roman Lebedev
67198bc6db [Reduce] Rewrite runDeltaPass() workloop: do reduce a single and/or last target
Summary:
If there was a single target to begin with, because a single target
can only occupy a single chunk, we couldn't increase granularity.
and would immediately give up.

Likewise, if we had multiple targets, if by the end we'd end up with
a single target, we wouldn't finish reducing it, it would always
end up being "interesting"

Reviewers: dblaikie, nickdesaulniers, diegotf

Reviewed By: dblaikie

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84318
2020-07-23 10:51:46 +03:00
Roman Lebedev
eb0d395cfb [NFC][Reduce] Group llvm-reduce options into a group, uncluttering --help 2020-07-22 10:00:31 +03:00
Roman Lebedev
0885e066d4 [Reduce] Argument reduction: don't try to drop terminator instructions
Newly-added test previously crashed.

While it is up for debate whether or not instruction reduction
should be indiscriminate in instruction dropping (there you can
just ensure that the test case is still -verify'ies), here
if we drop terminator, CloneFunctionInto() will immediately crash.

So let's not do that :)
2020-07-21 00:06:03 +03:00
Alex Richardson
f2c854cb7c [llvm-reduce] Fix incorrect indices in argument reduction pass
The function extractArgumentsFromModule() was passing a one-based index to,
but replaceFunctionCalls() was expecting a zero-based argument index. This
resulted in assertion errors when reducing function call arguments with
different types. Additionally, the

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D84099
2020-07-19 18:06:47 +01:00
Roman Lebedev
892d28a558 [llvm-reduce] Reducing attributes
Summary:
This handles all three places where attributes could currently be - `GlobalVariable`, `Function` and `CallBase`.
For last two, it correctly handles all three possible attribute locations (return value, arguments and function itself)

There was a previous attempt at it D73853,
which was committed in rGfc62b36a000681c01e993242b583c5ec4ab48a3c,
but then reverted all the way back in rGb12176d2aafa0ccb2585aa218fc3b454ba84f2a9
due to some (osx?) test failures.

Reviewers: nickdesaulniers, dblaikie, diegotf, george.burgess.iv, jdoerfert, Tyker, arsenm

Reviewed By: nickdesaulniers

Subscribers: wdng, MaskRay, arsenm, llvm-commits, mgorny

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83351
2020-07-09 23:10:43 +03:00
Roman Lebedev
90826c519d [NFC][llvm-reduce] Purify for_each usage in Operand Bundles into range-based for loop
Summary:
As per lengthy/heated disscussion in D83351,
and CodingStandards D83431.

Reviewers: dblaikie, nickdesaulniers

Reviewed By: nickdesaulniers

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83434
2020-07-09 23:10:43 +03:00
Roman Lebedev
1036a9e7d6 [NFCI][llvm-reduce] OperandBundleCounter: drop pointless constructor
Reviewers: nickdesaulniers, dblaikie

Reviewed By: nickdesaulniers

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83435
2020-07-09 23:10:42 +03:00
Roman Lebedev
986cd9219d [NFCI][llvm-reduce] Cleanup Delta passes to use Oracle abstraction
Summary:
I think, this results in much more understandable/readable flow.
At least the original logic was perhaps the most hard thing for me to grasp when taking an initial look on the delta passes.

Reviewers: nickdesaulniers, dblaikie, diegotf, george.burgess.iv

Reviewed By: nickdesaulniers

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83287
2020-07-08 12:26:00 +03:00
Roman Lebedev
abd4ea9318 [NFCI][llvm-reduce] ReduceOperandBundles: actually put Module forward-declaration back into llvm namespace 2020-07-07 01:32:26 +03:00
Roman Lebedev
40f6d0064d [llvm-reduce] Reducing call operand bundles
Summary:
This would have been marginally useful to me during/for rG7ea46aee3670981827c04df89b2c3a1cbdc7561b.

With ongoing migration to representing assumes via operand bundles on the assume, this will be gradually more useful.

Reviewers: nickdesaulniers, diegotf, dblaikie, george.burgess.iv, jdoerfert, Tyker

Reviewed By: nickdesaulniers

Subscribers: hiraditya, mgorny, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83177
2020-07-07 01:16:37 +03:00
Roman Lebedev
a24529a504 [llvm-reduce] extractGVsFromModule(): don't crash when deleting instr twice
As it can be seen in newly-added (previously-crashing) test-case,
there can be a situation where multiple GV's are used in instr,
and we would schedule the same instruction to be deleted several times,
crashing when trying to delete it the second time.

We could either store WeakVH (done here), or use something set-like.
I think using WeakVH is prevalent in these cases elsewhere.
2020-07-05 01:01:46 +03:00
Roman Lebedev
f794b74374 [llvm-reduce] extractArgumentsFromModule(): don't crash when deleting instr twice
As it can be seen in newly-added (previously-crashing) test-case,
there can be a situation where multiple arguments are used in instr,
and we would schedule the same instruction to be deleted several times,
crashing when trying to delete it the second time.

We could either store WeakVH (done here), or use something set-like.
I think using WeakVH is prevalent in these cases elsewhere.
2020-07-05 00:52:42 +03:00
Simon Pilgrim
e3b20aa31d Cloning.h - reduce AliasAnalysis.h include to forward declarations. NFC.
Fix implicit include dependencies in source files.
2020-06-24 15:48:10 +01:00
Nico Weber
878db5393d Revert "[llvm-reduce] add ReduceAttribute delta pass"
This reverts commit fc62b36a000681c01e993242b583c5ec4ab48a3c.
Breaks tests on mac: http://45.33.8.238/mac/7301/step_11.txt
2020-02-05 14:15:11 -05:00
Nick Desaulniers
686a91a786 [llvm-reduce] add ReduceAttribute delta pass
Summary:
The output from llvm-reduce still has significantly more attributes than
bugpoint does.  Teach llvm-reduce to remove attributes.

Reviewers: diegotf, dblaikie, george.burgess.iv

Subscribers: mgorny, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73853
2020-02-05 10:05:25 -08:00
Benjamin Kramer
87d13166c7 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
George Burgess IV
55d35050f5 llvm-reduce: Add a space to an option's --help
Otherwise, we get "filewith".
2019-12-05 19:46:16 -08:00
David Blaikie
0051a61051 llvm-reduce: Follow-up to 372280, now with more-better msan fixing
llvm-svn: 372349
2019-09-19 20:04:04 +00:00
Simon Pilgrim
e0162e73d8 Fix -Wdocumentation "@returns in a void function" warning. NFCI.
llvm-svn: 372310
2019-09-19 11:12:04 +00:00
David Blaikie
d5d1d93e4d llvm-reduce: Add pass to reduce instructions
Patch by Diego Treviño!

Differential Revision: https://reviews.llvm.org/D66263

llvm-svn: 372282
2019-09-19 00:59:27 +00:00
David Blaikie
7867f03df9 llvm-reduce: Avoid use-after-free when removing a branch instruction
Found my msan buildbot & pointed out by Nico Weber - thanks Nico!

llvm-svn: 372280
2019-09-19 00:35:32 +00:00
David Blaikie
0e33554f66 llvm-reduce: Remove inaccurate doxy comment about a return that isn't returned
Addressing post-commit code review feedback from Dávid Bolvanský -
thanks!

llvm-svn: 372271
2019-09-18 22:38:05 +00:00
David Blaikie
4d43efb06f llvm-reduce: Fix inconsistencies between int/unsigned usage (standardize on int)
llvm-svn: 372270
2019-09-18 22:30:25 +00:00
David Blaikie
c11946eb06 llvm-reduce: Add pass to reduce basic blocks
Patch by Diego Treviño!

Differential Revision: https://reviews.llvm.org/D66320

llvm-svn: 372264
2019-09-18 21:45:05 +00:00
Simon Pilgrim
cfa33bb88f Fix -Wdocumentation "@returns in a void function" warning. NFCI.
llvm-svn: 372212
2019-09-18 10:39:16 +00:00
David Blaikie
1018faa8e7 llvm-reduce: Remove some string copies
llvm-svn: 372053
2019-09-16 23:54:57 +00:00
David Blaikie
e6945e5ce7 llvm-reduce: Make tests shell-independent by passing the interpreter on the command line rather than using #! in the test file
llvm-svn: 372049
2019-09-16 23:41:19 +00:00
David Blaikie
70d10faac3 llvm-reduce: Remove unused plugin support/requirements
llvm-svn: 371755
2019-09-12 18:52:31 +00:00
David Blaikie
11d923a343 Reapply llvm-reduce: Add pass to reduce parameters""
Fixing a couple of asan-identified bugs
* use of an invalid "Use" iterator after the element was removed
* use of StringRef to Function name after the Function was erased

This reapplies r371567, which was reverted in r371580.

llvm-svn: 371700
2019-09-12 01:20:48 +00:00
David Blaikie
bcb0f91086 PR43278: llvm-reduce: Use temporary file names (and ToolOutputFile) rather than unique ones - to ensure they're cleaned up
This modifies the tool somewhat to only create files when about to run
the "interestingness" test, and delete them immediately after - this
means some more files will be created sometimes (when "double checking"
work - which should probably be fixed/avoided anyway).

This now creates temporary files, rather than only unique ones, and also
uses ToolOutputFile (without ever calling "keep") to ensure the files
are deleted as soon as the interestingness test is run.

llvm-svn: 371696
2019-09-12 00:31:57 +00:00