LLVM 24.0.0git
RegisterCoalescer.cpp File Reference
#include "RegisterCoalescer.h"
#include "CodeGenOptions.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/CalcSpillWeights.h"
#include "llvm/CodeGen/LiveInterval.h"
#include "llvm/CodeGen/LiveIntervals.h"
#include "llvm/CodeGen/LiveRangeEdit.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/RegisterClassInfo.h"
#include "llvm/CodeGen/RegisterCoalescerPass.h"
#include "llvm/CodeGen/SlotIndexes.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/LaneBitmask.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Pass.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <limits>
#include <tuple>
#include <utility>
#include <vector>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "regalloc"

Functions

 STATISTIC (numJoins, "Number of interval joins performed")
 STATISTIC (numCrossRCs, "Number of cross class joins performed")
 STATISTIC (numCommutes, "Number of instruction commuting performed")
 STATISTIC (numExtends, "Number of copies extended")
 STATISTIC (NumReMats, "Number of instructions re-materialized")
 STATISTIC (NumInflated, "Number of register classes inflated")
 STATISTIC (NumLaneConflicts, "Number of dead lane conflicts tested")
 STATISTIC (NumLaneResolves, "Number of dead lane conflicts resolved")
 STATISTIC (NumShrinkToUses, "Number of shrinkToUses called")
 INITIALIZE_PASS_BEGIN (RegisterCoalescerLegacy, "register-coalescer", "Register Coalescer", false, false) INITIALIZE_PASS_END(RegisterCoalescerLegacy
register Register static false bool isMoveInstr (const TargetRegisterInfo &tri, const MachineInstr *MI, Register &Src, Register &Dst, unsigned &SrcSub, unsigned &DstSub)
static bool isSplitEdge (const MachineBasicBlock *MBB)
 Return true if this block should be vacated by the coalescer to eliminate branches.
static std::pair< bool, bool > addSegmentsWithValNo (LiveRange &Dst, VNInfo *DstValNo, const LiveRange &Src, const VNInfo *SrcValNo)
 Copy segments with value number SrcValNo from liverange Src to live range @Dst and use value number DstValNo there.
static void collectPHIKills (const LiveRange &LR, const VNInfo *VNI, const SlotIndexes &Indexes, SmallVectorImpl< SlotIndex > &PHIKills)
 Collect the ends of the predecessors where VNI is live-out into a PHI value of LR.
static bool isLiveThrough (const LiveQueryResult Q)
static bool isDefInSubRange (LiveInterval &LI, SlotIndex Def)
 Check if any of the subranges of LI contain a definition at Def.
static int compareMBBPriority (const MBBPriorityInfo *LHS, const MBBPriorityInfo *RHS)
 C-style comparator that sorts first based on the loop depth of the basic block (the unsigned), and then on the MBB number.
static bool isLocalCopy (MachineInstr *Copy, const LiveIntervals *LIS)
static bool isTerminalReg (Register DstReg, const MachineInstr &Copy, const MachineRegisterInfo *MRI)
 Check if DstReg is a terminal node.

Variables

register coalescer
register Register Coalescer
register Register false

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "regalloc"

Definition at line 66 of file RegisterCoalescer.cpp.

Function Documentation

◆ addSegmentsWithValNo()

std::pair< bool, bool > addSegmentsWithValNo ( LiveRange & Dst,
VNInfo * DstValNo,
const LiveRange & Src,
const VNInfo * SrcValNo )
static

Copy segments with value number SrcValNo from liverange Src to live range @Dst and use value number DstValNo there.

Definition at line 760 of file RegisterCoalescer.cpp.

References Changed, llvm::LiveRange::Segment::end, llvm::SlotIndex::isDead(), llvm::LiveRange::Segment::start, and llvm::LiveRange::Segment::valno.

◆ collectPHIKills()

void collectPHIKills ( const LiveRange & LR,
const VNInfo * VNI,
const SlotIndexes & Indexes,
SmallVectorImpl< SlotIndex > & PHIKills )
static

◆ compareMBBPriority()

int compareMBBPriority ( const MBBPriorityInfo * LHS,
const MBBPriorityInfo * RHS )
static

C-style comparator that sorts first based on the loop depth of the basic block (the unsigned), and then on the MBB number.

EnableGlobalCopies assumes that the primary sort key is loop depth.

Definition at line 4009 of file RegisterCoalescer.cpp.

References LHS, and RHS.

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( RegisterCoalescerLegacy ,
"register-coalescer" ,
"Register Coalescer" ,
false ,
false  )

◆ isDefInSubRange()

bool isDefInSubRange ( LiveInterval & LI,
SlotIndex Def )
static

Check if any of the subranges of LI contain a definition at Def.

Definition at line 3444 of file RegisterCoalescer.cpp.

References llvm::VNInfo::def, llvm::LiveRange::Query(), llvm::LiveInterval::subranges(), and llvm::LiveQueryResult::valueOutOrDead().

◆ isLiveThrough()

◆ isLocalCopy()

bool isLocalCopy ( MachineInstr * Copy,
const LiveIntervals * LIS )
static
Returns
true if the given copy uses or defines a local live range.

Definition at line 4031 of file RegisterCoalescer.cpp.

References llvm::LiveIntervals::getInterval(), llvm::LiveIntervals::intervalIsInOneMBB(), and llvm::Register::isPhysical().

◆ isMoveInstr()

register Register static false bool isMoveInstr ( const TargetRegisterInfo & tri,
const MachineInstr * MI,
Register & Src,
Register & Dst,
unsigned & SrcSub,
unsigned & DstSub )
staticnodiscard

◆ isSplitEdge()

bool isSplitEdge ( const MachineBasicBlock * MBB)
static

Return true if this block should be vacated by the coalescer to eliminate branches.

The important cases to handle in the coalescer are critical edges split during phi elimination which contain only copies. Simple blocks that contain non-branches should also be vacated, but this can be handled by an earlier pass similar to early if-conversion.

Definition at line 415 of file RegisterCoalescer.cpp.

References MBB, and MI.

◆ isTerminalReg()

bool isTerminalReg ( Register DstReg,
const MachineInstr & Copy,
const MachineRegisterInfo * MRI )
static

Check if DstReg is a terminal node.

I.e., it does not have any affinity other than Copy.

Definition at line 4093 of file RegisterCoalescer.cpp.

References assert(), MI, and MRI.

◆ STATISTIC() [1/9]

STATISTIC ( numCommutes ,
"Number of instruction commuting performed"  )

◆ STATISTIC() [2/9]

STATISTIC ( numCrossRCs ,
"Number of cross class joins performed"  )

◆ STATISTIC() [3/9]

STATISTIC ( numExtends ,
"Number of copies extended"  )

◆ STATISTIC() [4/9]

STATISTIC ( NumInflated ,
"Number of register classes inflated"  )

◆ STATISTIC() [5/9]

STATISTIC ( numJoins ,
"Number of interval joins performed"  )

◆ STATISTIC() [6/9]

STATISTIC ( NumLaneConflicts ,
"Number of dead lane conflicts tested"  )

◆ STATISTIC() [7/9]

STATISTIC ( NumLaneResolves ,
"Number of dead lane conflicts resolved"  )

◆ STATISTIC() [8/9]

STATISTIC ( NumReMats ,
"Number of instructions re-materialized"  )

◆ STATISTIC() [9/9]

STATISTIC ( NumShrinkToUses ,
"Number of shrinkToUses called"  )

References Loops, MRI, Reg, TII, and TRI.

Variable Documentation

◆ Coalescer

◆ coalescer

register coalescer

Definition at line 387 of file RegisterCoalescer.cpp.

◆ false

register Register false

Definition at line 388 of file RegisterCoalescer.cpp.