blob: 09c4423a2f057319d5097d18bdc4c3f62eac48f4 [file] [log] [blame]
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +00001//===- llvm/CodeGen/CriticalAntiDepBreaker.h - Anti-Dep Support -*- C++ -*-===//
David Goodwin83704852009-10-26 16:59:04 +00002//
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 Kramera7c40ef2014-08-13 16:26:38 +000016#ifndef LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H
17#define LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H
David Goodwin83704852009-10-26 16:59:04 +000018
David Goodwine30ed532009-10-28 18:29:54 +000019#include "AntiDepBreaker.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000020#include "llvm/ADT/BitVector.h"
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000021#include "llvm/Support/Compiler.h"
22#include <map>
23#include <vector>
David Goodwin83704852009-10-26 16:59:04 +000024
25namespace llvm {
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000026
27class MachineBasicBlock;
28class MachineFunction;
29class MachineInstr;
30class MachineOperand;
31class MachineRegisterInfo;
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +000032class RegisterClassInfo;
Evan Chengf128bdc2010-06-16 07:35:02 +000033class TargetInstrInfo;
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000034class TargetRegisterClass;
Evan Chengf128bdc2010-06-16 07:35:02 +000035class TargetRegisterInfo;
36
Benjamin Kramerf4c20252015-07-01 14:47:39 +000037class LLVM_LIBRARY_VISIBILITY CriticalAntiDepBreaker : public AntiDepBreaker {
David Goodwin83704852009-10-26 16:59:04 +000038 MachineFunction& MF;
39 MachineRegisterInfo &MRI;
Evan Chengf128bdc2010-06-16 07:35:02 +000040 const TargetInstrInfo *TII;
David Goodwin83704852009-10-26 16:59:04 +000041 const TargetRegisterInfo *TRI;
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +000042 const RegisterClassInfo &RegClassInfo;
David Goodwin83704852009-10-26 16:59:04 +000043
Sanjay Pateld6492352014-09-21 14:48:16 +000044 /// The set of allocatable registers.
David Goodwin83704852009-10-26 16:59:04 +000045 /// 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 Pateld6492352014-09-21 14:48:16 +000049 /// For live regs that are only used in one register class in a
David Goodwin83704852009-10-26 16:59:04 +000050 /// 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 Zelenko4f81cdd2017-09-29 21:55:49 +000054 std::vector<const TargetRegisterClass *> Classes;
David Goodwin83704852009-10-26 16:59:04 +000055
Sanjay Pateld6492352014-09-21 14:48:16 +000056 /// Map registers to all their references within a live range.
David Goodwin83704852009-10-26 16:59:04 +000057 std::multimap<unsigned, MachineOperand *> RegRefs;
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000058
59 using RegRefIter =
60 std::multimap<unsigned, MachineOperand *>::const_iterator;
David Goodwin83704852009-10-26 16:59:04 +000061
Sanjay Pateld6492352014-09-21 14:48:16 +000062 /// The index of the most recent kill (proceeding bottom-up),
David Goodwin83704852009-10-26 16:59:04 +000063 /// or ~0u if the register is not live.
Bill Wendling51a9c0a2010-07-15 19:58:14 +000064 std::vector<unsigned> KillIndices;
David Goodwin83704852009-10-26 16:59:04 +000065
Sanjay Pateld6492352014-09-21 14:48:16 +000066 /// The index of the most recent complete def (proceeding
Sanjay Patel99475192014-06-24 21:11:51 +000067 /// bottom up), or ~0u if the register is live.
Bill Wendling51a9c0a2010-07-15 19:58:14 +000068 std::vector<unsigned> DefIndices;
David Goodwin83704852009-10-26 16:59:04 +000069
Sanjay Pateld6492352014-09-21 14:48:16 +000070 /// A set of registers which are live and cannot be changed to
David Goodwin83704852009-10-26 16:59:04 +000071 /// break anti-dependencies.
Benjamin Kramer5d1bca82012-03-17 20:22:57 +000072 BitVector KeepRegs;
David Goodwin83704852009-10-26 16:59:04 +000073
74 public:
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000075 CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo &RCI);
Alexander Kornienkof817c1c2015-04-11 02:11:45 +000076 ~CriticalAntiDepBreaker() override;
Jim Grosbacheb431da2010-01-06 16:48:02 +000077
Sanjay Pateld6492352014-09-21 14:48:16 +000078 /// Initialize anti-dep breaking for a new basic block.
Craig Topper4584cd52014-03-07 09:26:03 +000079 void StartBlock(MachineBasicBlock *BB) override;
David Goodwin83704852009-10-26 16:59:04 +000080
Sanjay Pateld6492352014-09-21 14:48:16 +000081 /// Identifiy anti-dependencies along the critical path
David Goodwin83704852009-10-26 16:59:04 +000082 /// of the ScheduleDAG and break them by renaming registers.
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000083 unsigned BreakAntiDependencies(const std::vector<SUnit> &SUnits,
Dan Gohman35bc4d42010-04-19 23:11:58 +000084 MachineBasicBlock::iterator Begin,
85 MachineBasicBlock::iterator End,
Devang Patelf02a3762011-06-02 21:26:52 +000086 unsigned InsertPosIndex,
Craig Topper4584cd52014-03-07 09:26:03 +000087 DbgValueVector &DbgValues) override;
David Goodwin83704852009-10-26 16:59:04 +000088
Sanjay Pateld6492352014-09-21 14:48:16 +000089 /// Update liveness information to account for the current
David Goodwin83704852009-10-26 16:59:04 +000090 /// instruction, which will not be scheduled.
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +000091 void Observe(MachineInstr &MI, unsigned Count,
Craig Topper4584cd52014-03-07 09:26:03 +000092 unsigned InsertPosIndex) override;
David Goodwin83704852009-10-26 16:59:04 +000093
Sanjay Pateld6492352014-09-21 14:48:16 +000094 /// Finish anti-dep breaking for a basic block.
Craig Topper4584cd52014-03-07 09:26:03 +000095 void FinishBlock() override;
David Goodwin83704852009-10-26 16:59:04 +000096
97 private:
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +000098 void PrescanInstruction(MachineInstr &MI);
99 void ScanInstruction(MachineInstr &MI, unsigned Count);
Andrew Trick4b491872011-02-08 17:39:46 +0000100 bool isNewRegClobberedByRefs(RegRefIter RegRefBegin,
101 RegRefIter RegRefEnd,
102 unsigned NewReg);
Andrew Trick82ae9a92010-11-02 18:16:45 +0000103 unsigned findSuitableFreeRegister(RegRefIter RegRefBegin,
104 RegRefIter RegRefEnd,
Jim Grosbacha7cef4f2010-01-06 22:21:25 +0000105 unsigned AntiDepReg,
David Goodwin83704852009-10-26 16:59:04 +0000106 unsigned LastNewReg,
Bill Schmidt2e4ae4e2013-01-28 18:36:58 +0000107 const TargetRegisterClass *RC,
Craig Topper72cde632013-07-03 05:16:59 +0000108 SmallVectorImpl<unsigned> &Forbid);
David Goodwin83704852009-10-26 16:59:04 +0000109 };
David Goodwin83704852009-10-26 16:59:04 +0000110
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +0000111} // end namespace llvm
112
113#endif // LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H