Commit Graph

181 Commits

Author SHA1 Message Date
Matthew Voss c4960f6363 [llvm-reduce] Change initialization order to fix bots. NFC
Fixes this error:
/var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/
llvm-project/llvm/tools/llvm-reduce/TestRunner.cpp:20:7:
error: field 'TM' will be initialized after field 'ToolName'
[-Werror,-Wreorder-ctor]
      TM(std::move(TM)), ToolName(ToolName) {
      ^~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~
      Program(std::move(Program)) TM(std::move(TM))
1 error generated.

https://lab.llvm.org/buildbot/\#/builders/77/builds/19154
2022-06-30 09:56:47 -07:00
Matthew Voss 6b3956e123 [llvm-reduce] Add support for LTO bitcode files
Adds support for reading and writing LTO bitcode files.

  - Emit a summary if the original bitcode file had a summary
  - Use split LTO units if the original bitcode file used them.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D127168
2022-06-30 08:58:24 -07:00
Matt Arsenault 261075590b llvm-reduce: Handle reducing FP values to nan
Prefer 0/1 over NaN, but it may make more sense to invert this as FP
operations with nan inputs can universally be folded into something
else.
2022-06-27 19:55:38 -04:00
Matt Arsenault 62b5aa984e llvm-reduce: Check shouldKeep before trying to reduce operands
No point doing the more complicated check first.
2022-06-27 13:16:15 -04:00
John Regehr 2962f9df7c stop llvm-reduce from introducing undefs
Differential Revision: https://reviews.llvm.org/D128317
2022-06-22 20:41:23 -06:00
John Regehr 8771023543 in the absense of the -max-pass-iterations command line options, make
llvm-reduce run its full pass sequence up to 5 times, instead of just
once

Differential Revision: https://reviews.llvm.org/D128284
2022-06-21 10:47:42 -06:00
Kazu Hirata 064a08cd95 Don't use Optional::hasValue (NFC) 2022-06-20 20:05:16 -07:00
Matt Arsenault 32bd0c1714 llvm-reduce: Try to fix dynamic libraries build 2022-06-16 21:48:04 -04:00
Matt Arsenault eea11e7369 llvm-reduce: Add reduction pass to simplify instructions 2022-06-16 20:39:27 -04:00
Matt Arsenault 6b8bd0f72d llvm-reduce: Support replacing FP values with 1.0 2022-06-16 20:13:17 -04:00
Matt Arsenault cbbc7e4a75 llvm-reduce: Don't set generic instruction operands to undef
The intention is that these should never have undef operands. It turns
out the restriction the verifier enforces is too lax. The verifier
enforces that registers without a register class cannot be undef, but
it's valid to use a register with a register class and type. The
verifier needs to change to be based on the opcode.
2022-06-07 10:28:23 -04:00
Matt Arsenault 47c8ec811f llvm-reduce: Add pass to remove register uses
Try to delete implicit uses, and add undef flags to explicit ones.
2022-06-07 10:28:23 -04:00
Matt Arsenault cc5a1b3dd9 llvm-reduce: Add cloning of target MachineFunctionInfo
MIR support is totally unusable for AMDGPU without this, since the set
of reserved registers is set from fields here.

Add a clone method to MachineFunctionInfo. This is a subtle variant of
the copy constructor that is required if there are any MIR constructs
that use pointers. Specifically, at minimum fields that reference
MachineBasicBlocks or the MachineFunction need to be adjusted to the
values in the new function.
2022-06-07 10:14:48 -04:00
Matt Arsenault e6723d80c7 llvm-reduce: Fix crashes on unreachable blocks for MIR instructions 2022-06-07 10:00:26 -04:00
Matt Arsenault 56303223ac llvm-reduce: Don't assert on functions which don't track liveness
Use the query that doesn't assert if TracksLiveness isn't set, which
needs to always be available. We also need to start printing liveins
regardless of TracksLiveness.
2022-06-07 10:00:25 -04:00
Fangrui Song d0d1c416cb Remove unneeded cl::ZeroOrMore for cl::list options 2022-06-04 23:51:13 -07:00
Kazu Hirata 4969a6924d Use llvm::less_first (NFC) 2022-06-04 21:23:18 -07:00
Clemens Wasser 42c7f494d9 [tools] Forward declare classes & remove includes
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D120208
2022-06-03 16:32:04 -07:00
Matt Arsenault a0dcbe45bd llvm-reduce: Add reduction pass to remove regalloc hints
I'm a bit confused by what's actually stored for the allocation
hints. The MIR parser only handles the "simple" case where there's a
single hint. I don't really understand the assertion in
clearSimpleHint, or under what circumstances there are multiple hint
registers.
2022-06-01 09:15:41 -04:00
Matt Arsenault 2011052150 llvm-reduce: Add pass to reduce MIR instruction flags 2022-06-01 08:58:34 -04:00
Balazs Benics a73b50ad06 Revert "[llvm][clang][bolt][NFC] Use llvm::less_first() when applicable"
This reverts commit 3988bd1398.

Did not build on this bot:
https://lab.llvm.org/buildbot#builders/215/builds/6372

/usr/include/c++/9/bits/predefined_ops.h:177:11: error: no match for call to
‘(llvm::less_first) (std::pair<long unsigned int, llvm::bolt::BinaryBasicBlock*>&, const std::pair<long unsigned int, std::nullptr_t>&)’
  177 |  { return bool(_M_comp(*__it, __val)); }
2022-05-27 11:19:18 +02:00
Balazs Benics 3988bd1398 [llvm][clang][bolt][NFC] Use llvm::less_first() when applicable
One could reuse this functor instead of rolling out your own version.
There were a couple other cases where the code was similar, but not
quite the same, such as it might have an assertion in the lambda or other
constructs. Thus, I've not touched any of those, as it might change the
behavior in some way.

As per https://discourse.llvm.org/t/submitting-simple-nfc-patches/62640/3?u=steakhal
Chris Lattner
> LLVM intentionally has a “yes, you can apply common sense judgement to
> things” policy when it comes to code review. If you are doing mechanical
> patches (e.g. adopting less_first) that apply to the entire monorepo,
> then you don’t need everyone in the monorepo to sign off on it. Having
> some +1 validation from someone is useful, but you don’t need everyone
> whose code you touch to weigh in.

Differential Revision: https://reviews.llvm.org/D126068
2022-05-27 11:15:23 +02:00
Markus Lavin bb8e02325f llvm-reduce: improve basic-blocks removal pass
When the single branch target of a block has been removed try updating
it to target a  block that is kept (by scanning forward in the sequence)
instead of replacing the branch with a return instruction. Doing so
reduces the risk of breaking loop structures meaning that when the loop
is 'interesting' these reductions should have more blocks eliminated.

Differential Revision: https://reviews.llvm.org/D125766
2022-05-24 09:51:25 +02:00
Matt Arsenault 241ca47db5 llvm-reduce: Reduce includes 2022-05-04 00:05:15 +01:00
Matt Arsenault aabea3b2ea llvm-reduce: Fix not removing first instruction in MachineBasicBlock
This had the surprising behavior of using whatever instruction
happened to be first in the block as an anchor point to stick random
implicit defs on. Use a real implicit_def instead.
2022-05-01 18:26:45 -04:00
Matt Arsenault 35264e7179 llvm-reduce: Introduce new scoring mechanism for MIR reductions
Many MIR reductions benefit from or require increasing the instruction
count. For example, unlike in the IR, you may need to insert a new
instruction to represent an undef. The current instruction reduction
pass works around this by sticking implicit defs on whatever
instruction happens to be first in the entry block block.

Other strategies I've applied manually include breaking instructions
with multiple defs into separate instructions, or breaking large
register defs into multiple subregister defs.

Make up a simple scoring system based on what I generally try to get
rid of first when manually reducing. Counts implicit defs as free
since reduction passes will be introducing them, although they
probably should count for something. It also might make more sense to
have a comparison the two functions, rather than having to compute a
contextless number. This isn't particularly well tested since overall
the MIR support isn't in a place where it is useful on the kinds of
testcases I want to throw at it.
2022-05-01 18:24:04 -04:00
Matt Arsenault 0b896b754e llvm-reduce: Do not try to delete frame instructions
The verifier enforces these appearing as balanced pairs, so just
deleting one has no real chance of producing something valid.
2022-05-01 18:21:52 -04:00
Matt Arsenault 3939e99aae llvm-reduce: Add pass to reduce IR references from MIR
This is typically the first thing I do when reducing a new testcase
until the IR section can be deleted.
2022-05-01 17:40:53 -04:00
Matt Arsenault 717209763e llvm-reduce: Fix incorrect cloning of MachineMemOperands
There were two problems with directly copying the MMOs from the old
function. The MMOs are owned by the function's Allocator, so need to
be reallocated anyways (surprisingly I didn't notice breakage on
this). Second, the PseudoSourceValues are also allocated per function
and need to be reallocated.
2022-04-27 18:51:38 -04:00
Matt Arsenault e39e9d339c llvm-reduce: Fix crashing on file opening error for mir path 2022-04-27 18:15:12 -04:00
Matt Arsenault 7c2db66632 llvm-reduce: Support multiple MachineFunctions
The current testcase I'm trying to reduce only reproduces with IPRA
enabled and requires handling multiple functions.

The only real difference vs. the IR is the extra indirect to look for
the underlying MachineFunction, so treat the ReduceWorkItem as the
module instead of the function.

The ugliest piece of this is really the ugliness of
MachineModuleInfo. It not only tracks actual module state, but has a
number of transient fields used for isel and/or the asm printer. These
shouldn't do any harm for the use here, though they should be
separated out.
2022-04-27 18:11:59 -04:00
Matt Arsenault 1747a93b28 llvm-reduce: Try to parse triple/datalayout from module
This saves needing to specify -mtriple on nearly every use for MIR
reduction.
2022-04-27 17:47:46 -04:00
Matt Arsenault 18b9c46370 llvm-reduce: Fix not cloning MachineInstr flags 2022-04-27 17:29:18 -04:00
Matt Arsenault e617d1a1d7 llvm-reduce: Fix mangling types of generic registers 2022-04-27 14:27:36 -04:00
Matt Arsenault 6d6288f2be llvm-reduce: Preserve subregisters and other fields for top block def 2022-04-27 14:21:43 -04:00
Matt Arsenault 7b57ef670c llvm-reduce: Simplify virtual register cloning
Just clone all the virtual registers instead of looking for def
operands. This preserves the register values used, simplifying the
rest of the code. This avoids needing to expose the register map to
target code.
2022-04-26 13:17:13 -04:00
Matt Arsenault a27b9ab391 llvm-reduce: Preserve frame index values when cloning function
Previously the specific values used for fixed frame indexes was in
reverse order in the cloned function from the original, and a map was
used to adjust all frame indexes to the potentially new values. Insert
the fixed objects in reverse to avoid this. This simplifies other
code, since now we don't need to track down all frame indexes. This
will allow targets that store frame indexes in MachineFunctionInfo to
simply copy the values.

Note this isn't directly observable in the test since the resulting
MIR print/parse can shuffle the IDs around (in particular the final
serialization implicitly strips out dead objects).
2022-04-26 13:17:13 -04:00
Matt Arsenault 49aeeafda3 llvm-reduce: Don't delete triple/datalayout
Removing these is extremely unhelpful and just adds extra hassle. This
is really finding out whether your test script uses -mtriple or
not. You can't meaningfully delete these fields, and the resulting
module defaults to the host.
2022-04-24 11:01:31 -04:00
Matt Arsenault debfb96be6 llvm-reduce: Fix cloning unset maxCallFrameSize
This was promoting an unset max call frame size to a max call frame
size of 0.
2022-04-22 18:28:45 -04:00
Matt Arsenault f7db8b7a9c llvm-reduce: Fix variable name typo 2022-04-22 11:07:41 -04:00
Matt Arsenault 53d88581f1 llvm-reduce: Clone properties of blocks
getSuccProbability was private for some reason, saying to go through
MachineBranchProbabilityInfo. There doesn't seem to be much point to
that, as that wrapper directly calls this.

Like other areas, some of these fields aren't handled by the MIR
printer/parser so aren't tested.
2022-04-20 09:47:45 -04:00
Matt Arsenault 67aa8ed547 llvm-reduce: Fix sources with executable permission 2022-04-20 09:31:13 -04:00
Matt Arsenault 193fde7509 llvm-reduce: Clone some of the easy function properties
Error on some of these other fields, since tracking down test cases
for all of these at once is exhausting.
2022-04-15 20:31:07 -04:00
Matt Arsenault f163106f39 llvm-reduce: Handle cloning MachineFrameInfo and stack objects
This didn't work at all before, and would assert on any frame
index. Also copy the other fields, which I believe should cover
everything. There are a few that are untested since MIR serialization
is apparently still missing them (isStatepointSpillSlot,
ObjectSSPLayout, and ObjectSExt/ObjectZExt).
2022-04-14 21:25:06 -04:00
Matt Arsenault e33b07f859 llvm-reduce: Inform MRI of used phys reg masks
I'm not sure how to directly observe this invisible cache for a test.
2022-04-14 20:52:05 -04:00
Matt Arsenault 3217ca0863 llvm-reduce: Copy register allocation hints to clone 2022-04-14 20:52:05 -04:00
Matt Arsenault b4ace5da45 llvm-reduce: Fix asserting on undef virtual registers
This was only populating the virtual register map for def operands
that appeared in the function, but that may not exist if there are
only undef uses.
2022-04-14 20:21:22 -04:00
Matt Arsenault a0f9e4ed2a llvm-reduce: Fix handling of generic virtual registers
Try to preserve register banks, types and names. Fixes the lowest
hanging fruit in issue 54894.
2022-04-14 20:21:22 -04:00
Matt Arsenault 6f3f19a36b llvm-reduce: Fix some copy-pasted comment errors 2022-04-14 20:21:21 -04:00
serge-sans-paille a494ae43be Cleanup includes: TransformsUtils
Estimation on the impact on preprocessor output:
before: 1065307662
after:  1064800684

Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup
Differential Revision: https://reviews.llvm.org/D120741
2022-03-01 21:00:07 +01:00