blob: 07107802972d5f037b4d1fb217f8ce857feba414 [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"
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +000020#include "RegisterClassInfo.h"
David Goodwin2e7be612009-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"
25#include "llvm/CodeGen/ScheduleDAG.h"
David Goodwin2e7be612009-10-26 16:59:04 +000026#include "llvm/ADT/BitVector.h"
27#include "llvm/ADT/SmallSet.h"
David Goodwin557bbe62009-11-20 19:32:48 +000028#include <map>
David Goodwin2e7be612009-10-26 16:59:04 +000029
30namespace llvm {
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +000031class RegisterClassInfo;
Evan Cheng46df4eb2010-06-16 07:35:02 +000032class TargetInstrInfo;
33class TargetRegisterInfo;
34
David Goodwin2e7be612009-10-26 16:59:04 +000035 class CriticalAntiDepBreaker : public AntiDepBreaker {
36 MachineFunction& MF;
37 MachineRegisterInfo &MRI;
Evan Cheng46df4eb2010-06-16 07:35:02 +000038 const TargetInstrInfo *TII;
David Goodwin2e7be612009-10-26 16:59:04 +000039 const TargetRegisterInfo *TRI;
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +000040 const RegisterClassInfo &RegClassInfo;
David Goodwin2e7be612009-10-26 16:59:04 +000041
42 /// AllocatableSet - The set of allocatable registers.
43 /// We'll be ignoring anti-dependencies on non-allocatable registers,
44 /// because they may not be safe to break.
45 const BitVector AllocatableSet;
46
47 /// Classes - For live regs that are only used in one register class in a
48 /// live range, the register class. If the register is not live, the
49 /// corresponding value is null. If the register is live but used in
50 /// multiple register classes, the corresponding value is -1 casted to a
51 /// pointer.
Bill Wendling9c2a0342010-07-15 19:58:14 +000052 std::vector<const TargetRegisterClass*> Classes;
David Goodwin2e7be612009-10-26 16:59:04 +000053
Mikhail Glushenkov35edc422011-02-09 22:55:48 +000054 /// RegRefs - Map registers to all their references within a live range.
David Goodwin2e7be612009-10-26 16:59:04 +000055 std::multimap<unsigned, MachineOperand *> RegRefs;
Andrew Trick46388522010-11-02 18:16:45 +000056 typedef std::multimap<unsigned, MachineOperand *>::const_iterator
57 RegRefIter;
David Goodwin2e7be612009-10-26 16:59:04 +000058
59 /// KillIndices - The index of the most recent kill (proceding bottom-up),
60 /// or ~0u if the register is not live.
Bill Wendling9c2a0342010-07-15 19:58:14 +000061 std::vector<unsigned> KillIndices;
David Goodwin2e7be612009-10-26 16:59:04 +000062
63 /// DefIndices - The index of the most recent complete def (proceding bottom
64 /// up), or ~0u if the register is live.
Bill Wendling9c2a0342010-07-15 19:58:14 +000065 std::vector<unsigned> DefIndices;
David Goodwin2e7be612009-10-26 16:59:04 +000066
67 /// KeepRegs - A set of registers which are live and cannot be changed to
68 /// break anti-dependencies.
69 SmallSet<unsigned, 4> KeepRegs;
70
71 public:
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +000072 CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo&);
David Goodwin2e7be612009-10-26 16:59:04 +000073 ~CriticalAntiDepBreaker();
Jim Grosbach2973b572010-01-06 16:48:02 +000074
David Goodwin2e7be612009-10-26 16:59:04 +000075 /// Start - Initialize anti-dep breaking for a new basic block.
76 void StartBlock(MachineBasicBlock *BB);
77
Jim Grosbach2973b572010-01-06 16:48:02 +000078 /// BreakAntiDependencies - Identifiy anti-dependencies along the critical
79 /// path
David Goodwin2e7be612009-10-26 16:59:04 +000080 /// of the ScheduleDAG and break them by renaming registers.
81 ///
Dan Gohman66db3a02010-04-19 23:11:58 +000082 unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits,
83 MachineBasicBlock::iterator Begin,
84 MachineBasicBlock::iterator End,
Devang Patele29e8e12011-06-02 21:26:52 +000085 unsigned InsertPosIndex,
86 DbgValueVector &DbgValues);
David Goodwin2e7be612009-10-26 16:59:04 +000087
88 /// Observe - Update liveness information to account for the current
89 /// instruction, which will not be scheduled.
90 ///
91 void Observe(MachineInstr *MI, unsigned Count, unsigned InsertPosIndex);
92
93 /// Finish - Finish anti-dep breaking for a basic block.
94 void FinishBlock();
95
96 private:
97 void PrescanInstruction(MachineInstr *MI);
98 void ScanInstruction(MachineInstr *MI, unsigned Count);
Andrew Trickbc4bd922011-02-08 17:39:46 +000099 bool isNewRegClobberedByRefs(RegRefIter RegRefBegin,
100 RegRefIter RegRefEnd,
101 unsigned NewReg);
Andrew Trick46388522010-11-02 18:16:45 +0000102 unsigned findSuitableFreeRegister(RegRefIter RegRefBegin,
103 RegRefIter RegRefEnd,
Jim Grosbach80c2b0d2010-01-06 22:21:25 +0000104 unsigned AntiDepReg,
David Goodwin2e7be612009-10-26 16:59:04 +0000105 unsigned LastNewReg,
Andrew Trick46388522010-11-02 18:16:45 +0000106 const TargetRegisterClass *RC);
David Goodwin2e7be612009-10-26 16:59:04 +0000107 };
108}
109
110#endif