379 Commits

Author SHA1 Message Date
Craig Topper
79858d1908 [CodeGen][Target] Remove uses of Register::isPhysicalRegister/isVirtualRegister. NFC
Use isPhysical/isVirtual methods.
2023-01-13 23:12:48 -08:00
Matt Arsenault
b44cd97241 llvm-reduce: Simplify attribute reduction implementation
There's no need to construct a map of attributes to modify throughout
the whole function before applying them all at once. The attribute
classes already have the necessary set behavior.
2023-01-12 08:03:13 -05:00
Jannik Silvanus
df1a74ac3c [IR] Support importing modules with invalid data layouts.
Use the existing mechanism to change the data layout using callbacks.

Before this patch, we had a callback type DataLayoutCallbackTy that receives
a single StringRef specifying the target triple, and optionally returns
the data layout string to be used. Module loaders (both IR and BC) then
apply the callback to potentially override the module's data layout,
after first having imported and parsed the data layout from the file.

We can't do the same to fix invalid data layouts, because the import will already
fail, before the callback has a chance to fix it.
Instead, module loaders now tentatively parse the data layout into a string,
wait until the target triple has been parsed, apply the override callback
to the imported string and only then parse the tentative string as a data layout.

Moreover, add the old data layout string S as second argument to the callback,
in addition to the already existing target triple argument.
S is either the default data layout string in case none is specified, or the data
layout string specified in the module, possibly after auto-upgrades (for the BitcodeReader).
This allows callbacks to inspect the old data layout string,
and fix it instead of setting a fixed data layout.

Also allow to pass data layout override callbacks to lazy bitcode module
loader functions.

Differential Revision: https://reviews.llvm.org/D140985
2023-01-12 10:10:45 +01:00
Matt Arsenault
1ad4527801 Revert "llvm-reduce: Try to kill parallel workitems once we have a result."
This reverts commit 4f575620d51032cf98424c9defafe4dfc8d66f45.

I realized the test wasn't very good and when fixed, shows the
reduction doesn't work correctly. Revert the change and keep the fixed
version of the test.
2023-01-11 11:11:23 -05:00
Matt Arsenault
4f575620d5 llvm-reduce: Try to kill parallel workitems once we have a result.
The current reduction logic tries to reproduce what a serial reduction
would produce, and just takes the first one that is still
interesting. We still have to wait for all others to complete though,
which at that point is just a waste.

This helps speed things up with long running reducers, which I
frequently have. e.g. for the added sleep test on my system, it took
about 8 seconds before this change and about 4 after.

https://reviews.llvm.org/D138953
2023-01-11 08:58:22 -05:00
Matt Arsenault
ae6a5c1d08 llvm-reduce: Fix assertion on blockaddress during function reduction
Just avoid crashing for now, we should be able to replace the blockaddresses
themselves.

BlockAddress::handleOperandChangeImpl assumes it can cast to Function.
The verifier seems nonexistent and the langref isn't particularly explicit
on what's allowed as a blockaddress operand. As far as I can tell bugpoint
isn't doing anything to handle this.

Something low level is broken with BlockAddress handling,
demonstrated by reduce-functions-blockaddress-wrong-function.ll.
The BasicBlock destructor of the deleted function is triggering replacement
of blockaddresses for the kept function in some cases. I've only half debugged
this but it seems like blockaddress is handled too-specially compared to other
Constants. I have tentative patches to allow any constant to be a blockaddress
input, but having the verifier check if it's really a function/block.

https://reviews.llvm.org/D140909
2023-01-11 08:10:04 -05:00
Matt Arsenault
a50cec5bf9 llvm-reduce: Don't delete instructions in global variable reduction
For some reason the global variable reduction was trying to delete
use instructions. This broke the verifier if the user was a terminator,
since the block now no longer has one. It doesn't make sense for this
reduction to delete the users, so just stop doing that.
2023-01-05 10:26:02 -05:00
Matt Arsenault
a455c91601 llvm-reduce: Add reduction for invokes
Main thing I was unsure about was to whether try to delete the now
dead landing blocks, or leave that for the unreachable block reduction.

Personality function is not reduced, but that should be a separate
reduction on the function.

