blob: 62ef72ace1130c990531a4117feb90d71e8dbb08 [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>
Bill Wendlingf7f72bc2010-07-15 05:56:32 +000028#include <vector>
David Goodwin2e7be612009-10-26 16:59:04 +000029
30namespace llvm {
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;
39
40 /// AllocatableSet - The set of allocatable registers.
41 /// We'll be ignoring anti-dependencies on non-allocatable registers,
42 /// because they may not be safe to break.
43 const BitVector AllocatableSet;
44
45 /// Classes - For live regs that are only used in one register class in a
46 /// live range, the register class. If the register is not live, the
47 /// corresponding value is null. If the register is live but used in
48 /// multiple register classes, the corresponding value is -1 casted to a
49 /// pointer.
Bill Wendlingf7f72bc2010-07-15 05:56:32 +000050 std::vector<const TargetRegisterClass *> Classes;
David Goodwin2e7be612009-10-26 16:59:04 +000051
52 /// RegRegs - Map registers to all their references within a live range.
53 std::multimap<unsigned, MachineOperand *> RegRefs;
54
55 /// KillIndices - The index of the most recent kill (proceding bottom-up),
56 /// or ~0u if the register is not live.
Bill Wendlingf7f72bc2010-07-15 05:56:32 +000057 std::vector<unsigned> KillIndices;
David Goodwin2e7be612009-10-26 16:59:04 +000058
59 /// DefIndices - The index of the most recent complete def (proceding bottom
60 /// up), or ~0u if the register is live.
Bill Wendlingf7f72bc2010-07-15 05:56:32 +000061 std::vector<unsigned> DefIndices;
David Goodwin2e7be612009-10-26 16:59:04 +000062
63 /// KeepRegs - A set of registers which are live and cannot be changed to
64 /// break anti-dependencies.
65 SmallSet<unsigned, 4> KeepRegs;
66
67 public:
68 CriticalAntiDepBreaker(MachineFunction& MFi);
69 ~CriticalAntiDepBreaker();
Jim Grosbach2973b572010-01-06 16:48:02 +000070
David Goodwin2e7be612009-10-26 16:59:04 +000071 /// Start - Initialize anti-dep breaking for a new basic block.
72 void StartBlock(MachineBasicBlock *BB);
73
Jim Grosbach2973b572010-01-06 16:48:02 +000074 /// BreakAntiDependencies - Identifiy anti-dependencies along the critical
75 /// path
David Goodwin2e7be612009-10-26 16:59:04 +000076 /// of the ScheduleDAG and break them by renaming registers.
77 ///
Dan Gohman66db3a02010-04-19 23:11:58 +000078 unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits,
79 MachineBasicBlock::iterator Begin,
80 MachineBasicBlock::iterator End,
David Goodwin2e7be612009-10-26 16:59:04 +000081 unsigned InsertPosIndex);
82
83 /// Observe - Update liveness information to account for the current
84 /// instruction, which will not be scheduled.
85 ///
86 void Observe(MachineInstr *MI, unsigned Count, unsigned InsertPosIndex);
87
88 /// Finish - Finish anti-dep breaking for a basic block.
89 void FinishBlock();
90
91 private:
92 void PrescanInstruction(MachineInstr *MI);
93 void ScanInstruction(MachineInstr *MI, unsigned Count);
Jim Grosbach80c2b0d2010-01-06 22:21:25 +000094 unsigned findSuitableFreeRegister(MachineInstr *MI,
95 unsigned AntiDepReg,
David Goodwin2e7be612009-10-26 16:59:04 +000096 unsigned LastNewReg,
97 const TargetRegisterClass *);
98 };
99}
100
101#endif