LLVM 23.0.0git
HexagonGlobalScheduler.cpp File Reference
#include "Hexagon.h"
#include "HexagonGlobalRegion.h"
#include "HexagonMachineFunctionInfo.h"
#include "HexagonRegisterInfo.h"
#include "HexagonSubtarget.h"
#include "HexagonTargetMachine.h"
#include "HexagonVLIWPacketizer.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/CodeGen/DFAPacketizer.h"
#include "llvm/CodeGen/LatencyPriorityQueue.h"
#include "llvm/CodeGen/LiveIntervals.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/PseudoSourceValue.h"
#include "llvm/CodeGen/SchedulerRegistry.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSchedule.h"
#include "llvm/IR/Operator.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/MCInstrItineraries.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include <list>
#include <map>

Go to the source code of this file.

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.

Macros

#define DEBUG_TYPE   "global_sched"

Functions

 STATISTIC (HexagonNumPullUps, "Number of instructions pull-ups")
 STATISTIC (HexagonNumDualJumps, "Number of dual jumps formed")
FunctionPassllvm::createHexagonGlobalScheduler ()
void llvm::initializeHexagonGlobalSchedulerPass (PassRegistry &)
 INITIALIZE_PASS_BEGIN (HexagonGlobalScheduler, "global-sched", "Hexagon Global Scheduler", false, false) INITIALIZE_PASS_END(HexagonGlobalScheduler
static unsigned nonDbgBundleSize (MachineBasicBlock::iterator &TargetPacket)
static bool IsSchedBarrier (const MachineInstr *MI)
static bool IsIndirectCall (const MachineInstr *MI)
static void DumpLinked (MachineInstr *MI)
static void DumpPacket (MachineBasicBlock::instr_iterator MII)
static void DumpPacket (MachineBasicBlock::instr_iterator MII, MachineBasicBlock::instr_iterator BBEnd)
static bool isBranch (MachineInstr *MI)
static MachineBasicBlock::instr_iterator getHexagonFirstInstrTerminator (MachineBasicBlock *MBB)
static bool selectBestBB (BlockFrequency &BBaFreq, unsigned BBaSize, BlockFrequency &BBbFreq, unsigned BBbSize)
 Select best candidate to form regions.
static bool isGlobalMemoryObject (MachineInstr *MI)
 Return true if MI is an instruction we are unable to reason about (like something with unmodeled memory side effects).
static bool isUnsafeMemoryObject (MachineInstr *MI)
static bool MIsNeedChainEdge (AliasAnalysis *AA, const TargetInstrInfo *TII, MachineInstr *MIa, MachineInstr *MIb)
 This returns true if the two MIs could be memory dependent.
static void parseOperands (MachineInstr *MI, SmallVector< unsigned, 4 > &Defs, SmallVector< unsigned, 8 > &Uses)
 Gather register def/uses from MI.
static bool isDelayedUseException (MachineInstr *MIa, MachineInstr *MIb)
 Some apparent dependencies are not actually restricting us since there is a delay between assignment and actual usage, like in case of a call.
static bool MIMustNotBePulledUp (MachineInstr *MI)
static bool MIShouldNotBePulledUp (MachineInstr *MI)
static void unmarkKillReg (MachineInstr *MI, unsigned Reg)
 Find use with this reg, and unmark the kill flag.
static void markKillReg (MachineInstr *MI, unsigned Reg)
 Find use with this reg, and unmark the kill flag.
static void debugLivenessForBB (const MachineBasicBlock *MBB, const TargetRegisterInfo *TRI)
static bool IsEmptyBlock (MachineBasicBlock *MBB)
static MachineBasicBlockgetBranchDestination (MachineInstr *MI)
 Treat given instruction as a branch, go through its operands and see if any of them is a BB address.
static void updateBranches (MachineBasicBlock &InBlock, MachineBasicBlock *From, MachineBasicBlock *To)
 updateBranches - Updates all branches to From in the basic block InBlock to branches to To.
static void updatePredecessors (MachineBasicBlock &MBB, MachineBasicBlock *MFBB)
 Rewrite all predecessors of the old block to go to the fallthrough instead.
static void UpdateCFG (MachineBasicBlock *HomeBB, MachineBasicBlock *OriginBB, MachineInstr *MII, MachineBasicBlock *HomeTBB, MachineBasicBlock *HomeFBB, MachineInstr *FTA, MachineInstr *STA, const MachineBranchProbabilityInfo *MBPI)
template<typename ElemType, typename IndexType>
void Unify (std::vector< ElemType > Range, std::map< ElemType, std::vector< IndexType > > &Set1, std::map< ElemType, std::vector< IndexType > > &Set2, std::pair< std::vector< IndexType >, std::vector< IndexType > > &UnionSet, unsigned union_size=100)
static void UpdateBundle (MachineInstr *BundleHead)

Variables

static cl::opt< boolDisablePullUp ("disable-pull-up", cl::Hidden, cl::desc("Disable Hexagon pull-up pass"))
static cl::opt< boolEnableSpeculativePullUp ("enable-speculative-pull-up", cl::Hidden, cl::desc("Enable speculation during Hexagon pull-up pass"))
static cl::opt< boolEnableLocalPullUp ("enable-local-pull-up", cl::Hidden, cl::init(true), cl::desc("Enable same BB pull during Hexagon pull-up pass"))
static cl::opt< boolAllowSpeculateLoads ("speculate-loads-on-pull-up", cl::Hidden, cl::init(true), cl::desc("Allow speculative loads during Hexagon pull-up pass"))
static cl::opt< boolAllowCmpBranchLoads ("cmp-branch-loads-pull-up", cl::Hidden, cl::init(true), cl::desc("Allow compare-branch loads during Hexagon pull-up pass"))
static cl::opt< boolAllowUnlikelyPath ("unlikely-path-pull-up", cl::Hidden, cl::init(true), cl::desc("Allow unlikely path pull up"))
static cl::opt< boolPerformDualJumps ("dual-jump-in-pull-up", cl::Hidden, cl::init(true), cl::desc("Perform dual jump formation during pull up"))
static cl::opt< boolAllowDependentPullUp ("enable-dependent-pull-up", cl::Hidden, cl::init(true), cl::desc("Perform dual jump formation during pull up"))
static cl::opt< boolAllowBBPeelPullUp ("enable-bb-peel-pull-up", cl::Hidden, cl::init(true), cl::desc("Peel a reg copy out of a BBloop"))
static cl::opt< boolPreventCompoundSeparation ("prevent-compound-separation", cl::Hidden, cl::desc("Do not destroy existing compounds during pull up"))
static cl::opt< boolPreventDuplexSeparation ("prevent-duplex-separation", cl::Hidden, cl::init(true), cl::desc("Do not destroy existing duplexes during pull up"))
static cl::opt< unsignedMainCandidateQueueSize ("pull-up-main-queue-size", cl::Hidden, cl::init(8))
static cl::opt< unsignedSecondaryCandidateQueueSize ("pull-up-sec-queue-size", cl::Hidden, cl::init(2))
static cl::opt< boolPostPullUpOpt ("post-pull-up-opt", cl::Hidden, cl::Optional, cl::init(true), cl::desc("Enable opt. exposed by pull-up e.g., remove redundant jumps"))
static cl::opt< boolSpeculateNonPredInsn ("speculate-non-pred-insn", cl::Hidden, cl::Optional, cl::init(true), cl::desc("Speculate non-predicable instructions in parent BB"))
static cl::opt< boolDisableCheckBundles ("disable-hexagon-check-bundles", cl::Hidden, cl::init(true), cl::desc("Disable Hexagon check bundles pass"))
static cl::opt< boolWarnOnBundleSize ("warn-on-bundle-size", cl::Hidden, cl::desc("Hexagon check bundles and warn on size"))
static cl::opt< boolForceNoopHazards ("force-noop-hazards", cl::Hidden, cl::init(false), cl::desc("Force noop hazards in scheduler"))
static cl::opt< boolOneFloatPerPacket ("single-float-packet", cl::Hidden, cl::desc("Allow only one single floating point instruction in a packet"))
static cl::opt< boolOneComplexPerPacket ("single-complex-packet", cl::Hidden, cl::desc("Allow only one complex instruction in a packet"))
global sched
global Hexagon Global Scheduler
global Hexagon Global false
static const unsigned SafetyBuffer = 200

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "global_sched"

Definition at line 59 of file HexagonGlobalScheduler.cpp.

Function Documentation

◆ debugLivenessForBB()

void debugLivenessForBB ( const MachineBasicBlock * MBB,
const TargetRegisterInfo * TRI )
static

Definition at line 2466 of file HexagonGlobalScheduler.cpp.

References llvm::dbgs(), E(), I, LLVM_DEBUG, MBB, llvm::printReg(), and TRI.

◆ DumpLinked()

void DumpLinked ( MachineInstr * MI)
static

Definition at line 690 of file HexagonGlobalScheduler.cpp.

References llvm::dbgs(), and MI.

Referenced by DumpPacket().

◆ DumpPacket() [1/2]

void DumpPacket ( MachineBasicBlock::instr_iterator MII)
static

Definition at line 702 of file HexagonGlobalScheduler.cpp.

References llvm::dbgs(), DumpLinked(), MBB, and MI.

Referenced by DumpPacket().

◆ DumpPacket() [2/2]

Definition at line 727 of file HexagonGlobalScheduler.cpp.

References llvm::dbgs(), and DumpPacket().

◆ getBranchDestination()

MachineBasicBlock * getBranchDestination ( MachineInstr * MI)
inlinestatic

Treat given instruction as a branch, go through its operands and see if any of them is a BB address.

If so, return it. Return NULL otherwise.

Definition at line 2498 of file HexagonGlobalScheduler.cpp.

References llvm::MachineOperand::getMBB(), llvm::MachineOperand::isMBB(), and MI.

Referenced by UpdateCFG().

◆ getHexagonFirstInstrTerminator()

MachineBasicBlock::instr_iterator getHexagonFirstInstrTerminator ( MachineBasicBlock * MBB)
static

Definition at line 835 of file HexagonGlobalScheduler.cpp.

References MBB.

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( HexagonGlobalScheduler ,
"global-sched" ,
"Hexagon Global Scheduler" ,
false ,
false  )

◆ isBranch()

bool isBranch ( MachineInstr * MI)
static

Definition at line 738 of file HexagonGlobalScheduler.cpp.

References MI.

◆ isDelayedUseException()

bool isDelayedUseException ( MachineInstr * MIa,
MachineInstr * MIb )
static

Some apparent dependencies are not actually restricting us since there is a delay between assignment and actual usage, like in case of a call.

There could be more cases here, but this one seems the most obvious.

Definition at line 1267 of file HexagonGlobalScheduler.cpp.

References llvm::MachineInstr::isCall().

◆ IsEmptyBlock()

bool IsEmptyBlock ( MachineBasicBlock * MBB)
static

Definition at line 2484 of file HexagonGlobalScheduler.cpp.

References MBB, and MBBI.

◆ isGlobalMemoryObject()

bool isGlobalMemoryObject ( MachineInstr * MI)
inlinestatic

Return true if MI is an instruction we are unable to reason about (like something with unmodeled memory side effects).

Definition at line 1120 of file HexagonGlobalScheduler.cpp.

References MI.

◆ IsIndirectCall()

◆ IsSchedBarrier()

bool IsSchedBarrier ( const MachineInstr * MI)
static

Definition at line 681 of file HexagonGlobalScheduler.cpp.

References MI.

Referenced by MIMustNotBePulledUp().

◆ isUnsafeMemoryObject()

bool isUnsafeMemoryObject ( MachineInstr * MI)
inlinestatic

Definition at line 1130 of file HexagonGlobalScheduler.cpp.

References MI.

Referenced by MIsNeedChainEdge().

◆ markKillReg()

void markKillReg ( MachineInstr * MI,
unsigned Reg )
inlinestatic

Find use with this reg, and unmark the kill flag.

Definition at line 2148 of file HexagonGlobalScheduler.cpp.

References llvm::MachineOperand::getReg(), llvm::MachineOperand::isReg(), llvm::MachineOperand::isUse(), MI, Reg, and llvm::MachineOperand::setIsKill().

◆ MIMustNotBePulledUp()

bool MIMustNotBePulledUp ( MachineInstr * MI)
inlinestatic

Definition at line 1683 of file HexagonGlobalScheduler.cpp.

References IsSchedBarrier(), and MI.

Referenced by MIShouldNotBePulledUp().

◆ MIShouldNotBePulledUp()

bool MIShouldNotBePulledUp ( MachineInstr * MI)
inlinestatic

Definition at line 1689 of file HexagonGlobalScheduler.cpp.

References MI, and MIMustNotBePulledUp().

◆ MIsNeedChainEdge()

◆ nonDbgBundleSize()

◆ parseOperands()

◆ selectBestBB()

bool selectBestBB ( BlockFrequency & BBaFreq,
unsigned BBaSize,
BlockFrequency & BBbFreq,
unsigned BBbSize )
inlinestatic

Select best candidate to form regions.

Definition at line 986 of file HexagonGlobalScheduler.cpp.

References llvm::BlockFrequency::getFrequency().

◆ STATISTIC() [1/2]

STATISTIC ( HexagonNumDualJumps ,
"Number of dual jumps formed"  )

◆ STATISTIC() [2/2]

STATISTIC ( HexagonNumPullUps ,
"Number of instructions pull-ups"  )

◆ Unify()

template<typename ElemType, typename IndexType>
void Unify ( std::vector< ElemType > Range,
std::map< ElemType, std::vector< IndexType > > & Set1,
std::map< ElemType, std::vector< IndexType > > & Set2,
std::pair< std::vector< IndexType >, std::vector< IndexType > > & UnionSet,
unsigned union_size = 100 )

Definition at line 3282 of file HexagonGlobalScheduler.cpp.

References assert(), llvm::dbgs(), LLVM_DEBUG, and Range.

◆ unmarkKillReg()

void unmarkKillReg ( MachineInstr * MI,
unsigned Reg )
inlinestatic

Find use with this reg, and unmark the kill flag.

Definition at line 2132 of file HexagonGlobalScheduler.cpp.

References llvm::MachineOperand::getReg(), llvm::MachineOperand::isKill(), llvm::MachineOperand::isReg(), MI, Reg, and llvm::MachineOperand::setIsKill().

◆ updateBranches()

void updateBranches ( MachineBasicBlock & InBlock,
MachineBasicBlock * From,
MachineBasicBlock * To )
static

updateBranches - Updates all branches to From in the basic block InBlock to branches to To.

Definition at line 2703 of file HexagonGlobalScheduler.cpp.

References E(), llvm::MachineOperand::getMBB(), InBlock(), llvm::MachineInstr::isBranch(), llvm::MachineOperand::isMBB(), llvm::MachineInstr::operands_begin(), llvm::MachineInstr::operands_end(), and llvm::MachineOperand::setMBB().

◆ UpdateBundle()

◆ UpdateCFG()

◆ updatePredecessors()

void updatePredecessors ( MachineBasicBlock & MBB,
MachineBasicBlock * MFBB )
static

Rewrite all predecessors of the old block to go to the fallthrough instead.

NB: Collect predecessors into a snapshot vector before iterating to avoid iterator invalidation on MBB's predecessor list. Each call to ReplaceUsesOfBlockWith modifies both the successor list of Pred and the predecessor list of MBB, which invalidates debug-mode iterators (detected by _GLIBCXX_DEBUG).

Definition at line 2732 of file HexagonGlobalScheduler.cpp.

References llvm::MachineFunction::end(), llvm::ilist_node_impl< OptionsT >::getIterator(), MBB, and updateBranches().

Variable Documentation

◆ AllowBBPeelPullUp

cl::opt< bool > AllowBBPeelPullUp("enable-bb-peel-pull-up", cl::Hidden, cl::init(true), cl::desc("Peel a reg copy out of a BBloop")) ( "enable-bb-peel-pull-up" ,
cl::Hidden ,
cl::init(true) ,
cl::desc("Peel a reg copy out of a BBloop")  )
static

◆ AllowCmpBranchLoads

cl::opt< bool > AllowCmpBranchLoads("cmp-branch-loads-pull-up", cl::Hidden, cl::init(true), cl::desc("Allow compare-branch loads during Hexagon pull-up pass")) ( "cmp-branch-loads-pull-up" ,
cl::Hidden ,
cl::init(true) ,
cl::desc("Allow compare-branch loads during Hexagon pull-up pass")  )
static

◆ AllowDependentPullUp

cl::opt< bool > AllowDependentPullUp("enable-dependent-pull-up", cl::Hidden, cl::init(true), cl::desc("Perform dual jump formation during pull up")) ( "enable-dependent-pull-up" ,
cl::Hidden ,
cl::init(true) ,
cl::desc("Perform dual jump formation during pull up")  )
static

◆ AllowSpeculateLoads

cl::opt< bool > AllowSpeculateLoads("speculate-loads-on-pull-up", cl::Hidden, cl::init(true), cl::desc("Allow speculative loads during Hexagon pull-up pass")) ( "speculate-loads-on-pull-up" ,
cl::Hidden ,
cl::init(true) ,
cl::desc("Allow speculative loads during Hexagon pull-up pass")  )
static

◆ AllowUnlikelyPath

cl::opt< bool > AllowUnlikelyPath("unlikely-path-pull-up", cl::Hidden, cl::init(true), cl::desc("Allow unlikely path pull up")) ( "unlikely-path-pull-up" ,
cl::Hidden ,
cl::init(true) ,
cl::desc("Allow unlikely path pull up")  )
static

◆ DisableCheckBundles

cl::opt< bool > DisableCheckBundles("disable-hexagon-check-bundles", cl::Hidden, cl::init(true), cl::desc("Disable Hexagon check bundles pass")) ( "disable-hexagon-check-bundles" ,
cl::Hidden ,
cl::init(true) ,
cl::desc("Disable Hexagon check bundles pass")  )
static

◆ DisablePullUp

cl::opt< bool > DisablePullUp("disable-pull-up", cl::Hidden, cl::desc("Disable Hexagon pull-up pass")) ( "disable-pull-up" ,
cl::Hidden ,
cl::desc("Disable Hexagon pull-up pass")  )
static

◆ EnableLocalPullUp

cl::opt< bool > EnableLocalPullUp("enable-local-pull-up", cl::Hidden, cl::init(true), cl::desc("Enable same BB pull during Hexagon pull-up pass")) ( "enable-local-pull-up" ,
cl::Hidden ,
cl::init(true) ,
cl::desc("Enable same BB pull during Hexagon pull-up pass")  )
static

◆ EnableSpeculativePullUp

cl::opt< bool > EnableSpeculativePullUp("enable-speculative-pull-up", cl::Hidden, cl::desc("Enable speculation during Hexagon pull-up pass")) ( "enable-speculative-pull-up" ,
cl::Hidden ,
cl::desc("Enable speculation during Hexagon pull-up pass")  )
static

◆ false

global Hexagon Global false

Definition at line 579 of file HexagonGlobalScheduler.cpp.

◆ ForceNoopHazards

cl::opt< bool > ForceNoopHazards("force-noop-hazards", cl::Hidden, cl::init(false), cl::desc("Force noop hazards in scheduler")) ( "force-noop-hazards" ,
cl::Hidden ,
cl::init(false) ,
cl::desc("Force noop hazards in scheduler")  )
static

◆ MainCandidateQueueSize

cl::opt< unsigned > MainCandidateQueueSize("pull-up-main-queue-size", cl::Hidden, cl::init(8)) ( "pull-up-main-queue-size" ,
cl::Hidden ,
cl::init(8)  )
static

◆ OneComplexPerPacket

cl::opt< bool > OneComplexPerPacket("single-complex-packet", cl::Hidden, cl::desc("Allow only one complex instruction in a packet")) ( "single-complex-packet" ,
cl::Hidden ,
cl::desc("Allow only one complex instruction in a packet")  )
static

◆ OneFloatPerPacket

cl::opt< bool > OneFloatPerPacket("single-float-packet", cl::Hidden, cl::desc("Allow only one single floating point instruction in a packet")) ( "single-float-packet" ,
cl::Hidden ,
cl::desc("Allow only one single floating point instruction in a packet")  )
static

◆ PerformDualJumps

cl::opt< bool > PerformDualJumps("dual-jump-in-pull-up", cl::Hidden, cl::init(true), cl::desc("Perform dual jump formation during pull up")) ( "dual-jump-in-pull-up" ,
cl::Hidden ,
cl::init(true) ,
cl::desc("Perform dual jump formation during pull up")  )
static

◆ PostPullUpOpt

cl::opt< bool > PostPullUpOpt("post-pull-up-opt", cl::Hidden, cl::Optional, cl::init(true), cl::desc("Enable opt. exposed by pull-up e.g., remove redundant jumps")) ( "post-pull-up-opt" ,
cl::Hidden ,
cl::Optional ,
cl::init(true) ,
cl::desc("Enable opt. exposed by pull-up e.g., remove redundant jumps")  )
static

◆ PreventCompoundSeparation

cl::opt< bool > PreventCompoundSeparation("prevent-compound-separation", cl::Hidden, cl::desc("Do not destroy existing compounds during pull up")) ( "prevent-compound-separation" ,
cl::Hidden ,
cl::desc("Do not destroy existing compounds during pull up")  )
static

◆ PreventDuplexSeparation

cl::opt< bool > PreventDuplexSeparation("prevent-duplex-separation", cl::Hidden, cl::init(true), cl::desc("Do not destroy existing duplexes during pull up")) ( "prevent-duplex-separation" ,
cl::Hidden ,
cl::init(true) ,
cl::desc("Do not destroy existing duplexes during pull up")  )
static

◆ SafetyBuffer

const unsigned SafetyBuffer = 200
static

Definition at line 832 of file HexagonGlobalScheduler.cpp.

◆ sched

global sched

Definition at line 578 of file HexagonGlobalScheduler.cpp.

◆ Scheduler

global Hexagon Global Scheduler

Definition at line 579 of file HexagonGlobalScheduler.cpp.

◆ SecondaryCandidateQueueSize

cl::opt< unsigned > SecondaryCandidateQueueSize("pull-up-sec-queue-size", cl::Hidden, cl::init(2)) ( "pull-up-sec-queue-size" ,
cl::Hidden ,
cl::init(2)  )
static

◆ SpeculateNonPredInsn

cl::opt< bool > SpeculateNonPredInsn("speculate-non-pred-insn", cl::Hidden, cl::Optional, cl::init(true), cl::desc("Speculate non-predicable instructions in parent BB")) ( "speculate-non-pred-insn" ,
cl::Hidden ,
cl::Optional ,
cl::init(true) ,
cl::desc("Speculate non-predicable instructions in parent BB")  )
static

◆ WarnOnBundleSize

cl::opt< bool > WarnOnBundleSize("warn-on-bundle-size", cl::Hidden, cl::desc("Hexagon check bundles and warn on size")) ( "warn-on-bundle-size" ,
cl::Hidden ,
cl::desc("Hexagon check bundles and warn on size")  )
static