blob: 10b873959ad0d4c797887daced150cdf757831a2 [file] [log] [blame]
David Goodwin83704852009-10-26 16:59:04 +00001//=- 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 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"
David Goodwin83704852009-10-26 16:59:04 +000021#include "llvm/CodeGen/MachineBasicBlock.h"
22#include "llvm/CodeGen/MachineFrameInfo.h"
23#include "llvm/CodeGen/MachineFunction.h"
24#include "llvm/CodeGen/MachineRegisterInfo.h"
Andrew Trick05ff4662012-06-06 20:29:31 +000025#include "llvm/CodeGen/RegisterClassInfo.h"
David Goodwin83704852009-10-26 16:59:04 +000026#include "llvm/CodeGen/ScheduleDAG.h"
David Goodwin80a03cc2009-11-20 19:32:48 +000027#include <map>
David Goodwin83704852009-10-26 16:59:04 +000028
29namespace llvm {
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +000030class RegisterClassInfo;
Evan Chengf128bdc2010-06-16 07:35:02 +000031class TargetInstrInfo;
32class TargetRegisterInfo;
33
Benjamin Kramerf4c20252015-07-01 14:47:39 +000034class LLVM_LIBRARY_VISIBILITY CriticalAntiDepBreaker : public AntiDepBreaker {
David Goodwin83704852009-10-26 16:59:04 +000035 MachineFunction& MF;
36 MachineRegisterInfo &MRI;
Evan Chengf128bdc2010-06-16 07:35:02 +000037 const TargetInstrInfo *TII;
David Goodwin83704852009-10-26 16:59:04 +000038 const TargetRegisterInfo *TRI;
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +000039 const RegisterClassInfo &RegClassInfo;
David Goodwin83704852009-10-26 16:59:04 +000040
Sanjay Pateld6492352014-09-21 14:48:16 +000041 /// The set of allocatable registers.
David Goodwin83704852009-10-26 16:59:04 +000042 /// 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 Pateld6492352014-09-21 14:48:16 +000046 /// For live regs that are only used in one register class in a
David Goodwin83704852009-10-26 16:59:04 +000047 /// 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 Wendling51a9c0a2010-07-15 19:58:14 +000051 std::vector<const TargetRegisterClass*> Classes;
David Goodwin83704852009-10-26 16:59:04 +000052
Sanjay Pateld6492352014-09-21 14:48:16 +000053 /// Map registers to all their references within a live range.
David Goodwin83704852009-10-26 16:59:04 +000054 std::multimap<unsigned, MachineOperand *> RegRefs;
Andrew Trick82ae9a92010-11-02 18:16:45 +000055 typedef std::multimap<unsigned, MachineOperand *>::const_iterator
56 RegRefIter;
David Goodwin83704852009-10-26 16:59:04 +000057
Sanjay Pateld6492352014-09-21 14:48:16 +000058 /// The index of the most recent kill (proceeding bottom-up),
David Goodwin83704852009-10-26 16:59:04 +000059 /// or ~0u if the register is not live.
Bill Wendling51a9c0a2010-07-15 19:58:14 +000060 std::vector<unsigned> KillIndices;
David Goodwin83704852009-10-26 16:59:04 +000061
Sanjay Pateld6492352014-09-21 14:48:16 +000062 /// The index of the most recent complete def (proceeding
Sanjay Patel99475192014-06-24 21:11:51 +000063 /// bottom up), or ~0u if the register is live.
Bill Wendling51a9c0a2010-07-15 19:58:14 +000064 std::vector<unsigned> DefIndices;
David Goodwin83704852009-10-26 16:59:04 +000065
Sanjay Pateld6492352014-09-21 14:48:16 +000066 /// A set of registers which are live and cannot be changed to
David Goodwin83704852009-10-26 16:59:04 +000067 /// break anti-dependencies.
Benjamin Kramer5d1bca82012-03-17 20:22:57 +000068 BitVector KeepRegs;
David Goodwin83704852009-10-26 16:59:04 +000069
70 public:
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +000071 CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo&);
Alexander Kornienkof817c1c2015-04-11 02:11:45 +000072 ~CriticalAntiDepBreaker() override;
Jim Grosbacheb431da2010-01-06 16:48:02 +000073
Sanjay Pateld6492352014-09-21 14:48:16 +000074 /// Initialize anti-dep breaking for a new basic block.
Craig Topper4584cd52014-03-07 09:26:03 +000075 void StartBlock(MachineBasicBlock *BB) override;
David Goodwin83704852009-10-26 16:59:04 +000076
Sanjay Pateld6492352014-09-21 14:48:16 +000077 /// Identifiy anti-dependencies along the critical path
David Goodwin83704852009-10-26 16:59:04 +000078 /// of the ScheduleDAG and break them by renaming registers.
Dan Gohman35bc4d42010-04-19 23:11:58 +000079 unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits,
80 MachineBasicBlock::iterator Begin,
81 MachineBasicBlock::iterator End,
Devang Patelf02a3762011-06-02 21:26:52 +000082 unsigned InsertPosIndex,
Craig Topper4584cd52014-03-07 09:26:03 +000083 DbgValueVector &DbgValues) override;
David Goodwin83704852009-10-26 16:59:04 +000084
Sanjay Pateld6492352014-09-21 14:48:16 +000085 /// Update liveness information to account for the current
David Goodwin83704852009-10-26 16:59:04 +000086 /// instruction, which will not be scheduled.
Craig Topper4584cd52014-03-07 09:26:03 +000087 void Observe(MachineInstr *MI, unsigned Count,
88 unsigned InsertPosIndex) override;
David Goodwin83704852009-10-26 16:59:04 +000089
Sanjay Pateld6492352014-09-21 14:48:16 +000090 /// Finish anti-dep breaking for a basic block.
Craig Topper4584cd52014-03-07 09:26:03 +000091 void FinishBlock() override;
David Goodwin83704852009-10-26 16:59:04 +000092
93 private:
94 void PrescanInstruction(MachineInstr *MI);
95 void ScanInstruction(MachineInstr *MI, unsigned Count);
Andrew Trick4b491872011-02-08 17:39:46 +000096 bool isNewRegClobberedByRefs(RegRefIter RegRefBegin,
97 RegRefIter RegRefEnd,
98 unsigned NewReg);
Andrew Trick82ae9a92010-11-02 18:16:45 +000099 unsigned findSuitableFreeRegister(RegRefIter RegRefBegin,
100 RegRefIter RegRefEnd,
Jim Grosbacha7cef4f2010-01-06 22:21:25 +0000101 unsigned AntiDepReg,
David Goodwin83704852009-10-26 16:59:04 +0000102 unsigned LastNewReg,
Bill Schmidt2e4ae4e2013-01-28 18:36:58 +0000103 const TargetRegisterClass *RC,
Craig Topper72cde632013-07-03 05:16:59 +0000104 SmallVectorImpl<unsigned> &Forbid);
David Goodwin83704852009-10-26 16:59:04 +0000105 };
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000106}
David Goodwin83704852009-10-26 16:59:04 +0000107
108#endif