blob: df21ef28340ec0eeb6ad55402ccdc3bbb1f1f9a0 [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"
24#include "llvm/CodeGen/ScheduleDAG.h"
David Goodwin2e7be612009-10-26 16:59:04 +000025#include "llvm/ADT/BitVector.h"
26#include "llvm/ADT/SmallSet.h"
David Goodwin557bbe62009-11-20 19:32:48 +000027#include <map>
David Goodwin2e7be612009-10-26 16:59:04 +000028
29namespace llvm {
Evan Cheng46df4eb2010-06-16 07:35:02 +000030class TargetInstrInfo;
31class TargetRegisterInfo;
32
David Goodwin2e7be612009-10-26 16:59:04 +000033 class CriticalAntiDepBreaker : public AntiDepBreaker {
34 MachineFunction& MF;
35 MachineRegisterInfo &MRI;
Evan Cheng46df4eb2010-06-16 07:35:02 +000036 const TargetInstrInfo *TII;
David Goodwin2e7be612009-10-26 16:59:04 +000037 const TargetRegisterInfo *TRI;
38
39 /// AllocatableSet - The set of allocatable registers.
40 /// We'll be ignoring anti-dependencies on non-allocatable registers,
41 /// because they may not be safe to break.
42 const BitVector AllocatableSet;
43
44 /// Classes - For live regs that are only used in one register class in a
45 /// 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 Wendling9c2a0342010-07-15 19:58:14 +000049 std::vector<const TargetRegisterClass*> Classes;
David Goodwin2e7be612009-10-26 16:59:04 +000050
51 /// RegRegs - Map registers to all their references within a live range.
52 std::multimap<unsigned, MachineOperand *> RegRefs;
Andrew Trick46388522010-11-02 18:16:45 +000053 typedef std::multimap<unsigned, MachineOperand *>::const_iterator
54 RegRefIter;
David Goodwin2e7be612009-10-26 16:59:04 +000055
56 /// KillIndices - The index of the most recent kill (proceding bottom-up),
57 /// or ~0u if the register is not live.
Bill Wendling9c2a0342010-07-15 19:58:14 +000058 std::vector<unsigned> KillIndices;
David Goodwin2e7be612009-10-26 16:59:04 +000059
60 /// DefIndices - The index of the most recent complete def (proceding bottom
61 /// up), or ~0u if the register is live.
Bill Wendling9c2a0342010-07-15 19:58:14 +000062 std::vector<unsigned> DefIndices;
David Goodwin2e7be612009-10-26 16:59:04 +000063
64 /// KeepRegs - A set of registers which are live and cannot be changed to
65 /// break anti-dependencies.
66 SmallSet<unsigned, 4> KeepRegs;
67
68 public:
69 CriticalAntiDepBreaker(MachineFunction& MFi);
70 ~CriticalAntiDepBreaker();
Jim Grosbach2973b572010-01-06 16:48:02 +000071
David Goodwin2e7be612009-10-26 16:59:04 +000072 /// Start - Initialize anti-dep breaking for a new basic block.
73 void StartBlock(MachineBasicBlock *BB);
74
Jim Grosbach2973b572010-01-06 16:48:02 +000075 /// BreakAntiDependencies - Identifiy anti-dependencies along the critical
76 /// path
David Goodwin2e7be612009-10-26 16:59:04 +000077 /// of the ScheduleDAG and break them by renaming registers.
78 ///
Dan Gohman66db3a02010-04-19 23:11:58 +000079 unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits,
80 MachineBasicBlock::iterator Begin,
81 MachineBasicBlock::iterator End,
David Goodwin2e7be612009-10-26 16:59:04 +000082 unsigned InsertPosIndex);
83
84 /// Observe - Update liveness information to account for the current
85 /// instruction, which will not be scheduled.
86 ///
87 void Observe(MachineInstr *MI, unsigned Count, unsigned InsertPosIndex);
88
89 /// Finish - Finish anti-dep breaking for a basic block.
90 void FinishBlock();
91
92 private:
93 void PrescanInstruction(MachineInstr *MI);
94 void ScanInstruction(MachineInstr *MI, unsigned Count);
Andrew Trick46388522010-11-02 18:16:45 +000095 bool isNewRegModifiedByRefs(RegRefIter RegRefBegin,
96 RegRefIter RegRefEnd,
97 unsigned NewReg);
98 unsigned findSuitableFreeRegister(RegRefIter RegRefBegin,
99 RegRefIter RegRefEnd,
Jim Grosbach80c2b0d2010-01-06 22:21:25 +0000100 unsigned AntiDepReg,
David Goodwin2e7be612009-10-26 16:59:04 +0000101 unsigned LastNewReg,
Andrew Trick46388522010-11-02 18:16:45 +0000102 const TargetRegisterClass *RC);
David Goodwin2e7be612009-10-26 16:59:04 +0000103 };
104}
105
106#endif