Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/CriticalAntiDepBreaker.h
35233 views
//===- llvm/CodeGen/CriticalAntiDepBreaker.h - Anti-Dep Support -*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements the CriticalAntiDepBreaker class, which9// implements register anti-dependence breaking along a blocks10// critical path during post-RA scheduler.11//12//===----------------------------------------------------------------------===//1314#ifndef LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H15#define LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H1617#include "llvm/ADT/BitVector.h"18#include "llvm/CodeGen/AntiDepBreaker.h"19#include "llvm/Support/Compiler.h"20#include <map>21#include <vector>2223namespace llvm {2425class MachineBasicBlock;26class MachineFunction;27class MachineInstr;28class MachineOperand;29class MachineRegisterInfo;30class RegisterClassInfo;31class TargetInstrInfo;32class TargetRegisterClass;33class TargetRegisterInfo;3435class LLVM_LIBRARY_VISIBILITY CriticalAntiDepBreaker : public AntiDepBreaker {36MachineFunction& MF;37MachineRegisterInfo &MRI;38const TargetInstrInfo *TII;39const TargetRegisterInfo *TRI;40const RegisterClassInfo &RegClassInfo;4142/// 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.45const BitVector AllocatableSet;4647/// For live regs that are only used in one register class in a48/// live range, the register class. If the register is not live, the49/// corresponding value is null. If the register is live but used in50/// multiple register classes, the corresponding value is -1 casted to a51/// pointer.52std::vector<const TargetRegisterClass *> Classes;5354/// Map registers to all their references within a live range.55std::multimap<unsigned, MachineOperand *> RegRefs;5657using RegRefIter =58std::multimap<unsigned, MachineOperand *>::const_iterator;5960/// The index of the most recent kill (proceeding bottom-up),61/// or ~0u if the register is not live.62std::vector<unsigned> KillIndices;6364/// The index of the most recent complete def (proceeding65/// bottom up), or ~0u if the register is live.66std::vector<unsigned> DefIndices;6768/// A set of registers which are live and cannot be changed to69/// break anti-dependencies.70BitVector KeepRegs;7172public:73CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo &RCI);74~CriticalAntiDepBreaker() override;7576/// Initialize anti-dep breaking for a new basic block.77void StartBlock(MachineBasicBlock *BB) override;7879/// Identifiy anti-dependencies along the critical path80/// of the ScheduleDAG and break them by renaming registers.81unsigned BreakAntiDependencies(const std::vector<SUnit> &SUnits,82MachineBasicBlock::iterator Begin,83MachineBasicBlock::iterator End,84unsigned InsertPosIndex,85DbgValueVector &DbgValues) override;8687/// Update liveness information to account for the current88/// instruction, which will not be scheduled.89void Observe(MachineInstr &MI, unsigned Count,90unsigned InsertPosIndex) override;9192/// Finish anti-dep breaking for a basic block.93void FinishBlock() override;9495private:96void PrescanInstruction(MachineInstr &MI);97void ScanInstruction(MachineInstr &MI, unsigned Count);98bool isNewRegClobberedByRefs(RegRefIter RegRefBegin,99RegRefIter RegRefEnd,100unsigned NewReg);101unsigned findSuitableFreeRegister(RegRefIter RegRefBegin,102RegRefIter RegRefEnd,103unsigned AntiDepReg,104unsigned LastNewReg,105const TargetRegisterClass *RC,106SmallVectorImpl<unsigned> &Forbid);107};108109} // end namespace llvm110111#endif // LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H112113114