123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- #pragma once
- #ifdef __GNUC__
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wunused-parameter"
- #endif
- #ifndef LLVM_CODEGEN_LIVEINTERVALS_H
- #define LLVM_CODEGEN_LIVEINTERVALS_H
- #include "llvm/ADT/ArrayRef.h"
- #include "llvm/ADT/IndexedMap.h"
- #include "llvm/ADT/SmallVector.h"
- #include "llvm/CodeGen/LiveInterval.h"
- #include "llvm/CodeGen/MachineBasicBlock.h"
- #include "llvm/CodeGen/MachineFunctionPass.h"
- #include "llvm/CodeGen/SlotIndexes.h"
- #include "llvm/CodeGen/TargetRegisterInfo.h"
- #include "llvm/MC/LaneBitmask.h"
- #include "llvm/Support/CommandLine.h"
- #include "llvm/Support/Compiler.h"
- #include "llvm/Support/ErrorHandling.h"
- #include <cassert>
- #include <cstdint>
- #include <utility>
- namespace llvm {
- extern cl::opt<bool> UseSegmentSetForPhysRegs;
- class BitVector;
- class LiveIntervalCalc;
- class MachineBlockFrequencyInfo;
- class MachineDominatorTree;
- class MachineFunction;
- class MachineInstr;
- class MachineRegisterInfo;
- class raw_ostream;
- class TargetInstrInfo;
- class VirtRegMap;
- class LiveIntervals : public MachineFunctionPass {
- MachineFunction* MF;
- MachineRegisterInfo* MRI;
- const TargetRegisterInfo* TRI;
- const TargetInstrInfo *TII;
- SlotIndexes* Indexes;
- MachineDominatorTree *DomTree = nullptr;
- LiveIntervalCalc *LICalc = nullptr;
-
- VNInfo::Allocator VNInfoAllocator;
-
- IndexedMap<LiveInterval*, VirtReg2IndexFunctor> VirtRegIntervals;
-
-
- SmallVector<SlotIndex, 8> RegMaskSlots;
-
-
-
-
-
-
-
-
-
-
-
- SmallVector<const uint32_t*, 8> RegMaskBits;
-
-
-
-
-
- SmallVector<std::pair<unsigned, unsigned>, 8> RegMaskBlocks;
-
-
- SmallVector<LiveRange*, 0> RegUnitRanges;
- public:
- static char ID;
- LiveIntervals();
- ~LiveIntervals() override;
-
- static float getSpillWeight(bool isDef, bool isUse,
- const MachineBlockFrequencyInfo *MBFI,
- const MachineInstr &MI);
-
- static float getSpillWeight(bool isDef, bool isUse,
- const MachineBlockFrequencyInfo *MBFI,
- const MachineBasicBlock *MBB);
- LiveInterval &getInterval(Register Reg) {
- if (hasInterval(Reg))
- return *VirtRegIntervals[Reg.id()];
- return createAndComputeVirtRegInterval(Reg);
- }
- const LiveInterval &getInterval(Register Reg) const {
- return const_cast<LiveIntervals*>(this)->getInterval(Reg);
- }
- bool hasInterval(Register Reg) const {
- return VirtRegIntervals.inBounds(Reg.id()) &&
- VirtRegIntervals[Reg.id()];
- }
-
- LiveInterval &createEmptyInterval(Register Reg) {
- assert(!hasInterval(Reg) && "Interval already exists!");
- VirtRegIntervals.grow(Reg.id());
- VirtRegIntervals[Reg.id()] = createInterval(Reg);
- return *VirtRegIntervals[Reg.id()];
- }
- LiveInterval &createAndComputeVirtRegInterval(Register Reg) {
- LiveInterval &LI = createEmptyInterval(Reg);
- computeVirtRegInterval(LI);
- return LI;
- }
-
- void removeInterval(Register Reg) {
- delete VirtRegIntervals[Reg];
- VirtRegIntervals[Reg] = nullptr;
- }
-
-
- LiveInterval::Segment addSegmentToEndOfBlock(Register Reg,
- MachineInstr &startInst);
-
-
-
-
-
-
- bool shrinkToUses(LiveInterval *li,
- SmallVectorImpl<MachineInstr*> *dead = nullptr);
-
-
-
-
-
-
- void shrinkToUses(LiveInterval::SubRange &SR, Register Reg);
-
-
-
-
-
-
-
-
-
-
-
-
- void extendToIndices(LiveRange &LR, ArrayRef<SlotIndex> Indices,
- ArrayRef<SlotIndex> Undefs);
- void extendToIndices(LiveRange &LR, ArrayRef<SlotIndex> Indices) {
- extendToIndices(LR, Indices, {});
- }
-
-
-
-
-
-
-
- void pruneValue(LiveRange &LR, SlotIndex Kill,
- SmallVectorImpl<SlotIndex> *EndPoints);
-
-
-
-
- LLVM_ATTRIBUTE_UNUSED void pruneValue(LiveInterval &, SlotIndex,
- SmallVectorImpl<SlotIndex> *) {
- llvm_unreachable(
- "Use pruneValue on the main LiveRange and on each subrange");
- }
- SlotIndexes *getSlotIndexes() const {
- return Indexes;
- }
-
-
- bool isNotInMIMap(const MachineInstr &Instr) const {
- return !Indexes->hasIndex(Instr);
- }
-
- SlotIndex getInstructionIndex(const MachineInstr &Instr) const {
- return Indexes->getInstructionIndex(Instr);
- }
-
- MachineInstr* getInstructionFromIndex(SlotIndex index) const {
- return Indexes->getInstructionFromIndex(index);
- }
-
- SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const {
- return Indexes->getMBBStartIdx(mbb);
- }
-
- SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const {
- return Indexes->getMBBEndIdx(mbb);
- }
- bool isLiveInToMBB(const LiveRange &LR,
- const MachineBasicBlock *mbb) const {
- return LR.liveAt(getMBBStartIdx(mbb));
- }
- bool isLiveOutOfMBB(const LiveRange &LR,
- const MachineBasicBlock *mbb) const {
- return LR.liveAt(getMBBEndIdx(mbb).getPrevSlot());
- }
- MachineBasicBlock* getMBBFromIndex(SlotIndex index) const {
- return Indexes->getMBBFromIndex(index);
- }
- void insertMBBInMaps(MachineBasicBlock *MBB) {
- Indexes->insertMBBInMaps(MBB);
- assert(unsigned(MBB->getNumber()) == RegMaskBlocks.size() &&
- "Blocks must be added in order.");
- RegMaskBlocks.push_back(std::make_pair(RegMaskSlots.size(), 0));
- }
- SlotIndex InsertMachineInstrInMaps(MachineInstr &MI) {
- return Indexes->insertMachineInstrInMaps(MI);
- }
- void InsertMachineInstrRangeInMaps(MachineBasicBlock::iterator B,
- MachineBasicBlock::iterator E) {
- for (MachineBasicBlock::iterator I = B; I != E; ++I)
- Indexes->insertMachineInstrInMaps(*I);
- }
- void RemoveMachineInstrFromMaps(MachineInstr &MI) {
- Indexes->removeMachineInstrFromMaps(MI);
- }
- SlotIndex ReplaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI) {
- return Indexes->replaceMachineInstrInMaps(MI, NewMI);
- }
- VNInfo::Allocator& getVNInfoAllocator() { return VNInfoAllocator; }
- void getAnalysisUsage(AnalysisUsage &AU) const override;
- void releaseMemory() override;
-
- bool runOnMachineFunction(MachineFunction&) override;
-
- void print(raw_ostream &O, const Module* = nullptr) const override;
-
-
- MachineBasicBlock *intervalIsInOneMBB(const LiveInterval &LI) const;
-
-
- bool hasPHIKill(const LiveInterval &LI, const VNInfo *VNI) const;
-
- void addKillFlags(const VirtRegMap*);
-
-
-
-
-
- void handleMove(MachineInstr &MI, bool UpdateFlags = false);
-
-
-
-
-
-
-
-
- void handleMoveIntoNewBundle(MachineInstr &BundleStart,
- bool UpdateFlags = false);
-
-
-
-
-
-
-
-
-
- void repairIntervalsInRange(MachineBasicBlock *MBB,
- MachineBasicBlock::iterator Begin,
- MachineBasicBlock::iterator End,
- ArrayRef<Register> OrigRegs);
-
-
-
-
-
-
-
-
-
-
-
-
- ArrayRef<SlotIndex> getRegMaskSlots() const { return RegMaskSlots; }
-
-
- ArrayRef<SlotIndex> getRegMaskSlotsInBlock(unsigned MBBNum) const {
- std::pair<unsigned, unsigned> P = RegMaskBlocks[MBBNum];
- return getRegMaskSlots().slice(P.first, P.second);
- }
-
-
- ArrayRef<const uint32_t*> getRegMaskBits() const { return RegMaskBits; }
-
-
- ArrayRef<const uint32_t*> getRegMaskBitsInBlock(unsigned MBBNum) const {
- std::pair<unsigned, unsigned> P = RegMaskBlocks[MBBNum];
- return getRegMaskBits().slice(P.first, P.second);
- }
-
-
-
-
-
-
- bool checkRegMaskInterference(const LiveInterval &LI,
- BitVector &UsableRegs);
-
-
-
-
-
-
-
-
-
-
-
-
- LiveRange &getRegUnit(unsigned Unit) {
- LiveRange *LR = RegUnitRanges[Unit];
- if (!LR) {
-
-
- RegUnitRanges[Unit] = LR = new LiveRange(UseSegmentSetForPhysRegs);
- computeRegUnitRange(*LR, Unit);
- }
- return *LR;
- }
-
-
- LiveRange *getCachedRegUnit(unsigned Unit) {
- return RegUnitRanges[Unit];
- }
- const LiveRange *getCachedRegUnit(unsigned Unit) const {
- return RegUnitRanges[Unit];
- }
-
-
- void removeRegUnit(unsigned Unit) {
- delete RegUnitRanges[Unit];
- RegUnitRanges[Unit] = nullptr;
- }
-
-
-
-
- void removeAllRegUnitsForPhysReg(MCRegister Reg) {
- for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units)
- removeRegUnit(*Units);
- }
-
-
-
- void removePhysRegDefAt(MCRegister Reg, SlotIndex Pos);
-
-
- void removeVRegDefAt(LiveInterval &LI, SlotIndex Pos);
-
- void splitSeparateComponents(LiveInterval &LI,
- SmallVectorImpl<LiveInterval*> &SplitLIs);
-
-
-
- void constructMainRangeFromSubranges(LiveInterval &LI);
- private:
-
- void computeVirtRegs();
-
- void computeRegMasks();
-
-
-
-
-
-
-
- bool computeDeadValues(LiveInterval &LI,
- SmallVectorImpl<MachineInstr*> *dead);
- static LiveInterval *createInterval(Register Reg);
- void printInstrs(raw_ostream &O) const;
- void dumpInstrs() const;
- void computeLiveInRegUnits();
- void computeRegUnitRange(LiveRange&, unsigned Unit);
- bool computeVirtRegInterval(LiveInterval&);
- using ShrinkToUsesWorkList = SmallVector<std::pair<SlotIndex, VNInfo*>, 16>;
- void extendSegmentsToUses(LiveRange &Segments,
- ShrinkToUsesWorkList &WorkList, Register Reg,
- LaneBitmask LaneMask);
-
-
-
-
- void repairOldRegInRange(MachineBasicBlock::iterator Begin,
- MachineBasicBlock::iterator End,
- const SlotIndex endIdx, LiveRange &LR,
- Register Reg,
- LaneBitmask LaneMask = LaneBitmask::getAll());
- class HMEditor;
- };
- }
- #endif
- #ifdef __GNUC__
- #pragma GCC diagnostic pop
- #endif
|