CriticalAntiDepBreaker.h revision 263508
174462Salfred//=- llvm/CodeGen/CriticalAntiDepBreaker.h - Anti-Dep Support -*- C++ -*-=// 274462Salfred// 3261046Smav// The LLVM Compiler Infrastructure 4261046Smav// 5261046Smav// This file is distributed under the University of Illinois Open Source 674462Salfred// License. See LICENSE.TXT for details. 7261046Smav// 8261046Smav//===----------------------------------------------------------------------===// 9261046Smav// 10261046Smav// This file implements the CriticalAntiDepBreaker class, which 11261046Smav// implements register anti-dependence breaking along a blocks 12261046Smav// critical path during post-RA scheduler. 13261046Smav// 14261046Smav//===----------------------------------------------------------------------===// 15261046Smav 16261046Smav#ifndef LLVM_CODEGEN_CRITICALANTIDEPBREAKER_H 17261046Smav#define LLVM_CODEGEN_CRITICALANTIDEPBREAKER_H 18261046Smav 19261046Smav#include "AntiDepBreaker.h" 20261046Smav#include "llvm/ADT/BitVector.h" 21261046Smav#include "llvm/CodeGen/MachineBasicBlock.h" 22261046Smav#include "llvm/CodeGen/MachineFrameInfo.h" 23261046Smav#include "llvm/CodeGen/MachineFunction.h" 24261046Smav#include "llvm/CodeGen/MachineRegisterInfo.h" 25261046Smav#include "llvm/CodeGen/RegisterClassInfo.h" 26261046Smav#include "llvm/CodeGen/ScheduleDAG.h" 27261046Smav#include <map> 28261046Smav 2974462Salfrednamespace llvm { 30136581Sobrienclass RegisterClassInfo; 31136581Sobrienclass TargetInstrInfo; 32136581Sobrienclass TargetRegisterInfo; 3374462Salfred 3492990Sobrien class CriticalAntiDepBreaker : public AntiDepBreaker { 3592990Sobrien MachineFunction& MF; 3674462Salfred MachineRegisterInfo &MRI; 3774462Salfred const TargetInstrInfo *TII; 3874462Salfred const TargetRegisterInfo *TRI; 3974462Salfred const RegisterClassInfo &RegClassInfo; 4074462Salfred 4174462Salfred /// AllocatableSet - The set of allocatable registers. 4274462Salfred /// We'll be ignoring anti-dependencies on non-allocatable registers, 4374462Salfred /// because they may not be safe to break. 4474462Salfred const BitVector AllocatableSet; 4574462Salfred 4674462Salfred /// Classes - For live regs that are only used in one register class in a 4774462Salfred /// live range, the register class. If the register is not live, the 4874462Salfred /// corresponding value is null. If the register is live but used in 4974462Salfred /// multiple register classes, the corresponding value is -1 casted to a 5074462Salfred /// pointer. 5174462Salfred std::vector<const TargetRegisterClass*> Classes; 5274462Salfred 5374462Salfred /// RegRefs - Map registers to all their references within a live range. 5474462Salfred std::multimap<unsigned, MachineOperand *> RegRefs; 5574462Salfred typedef std::multimap<unsigned, MachineOperand *>::const_iterator 5674462Salfred RegRefIter; 5774462Salfred 5874462Salfred /// KillIndices - The index of the most recent kill (proceding bottom-up), 5974462Salfred /// or ~0u if the register is not live. 6074462Salfred std::vector<unsigned> KillIndices; 6174462Salfred 6274462Salfred /// DefIndices - The index of the most recent complete def (proceding bottom 6374462Salfred /// up), or ~0u if the register is live. 6474462Salfred std::vector<unsigned> DefIndices; 6574462Salfred 6674462Salfred /// KeepRegs - A set of registers which are live and cannot be changed to 6774462Salfred /// break anti-dependencies. 6874462Salfred BitVector KeepRegs; 6974462Salfred 7092905Sobrien public: 7174462Salfred CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo&); 7274462Salfred ~CriticalAntiDepBreaker(); 7374462Salfred 7474462Salfred /// Start - Initialize anti-dep breaking for a new basic block. 7574462Salfred void StartBlock(MachineBasicBlock *BB); 7674462Salfred 7774462Salfred /// BreakAntiDependencies - Identifiy anti-dependencies along the critical 7874462Salfred /// path 7974462Salfred /// of the ScheduleDAG and break them by renaming registers. 8074462Salfred /// 8174462Salfred unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits, 8274462Salfred MachineBasicBlock::iterator Begin, 8374462Salfred MachineBasicBlock::iterator End, 8474462Salfred unsigned InsertPosIndex, 85309487Sngie DbgValueVector &DbgValues); 8674462Salfred 8774462Salfred /// Observe - Update liveness information to account for the current 8874462Salfred /// instruction, which will not be scheduled. 8974462Salfred /// 9074462Salfred void Observe(MachineInstr *MI, unsigned Count, unsigned InsertPosIndex); 9174462Salfred 9274462Salfred /// Finish - Finish anti-dep breaking for a basic block. 9374462Salfred void FinishBlock(); 9474462Salfred 9574462Salfred private: 9674462Salfred void PrescanInstruction(MachineInstr *MI); 9774462Salfred void ScanInstruction(MachineInstr *MI, unsigned Count); 9874462Salfred bool isNewRegClobberedByRefs(RegRefIter RegRefBegin, 9974462Salfred RegRefIter RegRefEnd, 10074462Salfred unsigned NewReg); 101238483Sbrueffer unsigned findSuitableFreeRegister(RegRefIter RegRefBegin, 10274462Salfred RegRefIter RegRefEnd, 10374462Salfred unsigned AntiDepReg, 10474462Salfred unsigned LastNewReg, 10574462Salfred const TargetRegisterClass *RC, 10674462Salfred SmallVectorImpl<unsigned> &Forbid); 10774462Salfred }; 10874462Salfred} 10974462Salfred 110172259Smatteo#endif 111172259Smatteo