Fixes #58815
2023-01-03 17:03:44 -05:00
Matt Arsenault
f4cb935ce8 llvm-reduce: Fix invalid reductions for exceptions, tokens and swifterror
Copies the same special cases that bugpoint uses. Technically the
token condition is stricter than what the verifier enforces.

Part 1 of #58815
2023-01-03 17:03:20 -05:00
Matt Arsenault
0008afc632 llvm-reduce: Remove leftover comment 2023-01-03 17:00:35 -05:00
Matt Arsenault
9c8b89f580 llvm-reduce: Refine missing argument behavior
We required the test and input arguments for --print-delta-passes
which is unhelpful. Also, start printing the help output if no
arguments were supplied.

It looks like there's more sophisticated ways to accomplish this with
the opt library, but it was less work to manually emit these errors.
2023-01-03 16:01:36 -05:00
Matt Arsenault
d5b7514c3d llvm-reduce: Don't remove strictfp
The verifier should fail if constrained intrinsics are used in
functions with strictfp, but that patch hasn't been pushed yet.

Ideally we would be able to analyze the function body to see if any
constrained intrinsics were used, but we seem to be missing a utility
function to check for any constrained ops.
2023-01-03 15:57:58 -05:00
Matt Arsenault
7cd0fd6f51 llvm-reduce: Avoid invalid attribute reduction on optnone functions
We have this ridiculous restriction that optnone requires noinline,
so the pair needs to be removed if we want to remove noinline.
2023-01-03 15:48:14 -05:00
Matt Arsenault
5f6bf752d9 llvm-reduce: Reduce individual operands of named metadata
The current reduction tries all or nothing elimination of named
metadata. I noticed in one case where one of the module flags was
necessary, but it left the rest. Reduce the individual operands of
named metadata nodes that are known to behave like lists. Be
conservative since some named metadata may have more specific verifier
requirements for the operands.
2023-01-03 11:48:00 -05:00
Matt Arsenault
e60b0d2a22 llvm-reduce: Reduce prologue data
Identical to the prefix data handling, and also had broken cloning.
2023-01-03 11:07:02 -05:00
Matt Arsenault
4afb10d572 llvm-reduce: Reduce prefix data
Also fixes broken cloning.
2023-01-03 11:03:43 -05:00
Matt Arsenault
47e44c0c2e llvm-reduce: Add reduction for function personalities
Fixes second piece of #58815
2023-01-03 11:02:34 -05:00
Matt Arsenault
89ada6c51f llvm-reduce: Avoid push_back for constant array 2023-01-03 10:13:17 -05:00
Matt Arsenault
875ecca762 llvm-reduce: Remove unused class 2023-01-03 10:13:17 -05:00
Matt Arsenault
40903bad46 llvm-reduce: Fix missing newline after error message
Fixes missing test coverage for the failed to execute case. However,
this test fails to verify the newline is printed. I can't figure out
how to get FileCheck to match the trailing newline.
2023-01-03 09:09:17 -05:00
Matt Arsenault
95abdeba61 llvm-reduce: Disable crash reports, symbolization and core dumps
These are going to waste a lot of time and produce clutter when we're
bulk introducing crashes. Add a flag to disable this behavior in case
this matters to a reproducer.
2022-12-20 19:01:26 -05:00
Matt Arsenault
49f80a5d34 llvm-reduce: Fix build
Fix build after e49f8eef41d58a9b55cb4347826d353ecf170f8b
2022-12-20 13:03:07 -05:00
Roman Lebedev
e49f8eef41
[NFC][llvm-reduce] Do show -ir-passes in help
It's a bit non-useful when llvm-reduce runs a pass,
a testcase for a crash in which is being reduced in the first place :)
2022-12-20 20:42:25 +03:00
Archibald Elliott
f09cf34d00 [Support] Move TargetParsers to new component
This is a fairly large changeset, but it can be broken into a few
pieces:
- `llvm/Support/*TargetParser*` are all moved from the LLVM Support
  component into a new LLVM Component called "TargetParser". This
  potentially enables using tablegen to maintain this information, as
  is shown in https://reviews.llvm.org/D137517. This cannot currently
  be done, as llvm-tblgen relies on LLVM's Support component.
