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