Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 1 | //===- llvm/CodeGen/CriticalAntiDepBreaker.h - Anti-Dep Support -*- C++ -*-===// |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the CriticalAntiDepBreaker class, which |
| 10 | // implements register anti-dependence breaking along a blocks |
| 11 | // critical path during post-RA scheduler. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 15 | #ifndef LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H |
| 16 | #define LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 17 | |
David Goodwin | e30ed53 | 2009-10-28 18:29:54 +0000 | [diff] [blame] | 18 | #include "AntiDepBreaker.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/BitVector.h" |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Compiler.h" |
| 21 | #include <map> |
| 22 | #include <vector> |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 25 | |
| 26 | class MachineBasicBlock; |
| 27 | class MachineFunction; |
| 28 | class MachineInstr; |
| 29 | class MachineOperand; |
| 30 | class MachineRegisterInfo; |
Jakob Stoklund Olesen | 4f5f84c | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 31 | class RegisterClassInfo; |
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 32 | class TargetInstrInfo; |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 33 | class TargetRegisterClass; |
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 34 | class TargetRegisterInfo; |
| 35 | |
Benjamin Kramer | f4c2025 | 2015-07-01 14:47:39 +0000 | [diff] [blame] | 36 | class LLVM_LIBRARY_VISIBILITY CriticalAntiDepBreaker : public AntiDepBreaker { |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 37 | MachineFunction& MF; |
| 38 | MachineRegisterInfo &MRI; |
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 39 | const TargetInstrInfo *TII; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 40 | const TargetRegisterInfo *TRI; |
Jakob Stoklund Olesen | 4f5f84c | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 41 | const RegisterClassInfo &RegClassInfo; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 42 | |
Sanjay Patel | d649235 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 43 | /// The set of allocatable registers. |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 44 | /// We'll be ignoring anti-dependencies on non-allocatable registers, |
| 45 | /// because they may not be safe to break. |
| 46 | const BitVector AllocatableSet; |
| 47 | |
Sanjay Patel | d649235 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 48 | /// For live regs that are only used in one register class in a |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 49 | /// live range, the register class. If the register is not live, the |
| 50 | /// corresponding value is null. If the register is live but used in |
| 51 | /// multiple register classes, the corresponding value is -1 casted to a |
| 52 | /// pointer. |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 53 | std::vector<const TargetRegisterClass *> Classes; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 54 | |
Sanjay Patel | d649235 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 55 | /// Map registers to all their references within a live range. |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 56 | std::multimap<unsigned, MachineOperand *> RegRefs; |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 57 | |
| 58 | using RegRefIter = |
| 59 | std::multimap<unsigned, MachineOperand *>::const_iterator; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 60 | |
Sanjay Patel | d649235 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 61 | /// The index of the most recent kill (proceeding bottom-up), |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 62 | /// or ~0u if the register is not live. |
Bill Wendling | 51a9c0a | 2010-07-15 19:58:14 +0000 | [diff] [blame] | 63 | std::vector<unsigned> KillIndices; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 64 | |
Sanjay Patel | d649235 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 65 | /// The index of the most recent complete def (proceeding |
Sanjay Patel | 9947519 | 2014-06-24 21:11:51 +0000 | [diff] [blame] | 66 | /// bottom up), or ~0u if the register is live. |
Bill Wendling | 51a9c0a | 2010-07-15 19:58:14 +0000 | [diff] [blame] | 67 | std::vector<unsigned> DefIndices; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 68 | |
Sanjay Patel | d649235 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 69 | /// A set of registers which are live and cannot be changed to |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 70 | /// break anti-dependencies. |
Benjamin Kramer | 5d1bca8 | 2012-03-17 20:22:57 +0000 | [diff] [blame] | 71 | BitVector KeepRegs; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 72 | |
| 73 | public: |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 74 | CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo &RCI); |
Alexander Kornienko | f817c1c | 2015-04-11 02:11:45 +0000 | [diff] [blame] | 75 | ~CriticalAntiDepBreaker() override; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 76 | |
Sanjay Patel | d649235 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 77 | /// Initialize anti-dep breaking for a new basic block. |
Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 78 | void StartBlock(MachineBasicBlock *BB) override; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 79 | |
Sanjay Patel | d649235 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 80 | /// Identifiy anti-dependencies along the critical path |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 81 | /// of the ScheduleDAG and break them by renaming registers. |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 82 | unsigned BreakAntiDependencies(const std::vector<SUnit> &SUnits, |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 83 | MachineBasicBlock::iterator Begin, |
| 84 | MachineBasicBlock::iterator End, |
Devang Patel | f02a376 | 2011-06-02 21:26:52 +0000 | [diff] [blame] | 85 | unsigned InsertPosIndex, |
Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 86 | DbgValueVector &DbgValues) override; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 87 | |
Sanjay Patel | d649235 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 88 | /// Update liveness information to account for the current |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 89 | /// instruction, which will not be scheduled. |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 90 | void Observe(MachineInstr &MI, unsigned Count, |
Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 91 | unsigned InsertPosIndex) override; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 92 | |
Sanjay Patel | d649235 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 93 | /// Finish anti-dep breaking for a basic block. |
Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 94 | void FinishBlock() override; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 95 | |
| 96 | private: |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 97 | void PrescanInstruction(MachineInstr &MI); |
| 98 | void ScanInstruction(MachineInstr &MI, unsigned Count); |
Andrew Trick | 4b49187 | 2011-02-08 17:39:46 +0000 | [diff] [blame] | 99 | bool isNewRegClobberedByRefs(RegRefIter RegRefBegin, |
| 100 | RegRefIter RegRefEnd, |
| 101 | unsigned NewReg); |
Andrew Trick | 82ae9a9 | 2010-11-02 18:16:45 +0000 | [diff] [blame] | 102 | unsigned findSuitableFreeRegister(RegRefIter RegRefBegin, |
| 103 | RegRefIter RegRefEnd, |
Jim Grosbach | a7cef4f | 2010-01-06 22:21:25 +0000 | [diff] [blame] | 104 | unsigned AntiDepReg, |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 105 | unsigned LastNewReg, |
Bill Schmidt | 2e4ae4e | 2013-01-28 18:36:58 +0000 | [diff] [blame] | 106 | const TargetRegisterClass *RC, |
Craig Topper | 72cde63 | 2013-07-03 05:16:59 +0000 | [diff] [blame] | 107 | SmallVectorImpl<unsigned> &Forbid); |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 108 | }; |
David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 109 | |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 110 | } // end namespace llvm |
| 111 | |
| 112 | #endif // LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H |