aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
AgeCommit message (Collapse)AuthorFilesLines
6 days[MIR] Support save/restore points with independent sets of registers (#119358)Elizaveta Noskova1-4/+4
This patch adds the MIR parsing and serialization support for save and restore points with subsets of callee saved registers. That is, it syntactically allows a function to contain two or more distinct sub-regions in which distinct subsets of registers are spilled/filled as callee save. This is useful if e.g. one of the CSRs isn't modified in one of the sub-regions, but is in the other(s). Support for actually using this capability in code generation is still forthcoming. This patch is the next logical step for multiple save/restore points support. All points are now stored in DenseMap from MBB to vector of CalleeSavedInfo. Shrink-Wrap points split Part 4. RFC: https://discourse.llvm.org/t/shrink-wrap-save-restore-points-splitting/83581 Part 1: https://github.com/llvm/llvm-project/pull/117862 (landed) Part 2: https://github.com/llvm/llvm-project/pull/119355 (landed) Part 3: https://github.com/llvm/llvm-project/pull/119357 (landed) Part 5: https://github.com/llvm/llvm-project/pull/119359 (likely to be further split)
2025-08-12[MIR] Further cleanup on mutliple save/restore point support [nfc] (#153250)Philip Reames1-4/+13
Remove the type alias now that the std::variant aspect is gone, directly using std::vector in the few places that need it is more idiomatic. Move a routine from a core header to single user.
2025-08-12[llvm] Support multiple save/restore points in mir (#119357)Elizaveta Noskova1-4/+10
Currently mir supports only one save and one restore point specification: ``` savePoint: '%bb.1' restorePoint: '%bb.2' ``` This patch provide possibility to have multiple save and multiple restore points in mir: ``` savePoints: - point: '%bb.1' restorePoints: - point: '%bb.2' ``` Shrink-Wrap points split Part 3. RFC: https://discourse.llvm.org/t/shrink-wrap-save-restore-points-splitting/83581 Part 1: https://github.com/llvm/llvm-project/pull/117862 Part 2: https://github.com/llvm/llvm-project/pull/119355 Part 4: https://github.com/llvm/llvm-project/pull/119358 Part 5: https://github.com/llvm/llvm-project/pull/119359
2025-05-23[llvm-reduce] Remove unused includes (NFC) (#141322)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-04-14llvm-reduce: Preserve uselistorder when writing thinlto bitcode (#133369)Matt Arsenault1-3/+6
Fixes #63621
2025-04-09llvm-reduce: Fix taking wrong error before exit (#135020)Matt Arsenault1-2/+9
2025-03-26[llvm] Use *Set::insert_range (NFC) (#133041)Kazu Hirata1-4/+2
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E); down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration.
2025-03-06[win] NFC: Rename `EHCatchret` to `EHCont` to allow for EH Continuation ↵Daniel Paoliello1-4/+3
targets that aren't `catchret` instructions (#129953) This change splits out the renaming and comment updates from #129612 as a non-functional change.
2024-11-14Overhaul the TargetMachine and LLVMTargetMachine Classes (#111234)Matin Raayai1-5/+2
Following discussions in #110443, and the following earlier discussions in https://lists.llvm.org/pipermail/llvm-dev/2017-October/117907.html, https://reviews.llvm.org/D38482, https://reviews.llvm.org/D38489, this PR attempts to overhaul the `TargetMachine` and `LLVMTargetMachine` interface classes. More specifically: 1. Makes `TargetMachine` the only class implemented under `TargetMachine.h` in the `Target` library. 2. `TargetMachine` contains target-specific interface functions that relate to IR/CodeGen/MC constructs, whereas before (at least on paper) it was supposed to have only IR/MC constructs. Any Target that doesn't want to use the independent code generator simply does not implement them, and returns either `false` or `nullptr`. 3. Renames `LLVMTargetMachine` to `CodeGenCommonTMImpl`. This renaming aims to make the purpose of `LLVMTargetMachine` clearer. Its interface was moved under the CodeGen library, to further emphasis its usage in Targets that use CodeGen directly. 4. Makes `TargetMachine` the only interface used across LLVM and its projects. With these changes, `CodeGenCommonTMImpl` is simply a set of shared function implementations of `TargetMachine`, and CodeGen users don't need to static cast to `LLVMTargetMachine` every time they need a CodeGen-specific feature of the `TargetMachine`. 5. More importantly, does not change any requirements regarding library linking. cc @arsenm @aeubanks
2024-10-04[LLVM] Add HasFakeUses to MachineFunction (#110097)Stephen Tozer1-0/+1
Following the addition of the llvm.fake.use intrinsic and corresponding MIR instruction, two further changes are planned: to add an -fextend-lifetimes flag to Clang that emits these intrinsics, and to have -Og enable this flag by default. Currently, some logic for handling fake uses is gated by the optdebug attribute, which is intended to be switched on by -fextend-lifetimes (and by extension -Og later on). However, the decision was made that a general optdebug attribute should be incompatible with other opt_ attributes (e.g. optsize, optnone), since they all express different intents for how to optimize the program. We would still like to allow -fextend-lifetimes with optsize however (i.e. -Os -fextend-lifetimes should be legal), since it may be a useful configuration and there is no technical reason to not allow it. This patch resolves this by tracking MachineFunctions that have fake uses, allowing us to run passes that interact with them and skip passes that clash with them.
2024-09-24llvm-reduce: Don't print verifier failed machine functions (#109673)Matt Arsenault1-2/+20
This produces far too much terminal output, particularly for the instruction reduction. Since it doesn't consider the liveness of of the instructions it's deleting, it produces quite a lot of verifier errors.
2024-08-07[llvm-reduce] Handle new flags in complexity scoreNikita Popov1-2/+17
This has gotten out of sync with the actual flag reduction. It's not particularly important though, as it only seems to be used to determine whether to do another round of delta reduction.
2024-08-07[CodeGen] Allocate RegAllocHints map lazily (#102186)Alexis Engelke1-4/+6
This hint map is not required whenever a new register is added, in fact, at -O0, it is not used at all. Growing this map is quite expensive, as SmallVectors are not trivially copyable. Grow this map only when hints are actually added to avoid multiple grows and grows when no hints are added at all.
2024-07-26CodeGen: Remove MachineModuleInfo reference from MachineFunction (#100357)Matt Arsenault1-1/+1
This avoids another unserializable field. Move the DbgInfoAvailable field into the AsmPrinter, which is only really a cache/convenience bit for checking a direct IR module metadata check.
2024-07-24CodeGen: Avoid using MachineFunction::getMMI in MachineModuleSlotTracker ↵Matt Arsenault1-1/+1
(#100310)
2024-03-11[CodeGen] Do not pass MF into MachineRegisterInfo methods. NFC. (#84770)Jay Foad1-1/+1
MachineRegisterInfo already knows the MF so there is no need to pass it in as an argument.
2023-12-04[CodeGen] Split off PseudoSourceValueManager into separate header (NFC) (#73327)Nikita Popov1-0/+1
Most users of PseudoSourceValue.h only need PseudoSourceValue, not the PseudoSourceValueManager. However, this header pulls in some very expensive dependencies like ValueMap.h, which is only used for the manager. Split off the manager into a separate header and include it only where used.
2023-10-31llvm-reduce: Handle cloning for MachineJumpTableInfo (#69086)Matt Arsenault1-0/+22
2023-10-04Introduce and use codegen::createTargetMachineForTriple()Alex Richardson1-19/+5
This creates a TargetMachine with the default options (from the command line flags). This allows us to share a bit more code between tools. Differential Revision: https://reviews.llvm.org/D141057
2023-09-14[NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes ↵Arthur Eubanks1-1/+1
(#66295) This will make it easy for callers to see issues with and fix up calls to createTargetMachine after a future change to the params of TargetMachine. This matches other nearby enums. For downstream users, this should be a fairly straightforward replacement, e.g. s/CodeGenOpt::Aggressive/CodeGenOptLevel::Aggressive or s/CGFT_/CodeGenFileType::
2023-07-27[CodeGen] Store call frame size in MachineBasicBlockJay Foad1-0/+2
Record the call frame size on entry to each basic block. This is usually zero except when a basic block has been split in the middle of a call sequence. This simplifies PEI::replaceFrameIndices which previously had to visit basic blocks in a specific order and had special handling for unreachable blocks. More importantly it paves the way for an equally simple implementation of a backwards version of replaceFrameIndices, which is required to fully convert PrologEpilogInserter to backwards register scavenging, which is preferred because it does not rely on accurate kill flags. Differential Revision: https://reviews.llvm.org/D156113
2023-07-13Revert "[CodeGen] Store SP adjustment in MachineBasicBlock. NFCI."Oliver Stannard1-2/+0
This reverts commit 58d1eaa3b6ce4f7285c51f83faff7a3ac374c746.
2023-07-12[CodeGen] Store SP adjustment in MachineBasicBlock. NFCI.Jay Foad1-0/+2
Record the SP adjustment on entry to each basic block. This is almost always zero except on targets like ARM which can split a basic block in the middle of a call sequence. This simplifies PEI::replaceFrameIndices which previously had to visit basic blocks in a specific order and had special handling for unreachable blocks. More importantly it paves the way for an equally simple implementation of a backwards version of replaceFrameIndices, which is required to fully convert PrologEpilogInserter to backwards register scavenging, which is preferred because it does not rely on accurate kill flags. Differential Revision: https://reviews.llvm.org/D154281
2023-06-30llvm-reduce: Fix not preserving uselistorder with bitcodeMatt Arsenault1-1/+2
Fix accidentally passing pointer to bool argument This was supposed to be writing bitcode with preserved uselistorder, but instead was only enabling it with LTO module summaries.
2023-04-17[nfc][llvm] Replace pointer cast functions in PointerUnion by llvm casting ↵Shraiysh Vaishay1-1/+1
functions. This patch replaces the uses of PointerUnion.is function by llvm::isa, PointerUnion.get function by llvm::cast, and PointerUnion.dyn_cast by llvm::dyn_cast_if_present. This is according to the FIXME in the definition of the class PointerUnion. This patch does not remove them as they are being used in other subprojects. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D148449
2023-04-10[MachineOutliner] Add IsOutlined to MachineFunctionwangpc1-0/+1
We add a field `IsOutlined` to indicate whether a MachineFunction is outlined and set it true for outlined functions in MachineOutliner. Reviewed By: paquette Differential Revision: https://reviews.llvm.org/D146191
2023-02-10[NFC][TargetParser] Replace uses of llvm/Support/Host.hArchibald Elliott1-1/+1
The forwarding header is left in place because of its use in `polly/lib/External/isl/interface/extract_interface.cc`, but I have added a GCC warning about the fact it is deprecated, because it is used in `isl` from where it is included by Polly.
2023-01-27llvm-reduce: Parse file from the opened buffer instead of the fileMatt Arsenault1-1/+1
If this wasn't bitcode this was opening a second MemoryBuffer.
2023-01-27llvm-reduce: Use WithColor in another placeMatt Arsenault1-3/+5
Use more consistently capitalized/colorized/punctuated error messages.
2023-01-20llvm-reduce: Fix default handling of intermediate formatMatt Arsenault1-2/+1
Bitcode inputs should produce bitcode intermediates by default.
2023-01-20llvm-reduce: Reorganize some function locationsMatt Arsenault1-112/+208
Move things that are naturally methods of ReducerWorkItem to be methods of ReducerWorkItem in the same source file.
2023-01-19llvm-reduce: Trim includes and avoid using namespace in a headerMatt Arsenault1-0/+5
2023-01-19llvm-reduce: Account for initializer complexityMatt Arsenault1-1/+1
2023-01-19llvm-reduce: Account for aliases and ifuncs in IR complexity scoreMatt Arsenault1-0/+6
2023-01-12[IR] Support importing modules with invalid data layouts.Jannik Silvanus1-2/+2
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-03llvm-reduce: Refine missing argument behaviorMatt Arsenault1-5/+5
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.
2022-12-07[IRReader] Convert Optional in DataLayoutCallbackTy to std::optionalKrzysztof Parzyszek1-1/+2
2022-12-05[IR] llvm::Optional => std::optionalFangrui Song1-1/+1
Many llvm/IR/* files have been migrated by other contributors. This migrates most remaining files.
2022-12-03CodeGen/CommandFlags: Convert Optional to std::optionalFangrui Song1-1/+1
2022-10-31llvm-reduce: Support emitting bitcode for final resultMatt Arsenault1-6/+8
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-12llvm-reduce: Don't write out IR to score IR complexityMatt Arsenault1-10/+120
In a testcase I'm working on, the old write out and count IR lines was taking about 200-300ms per iteration. This drops it out of the profile. This doesn't account for everything, but it doesn't seem to matter. We should probably try to account for metadata and constantexpr tree depths.
2022-08-16Untangle the mess which is MachineBasicBlock::hasAddressTaken().Eli Friedman1-2/+4
There are two different senses in which a block can be "address-taken". There can be a BlockAddress involved, which means we need to map the IR-level value to some specific block of machine code. Or there can be constructs inside a function which involve using the address of a basic block to implement certain kinds of control flow. Mixing these together causes a problem: if target-specific passes are marking random blocks "address-taken", if we have a BlockAddress, we can't actually tell which MachineBasicBlock corresponds to the BlockAddress. So split this into two separate bits: one for BlockAddress, and one for the machine-specific bits. Discovered while trying to sort out related stuff on D102817. Differential Revision: https://reviews.llvm.org/D124697
2022-07-18llvm-reduce: Add reduction for custom register masksMatt Arsenault1-1/+16
I have a register allocator failure that only reproduces with IPRA enabled, and requires the specific regmask if I want to only run the one relevant pass. The printed custom regmask is enormous and I would like to reduce it. This reduces each individual bit in the mask, but it would probably be better to start at register units and clear all aliasing fields at a time. This would require stricter verification that all aliasing bits are set in regmasks (although I would prefer to switch regmasks to use register units in the first place).
2022-06-30[llvm-reduce] Add support for LTO bitcode filesMatthew Voss1-6/+35
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-07llvm-reduce: Add cloning of target MachineFunctionInfoMatt Arsenault1-2/+5
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-07llvm-reduce: Don't assert on functions which don't track livenessMatt Arsenault1-1/+2
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-03[tools] Forward declare classes & remove includesClemens Wasser1-0/+1
Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D120208
2022-06-01llvm-reduce: Add reduction pass to remove regalloc hintsMatt Arsenault1-0/+6
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-05-01llvm-reduce: Introduce new scoring mechanism for MIR reductionsMatt Arsenault1-0/+77
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-04-27llvm-reduce: Fix incorrect cloning of MachineMemOperandsMatt Arsenault1-1/+58
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.