Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 1 | //===- llvm/CodeGen/CriticalAntiDepBreaker.h - Anti-Dep Support -*- C++ -*-===// |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 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 | 00e08fc | 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 | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 18 | |
David Goodwin | 82c7248 | 2009-10-28 18:29:54 +0000 | [diff] [blame] | 19 | #include "AntiDepBreaker.h" |
Chandler Carruth | a1514e2 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/BitVector.h" |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Compiler.h" |
| 22 | #include <map> |
| 23 | #include <vector> |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 24 | |
| 25 | namespace llvm { |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 26 | |
| 27 | class MachineBasicBlock; |
| 28 | class MachineFunction; |
| 29 | class MachineInstr; |
| 30 | class MachineOperand; |
| 31 | class MachineRegisterInfo; |
Jakob Stoklund Olesen | fa796dd | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 32 | class RegisterClassInfo; |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 33 | class TargetInstrInfo; |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 34 | class TargetRegisterClass; |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 35 | class TargetRegisterInfo; |
| 36 | |
Benjamin Kramer | b453775 | 2015-07-01 14:47:39 +0000 | [diff] [blame] | 37 | class LLVM_LIBRARY_VISIBILITY CriticalAntiDepBreaker : public AntiDepBreaker { |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 38 | MachineFunction& MF; |
| 39 | MachineRegisterInfo &MRI; |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 40 | const TargetInstrInfo *TII; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 41 | const TargetRegisterInfo *TRI; |
Jakob Stoklund Olesen | fa796dd | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 42 | const RegisterClassInfo &RegClassInfo; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 43 | |
Sanjay Patel | 42dac65 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 44 | /// The set of allocatable registers. |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 45 | /// We'll be ignoring anti-dependencies on non-allocatable registers, |
| 46 | /// because they may not be safe to break. |
| 47 | const BitVector AllocatableSet; |
| 48 | |
Sanjay Patel | 42dac65 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 49 | /// For live regs that are only used in one register class in a |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 50 | /// live range, the register class. If the register is not live, the |
| 51 | /// corresponding value is null. If the register is live but used in |
| 52 | /// multiple register classes, the corresponding value is -1 casted to a |
| 53 | /// pointer. |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 54 | std::vector<const TargetRegisterClass *> Classes; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 55 | |
Sanjay Patel | 42dac65 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 56 | /// Map registers to all their references within a live range. |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 57 | std::multimap<unsigned, MachineOperand *> RegRefs; |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 58 | |
| 59 | using RegRefIter = |
| 60 | std::multimap<unsigned, MachineOperand *>::const_iterator; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 61 | |
Sanjay Patel | 42dac65 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 62 | /// The index of the most recent kill (proceeding bottom-up), |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 63 | /// or ~0u if the register is not live. |
Bill Wendling | 9c2a034 | 2010-07-15 19:58:14 +0000 | [diff] [blame] | 64 | std::vector<unsigned> KillIndices; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 65 | |
Sanjay Patel | 42dac65 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 66 | /// The index of the most recent complete def (proceeding |
Sanjay Patel | 0029534 | 2014-06-24 21:11:51 +0000 | [diff] [blame] | 67 | /// bottom up), or ~0u if the register is live. |
Bill Wendling | 9c2a034 | 2010-07-15 19:58:14 +0000 | [diff] [blame] | 68 | std::vector<unsigned> DefIndices; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 69 | |
Sanjay Patel | 42dac65 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 70 | /// A set of registers which are live and cannot be changed to |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 71 | /// break anti-dependencies. |
Benjamin Kramer | cff4ad7 | 2012-03-17 20:22:57 +0000 | [diff] [blame] | 72 | BitVector KeepRegs; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 73 | |
| 74 | public: |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 75 | CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo &RCI); |
Alexander Kornienko | c16fc54 | 2015-04-11 02:11:45 +0000 | [diff] [blame] | 76 | ~CriticalAntiDepBreaker() override; |
Jim Grosbach | 2973b57 | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 77 | |
Sanjay Patel | 42dac65 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 78 | /// Initialize anti-dep breaking for a new basic block. |
Craig Topper | 9f998de | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 79 | void StartBlock(MachineBasicBlock *BB) override; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 80 | |
Sanjay Patel | 42dac65 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 81 | /// Identifiy anti-dependencies along the critical path |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 82 | /// of the ScheduleDAG and break them by renaming registers. |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 83 | unsigned BreakAntiDependencies(const std::vector<SUnit> &SUnits, |
Dan Gohman | 66db3a0 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 84 | MachineBasicBlock::iterator Begin, |
| 85 | MachineBasicBlock::iterator End, |
Devang Patel | e29e8e1 | 2011-06-02 21:26:52 +0000 | [diff] [blame] | 86 | unsigned InsertPosIndex, |
Craig Topper | 9f998de | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 87 | DbgValueVector &DbgValues) override; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 88 | |
Sanjay Patel | 42dac65 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 89 | /// Update liveness information to account for the current |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 90 | /// instruction, which will not be scheduled. |
Duncan P. N. Exon Smith | a26cd9c | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 91 | void Observe(MachineInstr &MI, unsigned Count, |
Craig Topper | 9f998de | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 92 | unsigned InsertPosIndex) override; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 93 | |
Sanjay Patel | 42dac65 | 2014-09-21 14:48:16 +0000 | [diff] [blame] | 94 | /// Finish anti-dep breaking for a basic block. |
Craig Topper | 9f998de | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 95 | void FinishBlock() override; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 96 | |
| 97 | private: |
Duncan P. N. Exon Smith | a26cd9c | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 98 | void PrescanInstruction(MachineInstr &MI); |
| 99 | void ScanInstruction(MachineInstr &MI, unsigned Count); |
Andrew Trick | bc4bd92 | 2011-02-08 17:39:46 +0000 | [diff] [blame] | 100 | bool isNewRegClobberedByRefs(RegRefIter RegRefBegin, |
| 101 | RegRefIter RegRefEnd, |
| 102 | unsigned NewReg); |
Andrew Trick | 4638852 | 2010-11-02 18:16:45 +0000 | [diff] [blame] | 103 | unsigned findSuitableFreeRegister(RegRefIter RegRefBegin, |
| 104 | RegRefIter RegRefEnd, |
Jim Grosbach | 80c2b0d | 2010-01-06 22:21:25 +0000 | [diff] [blame] | 105 | unsigned AntiDepReg, |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 106 | unsigned LastNewReg, |
Bill Schmidt | 5ff776b | 2013-01-28 18:36:58 +0000 | [diff] [blame] | 107 | const TargetRegisterClass *RC, |
Craig Topper | 78477ff | 2013-07-03 05:16:59 +0000 | [diff] [blame] | 108 | SmallVectorImpl<unsigned> &Forbid); |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 109 | }; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 110 | |
Eugene Zelenko | 9434811 | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 111 | } // end namespace llvm |
| 112 | |
| 113 | #endif // LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H |