blob: 678779fa1a2677960614d0c418f44506a6ecb190 [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"
David Goodwin83704852009-10-26 16:59:04 +000022#include "llvm/CodeGen/MachineRegisterInfo.h"
Andrew Trick05ff4662012-06-06 20:29:31 +000023#include "llvm/CodeGen/RegisterClassInfo.h"
David Goodwin83704852009-10-26 16:59:04 +000024#include "llvm/CodeGen/ScheduleDAG.h"
David Goodwin83704852009-10-26 16:59:04 +000025
26namespace llvm {
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +000027class RegisterClassInfo;
Evan Chengf128bdc2010-06-16 07:35:02 +000028class TargetInstrInfo;
29class TargetRegisterInfo;
Mehdi Aminib550cb12016-04-18 09:17:29 +000030class MachineFunction;
Evan Chengf128bdc2010-06-16 07:35:02 +000031
Benjamin Kramerf4c20252015-07-01 14:47:39 +000032class LLVM_LIBRARY_VISIBILITY CriticalAntiDepBreaker : public AntiDepBreaker {
David Goodwin83704852009-10-26 16:59:04 +000033 MachineFunction& MF;
34 MachineRegisterInfo &MRI;
Evan Chengf128bdc2010-06-16 07:35:02 +000035 const TargetInstrInfo *TII;
David Goodwin83704852009-10-26 16:59:04 +000036 const TargetRegisterInfo *TRI;
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +000037 const RegisterClassInfo &RegClassInfo;
David Goodwin83704852009-10-26 16:59:04 +000038
Sanjay Pateld6492352014-09-21 14:48:16 +000039 /// The set of allocatable registers.
David Goodwin83704852009-10-26 16:59:04 +000040 /// We'll be ignoring anti-dependencies on non-allocatable registers,
41 /// because they may not be safe to break.
42 const BitVector AllocatableSet;
43
Sanjay Pateld6492352014-09-21 14:48:16 +000044 /// For live regs that are only used in one register class in a
David Goodwin83704852009-10-26 16:59:04 +000045 /// live range, the register class. If the register is not live, the
46 /// corresponding value is null. If the register is live but used in
47 /// multiple register classes, the corresponding value is -1 casted to a
48 /// pointer.
Bill Wendling51a9c0a2010-07-15 19:58:14 +000049 std::vector<const TargetRegisterClass*> Classes;
David Goodwin83704852009-10-26 16:59:04 +000050
Sanjay Pateld6492352014-09-21 14:48:16 +000051 /// Map registers to all their references within a live range.
David Goodwin83704852009-10-26 16:59:04 +000052 std::multimap<unsigned, MachineOperand *> RegRefs;
Andrew Trick82ae9a92010-11-02 18:16:45 +000053 typedef std::multimap<unsigned, MachineOperand *>::const_iterator
54 RegRefIter;
David Goodwin83704852009-10-26 16:59:04 +000055
Sanjay Pateld6492352014-09-21 14:48:16 +000056 /// The index of the most recent kill (proceeding bottom-up),
David Goodwin83704852009-10-26 16:59:04 +000057 /// or ~0u if the register is not live.
Bill Wendling51a9c0a2010-07-15 19:58:14 +000058 std::vector<unsigned> KillIndices;
David Goodwin83704852009-10-26 16:59:04 +000059
Sanjay Pateld6492352014-09-21 14:48:16 +000060 /// The index of the most recent complete def (proceeding
Sanjay Patel99475192014-06-24 21:11:51 +000061 /// bottom up), or ~0u if the register is live.
Bill Wendling51a9c0a2010-07-15 19:58:14 +000062 std::vector<unsigned> DefIndices;
David Goodwin83704852009-10-26 16:59:04 +000063
Sanjay Pateld6492352014-09-21 14:48:16 +000064 /// A set of registers which are live and cannot be changed to
David Goodwin83704852009-10-26 16:59:04 +000065 /// break anti-dependencies.
Benjamin Kramer5d1bca82012-03-17 20:22:57 +000066 BitVector KeepRegs;
David Goodwin83704852009-10-26 16:59:04 +000067
68 public:
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +000069 CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo&);
Alexander Kornienkof817c1c2015-04-11 02:11:45 +000070 ~CriticalAntiDepBreaker() override;
Jim Grosbacheb431da2010-01-06 16:48:02 +000071
Sanjay Pateld6492352014-09-21 14:48:16 +000072 /// Initialize anti-dep breaking for a new basic block.
Craig Topper4584cd52014-03-07 09:26:03 +000073 void StartBlock(MachineBasicBlock *BB) override;
David Goodwin83704852009-10-26 16:59:04 +000074
Sanjay Pateld6492352014-09-21 14:48:16 +000075 /// Identifiy anti-dependencies along the critical path
David Goodwin83704852009-10-26 16:59:04 +000076 /// of the ScheduleDAG and break them by renaming registers.
Dan Gohman35bc4d42010-04-19 23:11:58 +000077 unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits,
78 MachineBasicBlock::iterator Begin,
79 MachineBasicBlock::iterator End,
Devang Patelf02a3762011-06-02 21:26:52 +000080 unsigned InsertPosIndex,
Craig Topper4584cd52014-03-07 09:26:03 +000081 DbgValueVector &DbgValues) override;
David Goodwin83704852009-10-26 16:59:04 +000082
Sanjay Pateld6492352014-09-21 14:48:16 +000083 /// Update liveness information to account for the current
David Goodwin83704852009-10-26 16:59:04 +000084 /// instruction, which will not be scheduled.
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +000085 void Observe(MachineInstr &MI, unsigned Count,
Craig Topper4584cd52014-03-07 09:26:03 +000086 unsigned InsertPosIndex) override;
David Goodwin83704852009-10-26 16:59:04 +000087
Sanjay Pateld6492352014-09-21 14:48:16 +000088 /// Finish anti-dep breaking for a basic block.
Craig Topper4584cd52014-03-07 09:26:03 +000089 void FinishBlock() override;
David Goodwin83704852009-10-26 16:59:04 +000090
91 private:
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +000092 void PrescanInstruction(MachineInstr &MI);
93 void ScanInstruction(MachineInstr &MI, unsigned Count);
Andrew Trick4b491872011-02-08 17:39:46 +000094 bool isNewRegClobberedByRefs(RegRefIter RegRefBegin,
95 RegRefIter RegRefEnd,
96 unsigned NewReg);
Andrew Trick82ae9a92010-11-02 18:16:45 +000097 unsigned findSuitableFreeRegister(RegRefIter RegRefBegin,
98 RegRefIter RegRefEnd,
Jim Grosbacha7cef4f2010-01-06 22:21:25 +000099 unsigned AntiDepReg,
David Goodwin83704852009-10-26 16:59:04 +0000100 unsigned LastNewReg,
Bill Schmidt2e4ae4e2013-01-28 18:36:58 +0000101 const TargetRegisterClass *RC,
Craig Topper72cde632013-07-03 05:16:59 +0000102 SmallVectorImpl<unsigned> &Forbid);
David Goodwin83704852009-10-26 16:59:04 +0000103 };
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000104}
David Goodwin83704852009-10-26 16:59:04 +0000105
106#endif