53#define DEBUG_TYPE "global_sched"
57STATISTIC(HexagonNumPullUps,
"Number of instructions pull-ups");
58STATISTIC(HexagonNumDualJumps,
"Number of dual jumps formed");
61 cl::desc(
"Disable Hexagon pull-up pass"));
65 cl::desc(
"Enable speculation during Hexagon pull-up pass"));
69 cl::desc(
"Enable same BB pull during Hexagon pull-up pass"));
73 cl::desc(
"Allow speculative loads during Hexagon pull-up pass"));
77 cl::desc(
"Allow compare-branch loads during Hexagon pull-up pass"));
81 cl::desc(
"Allow unlikely path pull up"));
85 cl::desc(
"Perform dual jump formation during pull up"));
89 cl::desc(
"Perform dual jump formation during pull up"));
93 cl::desc(
"Peel a reg copy out of a BBloop"));
97 cl::desc(
"Do not destroy existing compounds during pull up"));
101 cl::desc(
"Do not destroy existing duplexes during pull up"));
111 cl::desc(
"Enable opt. exposed by pull-up e.g., remove redundant jumps"));
115 cl::desc(
"Speculate non-predicable instructions in parent BB"));
120 cl::desc(
"Disable Hexagon check bundles pass"));
124 cl::desc(
"Hexagon check bundles and warn on size"));
128 cl::desc(
"Force noop hazards in scheduler"));
132 "Allow moving an instruction out of a packet that redefines one of "
133 "its source registers"));
143class HexagonGlobalSchedulerImpl;
147enum class DepKind { Independent, WAR_SameBundle, Dependent };
152 HexagonGlobalScheduler() : MachineFunctionPass(ID) {
156 void getAnalysisUsage(AnalysisUsage &AU)
const override {
160 AU.
addRequired<MachineBranchProbabilityInfoWrapperPass>();
161 AU.
addRequired<MachineBlockFrequencyInfoWrapperPass>();
166 StringRef getPassName()
const override {
return "Hexagon Global Scheduler"; }
170char HexagonGlobalScheduler::ID = 0;
173class PullUpCandidate {
178 std::vector<MachineInstr *> Backtrack;
182 CandidateLocation = MII;
188 std::vector<MachineInstr *> &backtrack,
bool DependentOp,
190 : CandidateLocation(MII), HomeBundle(HomeBundle),
191 DependentOp(DependentOp), BenefitCost(
Cost) {
193 Backtrack = backtrack;
198 std::vector<MachineInstr *> &backtrack,
bool &dependentOp) {
199 MII = CandidateLocation;
200 WorkPoint = HomeBundle;
201 backtrack = Backtrack;
202 dependentOp = DependentOp;
205 signed getCost() {
return BenefitCost; }
207 MachineInstr *getCandidate() {
return &*CandidateLocation; }
210 dbgs() <<
"Cost(" << BenefitCost;
211 dbgs() <<
") Dependent(" << DependentOp;
212 dbgs() <<
") backtrack size(" << Backtrack.size() <<
")\t";
213 CandidateLocation->dump();
218struct PullUpCandidateSorter {
219 PullUpCandidateSorter() {}
220 bool operator()(PullUpCandidate *
LHS, PullUpCandidate *
RHS) {
221 return LHS->getCost() >
RHS->getCost();
229 friend class HexagonGlobalSchedulerImpl;
238 const HexagonInstrInfo *QII;
241 PullUpState(
const HexagonInstrInfo *QII) : HomeLocation(NULL), QII(QII) {}
243 ~PullUpState() { reset(); }
247 std::vector<MachineInstr *> &backtrack,
248 bool DependentOp,
signed Cost) {
250 PullUpCandidate *PUI =
251 new PullUpCandidate(MII, HomeBundle, backtrack, DependentOp,
Cost);
252 PullUpCandidates.push_back(PUI);
256 unsigned element = 0;
257 for (
unsigned i = 0; i < HomeBundle.size(); i++) {
258 dbgs() <<
"[" << element++;
259 dbgs() <<
"] Home Duplex("
260 << QII->getDuplexCandidateGroup(*HomeBundle[i]);
261 dbgs() <<
") Compound (" << QII->getCompoundCandidateGroup(*HomeBundle[i])
263 HomeBundle[i]->dump();
267 for (SmallVector<PullUpCandidate *, 4>::iterator
268 I = PullUpCandidates.begin(),
269 E = PullUpCandidates.end();
271 dbgs() <<
"[" << element++ <<
"] Cand: Compound(";
272 dbgs() << QII->getCompoundCandidateGroup(*(*I)->getCandidate()) <<
") ";
279 for (SmallVector<PullUpCandidate *, 4>::iterator
280 I = PullUpCandidates.begin(),
281 E = PullUpCandidates.end();
284 PullUpCandidates.clear();
290 HomeLocation = WorkPoint;
293 unsigned haveCandidates() {
return PullUpCandidates.size(); }
298 std::vector<BasicBlockRegion *> PullUpRegions;
301 DenseMap<MachineBasicBlock *, unsigned> BlockToInstOffset;
303 PullUpState CurrentState;
305 std::vector<MachineBasicBlock *> EmptyBBs;
311 std::map<MachineInstr *, MachineBasicBlock *> SpeculatedIns;
313 std::map<MachineInstr *, std::vector<unsigned>> MIUseSet;
315 std::map<MachineInstr *, std::vector<unsigned>> MIDefSet;
318 const MachineBranchProbabilityInfo *MBPI;
319 const MachineBlockFrequencyInfo *MBFI;
320 const MachineRegisterInfo *MRI;
321 const MachineFrameInfo &MFI;
322 const HexagonRegisterInfo *QRI;
323 const HexagonInstrInfo *QII;
324 MachineLoopInfo &MLI;
325 MachineDominatorTree &MDT;
326 MachineInstrBuilder Ext;
327 MachineInstrBuilder Nop;
328 const unsigned PacketSize;
329 TargetSchedModel TSchedModel;
335 const MachineBranchProbabilityInfo *MBPI,
336 const MachineBlockFrequencyInfo *MBFI,
337 const MachineRegisterInfo *MRI,
338 const MachineFrameInfo &MFI,
339 const HexagonRegisterInfo *QRI);
340 HexagonGlobalSchedulerImpl(
const HexagonGlobalSchedulerImpl &) =
delete;
341 HexagonGlobalSchedulerImpl &
342 operator=(
const HexagonGlobalSchedulerImpl &) =
delete;
344 ~HexagonGlobalSchedulerImpl() {
346 for (std::vector<BasicBlockRegion *>::iterator
I = PullUpRegions.begin(),
347 E = PullUpRegions.end();
350 MF.deleteMachineInstr(Ext);
351 MF.deleteMachineInstr(Nop);
355 void initPacketizerState()
override;
358 bool ignoreInstruction(MachineInstr *
MI);
362 bool isSoloInstruction(
const MachineInstr &
MI)
override;
365 bool incrementalAddToPacket(MachineInstr &
MI);
371 bool performPullUp();
391 MachineBasicBlock *optimizeBranches(MachineBasicBlock *
MBB,
392 MachineBasicBlock *
TBB,
393 MachineInstr *FirstTerm,
394 MachineBasicBlock *FBB);
399 bool removeRedundantBranches(MachineBasicBlock *
MBB, MachineBasicBlock *
TBB,
400 MachineInstr *FirstTerm, MachineBasicBlock *FBB,
401 MachineInstr *SecondTerm);
405 bool optimizeDualJumps(MachineBasicBlock *
MBB, MachineBasicBlock *
TBB,
406 MachineInstr *FirstTerm, MachineBasicBlock *FBB,
407 MachineInstr *SecondTerm);
412 BasicBlockRegion *getRegionForMBB(std::vector<BasicBlockRegion *> &Regions,
413 MachineBasicBlock *
MBB);
417 void MIUseDefSet(MachineInstr *
MI, std::vector<unsigned> &Defs,
418 std::vector<unsigned> &
Uses);
428 MachineBasicBlock *getNextPURBB(MachineBasicBlock *
MBB,
bool SecondBest);
430 void setUsedRegs(BitVector &Set,
unsigned Reg);
431 bool AliasingRegs(
unsigned RegA,
unsigned RegB);
434 bool ReorderDependencyTest(MachineInstr *MIa, MachineInstr *MIb) {
435 return analyzeDependence(MIa, MIb) != DepKind::Independent;
437 DepKind analyzeDependence(MachineInstr *MIa, MachineInstr *MIb);
439 bool canAddMIToThisPacket(
443 bool pullUpPeelBBLoop(MachineBasicBlock *PredBB, MachineBasicBlock *LoopBB);
445 MachineInstr *findBundleAndBranch(MachineBasicBlock *BB,
449 bool ResourcesAvailableInBundle(BasicBlockRegion *CurrentRegion,
453 MachineInstr *MoveAndUpdateLiveness(
454 BasicBlockRegion *CurrentRegion, MachineBasicBlock *HomeBB,
455 MachineInstr *InstrToMove,
bool NeedToNewify,
unsigned DepReg,
456 bool MovingDependentOp, MachineBasicBlock *OriginBB,
457 MachineInstr *OriginalInstruction, SmallVector<MachineOperand, 4> &
Cond,
461 std::vector<MachineInstr *> &backtrack);
464 void updateKillAlongThePath(MachineBasicBlock *HomeBB,
465 MachineBasicBlock *OriginBB,
470 std::vector<MachineInstr *> &backtrack);
475 std::vector<MachineInstr *> &backtrack,
476 unsigned MaxCandidates);
479 bool tryMultipleInstructions(
481 std::vector<BasicBlockRegion *>::iterator &CurrentRegion,
487 bool MoveMItoBundle(BasicBlockRegion *CurrentRegion,
492 std::vector<MachineInstr *> &backtrack,
493 bool MovingDependentOp,
bool PathInRegion);
497 insertTempCopy(MachineBasicBlock *
MBB,
503 MachineInstr *
MI,
bool &LastInBundle);
506 MachineInstr *TargetPacket);
509 unsigned DepReg, MachineInstr *TargetPacket);
511 void addInstructionToExistingBundle(MachineBasicBlock *HomeBB,
517 std::vector<MachineInstr *> &backtrack);
519 void removeInstructionFromExistingBundle(
524 std::vector<MachineInstr *> &backtrack);
527 bool MIsCondAssign(MachineInstr *BMI, MachineInstr *
MI,
528 SmallVector<unsigned, 4> &Defs);
533 bool canMIBeSpeculated(MachineInstr *
MI, MachineBasicBlock *ToBB,
534 MachineBasicBlock *FromBB,
535 std::vector<MachineInstr *> &backtrack);
538 bool isBranchWithinRegion(BasicBlockRegion *CurrentRegion, MachineInstr *
MI);
541 bool MIsAreDependent(MachineInstr *MIa, MachineInstr *MIb);
542 bool MIsHaveTrueDependency(MachineInstr *MIa, MachineInstr *MIb);
543 bool canReorderMIs(MachineInstr *MIa, MachineInstr *MIb);
544 bool canCauseStall(MachineInstr *
MI, MachineInstr *MJ);
545 bool canThisMIBeMoved(MachineInstr *
MI,
547 bool &MovingDependentOp,
int &
Cost);
548 bool MIisDualJumpCandidate(MachineInstr *
MI,
550 bool DemoteToDotOld(MachineInstr *
MI);
552 MachineInstr *TargetPacket);
553 bool IsNewifyStore(MachineInstr *
MI);
554 bool isJumpOutOfRange(MachineInstr *
MI);
555 bool IsDualJumpFirstCandidate(MachineInstr *
MI);
556 bool IsDualJumpFirstCandidate(MachineBasicBlock *
MBB);
558 bool IsNotDualJumpFirstCandidate(MachineInstr *
MI);
559 bool isJumpOutOfRange(MachineInstr *UnCond, MachineInstr *
Cond);
560 bool IsDualJumpSecondCandidate(MachineInstr *
MI);
561 bool tryAllocateResourcesForConstExt(MachineInstr *
MI,
bool UpdateState);
562 bool isCompoundPair(MachineInstr *MIa, MachineInstr *MIb);
563 bool doesMIDefinesPredicate(MachineInstr *
MI, SmallVector<unsigned, 4> &Defs);
564 bool AnalyzeBBBranches(MachineBasicBlock *
MBB, MachineBasicBlock *&
TBB,
565 MachineInstr *&FirstTerm, MachineBasicBlock *&FBB,
566 MachineInstr *&SecondTerm);
567 inline bool multipleBranchesFromToBB(MachineBasicBlock *BB)
const;
572 "Hexagon Global Scheduler",
false,
false)
582HexagonGlobalSchedulerImpl::HexagonGlobalSchedulerImpl(
589 MBFI(MBFI),
MRI(
MRI), MFI(MFI), QRI(QRI), MLI(MLI), MDT(MDT),
590 PacketSize(MF.getSubtarget().getSchedModel().IssueWidth) {
594 TSchedModel.
init(&MF.getSubtarget());
602 for (++MII; MII !=
End && MII->isInsideBundle(); ++MII) {
603 if (MII->isDebugInstr())
611bool HexagonGlobalScheduler::runOnMachineFunction(
MachineFunction &Fn) {
618 const HexagonRegisterInfo *QRI = HST.getRegisterInfo();
619 MachineLoopInfo &MLI = getAnalysis<MachineLoopInfoWrapperPass>().getLI();
620 MachineDominatorTree &MDT =
621 getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
622 const MachineBranchProbabilityInfo *MBPI =
623 &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
624 const MachineBlockFrequencyInfo *MBFI =
625 &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
626 AliasAnalysis *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
634 HexagonGlobalSchedulerImpl GlobalSchedulerState(Fn, MLI, MDT, AA, MBPI, MBFI,
638 assert(GlobalSchedulerState.getResourceTracker() &&
"Empty DFA table!");
643 GlobalSchedulerState.checkBundleCounts(Fn);
649 LLVM_DEBUG(GlobalSchedulerState.countCompounds(Fn));
650 GlobalSchedulerState.GenUseDefChain(Fn);
651 GlobalSchedulerState.formPullUpRegions(Fn);
652 GlobalSchedulerState.performPullUp();
653 GlobalSchedulerState.performPullUpCFG(Fn);
655 GlobalSchedulerState.formPullUpRegions(Fn);
656 GlobalSchedulerState.performExposedOptimizations(Fn);
658 LLVM_DEBUG(GlobalSchedulerState.countCompounds(Fn));
665bool HexagonGlobalSchedulerImpl::tryAllocateResourcesForConstExt(
666 MachineInstr *
MI,
bool UpdateState =
true) {
667 if (ResourceTracker->canReserveResources(*Ext)) {
672 ResourceTracker->reserveResources(*Ext);
673 else if (CurrentPacketMIs.size() >= PacketSize - 1)
682 return MI->getOpcode() == Hexagon::Y2_barrier;
686 return MI->getOpcode() == Hexagon::J2_callr;
691 if (
MI->isBundledWithPred())
695 if (
MI->isBundledWithSucc())
704 dbgs() <<
"\tNULL\n";
711 dbgs() <<
"\tUnattached: ";
717 if (
MI->isBundle()) {
719 for (++MII; MII != MIE && MII->isInsideBundle() && !MII->isBundle();
730 dbgs() <<
"\tBBEnd\n";
739 if (
MI->isBundle()) {
742 for (++MII; MII != MIE && MII->isInsideBundle() && !MII->isBundle();
748 return MI->isBranch();
753bool HexagonGlobalSchedulerImpl::IsNotDualJumpFirstCandidate(MachineInstr *
MI) {
762bool HexagonGlobalSchedulerImpl::IsDualJumpFirstCandidate(MachineInstr *
MI) {
773bool HexagonGlobalSchedulerImpl::IsDualJumpFirstCandidate(
777 MachineInstr *
MI = &*TargetPacket;
779 if (
MI->isBundle()) {
781 if (&(*
MI->getParent()->rbegin()) !=
MI)
788 for (++MII; MII != BBEnd && MII->isInsideBundle() && !MII->isBundle();
790 if (IsNotDualJumpFirstCandidate(&*MII))
793 return IsDualJumpFirstCandidate(
MI);
801bool HexagonGlobalSchedulerImpl::IsDualJumpFirstCandidate(
802 MachineBasicBlock *
MBB) {
808 MII != MBBEnd; ++MII) {
809 MachineInstr *
MI = &*MII;
810 if (
MI->isDebugInstr())
812 if (!
MI->isBundle() && IsNotDualJumpFirstCandidate(
MI))
819bool HexagonGlobalSchedulerImpl::IsDualJumpSecondCandidate(MachineInstr *
MI) {
840 if (!MII->isBundle() && MII->isTerminator())
851bool HexagonGlobalSchedulerImpl::isJumpOutOfRange(MachineInstr *
MI) {
852 if (!
MI || !
MI->isBranch())
859 unsigned InstOffset = BlockToInstOffset[
MBB];
860 unsigned Distance = 0;
868 MachineBasicBlock *
TBB = NULL, *FBB = NULL;
869 SmallVector<MachineOperand, 4>
Cond;
879 if (
TBB && (
MI == &*FirstTerm)) {
881 (unsigned)std::abs((
long long)InstOffset - BlockToInstOffset[
TBB]) +
890 MachineInstr *SecondTerm = &*FTMII;
893 "Bad second terminator");
894 if (
MI != SecondTerm)
898 (unsigned)std::abs((
long long)InstOffset - BlockToInstOffset[FBB]) +
900 LLVM_DEBUG(
dbgs() <<
"\tSecond term offset(" << Distance <<
"): ";
910bool HexagonGlobalSchedulerImpl::isNewifiable(
912 MachineInstr *TargetPacket) {
913 MachineInstr *
MI = &*MII;
915 !CanNewifiedBeUsedInBundle(MII, DepReg, TargetPacket))
921bool HexagonGlobalSchedulerImpl::DemoteToDotOld(MachineInstr *
MI) {
923 MI->setDesc(QII->get(NewOpcode));
928void HexagonGlobalSchedulerImpl::initPacketizerState(
void) {
929 CurrentPacketMIs.clear();
934bool HexagonGlobalSchedulerImpl::ignoreInstruction(MachineInstr *
MI) {
935 if (
MI->isDebugInstr())
939 if (
MI->isInlineAsm())
944 const MCInstrDesc &TID =
MI->getDesc();
946 const InstrStage *
IS =
947 ResourceTracker->getInstrItins()->beginStage(SchedClass);
948 unsigned FuncUnits =
IS->getUnits();
954bool HexagonGlobalSchedulerImpl::isSoloInstruction(
const MachineInstr &
MI) {
955 if (
MI.isInlineAsm())
967 if (
MI.getOpcode() == Hexagon::A2_nop)
974BasicBlockRegion *HexagonGlobalSchedulerImpl::getRegionForMBB(
975 std::vector<BasicBlockRegion *> &Regions, MachineBasicBlock *
MBB) {
976 for (std::vector<BasicBlockRegion *>::iterator
I = Regions.begin(),
979 if ((*I)->findMBB(
MBB))
1005HexagonGlobalSchedulerImpl::getNextPURBB(MachineBasicBlock *
MBB,
1006 bool SecondBest =
false) {
1010 BlockFrequency BestBlockFreq = BlockFrequency(0);
1011 unsigned BestBlockSize = 0;
1012 MachineBasicBlock *BestBB = NULL;
1013 MachineBasicBlock *SecondBestBB = NULL;
1024 LLVM_DEBUG(
dbgs() <<
"\tsucc BB(" << Succ->getNumber() <<
") freq("
1027 if (!SecondBest && getRegionForMBB(PullUpRegions, Succ))
1032 if (Succ->pred_size() > 1)
1037 if (Succ->isEHPad() || Succ->hasAddressTaken())
1047 BestBlockFreq = EdgeFreq;
1049 SecondBestBB = BestBB;
1051 }
else if (!SecondBestBB) {
1052 SecondBestBB = Succ;
1056 return SecondBestBB;
1062bool HexagonGlobalSchedulerImpl::formPullUpRegions(
MachineFunction &Fn) {
1065 if (std::next(
F.begin()) ==
F.end())
1070 unsigned InstOffset = 0;
1072 LLVM_DEBUG(
dbgs() <<
"****** Form PullUpRegions **************\n");
1082 InstOffset = (InstOffset + ByteAlign) & ~(ByteAlign);
1085 BlockToInstOffset[&*
MBB] = InstOffset;
1089 if (!MII->isBundle())
1090 InstOffset += QII->
getSize(*MII);
1093 if (getRegionForMBB(PullUpRegions, &*
MBB))
1102 BasicBlockRegion *PUR =
new BasicBlockRegion(
TII, QRI, &*
MBB);
1103 PullUpRegions.push_back(PUR);
1105 for (MachineBasicBlock *MBBR = getNextPURBB(&*
MBB); MBBR;
1106 MBBR = getNextPURBB(MBBR)) {
1108 << MBBR->getName() <<
") size("
1111 << MBBR->getParent()->getFunction().getName() <<
")\n");
1121 if (
MI->hasUnmodeledSideEffects() ||
MI->hasOrderedMemoryRef() ||
1123 (
MI->getOpcode() == Hexagon::J2_jump && !
MI->getOperand(0).isMBB()))
1137 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
1150 for (
unsigned R = 1, NR = Hexagon::NUM_TARGET_REGS; R != NR; ++R)
1157void HexagonGlobalSchedulerImpl::MIUseDefSet(MachineInstr *
MI,
1158 std::vector<unsigned> &Defs,
1159 std::vector<unsigned> &
Uses) {
1162 assert(!
MI->isBundle() &&
"Cannot parse regs of a bundle.");
1163 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
1164 const MachineOperand &MO =
MI->getOperand(i);
1170 assert(Register::isPhysicalRegister(
Reg));
1171 std::vector<unsigned> &Refs = MO.
isUse() ?
Uses : Defs;
1172 for (MCRegAliasIterator AI(MO.
getReg(), QRI,
true); AI.isValid(); ++AI)
1173 Refs.push_back(*AI);
1175 for (
unsigned R = 1, NR = Hexagon::NUM_TARGET_REGS;
R != NR; ++
R)
1212bool HexagonGlobalSchedulerImpl::canAddMIToThisPacket(
1222 isJumpOutOfRange(
MI)) &&
1223 !tryAllocateResourcesForConstExt(
MI,
false))
1227 if (!ResourceTracker->canReserveResources(*
MI) || !shouldAddToPacket(*
MI)) {
1232 SmallVector<unsigned, 4> BundleDefs;
1233 SmallVector<unsigned, 8> BundleUses;
1234 SmallVector<unsigned, 4> Defs;
1235 SmallVector<unsigned, 8>
Uses;
1236 MachineInstr *FirstCompound = NULL, *SecondCompound = NULL;
1237 MachineInstr *FirstDuplex = NULL, *SecondDuplex = NULL;
1240 for (SmallVector<MachineInstr *, HEXAGON_PACKET_SIZE>::iterator
1241 BI = Bundle.
begin(),
1248 MachineInstr *Inst1 = *BI;
1249 MachineInstr *Inst2 =
MI;
1262 FirstCompound = *BI;
1264 SecondCompound = *BI;
1265 if (isCompoundPair(FirstCompound, SecondCompound)) {
1266 if (
MI->mayLoad() ||
MI->mayStore()) {
1280 if (
MI->mayLoad() ||
MI->mayStore()) {
1288 for (
unsigned i = 0; i < Defs.
size(); i++) {
1290 for (
unsigned j = 0;
j < BundleDefs.
size();
j++)
1295 if (AliasingRegs(Defs[i], BundleDefs[j]) &&
1297 !(IsDualJumpFirstCandidate(*BI) && IsDualJumpSecondCandidate(
MI))) {
1299 dbgs() <<
"\t"; (*BI)->dump());
1315 for (
unsigned j = 0;
j < BundleUses.
size();
j++)
1316 if (AliasingRegs(Defs[i], BundleUses[j])) {
1317 for (
unsigned k = 0;
k < BundleDefs.
size();
k++)
1318 for (
unsigned l = 0;
l <
Uses.size();
l++) {
1319 if (AliasingRegs(BundleDefs[k],
Uses[l]) &&
1322 dbgs() <<
"\t"; (*BI)->dump());
1329 for (
unsigned i = 0; i <
Uses.size(); i++) {
1331 for (
unsigned j = 0;
j < BundleDefs.
size();
j++)
1332 if (AliasingRegs(
Uses[i], BundleDefs[j]) &&
1336 MI->dump();
dbgs() <<
"\t"; (*BI)->dump());
1348 if ((*BI)->isCall()) {
1350 for (
unsigned i = 0; i < Defs.
size(); i++) {
1351 if (AliasingRegs(Defs[i], *
I)) {
1366 if ((*BI)->isBarrier()) {
1399 (
MI->mayStore() ||
MI->getOpcode() == Hexagon::S2_allocframe ||
1422 if ((QII->
isMemOp(**BI) &&
MI->mayStore()) ||
1423 (QII->
isMemOp(*
MI) && (*BI)->mayStore())) {
1425 dbgs() <<
"\tSlot 0 not available for store because of memop.\n");
1430 if ((
MI->mayLoad() && (*BI)->mayStore()) ||
1431 (
MI->mayStore() && (*BI)->mayLoad()) ||
1432 (
MI->mayStore() && (*BI)->mayStore())) {
1435 dbgs() <<
"\t"; (*BI)->dump());
1441 std::map<MachineInstr *, MachineBasicBlock *>::iterator MIMoved;
1442 MIMoved = SpeculatedIns.find(*BI);
1443 if ((MIMoved != SpeculatedIns.end()) &&
1444 (MIMoved->second != (*BI)->getParent())) {
1446 dbgs() <<
"This packet already contains a speculated instruction";
1470DepKind HexagonGlobalSchedulerImpl::analyzeDependence(MachineInstr *MIa,
1471 MachineInstr *MIb) {
1473 return DepKind::Independent;
1478 bool foundBundleWAR =
false;
1480 SmallVector<unsigned, 4> DefsA;
1481 SmallVector<unsigned, 4> DefsB;
1482 SmallVector<unsigned, 8> UsesA;
1483 SmallVector<unsigned, 8> UsesB;
1488 for (SmallVector<unsigned, 4>::iterator IDA = DefsA.
begin(),
1490 IDA != IDAE; ++IDA) {
1491 for (SmallVector<unsigned, 8>::iterator IUB = UsesB.
begin(),
1496 if (AliasingRegs(*IDA, *IUB)) {
1502 bool DefViaRegMask = DefIdx < 0;
1504 *MIa, DefViaRegMask ? 0 : DefIdx, *MIb, UseIdx,
1505 false, DefViaRegMask)) {
1506 foundBundleWAR =
true;
1510 return DepKind::Dependent;
1513 for (SmallVector<unsigned, 4>::iterator IDB = DefsB.
begin(),
1517 if (AliasingRegs(*IDA, *IDB))
1518 return DepKind::Dependent;
1521 for (SmallVector<unsigned, 4>::iterator IDB = DefsB.
begin(),
1523 IDB != IDBE; ++IDB) {
1524 for (SmallVector<unsigned, 8>::iterator IUA = UsesA.
begin(),
1528 if (AliasingRegs(*IDB, *IUA))
1529 return DepKind::Dependent;
1534 return DepKind::Dependent;
1539 for (
unsigned i = 0; i < DefsB.
size(); i++) {
1540 if (AliasingRegs(DefsB[i], *
I))
1541 return DepKind::Dependent;
1547 for (
unsigned i = 0; i < DefsA.
size(); i++) {
1548 if (AliasingRegs(DefsA[i], *
I))
1549 return DepKind::Dependent;
1557 return DepKind::Dependent;
1564 return DepKind::Dependent;
1566 return foundBundleWAR ? DepKind::WAR_SameBundle : DepKind::Independent;
1570bool HexagonGlobalSchedulerImpl::MIsAreDependent(MachineInstr *MIa,
1571 MachineInstr *MIb) {
1575 if (ReorderDependencyTest(MIa, MIb)) {
1584bool HexagonGlobalSchedulerImpl::MIsHaveTrueDependency(MachineInstr *MIa,
1585 MachineInstr *MIb) {
1589 SmallVector<unsigned, 4> DefsA;
1590 SmallVector<unsigned, 4> DefsB;
1591 SmallVector<unsigned, 8> UsesA;
1592 SmallVector<unsigned, 8> UsesB;
1597 for (SmallVector<unsigned, 4>::iterator IDA = DefsA.
begin(),
1599 IDA != IDAE; ++IDA) {
1600 for (SmallVector<unsigned, 8>::iterator IUB = UsesB.
begin(),
1604 if (AliasingRegs(*IDA, *IUB))
1612bool HexagonGlobalSchedulerImpl::canReorderMIs(MachineInstr *MIa,
1613 MachineInstr *MIb) {
1622 for (++MII; MII != MIIE && MII->isInsideBundle(); ++MII) {
1623 if (MII->isDebugInstr())
1625 DepKind dk = analyzeDependence(&*MII, MIb);
1626 if (dk == DepKind::Independent)
1628 LLVM_DEBUG(
dbgs() <<
"\t\t[MIsAreDependent]:\n\t\t"; (*MII).dump();
1630 if (dk == DepKind::WAR_SameBundle) {
1631 LLVM_DEBUG(
dbgs() <<
"\t\t[canReorderMIs] WAR_SameBundle, allow.\n");
1638 return !MIsAreDependent(MIa, MIb);
1648 if (
MI->isBranch() ||
MI->isReturn() ||
MI->isCall() ||
MI->isBarrier() ||
1656bool HexagonGlobalSchedulerImpl::MIisDualJumpCandidate(
1662 MachineBasicBlock *FromThisBB =
MI->getParent();
1663 MachineBasicBlock *ToThisBB = WorkPoint->getParent();
1666 << ToThisBB->
getNumber() <<
") From BB("
1670 if (FromThisBB == ToThisBB)
1676 if ((*(FromThisBB->
pred_begin()) != ToThisBB) ||
1687 MachineBasicBlock *ToTBB = NULL, *ToFBB = NULL;
1692 SmallVector<MachineOperand, 4> ToCond;
1693 if (!QII->
analyzeBranch(*ToThisBB, ToTBB, ToFBB, ToCond,
false)) {
1697 if (ToFBB)
dbgs() << ToFBB->getNumber() <<
").\n";
1698 else dbgs() <<
"None"
1700 if (ToTBB == FromThisBB) {
1704 }
else if (ToFBB == FromThisBB || !ToFBB) {
1713 }
else if (ToThisBB->
succ_size() == 1) {
1715 assert(ToFBB == FromThisBB &&
"Bad CFG layout");
1721 return IsDualJumpFirstCandidate(WorkPoint);
1728bool HexagonGlobalSchedulerImpl::canCauseStall(MachineInstr *
MI,
1730 SmallVector<unsigned, 4> DefsMJI;
1731 SmallVector<unsigned, 8> UsesMJI;
1732 SmallVector<unsigned, 4> DefsMI;
1733 SmallVector<unsigned, 8> UsesMI;
1736 for (
auto Use : UsesMI) {
1737 int UseIdx =
MI->findRegisterUseOperandIdx(Use,
nullptr);
1740 bool ShouldBreak =
false;
1741 int BundleCount = 0;
1745 MJI != Begin; --MJI) {
1746 if (MJI->isBundle()) {
1751 for (
auto Def : DefsMJI) {
1752 if (Def == Use || AliasingRegs(Def, Use)) {
1753 int DefIdx = MJI->findRegisterDefOperandIdx(Def,
nullptr);
1757 Latency = MF.getSubtarget<HexagonSubtarget>().updateLatency(
1771 if (!MJI->isBundled() && !MJI->isDebugInstr())
1782bool HexagonGlobalSchedulerImpl::canThisMIBeMoved(
1784 bool &MovingDependentOp,
int &
Cost) {
1788 MovingDependentOp =
false;
1801 for (--MII; MII->isBundled(); --MII)
1802 if (MII->isBundle())
1806 for (++MII; MII != BBEnd && MII->isInsideBundle() && !MII->isBundle();
1810 if (isCompoundPair(&*MII,
MI)) {
1823 for (--MII; MII->isBundled(); --MII)
1824 if (MII->isBundle())
1828 for (++MII; MII != BBEnd && MII->isInsideBundle() && !MII->isBundle();
1843 if (MIisDualJumpCandidate(
MI, WorkPoint)) {
1848 MovingDependentOp =
true;
1858 unsigned dist_looplabel =
1859 BlockToInstOffset.
find(
MI->getOperand(0).getMBB())->second;
1860 unsigned dist_newloop0 =
1861 BlockToInstOffset.
find(WorkPoint->getParent())->second;
1864 (unsigned)std::abs((
long long)dist_looplabel - dist_newloop0) +
1866 const HexagonInstrInfo *HII = (
const HexagonInstrInfo *)
TII;
1869 << Distance <<
" outside branch range.";);
1872 LLVM_DEBUG(
dbgs() <<
"\nloopN can be moved since Distance: " << Distance
1873 <<
" within branch range.";);
1878 std::map<MachineInstr *, std::vector<unsigned>>::const_iterator DefIter =
1881 for (
unsigned i = 0; DefIter != MIDefSet.end() && i < DefIter->second.size();
1888 if (
MI->isBundled()) {
1897 for (--MII; MII->isBundled(); --MII)
1898 if (MII->isBundle())
1902 for (++MII; MII != BBEnd && MII->isInsideBundle() && !MII->isBundle();
1904 if (MII->isDebugInstr())
1906 DepKind dk = analyzeDependence(&*MII,
MI);
1907 if (dk == DepKind::Independent)
1909 LLVM_DEBUG(
dbgs() <<
"\t\t[MIsAreDependent]:\n\t\t"; (*MII).dump();
1910 dbgs() <<
"\t\t";
MI->dump());
1911 if (dk == DepKind::WAR_SameBundle) {
1912 LLVM_DEBUG(
dbgs() <<
"\t\t[canThisMIBeMoved] WAR_SameBundle, allow.\n");
1923 IsDualJumpSecondCandidate(&*MII) ||
MI->isBranch()) {
1925 MovingDependentOp =
true;
1929 LLVM_DEBUG(
dbgs() <<
"\t\tDependent, and do not allow for now.\n");
1939bool HexagonGlobalSchedulerImpl::doesMIDefinesPredicate(
1940 MachineInstr *
MI, SmallVector<unsigned, 4> &Defs) {
1941 bool defsPredicate =
false;
1944 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
1945 const MachineOperand &MO =
MI->getOperand(i);
1955 assert(Register::isPhysicalRegister(
Reg));
1959 if (RC == &Hexagon::PredRegsRegClass) {
1960 defsPredicate =
true;
1965 return defsPredicate;
1973bool HexagonGlobalSchedulerImpl::NeedToNewify(
1975 MachineInstr *TargetPacket = NULL) {
1977 SmallVector<unsigned, 4> DefsA;
1978 SmallVector<unsigned, 4> DefsB;
1979 SmallVector<unsigned, 8> UsesB;
1990 if (TargetPacket && !TargetPacket->
isBundled()) {
1991 if (doesMIDefinesPredicate(TargetPacket, DefsA)) {
1992 for (SmallVector<unsigned, 4>::iterator IA = DefsA.
begin(),
1995 for (SmallVector<unsigned, 8>::iterator IB = UsesB.
begin(),
2007 for (--MII; MII->isBundled(); --MII)
2008 if (MII->isBundle())
2019 for (++MII; MII != BBEnd && MII->isBundled() && !MII->isBundle(); ++MII) {
2022 if (doesMIDefinesPredicate(&*MII, DefsA)) {
2023 for (SmallVector<unsigned, 4>::iterator IA = DefsA.
begin(),
2026 for (SmallVector<unsigned, 8>::iterator IB = UsesB.
begin(),
2046bool HexagonGlobalSchedulerImpl::CanNewifiedBeUsedInBundle(
2048 MachineInstr *TargetPacket) {
2050 if (!TargetPacket || !TargetPacket->
isBundled())
2054 for (--MII; MII->isBundled(); --MII)
2055 if (MII->isBundle())
2059 for (++MII; MII != BBEnd && MII->isBundled() && !MII->isBundle(); ++MII) {
2064 SmallVector<unsigned, 4> DefsA;
2065 if (!doesMIDefinesPredicate(&*MII, DefsA))
2067 for (
auto &IA : DefsA)
2076void HexagonGlobalSchedulerImpl::setUsedRegs(BitVector &Set,
unsigned Reg) {
2078 for (MCSubRegIterator SubRegs(
Reg, QRI); SubRegs.isValid(); ++SubRegs)
2079 Set.reset(*SubRegs);
2083bool HexagonGlobalSchedulerImpl::AliasingRegs(
unsigned RegA,
unsigned RegB) {
2087 for (MCSubRegIterator SubRegs(RegA, QRI); SubRegs.isValid(); ++SubRegs)
2088 if (RegB == *SubRegs)
2091 for (MCSubRegIterator SubRegs(RegB, QRI); SubRegs.isValid(); ++SubRegs)
2092 if (RegA == *SubRegs)
2100 if (
MI->isDebugInstr())
2103 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
2116 if (
MI->isDebugInstr())
2119 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
2132void HexagonGlobalSchedulerImpl::updateKillAlongThePath(
2133 MachineBasicBlock *HomeBB, MachineBasicBlock *OriginBB,
2138 std::vector<MachineInstr *> &backtrack) {
2140 MachineInstr *
MI = &*Head;
2141 MachineBasicBlock *CurrentBB = OriginBB;
2142 SmallSet<unsigned, 8> KilledUseSet;
2144 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
2145 const MachineOperand &MO =
MI->getOperand(i);
2157 if (KilledUseSet.
empty())
2167 <<
")kills. From BB (" << OriginBB->
getNumber() <<
")\n");
2169 assert(!backtrack.empty() &&
"Empty back track");
2175 for (
signed i = backtrack.size() - 1; i >= 0; --i) {
2177 << backtrack[i]->
getParent()->getNumber() <<
")\t";
2178 backtrack[i]->dump());
2179 if (CurrentBB != backtrack[i]->
getParent()) {
2181 <<
") to(" << backtrack[i]->getParent()->getNumber()
2187 if (*SI == CurrentBB)
2194 E = (*SI)->livein_end();
2196 if (KilledUseSet.
count((*I).PhysReg)) {
2198 <<
") is LiveIn along side exit.\n");
2199 KilledUseSet.
erase((*I).PhysReg);
2202 if (KilledUseSet.
empty())
2206 CurrentBB = backtrack[i]->getParent();
2210 if (backtrack[i] == &*TargetPacket)
2216 if (backtrack[i] == &*SourcePacket)
2220 if (backtrack[i]->isDebugInstr())
2226 SmallVector<unsigned, 4> Defs;
2227 SmallVector<unsigned, 8>
Uses;
2228 MachineInstr *MIU = backtrack[i];
2231 for (SmallVector<unsigned, 8>::iterator IA =
Uses.begin(), IAE =
Uses.end();
2233 if (KilledUseSet.
count(*IA)) {
2245 for (++MII; MII !=
End && MII->isInsideBundle(); ++MII)
2250 KilledUseSet.
erase(*IA);
2253 if (KilledUseSet.
empty())
2261void HexagonGlobalSchedulerImpl::addInstructionToExistingBundle(
2267 std::vector<MachineInstr *> &backtrack) {
2274 if (Outcast->isBundle() && Outcast->isBundledWithSucc())
2275 Outcast->unbundleFromSucc();
2282 if (memShufDisabled)
2290 for (
unsigned i = 0; i < backtrack.size(); ++i)
2291 if (backtrack[i] == &*Outcast)
2292 backtrack[i] = &*Head;
2295 if (NextMI == Outcast)
2298 TargetPacket = Head;
2299 HomeBB->
erase(Outcast);
2304void HexagonGlobalSchedulerImpl::removeInstructionFromExistingBundle(
2309 std::vector<MachineInstr *> &backtrack) {
2311 if (HomeBB->
empty()) {
2317 if (!SourceLocation->isBundle()) {
2318 LLVM_DEBUG(
dbgs() <<
"\t\t\tOriginal instruction was not bundled.\n\t\t\t";
2319 SourceLocation->dump());
2324 for (
unsigned i = 0; i < backtrack.size(); ++i) {
2325 if (backtrack[i] == &*SourceLocation) {
2327 assert((backtrack[i] == backtrack.back()) &&
"Lost back track");
2328 backtrack.pop_back();
2331 if (NextMI == SourceLocation)
2342 LLVM_DEBUG(
dbgs() <<
"\t\t\t[Rem] SourceLocation after bundle update: ";
2348 if (!SourceLocation->isBundledWithSucc()) {
2349 assert(!Head->isBundledWithSucc() && !Head->isBundledWithPred() &&
2355 unsigned BBSizeWithDbg = 0;
2359 for (++
I;
I !=
E &&
I->isBundledWithPred(); ++
I) {
2361 if (!
I->isDebugInstr())
2372 if (Outcast->isBundle() && Outcast->isBundledWithSucc())
2373 Outcast->unbundleFromSucc();
2386 if (memShufDisabled)
2390 }
else if (
Size == 1) {
2392 if (BBSizeWithDbg > 1) {
2396 for (++
I;
I !=
E &&
I->isBundledWithPred(); ++
I) {
2397 I->unbundleFromPred();
2399 if (!
I->isDebugInstr())
2407 if (Head->isBundledWithPred())
2408 Head->unbundleFromPred();
2409 if (Head->isBundledWithSucc())
2410 Head->unbundleFromSucc();
2413 for (MachineOperand &MO : Head->all_uses())
2420 SourceLocation = Head;
2424 for (
unsigned i = 0; i < backtrack.size(); ++i)
2425 if (backtrack[i] == &*Outcast)
2426 backtrack[i] = &*Head;
2429 if (NextMI == Outcast)
2432 HomeBB->
erase(Outcast);
2440 SE =
MBB->succ_end();
2442 LLVM_DEBUG(
dbgs() <<
"\tSuccessor BB (" << (*SI)->getNumber() <<
"):");
2444 E = (*SI)->livein_end();
2459 if (!
MBBI->isDebugInstr())
2469 if (!
MI || !
MI->isBranch() ||
MI->isBundle())
2472 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
2482bool HexagonGlobalSchedulerImpl::AnalyzeBBBranches(MachineBasicBlock *
MBB,
2483 MachineBasicBlock *&
TBB,
2484 MachineInstr *&FirstTerm,
2485 MachineBasicBlock *&FBB,
2486 MachineInstr *&SecondTerm) {
2509 if (MII->isBranch())
2513 while (MII != MIE) {
2514 if (!MII->isBundle() && MII->isBranch()) {
2525 LLVM_DEBUG(
dbgs() <<
"\n\t\tCannot analyze BB with indirect branch.");
2528 if ((FirstTerm && FirstTerm->
getOpcode() == Hexagon::J2_jump &&
2530 (SecondTerm && SecondTerm->
getOpcode() == Hexagon::J2_jump &&
2533 dbgs() <<
"\n\t\tCannot analyze BB with a branch out of function.");
2538 SmallVector<MachineOperand, 4>
Cond;
2540 LLVM_DEBUG(
dbgs() <<
"\t\tFail to analyze with analyzeBranch.\n");
2542 else dbgs() <<
"None\n";);
2559 if (FirstTerm && SecondTerm &&
2568 }
else if (SecondTerm && SecondTerm->
getOpcode() == Hexagon::J2_jump &&
2581 <<
") FBB(" << FBB->
getNumber() <<
").\n");
2596 assert(MBBIter != MF.
end() &&
"I give up.");
2603 else if (FBB ==
S1) {
2609 MBBIter = MF.
begin();
2612 assert(MBBIter != MF.
end() &&
"Malformed BB with invalid successors");
2620 <<
") FBB(" << FBB->
getNumber() <<
").\n");
2624 assert(!FirstTerm &&
"Bad BB");
2628 if (!FBB && SecondTerm) {
2644 LLVM_DEBUG(
dbgs() <<
"Possibly the layout successor is an empty BB");
2648 LLVM_DEBUG(
dbgs() <<
"Malformed branch with useless branch condition";);
2651 }
else if (
TBB && !FBB) {
2667 else dbgs() <<
"\t\tFinal FBB(None)\n";);
2714 Pred->ReplaceUsesOfBlockWith(&
MBB, MFBB);
2725 bool RemoveLSIfPresent =
false;
2727 LLVM_DEBUG(
dbgs() <<
"\nNew firstterm conditional jump added to HomeBB";);
2731 LLVM_DEBUG(
dbgs() <<
"\nNew secondterm conditional jump added to HomeBB";);
2735 LLVM_DEBUG(
dbgs() <<
"\nBranch destination for pulled instruction is BB#"
2736 << Dest->getNumber(););
2741 LLVM_DEBUG(
dbgs() <<
"\nNew firstterm unconditional jump added to HomeBB";);
2744 RemoveLSIfPresent =
true;
2747 dbgs() <<
"\nNew secondterm unconditional jump added to HomeBB";);
2750 RemoveLSIfPresent =
true;
2757 if (RemoveLSIfPresent) {
2762 LLVM_DEBUG(
dbgs() <<
"\nRemoving LayoutSucc BB#" << HomeBBLS->getNumber()
2763 <<
"from list of successors";);
2772MachineInstr *HexagonGlobalSchedulerImpl::MoveAndUpdateLiveness(
2773 BasicBlockRegion *CurrentRegion, MachineBasicBlock *HomeBB,
2774 MachineInstr *InstrToMove,
bool NeedToNewify,
unsigned DepReg,
2775 bool MovingDependentOp, MachineBasicBlock *OriginBB,
2776 MachineInstr *OriginalInstruction, SmallVector<MachineOperand, 4> &
Cond,
2780 std::vector<MachineInstr *> &backtrack) {
2782 dbgs() <<
"\n...............[MoveAndUpdateLiveness]..............\n");
2785 OriginalInstruction->
dump());
2799 HomeBB->
erase(kill_it);
2810 std::list<MachineBasicBlock *> WorkList;
2813 for (std::vector<MachineInstr *>::iterator RI = backtrack.begin(),
2814 RIE = backtrack.end();
2816 WorkList.push_back((*RI)->getParent());
2825 TargetHead->getParent()->instr_end();
2826 bool LastInstructionInBundle =
false;
2828 TargetPacket, &*OutcastFrom, LastInstructionInBundle);
2836 MIBundleBuilder Bundle(&*TargetHead);
2846 if (OriginalInstruction->
getIterator() == TargetTail) {
2853 if (OutcastFrom->isBundledWithSucc()) {
2856 }
else if (OutcastFrom->isBundledWithPred()) {
2857 OutcastFrom->unbundleFromPred();
2859 HomeBB->
splice(MII, OriginBB, OutcastFrom);
2860 if (!MII->isBundledWithPred())
2861 MII->bundleWithPred();
2862 if (!LastInstructionInBundle && !MII->isBundledWithSucc())
2863 MII->bundleWithSucc();
2865 if (!MIIToPred->isBundledWithSucc())
2866 MIIToPred->bundleWithSucc();
2884 updateKillAlongThePath(HomeBB, OriginBB, MII, TargetTail, SourceLocation,
2885 TargetPacket, backtrack);
2894 DemoteToDotOld(&*MII);
2909 assert((DepReg < std::numeric_limits<unsigned>::max()) &&
2910 "Invalid pred reg value");
2912 <<
printReg(DepReg, QRI) <<
").\n");
2914 MII->setDesc(QII->get(NewOpcode));
2919 for (
unsigned i = 0, e = MII->getNumOperands(); i != e; ++i) {
2920 MachineOperand &MO = MII->getOperand(i);
2925 if (DepReg == MO.
getReg())
2929 LLVM_DEBUG(
dbgs() <<
"\t\t\tNew predicated form:\t"; MII->dump());
2932 updateKillAlongThePath(HomeBB, OriginBB, MII, TargetTail, SourceLocation,
2933 TargetPacket, backtrack);
2937 addInstructionToExistingBundle(HomeBB, TargetHead, TargetTail, MII,
2938 TargetPacket, NextMI, backtrack);
2941 removeInstructionFromExistingBundle(OriginBB, ++OriginalHead, OriginalTail,
2942 SourceLocation, NextMI, MovingDependentOp,
2955 QII->
isEndLoopN(OriginalHead->getOpcode())) {
2961 if (OriginBB->
begin() !=
I) {
2963 if (
I->isBundled()) {
2964 if (!
I->isBundledWithSucc())
2965 I->bundleWithSucc();
2966 if (!OriginalHead->isBundledWithPred())
2967 OriginalHead->bundleWithPred();
2972 }
else if (MovingDependentOp &&
2974 if (OriginalHead->isBundled()) {
2976 J != OriginalTail && J->isInsideBundle() && !J->isBundle(); ++J) {
2978 if (MIsHaveTrueDependency(OriginalInstruction, &*J) &&
2981 DemoteToDotOld(&*J);
2986 if (MIsHaveTrueDependency(OriginalInstruction, &*OriginalHead) &&
2989 OriginalHead->dump());
2990 DemoteToDotOld(&*OriginalHead);
3003 for (std::list<MachineBasicBlock *>::iterator BBI = WorkList.begin(),
3004 BBIE = WorkList.end();
3005 BBI != BBIE; BBI++) {
3011 MachineBasicBlock *BB = WorkList.back();
3012 WorkList.pop_back();
3014 }
while (!WorkList.empty());
3017 if (OriginBB == HomeBB)
3018 return &*TargetHead;
3021 MachineBasicBlock *HomeTBB, *HomeFBB;
3022 MachineInstr *FTA = NULL, *STA = NULL;
3023 bool HomeBBAnalyzed = !AnalyzeBBBranches(HomeBB, HomeTBB, FTA, HomeFBB, STA);
3024 if (MII->isBranch()) {
3025 if (HomeBBAnalyzed) {
3026 UpdateCFG(HomeBB, OriginBB, &*MII, HomeTBB, HomeFBB, FTA, STA, MBPI);
3041 EmptyBBs.push_back(OriginBB);
3043 return &*TargetHead;
3047 MachineBasicBlock *CommonFBB = *OriginBB->
succ_begin();
3053 assert((OriginBB->
succ_size() == 2) &&
"Underimplemented 3way branch.");
3054 MachineBasicBlock *OriginTBB, *OriginFBB;
3055 MachineInstr *FTB = NULL, *STB = NULL;
3058 if (HomeBBAnalyzed &&
3059 !AnalyzeBBBranches(OriginBB, OriginTBB, FTB, OriginFBB, STB)) {
3060 assert(OriginFBB &&
"Missing Origin FBB");
3061 if (HomeFBB == OriginBB) {
3063 if (HomeTBB == OriginTBB) {
3066 }
else if (HomeTBB == OriginFBB) {
3077 }
else if (HomeTBB == OriginBB) {
3079 if (HomeFBB == OriginTBB) {
3082 }
else if (HomeFBB == OriginFBB) {
3104 return &*TargetHead;
3110HexagonGlobalSchedulerImpl::findInsertPositionInBundle(
3119 assert(MII->isBundle() &&
"Missing insert location");
3120 bool isDualJumpSecondCandidate = IsDualJumpSecondCandidate(
MI);
3121 LastInBundle =
false;
3123 for (++MII; MII != BBEnd && MII->isInsideBundle() && !MII->isBundle();
3125 if (MII->isBranch() && (FirstBranch == BBEnd))
3129 if (isDualJumpSecondCandidate && IsDualJumpFirstCandidate(&*MII))
3130 DualJumpFirstCandidate = MII;
3131 LastBundledInstruction = MII;
3134 if (DualJumpFirstCandidate != BBEnd) {
3136 ++DualJumpFirstCandidate;
3137 if (DualJumpFirstCandidate == BBEnd ||
3138 DualJumpFirstCandidate == LastBundledInstruction)
3139 LastInBundle =
true;
3140 return DualJumpFirstCandidate;
3141 }
else if (FirstBranch != BBEnd) {
3146 }
else if (LastBundledInstruction != BBEnd) {
3147 LastInBundle =
true;
3148 return ++LastBundledInstruction;
3159 MachineInstr *
MI,
bool DeleteOldCopy) {
3163 assert(CurrentBB &&
"Corrupt instruction");
3170 MachineInstr *NewMI =
MI->getParent()->getParent()->CloneMachineInstr(
MI);
3177 if (DeleteOldCopy) {
3182 CurrentBB->
erase(kill_it);
3189 DemoteToDotOld(NewMI);
3194 if (TargetPacket->getParent() ==
MBB) {
3197 if (MII->isBundled()) {
3198 bool LastInBundle =
false;
3200 findInsertPositionInBundle(TargetPacket, NewMI, LastInBundle);
3201 MIBundleBuilder Bundle(&*TargetPacket);
3202 Bundle.insert(InsertBefore, NewMI);
3209 while (MII->isDebugInstr())
3212 if (MII->isBundled()) {
3213 MIBundleBuilder Bundle(&*MII);
3214 Bundle.insert(++MII, NewMI);
3222bool HexagonGlobalSchedulerImpl::MIsCondAssign(MachineInstr *BMI,
3224 SmallVector<unsigned, 4> &Defs) {
3228 SmallVector<unsigned, 4> CondDefs;
3229 SmallVector<unsigned, 8> CondUses;
3232 for (SmallVector<unsigned, 4>::iterator ID = Defs.
begin(), IDE = Defs.
end();
3234 for (SmallVector<unsigned, 4>::iterator CID = CondDefs.
begin(),
3235 CIDE = CondDefs.
end();
3236 CID != CIDE; ++CID) {
3237 if (AliasingRegs(*CID, *ID)) {
3251template <
typename ElemType,
typename IndexType>
3253 std::map<ElemType, std::vector<IndexType>> &Set1,
3254 std::map<ElemType, std::vector<IndexType>> &Set2,
3255 std::pair<std::vector<IndexType>, std::vector<IndexType>> &UnionSet,
3256 unsigned union_size = 100) {
3258 typename std::map<ElemType, std::vector<IndexType>>
::iterator PosIter_t;
3259 typedef typename std::vector<IndexType>::iterator IndexIter_t;
3260 std::vector<IndexType> &Union1 = UnionSet.first;
3261 std::vector<IndexType> &Union2 = UnionSet.second;
3262 Union1.resize(union_size, 0);
3263 Union2.resize(union_size, 0);
3265 typename std::vector<ElemType>::iterator iter =
Range.begin();
3266 while (iter !=
Range.end()) {
3267 if ((*iter)->isDebugInstr()) {
3272 PosIter_t set1_pos = Set1.find(*iter);
3273 assert(set1_pos != Set1.end() &&
3274 "Set1 should contain an entry for each element in Range.");
3275 IndexIter_t set1idx = set1_pos->second.begin();
3276 while (set1idx != set1_pos->second.end()) {
3277 Union1[*set1idx] = 1;
3280 PosIter_t set2_pos = Set2.find(*iter);
3281 assert(set2_pos != Set2.end() &&
3282 "Set2 should contain an entry for each element in Range.");
3283 IndexIter_t set2idx = set2_pos->second.begin();
3284 while (set2idx != set2_pos->second.end()) {
3285 Union2[*set2idx] = 1;
3302 MI->unbundleFromPred();
3311bool HexagonGlobalSchedulerImpl::canMIBeSpeculated(
3312 MachineInstr *
MI, MachineBasicBlock *ToBB, MachineBasicBlock *FromBB,
3313 std::vector<MachineInstr *> &backtrack) {
3336 if (!
MI->isDereferenceableInvariantLoad())
3341 SmallVector<unsigned, 4> Defs;
3342 SmallVector<unsigned, 8>
Uses;
3346 for (
unsigned R : Defs)
3359 LLVM_DEBUG(
dbgs() <<
"\tTarget succesor BB to check:\n"; (*SI)->dump());
3362 SIE = (*SI)->succ_end();
3363 SII != SIE; ++SII)(*SII)
3366 E = (*SI)->livein_end();
3368 for (SmallVector<unsigned, 4>::iterator ID = Defs.begin(),
3371 if (AliasingRegs((*I).PhysReg, *ID))
3378 E = (*SI)->instr_end();
3380 if (BI->isBundle() || BI->isDebugInstr())
3383 if (MIsCondAssign(&*BI,
MI, Defs))
3391 std::vector<MachineBasicBlock *> PathBB;
3392 for (
unsigned i = 0; i < backtrack.size(); ++i) {
3394 MachineBasicBlock *
MBB = backtrack[i]->getParent();
3395 if ((
MBB != FromBB) &&
3396 (std::find(PathBB.begin(), PathBB.end(),
MBB) == PathBB.end()))
3397 PathBB.push_back(
MBB);
3399 bool WaitingForTargetPacket =
true;
3401 std::vector<MachineInstr *> TraversalRange;
3409 for (
unsigned i = 0; i < PathBB.size(); ++i) {
3410 for (MII = PathBB[i]->instr_begin(); MII != PathBB[i]->instr_end(); ++MII) {
3414 if (backtrack[0] == &*MII)
3415 WaitingForTargetPacket =
false;
3416 if (WaitingForTargetPacket)
3418 if (MII->isBundle())
3425 if (MII->isCall() || MII->isReturn() ||
3426 (MII->getOpcode() == Hexagon::J2_jump && !MII->getOperand(0).isMBB()))
3429 TraversalRange.push_back(&*MII);
3435 std::pair<std::vector<unsigned>, std::vector<unsigned>> RangeDefUse;
3436 Unify(TraversalRange, MIDefSet, MIUseSet, RangeDefUse, QRI->getNumRegs());
3438 for (
unsigned j = 0;
j <
Uses.size(); ++
j)
3439 if (RangeDefUse.first[
Uses[j]]) {
3440 LLVM_DEBUG(
dbgs() <<
"\n\t\tUnresolved dependency along path to HOME for "
3446 for (
unsigned j = 0;
j < Defs.size(); ++
j)
3447 if (RangeDefUse.first[Defs[j]] || RangeDefUse.second[Defs[j]]) {
3448 LLVM_DEBUG(
dbgs() <<
"\n\t\tUnresolved dependency along path to HOME for "
3471bool HexagonGlobalSchedulerImpl::MoveMItoBundle(
3472 BasicBlockRegion *CurrentRegion,
3477 std::vector<MachineInstr *> &backtrack,
bool MovingDependentOp,
3478 bool PathInRegion) {
3479 MachineBasicBlock *HomeBB = TargetPacket->getParent();
3480 MachineBasicBlock *OriginBB = InstrToMove->
getParent();
3481 MachineBasicBlock *CurrentBB = OriginBB;
3482 MachineBasicBlock *CleanupBB = OriginBB;
3483 MachineBasicBlock *PreviousBB = OriginBB;
3484 MachineInstr *OriginalInstructionToMove = &*InstrToMove;
3486 assert(HomeBB &&
"Missing HomeBB");
3487 assert(OriginBB &&
"Missing OriginBB");
3489 LLVM_DEBUG(
dbgs() <<
"\n.........[MoveMItoBundle]..............\n");
3490 LLVM_DEBUG(
dbgs() <<
"\t\tInstrToMove :\t"; InstrToMove->dump());
3497 if (HomeBB == OriginBB) {
3513 for (
unsigned i = 0; i < backtrack.size(); ++i) {
3516 << backtrack[i]->
getParent()->getNumber() <<
")\t";
3517 backtrack[i]->dump());
3521 bool NeedCleanup =
false;
3522 bool NeedToPredicate =
false;
3523 bool MINeedToNewify =
false;
3524 unsigned DepReg = std::numeric_limits<unsigned>::max();
3525 bool isDualJump =
false;
3526 SmallVector<MachineOperand, 4>
Cond;
3527 SmallVector<MachineOperand, 4> PredCond;
3528 std::vector<MachineInstr *> PullUpPath;
3530 PullUpPath = backtrack;
3532 PullUpPath.push_back(&*TargetPacket);
3533 PullUpPath.push_back(&*InstrToMove);
3539 for (std::vector<MachineInstr *>::reverse_iterator RI = backtrack.rbegin(),
3540 RIE = backtrack.rend();
3544 MachineInstr *MIWH = *RI;
3547 InstrToMove->dump());
3549 CleanupBB->
erase(InstrToMove);
3552 if (canCauseStall(&*InstrToMove, MIWH)) {
3554 CleanupBB->
erase(InstrToMove);
3564 bool isBranchMIWH =
isBranch(MIWH);
3565 if (((&*SourceLocation != MIWH) && isBranchMIWH) ||
3569 PreviousBB = CurrentBB;
3573 MachineBasicBlock *PredTBB = NULL;
3574 MachineBasicBlock *PredFBB = NULL;
3585 if (!canMIBeSpeculated(&*InstrToMove, CurrentBB, PreviousBB,
3588 CleanupBB->
erase(InstrToMove);
3592 SpeculatedIns.insert(
3593 std::make_pair(OriginalInstructionToMove, OriginBB));
3594 LLVM_DEBUG(
dbgs() <<
"\nSpeculatedInsToMove"; InstrToMove->dump());
3602 if (NeedToPredicate) {
3604 <<
"\tUnderimplemented pred for speculative move.\n");
3606 CleanupBB->
erase(InstrToMove);
3610 insertTempCopy(CurrentBB, TargetPacket, &*InstrToMove, NeedCleanup);
3612 NeedToPredicate =
false;
3613 assert(!NeedToPredicate &&
"Need to handle predication for this case");
3614 CleanupBB = CurrentBB;
3618 bool LocalNeedPredication =
true;
3620 if (!isBranchMIWH && !PredTBB) {
3621 LLVM_DEBUG(
dbgs() <<
"\tDo not need predicate for this case.\n");
3622 LocalNeedPredication =
false;
3625 if (IsDualJumpSecondCandidate(&*InstrToMove) &&
3626 IsDualJumpFirstCandidate(TargetPacket)) {
3629 }
else if (LocalNeedPredication && (PredFBB != PreviousBB)) {
3635 if (PreviousBB != PredTBB) {
3640 CleanupBB->
erase(InstrToMove);
3645 <<
")InvertCondition("
3646 << (PreviousBB != PredTBB) <<
")\n");
3651 InstrToMove = insertTempCopy(CurrentBB, TargetPacket, &*InstrToMove,
3654 NeedToPredicate =
true;
3655 CleanupBB = CurrentBB;
3657 if (PredCond.
empty() &&
3660 InstrToMove->dump());
3667 isJumpOutOfRange(&*InstrToMove)) &&
3668 !tryAllocateResourcesForConstExt(&*InstrToMove,
false)) {
3671 <<
"\tEI Could not be added to the packet.\n");
3672 CleanupBB->
erase(InstrToMove);
3676 if (!ResourceTracker->canReserveResources(*InstrToMove) ||
3677 !shouldAddToPacket(*InstrToMove)) {
3680 CurrentBB->
erase(InstrToMove);
3685 if (NeedToNewify(InstrToMove, &DepReg, &*TargetPacket)) {
3686 if (isNewifiable(InstrToMove, DepReg, &*TargetPacket)) {
3687 MINeedToNewify =
true;
3689 <<
printReg(DepReg, QRI) <<
").\n");
3692 InstrToMove->dump());
3693 CleanupBB->
erase(InstrToMove);
3702 MIUseSet[OriginalInstructionToMove].push_back(
Cond[1].
getReg());
3706 "Update MIUseSet for new-value compare jumps");
3710 InstrToMove->dump());
3711 bool DistantSpeculation =
false;
3712 std::vector<MachineInstr *> NonPredPullUpPath;
3717 while (btidx < backtrack.size()) {
3718 const MachineBasicBlock *btBB = backtrack[btidx]->getParent();
3719 if ((btBB == PreviousBB) || (btBB == CurrentBB))
3720 NonPredPullUpPath.push_back(backtrack[btidx]);
3724 if (PreviousBB != CurrentBB) {
3725 if (*(PreviousBB->
pred_begin()) != CurrentBB) {
3727 DistantSpeculation =
true;
3729 <<
"\n\tMI not in immediate successor of BB#"
3730 << CurrentBB->
getNumber() <<
", MI is in BB#"
3734 "Region with a side entry");
3737 if (DistantSpeculation ||
3738 InstrToMove->mayLoad() || InstrToMove->mayStore() ||
3739 InstrToMove->hasUnmodeledSideEffects() ||
3740 !canMIBeSpeculated(&*InstrToMove, CurrentBB, PreviousBB,
3741 NonPredPullUpPath)) {
3742 CleanupBB->
erase(InstrToMove);
3746 NeedToPredicate =
false;
3747 SpeculatedIns.insert(
3748 std::make_pair(OriginalInstructionToMove, OriginBB));
3750 InstrToMove->dump());
3757 InstrToMove->dump());
3760 InstrToMove->mayLoad() || InstrToMove->mayStore() ||
3761 InstrToMove->hasUnmodeledSideEffects() ||
3762 !canMIBeSpeculated(&*InstrToMove, CurrentBB, PreviousBB,
3765 CleanupBB->
erase(InstrToMove);
3769 SpeculatedIns.insert(
3770 std::make_pair(OriginalInstructionToMove, OriginBB));
3772 InstrToMove->dump());
3775 InstrToMove = insertTempCopy(CurrentBB, TargetPacket, &*InstrToMove,
3778 CleanupBB = CurrentBB;
3783 <<
"\tCurrentBB:" << CurrentBB->
getNumber()
3784 <<
"\tPreviousBB:" << PreviousBB->
getNumber();
3786 <<
"\tPredFBB:" << PredFBB->
getNumber(););
3790 if (IsDualJumpSecondCandidate(&*InstrToMove)) {
3792 LLVM_DEBUG(
dbgs() <<
"\tUnderimplemented dual jump formation.\n");
3794 CleanupBB->
erase(InstrToMove);
3801 CleanupBB->
erase(InstrToMove);
3808 if (!PredCond.
empty()) {
3809 for (
const MachineOperand &CMO : PredCond) {
3813 bool DefinedInPrev =
false;
3814 for (MachineInstr &PMI : PreviousBB->
instrs()) {
3817 if (PMI.definesRegister(PredReg, QRI)) {
3818 DefinedInPrev =
true;
3822 if (DefinedInPrev) {
3824 <<
"\tFall-through would pull predicated insn above "
3825 "its predicate def; bailing out.\n");
3827 CleanupBB->
erase(InstrToMove);
3832 SpeculatedIns.insert(
3833 std::make_pair(OriginalInstructionToMove, OriginBB));
3835 InstrToMove->dump());
3837 InstrToMove = insertTempCopy(CurrentBB, TargetPacket, &*InstrToMove,
3840 NeedToPredicate =
false;
3841 CleanupBB = CurrentBB;
3849 if (MIWH == backtrack.front()) {
3860 if (!(MovingDependentOp && (MIWH == &*SourceLocation)) &&
3861 !canReorderMIs(MIWH, &*InstrToMove)) {
3863 CleanupBB->
erase(InstrToMove);
3870 isJumpOutOfRange(&*InstrToMove)) {
3871 if (!tryAllocateResourcesForConstExt(&*InstrToMove))
3880 if (MovingDependentOp)
dbgs() <<
"dependent op";
dbgs() <<
": ";
3881 InstrToMove->dump();
dbgs() <<
"To BB:\n"; HomeBB->
dump();
3882 dbgs() <<
"From BB:\n"; OriginBB->
dump());
3886 HexagonNumPullUps++;
3888 HexagonNumDualJumps++;
3894 insertTempCopy(HomeBB, TargetPacket, &*InstrToMove, NeedCleanup);
3902 if (!TargetPacket->isBundle()) {
3905 std::next(InstrToMove));
3912 for (
unsigned i = 0; i < backtrack.size(); ++i)
3913 if (backtrack[i] == &*TargetPacket)
3914 backtrack[i] = &*MII;
3917 if (NextMI == TargetPacket)
3923 MoveAndUpdateLiveness(CurrentRegion, HomeBB, &*InstrToMove, MINeedToNewify,
3924 DepReg, MovingDependentOp, OriginBB,
3925 OriginalInstructionToMove, PredCond, SourceLocation,
3926 TargetPacket, NextMI, backtrack);
3935bool HexagonGlobalSchedulerImpl::isBranchWithinRegion(
3936 BasicBlockRegion *CurrentRegion, MachineInstr *
MI) {
3937 assert(
MI &&
MI->isBranch() &&
"Missing call info");
3941 <<
") Branch instr:\t";
3951 MachineBasicBlock *NextRegionBB;
3952 MachineBasicBlock *
TBB, *FBB;
3953 MachineInstr *FirstTerm = NULL;
3954 MachineInstr *SecondTerm = NULL;
3956 if (AnalyzeBBBranches(
MBB,
TBB, FirstTerm, FBB, SecondTerm)) {
3989 else dbgs() <<
"None\n";);
4001 if (!NextRegionBB) {
4010 if (
MI == FirstTerm) {
4012 <<
") NextBB in the region(" << NextRegionBB->
getNumber()
4014 return (
TBB == NextRegionBB);
4016 assert(FBB &&
"Corrupt BB layout");
4020 if ((
MI != SecondTerm)) {
4021 LLVM_DEBUG(
dbgs() <<
"\t\tDual terminator not matching SecondTerm.\n");
4026 <<
") NextBB in the region(" << NextRegionBB->
getNumber()
4028 return (FBB == NextRegionBB);
4035bool HexagonGlobalSchedulerImpl::isJumpOutOfRange(MachineInstr *UnCond,
4036 MachineInstr *
Cond) {
4037 if (!UnCond || !UnCond->
isBranch())
4040 MachineBasicBlock *UnCondBB = UnCond->
getParent();
4041 MachineBasicBlock *CondBB =
Cond->getParent();
4047 unsigned InstOffset = BlockToInstOffset[UnCondBB];
4048 unsigned Distance = 0;
4055 MachineBasicBlock *
TBB = NULL, *FBB = NULL;
4056 SmallVector<MachineOperand, 4> CondList;
4066 if (
TBB && (
Cond == FirstTerm)) {
4068 (unsigned)std::abs((
long long)InstOffset - BlockToInstOffset[
TBB]) +
4077MachineInstr *HexagonGlobalSchedulerImpl::findBundleAndBranch(
4082 MachineInstr *CondBranch = NULL;
4086 MII != MBBEnd; ++MII) {
4087 MachineInstr *
MI = &*MII;
4088 if (MII->isConditionalBranch()) {
4095 if (!MII->isBundled())
4098 for (--MII; MII->isBundled(); --MII)
4099 if (MII->isBundle()) {
4111bool HexagonGlobalSchedulerImpl::pullUpPeelBBLoop(MachineBasicBlock *PredBB,
4112 MachineBasicBlock *LoopBB) {
4115 if (!LoopBB || !PredBB)
4130 MachineBasicBlock *SuccBB = NULL;
4134 if (*SI != LoopBB) {
4143 MachineInstr *PredCondBranch = NULL;
4144 PredCondBranch = findBundleAndBranch(PredBB, PredBundle);
4145 if (!PredCondBranch)
4147 if (PredBundle == PredBB->
end())
4155 while (FMI->isDebugInstr())
4158 MachineInstr *RegMI = &*FMI;
4161 if (RegMI->
getOpcode() != Hexagon::A2_tfr)
4170 BasicBlockRegion PUR(BasicBlockRegion(
TII, QRI, PredBB));
4175 if (!ResourcesAvailableInBundle(&PUR, PredBundle))
4178 CurrentState.HomeBundle);
4181 MachineBasicBlock *
TBB = NULL, *FBB = NULL;
4182 SmallVector<MachineOperand, 4>
Cond;
4189 MachineBasicBlock *LTBB = NULL, *LFBB = NULL;
4190 SmallVector<MachineOperand, 4> LCond;
4199 MachineInstr *InstrToMove =
4200 &*insertTempCopy(PredBB, PredBundle, RegMI,
false);
4201 if (!canAddMIToThisPacket(InstrToMove, PredBundlePkt)) {
4213 unsigned DepReg = 0;
4214 if (NeedToNewify(InstrToMove->
getIterator(), &DepReg, &*PredBundle) &&
4215 !isNewifiable(InstrToMove->
getIterator(), DepReg, &*PredBundle)) {
4226 InstrToMove->
setDesc(QII->get(NewOpcode));
4227 if (!incrementalAddToPacket(*InstrToMove)) {
4234 MachineInstr *LoopCondBranch = NULL;
4235 LoopCondBranch = findBundleAndBranch(LoopBB, LoopBundle);
4236 if (!LoopCondBranch)
4238 if (LoopBundle == LoopBB->
end())
4244 if (!ResourcesAvailableInBundle(&PUR, LoopBundle))
4247 CurrentState.HomeBundle);
4250 MachineInstr *InstrToSink =
4251 &*insertTempCopy(LoopBB, LoopBundle, RegMI,
false);
4252 if (!canAddMIToThisPacket(InstrToSink, LoopBundlePkt)) {
4266 if (NeedToNewify(InstrToSink->
getIterator(), &DepReg, &*LoopBundle) &&
4267 !isNewifiable(InstrToSink->
getIterator(), DepReg, &*LoopBundle)) {
4277 InstrToSink->
setDesc(QII->get(NewOpcode));
4278 if (!incrementalAddToPacket(*InstrToSink)) {
4300bool HexagonGlobalSchedulerImpl::performPullUpCFG(
MachineFunction &Fn) {
4303 if (std::next(
F.begin()) ==
F.end())
4310 MachineBasicBlock *PrevBlock = NULL;
4311 MachineBasicBlock *JumpBlock = NULL;
4314 MachineBasicBlock *FallBlock = &*
MBB;
4315 if (PrevBlock && JumpBlock) {
4316 Changed |= pullUpPeelBBLoop(PrevBlock, JumpBlock);
4318 PrevBlock = JumpBlock;
4319 JumpBlock = FallBlock;
4325 std::vector<unsigned> Defs;
4326 std::vector<unsigned>
Uses;
4330 MIter != MBBIter->instr_end(); ++MIter) {
4331 if (MIter->isBundle() || MIter->isDebugInstr())
4334 MIUseDefSet(&*MIter, Defs,
Uses);
4336 for (
unsigned i = 0; i < Defs.size(); ++i)
dbgs()
4339 for (
unsigned i = 0; i <
Uses.size(); ++i)
dbgs()
4341 MIDefSet[&*MIter] = Defs;
4342 MIUseSet[&*MIter] =
Uses;
4358MachineBasicBlock *HexagonGlobalSchedulerImpl::optimizeBranches(
4359 MachineBasicBlock *
MBB, MachineBasicBlock *
TBB, MachineInstr *FirstTerm,
4360 MachineBasicBlock *FBB) {
4371 MachineInstr *TBBMIb = &*
TBB->getFirstNonDebugInstr();
4372 if (TBBMIb->
getOpcode() == Hexagon::J2_jump &&
4375 if (
TBB == NewTarget)
4380 int64_t InstOffset =
4382 unsigned Distance = (unsigned)std::abs(
4383 InstOffset - BlockToInstOffset.
find(NewTarget)->second);
4386 <<
" out of range.");
4392 if (!
TBB->hasAddressTaken() && !
TBB->isEHPad() &&
TBB->pred_size() == 1) {
4395 TBB->removeSuccessor(
TBB->succ_begin());
4419 if (FBBMIb->
getOpcode() == Hexagon::J2_jump &&
4428 int64_t InstOffset =
4430 unsigned Distance = (unsigned)std::abs(
4431 InstOffset - BlockToInstOffset.
find(NewTarget)->second);
4434 <<
" out of range.");
4453bool HexagonGlobalSchedulerImpl::performExposedOptimizations(
4460 std::vector<MachineBasicBlock *>::iterator ebb = EmptyBBs.begin();
4461 while (ebb != EmptyBBs.end()) {
4464 <<
") from parent.\n");
4465 (*ebb)->eraseFromParent();
4468 MachineBasicBlock *
TBB = NULL, *FBB = NULL;
4469 MachineInstr *FirstTerm = NULL, *SecondTerm = NULL;
4471 SmallVector<MachineBasicBlock *, 4> Erase;
4473 for (MachineBasicBlock &
MBB : Fn) {
4475 AnalyzeBBBranches(&
MBB,
TBB, FirstTerm, FBB, SecondTerm)) {
4482 if (
TBB && FirstTerm &&
4483 removeRedundantBranches(&
MBB,
TBB, FirstTerm, FBB, SecondTerm)) {
4488 if (FirstTerm && SecondTerm &&
4489 optimizeDualJumps(&
MBB,
TBB, FirstTerm, FBB, SecondTerm)) {
4494 if (
TBB && FBB && FirstTerm && !SecondTerm) {
4495 MachineBasicBlock *MBBToErase =
4496 optimizeBranches(&
MBB,
TBB, FirstTerm, FBB);
4504 for (MachineBasicBlock *
MBB : Erase)
4512bool HexagonGlobalSchedulerImpl::removeRedundantBranches(
4513 MachineBasicBlock *
MBB, MachineBasicBlock *
TBB, MachineInstr *FirstTerm,
4514 MachineBasicBlock *FBB, MachineInstr *SecondTerm) {
4515 bool Analyzed =
false;
4517 MachineInstr *Head = NULL, *ToErase = NULL;
4518 if (!FBB && (FirstTerm->
getOpcode() == Hexagon::J2_jump) &&
4522 dbgs() <<
"\nRemoving Uncond. jump to the layout successor in BB#"
4524 ToErase = FirstTerm;
4525 }
else if (SecondTerm && (
TBB == FBB) &&
4526 (SecondTerm->
getOpcode() == Hexagon::J2_jump)) {
4535 if (++FirstTermIter == SecondTermIter) {
4536 LLVM_DEBUG(
dbgs() <<
"\nRemoving multiple branching to same target in BB#"
4540 ToErase = FirstTerm;
4542 }
else if (SecondTerm && (SecondTerm->
getOpcode() == Hexagon::J2_jump) &&
4548 ToErase = SecondTerm;
4555 LLVM_DEBUG(
dbgs() <<
"\nRemoving Cond. jump to the layout successor in BB#"
4557 ToErase = SecondTerm;
4561 if (ToErase->isBundled()) {
4563 ToErase->eraseFromBundle();
4566 ToErase->eraseFromParent();
4580bool HexagonGlobalSchedulerImpl::optimizeDualJumps(MachineBasicBlock *
MBB,
4581 MachineBasicBlock *
TBB,
4582 MachineInstr *FirstTerm,
4583 MachineBasicBlock *FBB,
4584 MachineInstr *SecondTerm) {
4587 bool Analyzed =
false;
4590 (SecondTerm->
getOpcode() == Hexagon::J2_jump)) {
4602 MachineInstr *
SI = &*SII;
4603 std::map<MachineInstr *, MachineBasicBlock *>::iterator MIMoved;
4604 MIMoved = SpeculatedIns.find(SI);
4605 if ((MIMoved != SpeculatedIns.end()) &&
4606 (MIMoved->second !=
SI->getParent())) {
4619 int64_t InstOffset =
4622 (unsigned)std::abs(InstOffset - BlockToInstOffset.
find(FBB)->second) +
4626 <<
" out of range.");
4640 MachineInstr *SecondHead, *FirstHead;
4651 else if (!FirstHead) {
4655 }
else if (FirstHead == SecondHead) {
4657 assert((FirstHead && SecondHead) &&
"Unbundled Instruction");
4659 if (SecondHead->getBundleSize() < 2)
4673bool HexagonGlobalSchedulerImpl::ResourcesAvailableInBundle(
4674 BasicBlockRegion *CurrentRegion,
4679 if (!TargetPacket->isBundle()) {
4680 if (ignoreInstruction(&*MII) || isSoloInstruction(*MII))
4685 if (MII->isBranch() && !isBranchWithinRegion(CurrentRegion, &*MII))
4691 initPacketizerState();
4692 ResourceTracker->clearResources();
4693 CurrentState.addHomeLocation(MII);
4694 return incrementalAddToPacket(*MII);
4700 initPacketizerState();
4701 ResourceTracker->clearResources();
4702 CurrentState.addHomeLocation(MII);
4704 for (++MII; MII !=
End && MII->isInsideBundle(); ++MII) {
4705 if (MII->getOpcode() == TargetOpcode::DBG_VALUE ||
4706 MII->getOpcode() == TargetOpcode::IMPLICIT_DEF ||
4707 MII->getOpcode() == TargetOpcode::CFI_INSTRUCTION || MII->isEHLabel())
4720 if (MII->isBranch() && !isBranchWithinRegion(CurrentRegion, &*MII))
4723 if (!incrementalAddToPacket(*MII))
4726 return ResourceTracker->canReserveResources(*Nop);
4730bool HexagonGlobalSchedulerImpl::isCompoundPair(MachineInstr *MIa,
4731 MachineInstr *MIb) {
4738 (Opcb == Hexagon::A2_tfr || Opcb == Hexagon::A2_tfrsi))
4742 (Opca == Hexagon::A2_tfr || Opca == Hexagon::A2_tfrsi))
4751inline bool HexagonGlobalSchedulerImpl::multipleBranchesFromToBB(
4752 MachineBasicBlock *BB)
const {
4756 return ((Jumpers.
size() == 1) && !Jumpers[0]->isUnconditionalBranch());
4761bool HexagonGlobalSchedulerImpl::findPullUpCandidates(
4764 std::vector<MachineInstr *> &backtrack,
unsigned MaxCandidates = 1) {
4766 const HexagonInstrInfo *QII = (
const HexagonInstrInfo *)
TII;
4767 MachineBasicBlock *FromThisBB = FromHere->getParent();
4768 bool MovingDependentOp =
false;
4772 if (CurrentState.haveCandidates() >= MaxCandidates)
4778 if (FromHere->isBundle()) {
4780 for (++MII; MII != FromThisBB->
instr_end() && MII->isInsideBundle();
4782 if (MII->isDebugInstr())
4785 << MII->getParent()->getNumber() <<
"): ";
4789 if (!canThisMIBeMoved(&*MII, WorkPoint, MovingDependentOp,
CostBenefit))
4793 if (canAddMIToThisPacket(&*InstrToMove, CurrentState.HomeBundle)) {
4798 if (MII->isCompare())
4801 for (
unsigned i = 0; i < CurrentState.HomeBundle.size(); i++) {
4802 if (QII->
isDuplexPair(*CurrentState.HomeBundle[i], *MII)) {
4806 if (isCompoundPair(CurrentState.HomeBundle[i], &*MII)) {
4812 CurrentState.addPullUpCandidate(InstrToMove, WorkPoint, backtrack,
4821 else if (canThisMIBeMoved(&*FromHere, WorkPoint, MovingDependentOp,
4824 if (canAddMIToThisPacket(&*InstrToMove, CurrentState.HomeBundle)) {
4827 if (InstrToMove->isCompare())
4833 for (
unsigned i = 0; i < CurrentState.HomeBundle.size(); i++) {
4834 if (QII->
isDuplexPair(*CurrentState.HomeBundle[i], *InstrToMove)) {
4838 if (isCompoundPair(CurrentState.HomeBundle[i], &*InstrToMove)) {
4844 CurrentState.addPullUpCandidate(InstrToMove, WorkPoint, backtrack,
4847 LLVM_DEBUG(
dbgs() <<
"\tNo resources for single in the target packet.\n");
4855bool HexagonGlobalSchedulerImpl::tryMultipleInstructions(
4857 std::vector<BasicBlockRegion *>::iterator &CurrentRegion,
4864 bool MovingDependentOp =
false;
4865 std::vector<MachineInstr *> backtrack;
4869 std::sort(CurrentState.PullUpCandidates.begin(),
4870 CurrentState.PullUpCandidates.end(), PullUpCandidateSorter());
4873 for (SmallVector<PullUpCandidate *, 4>::iterator
4874 I = CurrentState.PullUpCandidates.begin(),
4875 E = CurrentState.PullUpCandidates.end();
4877 (*I)->populate(MII, WorkPoint, backtrack, MovingDependentOp);
4879 MachineBasicBlock *FromThisBB = MII->
getParent();
4880 MachineBasicBlock *ToThisBB = WorkPoint->getParent();
4883 LLVM_DEBUG(
dbgs() <<
"\tDependent(" << MovingDependentOp <<
") FromBB("
4885 << ToThisBB->
getNumber() <<
") to this packet:\n";
4889 if (MII->isInsideBundle()) {
4890 while (!FromHereII->isBundle())
4896 if (MoveMItoBundle(*CurrentRegion, MII, NextMI, WorkPoint, FromHere,
4897 backtrack, MovingDependentOp, PathInRegion)) {
4903 FromThisBBEnd = FromThisBB->
end();
4904 ToThisBBEnd = ToThisBB->
end();
4918 if (MoveMItoBundle(*CurrentRegion, MII, NextMI, WorkPoint, FromHere,
4919 backtrack, MovingDependentOp, PathInRegion)) {
4926 FromThisBBEnd = FromThisBB->
end();
4927 ToThisBBEnd = ToThisBB->
end();
4954bool HexagonGlobalSchedulerImpl::performPullUp() {
4955 std::vector<MachineInstr *> backtrack;
4961 for (std::vector<BasicBlockRegion *>::iterator
4962 CurrentRegion = PullUpRegions.begin(),
4963 E = PullUpRegions.end();
4964 CurrentRegion !=
E; ++CurrentRegion) {
4966 LLVM_DEBUG(
dbgs() <<
"\n\nRegion with(" << (*CurrentRegion)->size()
4974 for (
auto ToThisBB = (*CurrentRegion)->getRootMBB(),
4975 LastBBInRegion = (*CurrentRegion)->getLastMBB();
4976 ToThisBB != LastBBInRegion; ++ToThisBB) {
4980 if (multipleBranchesFromToBB(*ToThisBB))
4983 auto FromThisBB = ToThisBB;
4988 << (*ToThisBB)->getNumber() <<
")\n";
4989 (*ToThisBB)->dump());
4992 while (
MI != ToThisBBEnd) {
4998 while (ResourcesAvailableInBundle(*CurrentRegion, WorkPoint)) {
5000 << (*ToThisBB)->getNumber() <<
"):\n";
5014 FromThisBB = ToThisBB;
5015 FromHere = WorkPoint;
5017 FromThisBBEnd = (*FromThisBB)->end();
5024 backtrack.push_back(&*
I);
5026 FromThisBB = ToThisBB;
5028 FromHere = (*FromThisBB)->begin();
5029 FromThisBBEnd = (*FromThisBB)->end();
5036 backtrack.push_back(&*
I);
5043 if (FromHere == FromThisBBEnd) {
5047 LastBBInRegion = (*CurrentRegion)->getLastMBB();
5048 if (FromThisBB == LastBBInRegion)
5052 (*FromThisBB)->dump());
5053 FromThisBBEnd = (*FromThisBB)->end();
5054 FromHere = (*FromThisBB)->begin();
5055 if (FromThisBBEnd == FromHere)
5059 if ((*FromHere).isDebugInstr()) {
5064 backtrack.push_back(&*FromHere);
5065 if (!findPullUpCandidates(WorkPoint, FromHere, backtrack,
5071 if (!tryMultipleInstructions( WorkPoint, CurrentRegion,
MI,
5072 ToThisBBEnd, FromThisBBEnd))
5077 LastBBInRegion = (*CurrentRegion)->getLastMBB();
5090 std::vector<std::pair<MachineBasicBlock *, MachineBasicBlock *>>
5092 UnlikelyWork.reserve((*CurrentRegion)->size());
5093 for (
auto ToIt = (*CurrentRegion)->getRootMBB(),
5094 End = (*CurrentRegion)->getLastMBB();
5095 ToIt !=
End; ++ToIt) {
5096 MachineBasicBlock *ToBB = *ToIt;
5097 MachineBasicBlock *SecondBest = getNextPURBB(ToBB,
true);
5099 UnlikelyWork.emplace_back(ToBB, SecondBest);
5102 for (
auto [ToBB, SecondBest] : UnlikelyWork) {
5107 (*CurrentRegion)->addBBtoRegion(SecondBest);
5115 while (
MI != ToThisBBEnd) {
5121 while (ResourcesAvailableInBundle(*CurrentRegion, WorkPoint)) {
5126 FromHere = SecondBest->
begin();
5127 FromThisBBEnd = SecondBest->
end();
5135 backtrack.push_back(&*
I);
5140 if (FromHere == FromThisBBEnd) {
5142 <<
"\tOnly do one successor for the second try\n");
5145 if ((*FromHere).isDebugInstr()) {
5150 backtrack.push_back(&*FromHere);
5151 if (!findPullUpCandidates(WorkPoint, FromHere, backtrack,
5157 if (!tryMultipleInstructions( WorkPoint, CurrentRegion,
MI,
5158 ToThisBBEnd, FromThisBBEnd,
false))
5167bool HexagonGlobalSchedulerImpl::incrementalAddToPacket(MachineInstr &
MI) {
5169 LLVM_DEBUG(
dbgs() <<
"\t[AddToPacket] (" << CurrentPacketMIs.size()
5173 if (!ResourceTracker->canReserveResources(
MI) || !shouldAddToPacket(
MI))
5176 ResourceTracker->reserveResources(
MI);
5177 CurrentPacketMIs.push_back(&
MI);
5178 CurrentState.HomeBundle.push_back(&
MI);
5181 isJumpOutOfRange(&
MI)) {
5187 if (ResourceTracker->canReserveResources(*Ext)) {
5188 ResourceTracker->reserveResources(*Ext);
5189 LLVM_DEBUG(
dbgs() <<
"\t[AddToPacket] (" << CurrentPacketMIs.size()
5190 <<
") adding:\t immext_i\n");
5191 CurrentPacketMIs.push_back(Ext);
5192 CurrentState.HomeBundle.push_back(Ext);
5202void HexagonGlobalSchedulerImpl::checkBundleCounts(
MachineFunction &Fn) {
5206 unsigned BundleLimit = 4;
5209 MBBi != MBBe; ++MBBi) {
5212 ME = MBBi->instr_end();
5214 if (
MI->isBundle()) {
5220 for (++MII; MII !=
End && MII->isInsideBundle(); ++MII) {
5221 if (MII->getOpcode() == TargetOpcode::DBG_VALUE ||
5222 MII->getOpcode() == TargetOpcode::IMPLICIT_DEF ||
5223 MII->getOpcode() == TargetOpcode::CFI_INSTRUCTION ||
5224 MII->isEHLabel() || QII->
isEndLoopN(MII->getOpcode())) {
5234 assert(0 &&
"Bundle size exceeded");
5243unsigned HexagonGlobalSchedulerImpl::countCompounds(
MachineFunction &Fn) {
5244 unsigned CompoundCount = 0;
5245 [[maybe_unused]]
unsigned DuplexCount = 0;
5246 [[maybe_unused]]
unsigned InstOffset = 0;
5257 if (
MI->isDebugInstr())
5259 if (
MI->isBundle()) {
5262 MachineInstr *FirstCompound = NULL, *SecondCompound = NULL;
5263 MachineInstr *FirstDuplex = NULL, *SecondDuplex = NULL;
5266 for (++MII; MII != MIE && MII->isInsideBundle() && !MII->isBundle();
5268 if (MII->isDebugInstr())
5271 InstOffset += QII->
getSize(*MII);
5273 if (!FirstCompound) {
5274 FirstCompound = &*MII;
5277 SecondCompound = &*MII;
5283 FirstDuplex = &*MII;
5286 SecondDuplex = &*MII;
5293 if (SecondCompound) {
5294 if (isCompoundPair(FirstCompound, SecondCompound)) {
5295 LLVM_DEBUG(
dbgs() <<
"Compound pair (" << CompoundCount <<
")\n");
5316 LLVM_DEBUG(
dbgs() <<
"Total compound(" << CompoundCount <<
") duplex("
5317 << DuplexCount <<
")\n");
5318 return CompoundCount;
5326 return new HexagonGlobalScheduler();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator MBBI
static const Function * getParent(const Value *V)
bbsections Prepares for basic block by splitting functions into clusters of basic static false void updateBranches(MachineFunction &MF, const SmallVector< MachineBasicBlock * > &PreLayoutFallThroughs)
static bool IsEmptyBlock(MachineBasicBlock *MBB)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static InstructionCost getCost(const AnalysisOptions &Opts, Instruction &Inst, TTI::TargetCostKind CostKind, TargetTransformInfo &TTI)
static unsigned InstrCount
This file defines the DenseMap class.
const HexagonInstrInfo * TII
static void DumpLinked(MachineInstr *MI)
static bool IsSchedBarrier(const MachineInstr *MI)
static cl::opt< bool > EnableSpeculativePullUp("enable-speculative-pull-up", cl::Hidden, cl::desc("Enable speculation during Hexagon pull-up pass"))
static cl::opt< bool > ForceNoopHazards("force-noop-hazards", cl::Hidden, cl::init(false), cl::desc("Force noop hazards in scheduler"))
static MachineBasicBlock::instr_iterator getHexagonFirstInstrTerminator(MachineBasicBlock *MBB)
static void debugLivenessForBB(const MachineBasicBlock *MBB, const TargetRegisterInfo *TRI)
static void markKillReg(MachineInstr *MI, unsigned Reg)
Find use with this reg, and unmark the kill flag.
static MachineBasicBlock * getBranchDestination(MachineInstr *MI)
Treat given instruction as a branch, go through its operands and see if any of them is a BB address.
static cl::opt< bool > AllowBBPeelPullUp("enable-bb-peel-pull-up", cl::Hidden, cl::init(true), cl::desc("Peel a reg copy out of a BBloop"))
cl::opt< bool > OneComplexPerPacket
static void updatePredecessors(MachineBasicBlock &MBB, MachineBasicBlock *MFBB)
Rewrite all predecessors of the old block to go to the fallthrough instead.
static void parseOperands(MachineInstr *MI, SmallVector< unsigned, 4 > &Defs, SmallVector< unsigned, 8 > &Uses)
Gather register def/uses from MI.
static bool selectBestBB(BlockFrequency &BBaFreq, unsigned BBaSize, BlockFrequency &BBbFreq, unsigned BBbSize)
Select best candidate to form regions.
static bool MIMustNotBePulledUp(MachineInstr *MI)
static cl::opt< bool > PreventDuplexSeparation("prevent-duplex-separation", cl::Hidden, cl::init(true), cl::desc("Do not destroy existing duplexes during pull up"))
static 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"))
static void DumpPacket(MachineBasicBlock::instr_iterator MII)
static cl::opt< unsigned > SecondaryCandidateQueueSize("pull-up-sec-queue-size", cl::Hidden, cl::init(2))
static bool isDelayedUseException(MachineInstr *MIa, MachineInstr *MIb)
Some apparent dependencies are not actually restricting us since there is a delay between assignment ...
static cl::opt< bool > AllowUnlikelyPath("unlikely-path-pull-up", cl::Hidden, cl::init(true), cl::desc("Allow unlikely path pull up"))
static const unsigned SafetyBuffer
static cl::opt< bool > EnableLocalPullUp("enable-local-pull-up", cl::Hidden, cl::init(true), cl::desc("Enable same BB pull during Hexagon pull-up pass"))
static cl::opt< bool > SpeculateNonPredInsn("speculate-non-pred-insn", cl::Hidden, cl::init(true), cl::desc("Speculate non-predicable instructions in parent BB"))
static void UpdateCFG(MachineBasicBlock *HomeBB, MachineBasicBlock *OriginBB, MachineInstr *MII, MachineBasicBlock *HomeTBB, MachineBasicBlock *HomeFBB, MachineInstr *FTA, MachineInstr *STA, const MachineBranchProbabilityInfo *MBPI)
static cl::opt< bool > WarnOnBundleSize("warn-on-bundle-size", cl::Hidden, cl::desc("Hexagon check bundles and warn on size"))
static unsigned nonDbgBundleSize(MachineBasicBlock::iterator &TargetPacket)
static bool isGlobalMemoryObject(MachineInstr *MI)
Return true if MI is an instruction we are unable to reason about (like something with unmodeled memo...
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 cl::opt< bool > PreventCompoundSeparation("prevent-compound-separation", cl::Hidden, cl::desc("Do not destroy existing compounds during pull up"))
static cl::opt< bool > AllowDependentPullUp("enable-dependent-pull-up", cl::Hidden, cl::init(true), cl::desc("Perform dual jump formation during pull up"))
static cl::opt< unsigned > MainCandidateQueueSize("pull-up-main-queue-size", cl::Hidden, cl::init(8))
static cl::opt< bool > DisableCheckBundles("disable-hexagon-check-bundles", cl::Hidden, cl::init(true), cl::desc("Disable Hexagon check bundles pass"))
cl::opt< bool > EnableDefUseSamePacket("enable-def-use-same-packet", cl::Hidden, cl::init(true), cl::desc("Allow moving an instruction out of a packet that redefines one of " "its source registers"))
static cl::opt< bool > PerformDualJumps("dual-jump-in-pull-up", cl::Hidden, cl::init(true), cl::desc("Perform dual jump formation during pull up"))
static void UpdateBundle(MachineInstr *BundleHead)
static bool IsIndirectCall(const MachineInstr *MI)
static cl::opt< bool > DisablePullUp("disable-pull-up", cl::Hidden, cl::desc("Disable Hexagon pull-up pass"))
static cl::opt< bool > AllowSpeculateLoads("speculate-loads-on-pull-up", cl::Hidden, cl::init(true), cl::desc("Allow speculative loads during Hexagon pull-up pass"))
static void unmarkKillReg(MachineInstr *MI, unsigned Reg)
Find use with this reg, and unmark the kill flag.
static bool MIShouldNotBePulledUp(MachineInstr *MI)
static cl::opt< bool > PostPullUpOpt("post-pull-up-opt", cl::Hidden, cl::init(true), cl::desc("Enable opt. exposed by pull-up e.g., remove redundant jumps"))
cl::opt< bool > OneFloatPerPacket
#define HEXAGON_INSTR_SIZE
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static bool isBranch(unsigned Opcode)
SmallVector< MachineOperand, 4 > Cond
MachineRegisterInfo & MRI
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
Remove Loads Into Fake Uses
static bool InBlock(const Value *V, const BasicBlock *BB)
This file defines the SmallSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
LLVM_ABI AnalysisUsage & addRequiredID(const void *ID)
AnalysisUsage & addRequired()
void RemoveBBFromRegion(MachineBasicBlock *MBB)
MachineBasicBlock * findNextMBB(MachineBasicBlock *MBB)
LivenessInfo * getLivenessInfoForBB(MachineBasicBlock *MBB)
void addBBtoRegion(MachineBasicBlock *MBB)
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
iterator find(const_arg_type_t< KeyT > Val)
FunctionPass class - This class is used to implement most global optimizations.
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
bool isCompoundBranchInstr(const MachineInstr &MI) const
bool isDuplexPair(const MachineInstr &MIa, const MachineInstr &MIb) const
Symmetrical. See if these two instructions are fit for duplex pair.
bool isJumpR(const MachineInstr &MI) const
bool invertAndChangeJumpTarget(MachineInstr &MI, MachineBasicBlock *NewTarget) const
int getDotNewPredOp(const MachineInstr &MI, const MachineBranchProbabilityInfo *MBPI) const
unsigned getInvertedPredicatedOpcode(const int Opc) const
HexagonII::SubInstructionGroup getDuplexCandidateGroup(const MachineInstr &MI) const
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
bool isPredicatedNew(const MachineInstr &MI) const
bool isJumpWithinBranchRange(const MachineInstr &MI, unsigned offset) const
bool mayBeNewStore(const MachineInstr &MI) const
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
Reverses the branch condition of the specified condition list, returning false on success and true if...
bool isLoopN(const MachineInstr &MI) const
bool isConstExtended(const MachineInstr &MI) const
bool PredOpcodeHasJMP_c(unsigned Opcode) const
bool areMemAccessesDependent(AAResults *AA, const MachineInstr *MIa, const MachineInstr *MIb) const
Return true if the memory accesses of MIa and MIb may depend on each other.
bool isExtended(const MachineInstr &MI) const
bool isPredicateLate(unsigned Opcode) const
bool isComplex(const MachineInstr &MI) const
void setBundleNoShuf(MachineBasicBlock::instr_iterator MIB) const
bool isMemOp(const MachineInstr &MI) const
int getDotOldOp(const MachineInstr &MI) const
bool isDeallocRet(const MachineInstr &MI) const
unsigned getCExtOpNum(const MachineInstr &MI) const
bool isDotNewInst(const MachineInstr &MI) const
unsigned getSize(const MachineInstr &MI) const
bool isSafeInBundleWAR(const MachineInstr &DefMI, unsigned DefOpIdx, const MachineInstr &UseMI, unsigned UseOpIdx, bool IsPullDown=false, bool DefViaRegMask=false) const
A use (UseMI) can share a bundle with an instruction that redefines the same register (DefMI),...
bool isHVXVec(const MachineInstr &MI) const
bool getBundleNoShuf(const MachineInstr &MIB) const
bool isNewValueJump(const MachineInstr &MI) const
bool PredicateInstruction(MachineInstr &MI, ArrayRef< MachineOperand > Cond) const override
Convert the instruction into a predicated instruction.
bool isFloat(const MachineInstr &MI) const
unsigned nonDbgBBSize(const MachineBasicBlock *BB) const
getInstrTimingClassLatency - Compute the instruction latency of a given instruction using Timing Clas...
bool isEndLoopN(unsigned Opcode) const
bool isPredicable(const MachineInstr &MI) const override
Return true if the specified instruction can be predicated.
HexagonII::CompoundGroup getCompoundCandidateGroup(const MachineInstr &MI) const
SmallVector< MachineInstr *, 2 > getBranchingInstrs(MachineBasicBlock &MBB) const
bool isNewValueStore(const MachineInstr &MI) const
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
bool isFakeReg(MCPhysReg Reg) const
Returns true if the given reserved physical register Reg is live across function calls/returns.
bool isGlobalReg(MCPhysReg Reg) const
Returns true if the given reserved physical register is live across function calls/returns.
void UpdateLiveness(MachineBasicBlock *MBB)
unsigned getSchedClass() const
Return the scheduling class for this instruction.
unsigned pred_size() const
bool isEHPad() const
Returns true if the block is a landing pad.
instr_iterator instr_begin()
reverse_instr_iterator instr_rbegin()
instr_iterator erase_instr(MachineInstr *I)
Remove an instruction from the instruction list and delete it.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
SmallVectorImpl< MachineBasicBlock * >::const_iterator const_succ_iterator
LLVM_ABI iterator getFirstNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the first non-debug instruction in the basic block, or end().
succ_iterator succ_begin()
LiveInVector::const_iterator livein_iterator
unsigned succ_size() const
bool hasAddressTaken() const
Test whether this block is used as something other than the target of a terminator,...
void setAlignment(Align A)
Set alignment of the basic block.
LLVM_ABI void dump() const
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
SmallVectorImpl< MachineBasicBlock * >::iterator succ_iterator
LLVM_ABI void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
LLVM_ABI iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
LLVM_ABI bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
reverse_instr_iterator instr_rend()
Instructions::iterator instr_iterator
pred_iterator pred_begin()
LLVM_ABI void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New)
Given a machine basic block that branched to 'Old', change the code and CFG so that it branches to 'N...
LLVM_ABI bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
instr_iterator instr_end()
Instructions::const_iterator const_instr_iterator
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
iterator_range< succ_iterator > successors()
LLVM_ABI instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
Align getAlignment() const
Return alignment of the basic block.
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
LLVM_ABI bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
Instructions::reverse_iterator reverse_instr_iterator
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
LLVM_ABI BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const
getblockFreq - Return block frequency.
LLVM_ABI BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
instr_iterator getInstrIterator() const
Representation of each machine instruction.
mop_iterator operands_begin()
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
LLVM_ABI MachineInstr * removeFromParent()
Unlink 'this' from the containing basic block, and return it without deleting it.
const MachineBasicBlock * getParent() const
bool isCall(QueryType Type=AnyInBundle) const
LLVM_ABI MachineInstr * removeFromBundle()
Unlink this instruction from its basic block and return it without deleting it.
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
bool isBundledWithPred() const
Return true if this instruction is part of a bundle, and it is not the first instruction in the bundl...
LLVM_ABI void unbundleFromPred()
Break bundle above this instruction.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
mop_iterator operands_end()
LLVM_ABI int findRegisterUseOperandIdx(Register Reg, const TargetRegisterInfo *TRI, bool isKill=false) const
Returns the operand index that is a use of the specific register or -1 if it is not found.
LLVM_ABI unsigned getBundleSize() const
Return the number of instructions inside the MI bundle, excluding the bundle header.
bool isConditionalBranch(QueryType Type=AnyInBundle) const
Return true if this is a branch which may fall through to the next instruction or may transfer contro...
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
bool isUnconditionalBranch(QueryType Type=AnyInBundle) const
Return true if this is a branch which always transfers control flow to some other block.
LLVM_ABI void eraseFromBundle()
Unlink 'this' from its basic block and delete it.
MachineOperand * mop_iterator
iterator/begin/end - Iterate over all operands of a machine instruction.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
LLVM_ABI void dump() const
bool isBundledWithSucc() const
Return true if this instruction is part of a bundle, and it is not the last instruction in the bundle...
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI void unbundleFromSucc()
Break bundle below this instruction.
LLVM_ABI int findRegisterDefOperandIdx(Register Reg, const TargetRegisterInfo *TRI, bool isDead=false, bool Overlap=false) const
Returns the operand index that is a def of the specified register or -1 if it is not found.
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool isIndirectBranch(QueryType Type=AnyInBundle) const
Return true if this is an indirect branch, such as a branch through a register.
bool isBundled() const
Return true if this instruction part of a bundle.
MachineOperand class - Representation of each machine instruction operand.
void setIsInternalRead(bool Val=true)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
MachineBasicBlock * getMBB() const
void setIsKill(bool Val=true)
void setMBB(MachineBasicBlock *MBB)
Register getReg() const
getReg - Returns the register number.
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVM_ABI void init(const TargetSubtargetInfo *TSInfo, bool EnableSModel=true, bool EnableSItins=true)
Initialize the machine model for instruction scheduling.
LLVM_ABI unsigned computeOperandLatency(const MachineInstr *DefMI, unsigned DefOperIdx, const MachineInstr *UseMI, unsigned UseOperIdx) const
Compute operand latency based on the available machine model.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
int getNumOccurrences() const
unsigned getPosition() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Abstract Attribute helper functions.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
LLVM_ABI void finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
finalizeBundle - Finalize a machine instruction bundle which includes a sequence of instructions star...
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM_ABI char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
void initializeHexagonGlobalSchedulerPass(PassRegistry &)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
LLVM_ABI Printable printBlockFreq(const BlockFrequencyInfo &BFI, BlockFrequency Freq)
Print the block frequency Freq relative to the current functions entry frequency.
@ End
Run the machine verifier once, at the end of the pipeline.
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
FunctionPass * createHexagonGlobalScheduler()
MCRegisterClass TargetRegisterClass
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.