- This also moves two files from Support which use and depend on
  information in the TargetParser:
  - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting
    the current Host machine for info about it, primarily to support
    getting the host triple, but also for `-mcpu=native` support in e.g.
    Clang. This is fairly tightly intertwined with the information in
    `X86TargetParser.h`, so keeping them in the same component makes
    sense.
  - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains
    the target triple parser and representation. This is very intertwined
    with the Arm target parser, because the arm architecture version
    appears in canonical triples on arm platforms.
- I moved the relevant unittests to their own directory.

And so, we end up with a single component that has all the information
about the following, which to me seems like a unified component:
- Triples that LLVM Knows about
- Architecture names and CPUs that LLVM knows about
- CPU detection logic for LLVM

Given this, I have also moved `RISCVISAInfo.h` into this component, as
it seems to me to be part of that same set of functionality.

If you get link errors in your components after this patch, you likely
need to add TargetParser into LLVM_LINK_COMPONENTS in CMake.

Differential Revision: https://reviews.llvm.org/D137838
2022-12-20 11:05:50 +00:00
Matt Arsenault
aa9bdd50c2 llvm-reduce: Fix invalid reductions with llvm.used
Fixes issue 59413.
2022-12-14 15:06:22 -05:00
Sebastian Neubauer
19158eb7f0 Revert "[llvm] Replace llvm::Any with std::any"
msvc fails to link when using any_cast. This seems to be fixed recently
only.

https://developercommunity.visualstudio.com/t/stdany-doesnt-link-when-exceptions-are-disabled/376072

This reverts commit aeac2e4884a3ce62c920cd51806a9396da64d9f7.
2022-12-08 12:07:30 +01:00
Sebastian Neubauer
aeac2e4884 [llvm] Replace llvm::Any with std::any
llvm::Any had several bugs in the past, due to being sensitive to symbol
visibility. (See D101972 and D108943)

Even with these fixes applied, I still encounter the same issue on
Windows.

Similar to llvm::Optional going away in favor of std::optional, we can
use std::any from C++17.

Using std::any fixes the problem and puts the burden to do it correctly
on the standard library.

