David Goodwin | 2e7be61 | 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 | |
| 16 | #ifndef LLVM_CODEGEN_CRITICALANTIDEPBREAKER_H |
| 17 | #define LLVM_CODEGEN_CRITICALANTIDEPBREAKER_H |
| 18 | |
David Goodwin | 82c7248 | 2009-10-28 18:29:54 +0000 | [diff] [blame] | 19 | #include "AntiDepBreaker.h" |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 21 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 22 | #include "llvm/CodeGen/MachineFunction.h" |
| 23 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Andrew Trick | 1525260 | 2012-06-06 20:29:31 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/RegisterClassInfo.h" |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/ScheduleDAG.h" |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/BitVector.h" |
David Goodwin | 557bbe6 | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 27 | #include <map> |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 28 | |
| 29 | namespace llvm { |
Jakob Stoklund Olesen | fa796dd | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 30 | class RegisterClassInfo; |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 31 | class TargetInstrInfo; |
| 32 | class TargetRegisterInfo; |
| 33 | |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 34 | class CriticalAntiDepBreaker : public AntiDepBreaker { |
| 35 | MachineFunction& MF; |
| 36 | MachineRegisterInfo &MRI; |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 37 | const TargetInstrInfo *TII; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 38 | const TargetRegisterInfo *TRI; |
Jakob Stoklund Olesen | fa796dd | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 39 | const RegisterClassInfo &RegClassInfo; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 40 | |
| 41 | /// AllocatableSet - The set of allocatable registers. |
| 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 | |
| 46 | /// Classes - For live regs that are only used in one register class in a |
| 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 | 9c2a034 | 2010-07-15 19:58:14 +0000 | [diff] [blame] | 51 | std::vector<const TargetRegisterClass*> Classes; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 52 | |
Mikhail Glushenkov | 35edc42 | 2011-02-09 22:55:48 +0000 | [diff] [blame] | 53 | /// RegRefs - Map registers to all their references within a live range. |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 54 | std::multimap<unsigned, MachineOperand *> RegRefs; |
Andrew Trick | 4638852 | 2010-11-02 18:16:45 +0000 | [diff] [blame] | 55 | typedef std::multimap<unsigned, MachineOperand *>::const_iterator |
| 56 | RegRefIter; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 57 | |
| 58 | /// KillIndices - The index of the most recent kill (proceding bottom-up), |
| 59 | /// or ~0u if the register is not live. |
Bill Wendling | 9c2a034 | 2010-07-15 19:58:14 +0000 | [diff] [blame] | 60 | std::vector<unsigned> KillIndices; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 61 | |
| 62 | /// DefIndices - The index of the most recent complete def (proceding bottom |
| 63 | /// up), or ~0u if the register is live. |
Bill Wendling | 9c2a034 | 2010-07-15 19:58:14 +0000 | [diff] [blame] | 64 | std::vector<unsigned> DefIndices; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 65 | |
| 66 | /// KeepRegs - A set of registers which are live and cannot be changed to |
| 67 | /// break anti-dependencies. |
Benjamin Kramer | cff4ad7 | 2012-03-17 20:22:57 +0000 | [diff] [blame] | 68 | BitVector KeepRegs; |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 69 | |
| 70 | public: |
Jakob Stoklund Olesen | fa796dd | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 71 | CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo&); |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 72 | ~CriticalAntiDepBreaker(); |
Jim Grosbach | 2973b57 | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 73 | |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 74 | /// Start - Initialize anti-dep breaking for a new basic block. |
| 75 | void StartBlock(MachineBasicBlock *BB); |
| 76 | |
Jim Grosbach | 2973b57 | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 77 | /// BreakAntiDependencies - Identifiy anti-dependencies along the critical |
| 78 | /// path |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 79 | /// of the ScheduleDAG and break them by renaming registers. |
| 80 | /// |
Dan Gohman | 66db3a0 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 81 | unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits, |
| 82 | MachineBasicBlock::iterator Begin, |
| 83 | MachineBasicBlock::iterator End, |
Devang Patel | e29e8e1 | 2011-06-02 21:26:52 +0000 | [diff] [blame] | 84 | unsigned InsertPosIndex, |
| 85 | DbgValueVector &DbgValues); |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 86 | |
| 87 | /// Observe - Update liveness information to account for the current |
| 88 | /// instruction, which will not be scheduled. |
| 89 | /// |
| 90 | void Observe(MachineInstr *MI, unsigned Count, unsigned InsertPosIndex); |
| 91 | |
| 92 | /// Finish - Finish anti-dep breaking for a basic block. |
| 93 | void FinishBlock(); |
| 94 | |
| 95 | private: |
| 96 | void PrescanInstruction(MachineInstr *MI); |
| 97 | void ScanInstruction(MachineInstr *MI, unsigned Count); |
Andrew Trick | bc4bd92 | 2011-02-08 17:39:46 +0000 | [diff] [blame] | 98 | bool isNewRegClobberedByRefs(RegRefIter RegRefBegin, |
| 99 | RegRefIter RegRefEnd, |
| 100 | unsigned NewReg); |
Andrew Trick | 4638852 | 2010-11-02 18:16:45 +0000 | [diff] [blame] | 101 | unsigned findSuitableFreeRegister(RegRefIter RegRefBegin, |
| 102 | RegRefIter RegRefEnd, |
Jim Grosbach | 80c2b0d | 2010-01-06 22:21:25 +0000 | [diff] [blame] | 103 | unsigned AntiDepReg, |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 104 | unsigned LastNewReg, |
Andrew Trick | 4638852 | 2010-11-02 18:16:45 +0000 | [diff] [blame] | 105 | const TargetRegisterClass *RC); |
David Goodwin | 2e7be61 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 106 | }; |
| 107 | } |
| 108 | |
| 109 | #endif |