blob: ad95c4819119fc5206ca17fe0fd9e32b7b4ca0f5 [file] [log] [blame]
David Goodwin2e7be612009-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
16#ifndef LLVM_CODEGEN_CRITICALANTIDEPBREAKER_H
17#define LLVM_CODEGEN_CRITICALANTIDEPBREAKER_H
18
David Goodwin82c72482009-10-28 18:29:54 +000019#include "AntiDepBreaker.h"
David Goodwin2e7be612009-10-26 16:59:04 +000020#include "llvm/CodeGen/MachineBasicBlock.h"
21#include "llvm/CodeGen/MachineFrameInfo.h"
22#include "llvm/CodeGen/MachineFunction.h"
23#include "llvm/CodeGen/MachineRegisterInfo.h"
Andrew Trick15252602012-06-06 20:29:31 +000024#include "llvm/CodeGen/RegisterClassInfo.h"
David Goodwin2e7be612009-10-26 16:59:04 +000025#include "llvm/CodeGen/ScheduleDAG.h"
David Goodwin2e7be612009-10-26 16:59:04 +000026#include "llvm/ADT/BitVector.h"
David Goodwin557bbe62009-11-20 19:32:48 +000027#include <map>
David Goodwin2e7be612009-10-26 16:59:04 +000028
29namespace llvm {
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +000030class RegisterClassInfo;
Evan Cheng46df4eb2010-06-16 07:35:02 +000031class TargetInstrInfo;
32class TargetRegisterInfo;
33
David Goodwin2e7be612009-10-26 16:59:04 +000034 class CriticalAntiDepBreaker : public AntiDepBreaker {
35 MachineFunction& MF;
36 MachineRegisterInfo &MRI;
Evan Cheng46df4eb2010-06-16 07:35:02 +000037 const TargetInstrInfo *TII;
David Goodwin2e7be612009-10-26 16:59:04 +000038 const TargetRegisterInfo *TRI;
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +000039 const RegisterClassInfo &RegClassInfo;
David Goodwin2e7be612009-10-26 16:59:04 +000040
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 Wendling9c2a0342010-07-15 19:58:14 +000051 std::vector<const TargetRegisterClass*> Classes;
David Goodwin2e7be612009-10-26 16:59:04 +000052
Mikhail Glushenkov35edc422011-02-09 22:55:48 +000053 /// RegRefs - Map registers to all their references within a live range.
David Goodwin2e7be612009-10-26 16:59:04 +000054 std::multimap<unsigned, MachineOperand *> RegRefs;
Andrew Trick46388522010-11-02 18:16:45 +000055 typedef std::multimap<unsigned, MachineOperand *>::const_iterator
56 RegRefIter;
David Goodwin2e7be612009-10-26 16:59:04 +000057
58 /// KillIndices - The index of the most recent kill (proceding bottom-up),
59 /// or ~0u if the register is not live.
Bill Wendling9c2a0342010-07-15 19:58:14 +000060 std::vector<unsigned> KillIndices;
David Goodwin2e7be612009-10-26 16:59:04 +000061
62 /// DefIndices - The index of the most recent complete def (proceding bottom
63 /// up), or ~0u if the register is live.
Bill Wendling9c2a0342010-07-15 19:58:14 +000064 std::vector<unsigned> DefIndices;
David Goodwin2e7be612009-10-26 16:59:04 +000065
66 /// KeepRegs - A set of registers which are live and cannot be changed to
67 /// break anti-dependencies.
Benjamin Kramercff4ad72012-03-17 20:22:57 +000068 BitVector KeepRegs;
David Goodwin2e7be612009-10-26 16:59:04 +000069
70 public:
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +000071 CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo&);
David Goodwin2e7be612009-10-26 16:59:04 +000072 ~CriticalAntiDepBreaker();
Jim Grosbach2973b572010-01-06 16:48:02 +000073
David Goodwin2e7be612009-10-26 16:59:04 +000074 /// Start - Initialize anti-dep breaking for a new basic block.
75 void StartBlock(MachineBasicBlock *BB);
76
Jim Grosbach2973b572010-01-06 16:48:02 +000077 /// BreakAntiDependencies - Identifiy anti-dependencies along the critical
78 /// path
David Goodwin2e7be612009-10-26 16:59:04 +000079 /// of the ScheduleDAG and break them by renaming registers.
80 ///
Dan Gohman66db3a02010-04-19 23:11:58 +000081 unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits,
82 MachineBasicBlock::iterator Begin,
83 MachineBasicBlock::iterator End,
Devang Patele29e8e12011-06-02 21:26:52 +000084 unsigned InsertPosIndex,
85 DbgValueVector &DbgValues);
David Goodwin2e7be612009-10-26 16:59:04 +000086
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 Trickbc4bd922011-02-08 17:39:46 +000098 bool isNewRegClobberedByRefs(RegRefIter RegRefBegin,
99 RegRefIter RegRefEnd,
100 unsigned NewReg);
Andrew Trick46388522010-11-02 18:16:45 +0000101 unsigned findSuitableFreeRegister(RegRefIter RegRefBegin,
102 RegRefIter RegRefEnd,
Jim Grosbach80c2b0d2010-01-06 22:21:25 +0000103 unsigned AntiDepReg,
David Goodwin2e7be612009-10-26 16:59:04 +0000104 unsigned LastNewReg,
Andrew Trick46388522010-11-02 18:16:45 +0000105 const TargetRegisterClass *RC);
David Goodwin2e7be612009-10-26 16:59:04 +0000106 };
107}
108
109#endif