Differential Revision: https://reviews.llvm.org/D139532
2022-12-08 11:48:00 +01:00
Krzysztof Parzyszek
110fe4f495 [IRReader] Convert Optional in DataLayoutCallbackTy to std::optional 2022-12-07 08:47:25 -08:00
Fangrui Song
89fae41ef1 [IR] llvm::Optional => std::optional
Many llvm/IR/* files have been migrated by other contributors.
This migrates most remaining files.
2022-12-05 04:13:11 +00:00
Fangrui Song
bac974278c CodeGen/CommandFlags: Convert Optional to std::optional 2022-12-03 18:38:12 +00:00
Kazu Hirata
b4482f7ca0 [tools] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02 21:11:40 -08:00
Matt Arsenault
e748db0f7f Support: Convert Program APIs to std::optional 2022-12-01 17:00:44 -05:00
Matt Arsenault
4ecdbf2e4e llvm-reduce: Fix tsan failures
There's a data race on the UninterestingChunks set. The code seems to
be operating on the assumption that all the tasks completed, so ensure
the unused results do complete. This started showing up about 50% of
the time when running operands-skip-parallel.ll after the recent
switch to use DenseSet; previously it failed much less frequently with
std::set.

We should introduce a mechanism to early terminate unused
results. Alternatively, I've been thinking about ways to to make the
reduction order smarter. I frequently have tests that take multiple
minutes to compile and hit the failure. It may be helpful to see which
chunks took the least time and prefer those over just taking the first
result.
2022-12-01 14:41:21 -05:00
Matt Arsenault
d939eeb9db llvm-reduce: Add some missing consts 2022-11-29 10:08:02 -05:00
Matt Arsenault
8e3e218a5f llvm-reduce: Fix producing invalid reductions on ifunc 2022-11-27 12:41:29 -05:00
Abhina Sreeskantharajan
625f08da73 [SystemZ][z/OS] Set text flag correctly for llvm-reduce tool
This patch sets the text flag correctly for llvm-reduce files

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D138304
2022-11-18 13:39:34 -05:00
Florian Hahn
5b6575d50e
[llvm-reduce] Do not crash when accessing landingpads of invokes.
Unconditionally removing landing pads results in invalid IR,
if there is a different `invoke` that uses it. Update the code
to only remove the landing pad if the current invoke is the only
user. Also carefully avoid creating plain branches to bbs with
landing pads we couldn't remove.

Reviewed By: arsenm, aeubanks

Differential Revision: https://reviews.llvm.org/D138072
2022-11-18 15:19:50 +00:00
Matt Arsenault
ea48d251c5 llvm-reduce: Minor code cleanups 2022-11-11 14:38:19 -08:00
Matt Arsenault
89b7391632 llvm-reduce: Use DenseSet 2022-11-11 14:33:17 -08:00
Matt Arsenault
8ca7ed7f93 llvm-reduce: Report number of new chunks 2022-11-11 13:00:56 -08:00
Matt Arsenault
4638ba7b45 llvm-reduce: Try to turn calls into something else
Try to turn calls that look like operators into known
intrinsics. Also try to turn calls that look like a load or
a store into a load or store.
2022-11-07 21:04:21 -08:00
Matt Arsenault
412c4a8be5 llvm-reduce: Write bitcode temporary files for bitcode inputs
Most tools accept .ll or .bc inputs interchangably, but some don't.
Default to writing temporary files that match the input. This
will also aid reducing deserialization bugs.
2022-10-31 20:35:08 -07:00
Matt Arsenault
4e21bc0c40 llvm-reduce: Drop guessing output format based on file extension 2022-10-31 20:35:08 -07:00
Matt Arsenault
3c436ab0d4 llvm-reduce: Support emitting bitcode for final result
Previously, this unconditionally emitted text IR. I ran
into a bug that manifested in broken disassembly, so the
desired output was the bitcode format. If the input format
was binary bitcode, the requested output file ends in .bc,
or an explicit -output-bitcode option was used, emit bitcode.
2022-10-31 20:35:08 -07:00
Matt Arsenault
4cf5e22d20 llvm-reduce: Report file opening errors
This was also trying to write the bitcode to the failed file
on failure, which asserts. Also, consistently use
ToolOutputFile, instead of one path manually removing
the temp file.
2022-10-31 18:37:33 -07:00
Matt Arsenault
756ee72a84 llvm-reduce: Fix typo 2022-10-28 21:42:57 -07:00
Matt Arsenault
f02bc70c7d llvm-reduce: Fix producing invalid reductions with landingpads
It's not valid to simply branch to a landingpad block, so it
needs to be removed.

Also stop trying to scan forward to find a block that can be merged.
The predecessor merge rules are more complex than this. This also
would need to have considered landingpads. Just do the minimum
to delete the block, and let the simplify-cfg reduction handle
the branch chain cleanups.
2022-10-28 17:07:26 -07:00
Matt Arsenault
45a91c1521 llvm-reduce: Fix block reduction with unreachable blocks
Previously this would produce many invalid reductions with
"Instruction does not dominate uses" verifier errors.

This fixes issues in cases where the incoming IR
has unreachable blocks, and the resulting reduction
introduced new reachable blocks.

Have basic-blocks skip functions that have unreachable
blocks, Introduce a separate reduction which only
deletes unreachable blocks. Cleanup any newly unreachable
blocks after trimming out the requested deletions.

Includes a variety of meta-reduced tests for llvm-reduce
itself with -abort-on-invalid-reduction that were failing
on different iterations of this patch.

Bugpoint's implementation is much simpler (but currently I don't
understand how it avoids disconnecting interesting blocks from the CFG).
2022-10-28 17:07:26 -07:00
Matt Arsenault
bc405e37ee llvm-reduce: Don't turn switches into returns
Re-use one of the existing successors as the new default.
This helps with a future patch to fix handling of unreachable
blocks.
2022-10-28 17:07:26 -07:00
Matt Arsenault
f041204ec8 llvm-reduce: Stop checking workitem is interesting before each pass
Each delta pass run should have guaranteed the output is still
interesting, so it should be pointless to recheck this each
iteration. I have many issues that take multiple minutes
to reproduce, so this ends up being a huge waste of time.

Also, remove broken line counting. This never worked, since
getLines was failing to open the temporary file which was just
deleted.
2022-10-28 16:39:09 -07:00