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"));
138class HexagonGlobalSchedulerImpl;
143 HexagonGlobalScheduler() : MachineFunctionPass(ID) {
147 void getAnalysisUsage(AnalysisUsage &AU)
const override {
151 AU.
addRequired<MachineBranchProbabilityInfoWrapperPass>();
152 AU.
addRequired<MachineBlockFrequencyInfoWrapperPass>();
157 StringRef getPassName()
const override {
return "Hexagon Global Scheduler"; }
161char HexagonGlobalScheduler::ID = 0;
164class PullUpCandidate {
169 std::vector<MachineInstr *> Backtrack;
173 CandidateLocation = MII;
179 std::vector<MachineInstr *> &backtrack,
bool DependentOp,
181 : CandidateLocation(MII), HomeBundle(HomeBundle),
182 DependentOp(DependentOp), BenefitCost(
Cost) {
184 Backtrack = backtrack;
189 std::vector<MachineInstr *> &backtrack,
bool &dependentOp) {
190 MII = CandidateLocation;
191 WorkPoint = HomeBundle;
192 backtrack = Backtrack;
193 dependentOp = DependentOp;
196 signed getCost() {
return BenefitCost; }
198 MachineInstr *getCandidate() {
return &*CandidateLocation; }
201 dbgs() <<
"Cost(" << BenefitCost;
202 dbgs() <<
") Dependent(" << DependentOp;
203 dbgs() <<
") backtrack size(" << Backtrack.size() <<
")\t";
204 CandidateLocation->dump();
209struct PullUpCandidateSorter {
210 PullUpCandidateSorter() {}
211 bool operator()(PullUpCandidate *
LHS, PullUpCandidate *
RHS) {
212 return LHS->getCost() >
RHS->getCost();
220 friend class HexagonGlobalSchedulerImpl;
229 const HexagonInstrInfo *QII;
232 PullUpState(
const HexagonInstrInfo *QII) : HomeLocation(NULL), QII(QII) {}
234 ~PullUpState() { reset(); }
238 std::vector<MachineInstr *> &backtrack,
239 bool DependentOp,
signed Cost) {
241 PullUpCandidate *PUI =
242 new PullUpCandidate(MII, HomeBundle, backtrack, DependentOp,
Cost);
243 PullUpCandidates.push_back(PUI);
247 unsigned element = 0;
248 for (
unsigned i = 0; i < HomeBundle.size(); i++) {
249 dbgs() <<
"[" << element++;
250 dbgs() <<
"] Home Duplex("
251 << QII->getDuplexCandidateGroup(*HomeBundle[i]);
252 dbgs() <<
") Compound (" << QII->getCompoundCandidateGroup(*HomeBundle[i])
254 HomeBundle[i]->dump();
258 for (SmallVector<PullUpCandidate *, 4>::iterator
259 I = PullUpCandidates.begin(),
260 E = PullUpCandidates.end();
262 dbgs() <<
"[" << element++ <<
"] Cand: Compound(";
263 dbgs() << QII->getCompoundCandidateGroup(*(*I)->getCandidate()) <<
") ";
270 for (SmallVector<PullUpCandidate *, 4>::iterator
271 I = PullUpCandidates.begin(),
272 E = PullUpCandidates.end();
275 PullUpCandidates.clear();
281 HomeLocation = WorkPoint;
284 unsigned haveCandidates() {
return PullUpCandidates.size(); }
289 std::vector<BasicBlockRegion *> PullUpRegions;
292 DenseMap<MachineBasicBlock *, unsigned> BlockToInstOffset;
294 PullUpState CurrentState;
296 std::vector<MachineBasicBlock *> EmptyBBs;
302 std::map<MachineInstr *, MachineBasicBlock *> SpeculatedIns;
304 std::map<MachineInstr *, std::vector<unsigned>> MIUseSet;
306 std::map<MachineInstr *, std::vector<unsigned>> MIDefSet;
309 const MachineBranchProbabilityInfo *MBPI;
310 const MachineBlockFrequencyInfo *MBFI;
311 const MachineRegisterInfo *MRI;
312 const MachineFrameInfo &MFI;
313 const HexagonRegisterInfo *QRI;
314 const HexagonInstrInfo *QII;
315 MachineLoopInfo &MLI;
316 MachineDominatorTree &MDT;
317 MachineInstrBuilder Ext;
318 MachineInstrBuilder Nop;
319 const unsigned PacketSize;
320 TargetSchedModel TSchedModel;
326 const MachineBranchProbabilityInfo *MBPI,
327 const MachineBlockFrequencyInfo *MBFI,
328 const MachineRegisterInfo *MRI,
329 const MachineFrameInfo &MFI,
330 const HexagonRegisterInfo *QRI);
331 HexagonGlobalSchedulerImpl(
const HexagonGlobalSchedulerImpl &) =
delete;
332 HexagonGlobalSchedulerImpl &
333 operator=(
const HexagonGlobalSchedulerImpl &) =
delete;
335 ~HexagonGlobalSchedulerImpl() {
337 for (std::vector<BasicBlockRegion *>::iterator
I = PullUpRegions.begin(),
338 E = PullUpRegions.end();
341 MF.deleteMachineInstr(Ext);
342 MF.deleteMachineInstr(Nop);
346 void initPacketizerState()
override;
349 bool ignoreInstruction(MachineInstr *
MI);
353 bool isSoloInstruction(
const MachineInstr &
MI)
override;
356 bool incrementalAddToPacket(MachineInstr &
MI);
362 bool performPullUp();
382 MachineBasicBlock *optimizeBranches(MachineBasicBlock *
MBB,
383 MachineBasicBlock *
TBB,
384 MachineInstr *FirstTerm,
385 MachineBasicBlock *FBB);
390 bool removeRedundantBranches(MachineBasicBlock *
MBB, MachineBasicBlock *
TBB,
391 MachineInstr *FirstTerm, MachineBasicBlock *FBB,
392 MachineInstr *SecondTerm);
396 bool optimizeDualJumps(MachineBasicBlock *
MBB, MachineBasicBlock *
TBB,
397 MachineInstr *FirstTerm, MachineBasicBlock *FBB,
398 MachineInstr *SecondTerm);
403 BasicBlockRegion *getRegionForMBB(std::vector<BasicBlockRegion *> &Regions,
404 MachineBasicBlock *
MBB);
408 void MIUseDefSet(MachineInstr *
MI, std::vector<unsigned> &Defs,
409 std::vector<unsigned> &
Uses);
419 MachineBasicBlock *getNextPURBB(MachineBasicBlock *
MBB,
bool SecondBest);
421 void setUsedRegs(BitVector &Set,
unsigned Reg);
422 bool AliasingRegs(
unsigned RegA,
unsigned RegB);
425 bool ReorderDependencyTest(MachineInstr *MIa, MachineInstr *MIb);
427 bool canAddMIToThisPacket(
431 bool pullUpPeelBBLoop(MachineBasicBlock *PredBB, MachineBasicBlock *LoopBB);
433 MachineInstr *findBundleAndBranch(MachineBasicBlock *BB,
437 bool ResourcesAvailableInBundle(BasicBlockRegion *CurrentRegion,
441 MachineInstr *MoveAndUpdateLiveness(
442 BasicBlockRegion *CurrentRegion, MachineBasicBlock *HomeBB,
443 MachineInstr *InstrToMove,
bool NeedToNewify,
unsigned DepReg,
444 bool MovingDependentOp, MachineBasicBlock *OriginBB,
445 MachineInstr *OriginalInstruction, SmallVector<MachineOperand, 4> &
Cond,
449 std::vector<MachineInstr *> &backtrack);
452 void updateKillAlongThePath(MachineBasicBlock *HomeBB,
453 MachineBasicBlock *OriginBB,
458 std::vector<MachineInstr *> &backtrack);
463 std::vector<MachineInstr *> &backtrack,
464 unsigned MaxCandidates);
467 bool tryMultipleInstructions(
469 std::vector<BasicBlockRegion *>::iterator &CurrentRegion,
475 bool MoveMItoBundle(BasicBlockRegion *CurrentRegion,
480 std::vector<MachineInstr *> &backtrack,
481 bool MovingDependentOp,
bool PathInRegion);
485 insertTempCopy(MachineBasicBlock *
MBB,
491 MachineInstr *
MI,
bool &LastInBundle);
494 MachineInstr *TargetPacket);
497 unsigned DepReg, MachineInstr *TargetPacket);
499 void addInstructionToExistingBundle(MachineBasicBlock *HomeBB,
505 std::vector<MachineInstr *> &backtrack);
507 void removeInstructionFromExistingBundle(
512 std::vector<MachineInstr *> &backtrack);
515 bool MIsCondAssign(MachineInstr *BMI, MachineInstr *
MI,
516 SmallVector<unsigned, 4> &Defs);
521 bool canMIBeSpeculated(MachineInstr *
MI, MachineBasicBlock *ToBB,
522 MachineBasicBlock *FromBB,
523 std::vector<MachineInstr *> &backtrack);
526 bool isBranchWithinRegion(BasicBlockRegion *CurrentRegion, MachineInstr *
MI);
529 bool MIsAreDependent(MachineInstr *MIa, MachineInstr *MIb);
530 bool MIsHaveTrueDependency(MachineInstr *MIa, MachineInstr *MIb);
531 bool canReorderMIs(MachineInstr *MIa, MachineInstr *MIb);
532 bool canCauseStall(MachineInstr *
MI, MachineInstr *MJ);
533 bool canThisMIBeMoved(MachineInstr *
MI,
535 bool &MovingDependentOp,
int &
Cost);
536 bool MIisDualJumpCandidate(MachineInstr *
MI,
538 bool DemoteToDotOld(MachineInstr *
MI);
540 MachineInstr *TargetPacket);
541 bool IsNewifyStore(MachineInstr *
MI);
542 bool isJumpOutOfRange(MachineInstr *
MI);
543 bool IsDualJumpFirstCandidate(MachineInstr *
MI);
544 bool IsDualJumpFirstCandidate(MachineBasicBlock *
MBB);
546 bool IsNotDualJumpFirstCandidate(MachineInstr *
MI);
547 bool isJumpOutOfRange(MachineInstr *UnCond, MachineInstr *
Cond);
548 bool IsDualJumpSecondCandidate(MachineInstr *
MI);
549 bool tryAllocateResourcesForConstExt(MachineInstr *
MI,
bool UpdateState);
550 bool isCompoundPair(MachineInstr *MIa, MachineInstr *MIb);
551 bool doesMIDefinesPredicate(MachineInstr *
MI, SmallVector<unsigned, 4> &Defs);
552 bool AnalyzeBBBranches(MachineBasicBlock *
MBB, MachineBasicBlock *&
TBB,
553 MachineInstr *&FirstTerm, MachineBasicBlock *&FBB,
554 MachineInstr *&SecondTerm);
555 inline bool multipleBranchesFromToBB(MachineBasicBlock *BB)
const;
560 "Hexagon Global Scheduler",
false,
false)
570HexagonGlobalSchedulerImpl::HexagonGlobalSchedulerImpl(
577 MBFI(MBFI),
MRI(
MRI), MFI(MFI), QRI(QRI), MLI(MLI), MDT(MDT),
578 PacketSize(MF.getSubtarget().getSchedModel().IssueWidth) {
582 TSchedModel.
init(&MF.getSubtarget());
590 for (++MII; MII !=
End && MII->isInsideBundle(); ++MII) {
591 if (MII->isDebugInstr())
599bool HexagonGlobalScheduler::runOnMachineFunction(
MachineFunction &Fn) {
606 const HexagonRegisterInfo *QRI = HST.getRegisterInfo();
607 MachineLoopInfo &MLI = getAnalysis<MachineLoopInfoWrapperPass>().getLI();
608 MachineDominatorTree &MDT =
609 getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
610 const MachineBranchProbabilityInfo *MBPI =
611 &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
612 const MachineBlockFrequencyInfo *MBFI =
613 &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
614 AliasAnalysis *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
622 HexagonGlobalSchedulerImpl GlobalSchedulerState(Fn, MLI, MDT, AA, MBPI, MBFI,
626 assert(GlobalSchedulerState.getResourceTracker() &&
"Empty DFA table!");
631 GlobalSchedulerState.checkBundleCounts(Fn);
637 LLVM_DEBUG(GlobalSchedulerState.countCompounds(Fn));
638 GlobalSchedulerState.GenUseDefChain(Fn);
639 GlobalSchedulerState.formPullUpRegions(Fn);
640 GlobalSchedulerState.performPullUp();
641 GlobalSchedulerState.performPullUpCFG(Fn);
643 GlobalSchedulerState.formPullUpRegions(Fn);
644 GlobalSchedulerState.performExposedOptimizations(Fn);
646 LLVM_DEBUG(GlobalSchedulerState.countCompounds(Fn));
653bool HexagonGlobalSchedulerImpl::tryAllocateResourcesForConstExt(
654 MachineInstr *
MI,
bool UpdateState =
true) {
655 if (ResourceTracker->canReserveResources(*Ext)) {
660 ResourceTracker->reserveResources(*Ext);
661 else if (CurrentPacketMIs.size() >= PacketSize - 1)
670 return MI->getOpcode() == Hexagon::Y2_barrier;
674 return MI->getOpcode() == Hexagon::J2_callr;
679 if (
MI->isBundledWithPred())
683 if (
MI->isBundledWithSucc())
692 dbgs() <<
"\tNULL\n";
699 dbgs() <<
"\tUnattached: ";
705 if (
MI->isBundle()) {
707 for (++MII; MII != MIE && MII->isInsideBundle() && !MII->isBundle();
718 dbgs() <<
"\tBBEnd\n";
727 if (
MI->isBundle()) {
730 for (++MII; MII != MIE && MII->isInsideBundle() && !MII->isBundle();
736 return MI->isBranch();
741bool HexagonGlobalSchedulerImpl::IsNotDualJumpFirstCandidate(MachineInstr *
MI) {
750bool HexagonGlobalSchedulerImpl::IsDualJumpFirstCandidate(MachineInstr *
MI) {
761bool HexagonGlobalSchedulerImpl::IsDualJumpFirstCandidate(
765 MachineInstr *
MI = &*TargetPacket;
767 if (
MI->isBundle()) {
769 if (&(*
MI->getParent()->rbegin()) !=
MI)
776 for (++MII; MII != BBEnd && MII->isInsideBundle() && !MII->isBundle();
778 if (IsNotDualJumpFirstCandidate(&*MII))
781 return IsDualJumpFirstCandidate(
MI);
789bool HexagonGlobalSchedulerImpl::IsDualJumpFirstCandidate(
790 MachineBasicBlock *
MBB) {
796 MII != MBBEnd; ++MII) {
797 MachineInstr *
MI = &*MII;
798 if (
MI->isDebugInstr())
800 if (!
MI->isBundle() && IsNotDualJumpFirstCandidate(
MI))
807bool HexagonGlobalSchedulerImpl::IsDualJumpSecondCandidate(MachineInstr *
MI) {
828 if (!MII->isBundle() && MII->isTerminator())
839bool HexagonGlobalSchedulerImpl::isJumpOutOfRange(MachineInstr *
MI) {
840 if (!
MI || !
MI->isBranch())
847 unsigned InstOffset = BlockToInstOffset[
MBB];
848 unsigned Distance = 0;
856 MachineBasicBlock *
TBB = NULL, *FBB = NULL;
857 SmallVector<MachineOperand, 4>
Cond;
867 if (
TBB && (
MI == &*FirstTerm)) {
869 (unsigned)std::abs((
long long)InstOffset - BlockToInstOffset[
TBB]) +
878 MachineInstr *SecondTerm = &*FTMII;
881 "Bad second terminator");
882 if (
MI != SecondTerm)
886 (unsigned)std::abs((
long long)InstOffset - BlockToInstOffset[FBB]) +
888 LLVM_DEBUG(
dbgs() <<
"\tSecond term offset(" << Distance <<
"): ";
898bool HexagonGlobalSchedulerImpl::isNewifiable(
900 MachineInstr *TargetPacket) {
901 MachineInstr *
MI = &*MII;
903 !CanNewifiedBeUsedInBundle(MII, DepReg, TargetPacket))
909bool HexagonGlobalSchedulerImpl::DemoteToDotOld(MachineInstr *
MI) {
911 MI->setDesc(QII->get(NewOpcode));
916void HexagonGlobalSchedulerImpl::initPacketizerState(
void) {
917 CurrentPacketMIs.clear();
922bool HexagonGlobalSchedulerImpl::ignoreInstruction(MachineInstr *
MI) {
923 if (
MI->isDebugInstr())
927 if (
MI->isInlineAsm())
932 const MCInstrDesc &TID =
MI->getDesc();
934 const InstrStage *
IS =
935 ResourceTracker->getInstrItins()->beginStage(SchedClass);
936 unsigned FuncUnits =
IS->getUnits();
942bool HexagonGlobalSchedulerImpl::isSoloInstruction(
const MachineInstr &
MI) {
943 if (
MI.isInlineAsm())
955 if (
MI.getOpcode() == Hexagon::A2_nop)
962BasicBlockRegion *HexagonGlobalSchedulerImpl::getRegionForMBB(
963 std::vector<BasicBlockRegion *> &Regions, MachineBasicBlock *
MBB) {
964 for (std::vector<BasicBlockRegion *>::iterator
I = Regions.begin(),
967 if ((*I)->findMBB(
MBB))
993HexagonGlobalSchedulerImpl::getNextPURBB(MachineBasicBlock *
MBB,
994 bool SecondBest =
false) {
998 BlockFrequency BestBlockFreq = BlockFrequency(0);
999 unsigned BestBlockSize = 0;
1000 MachineBasicBlock *BestBB = NULL;
1001 MachineBasicBlock *SecondBestBB = NULL;
1012 LLVM_DEBUG(
dbgs() <<
"\tsucc BB(" << Succ->getNumber() <<
") freq("
1015 if (!SecondBest && getRegionForMBB(PullUpRegions, Succ))
1020 if (Succ->pred_size() > 1)
1025 if (Succ->isEHPad() || Succ->hasAddressTaken())
1035 BestBlockFreq = EdgeFreq;
1037 SecondBestBB = BestBB;
1039 }
else if (!SecondBestBB) {
1040 SecondBestBB = Succ;
1044 return SecondBestBB;
1050bool HexagonGlobalSchedulerImpl::formPullUpRegions(
MachineFunction &Fn) {
1053 if (std::next(
F.begin()) ==
F.end())
1058 unsigned InstOffset = 0;
1060 LLVM_DEBUG(
dbgs() <<
"****** Form PullUpRegions **************\n");
1070 InstOffset = (InstOffset + ByteAlign) & ~(ByteAlign);
1073 BlockToInstOffset[&*
MBB] = InstOffset;
1077 if (!MII->isBundle())
1078 InstOffset += QII->
getSize(*MII);
1081 if (getRegionForMBB(PullUpRegions, &*
MBB))
1090 BasicBlockRegion *PUR =
new BasicBlockRegion(
TII, QRI, &*
MBB);
1091 PullUpRegions.push_back(PUR);
1093 for (MachineBasicBlock *MBBR = getNextPURBB(&*
MBB); MBBR;
1094 MBBR = getNextPURBB(MBBR)) {
1096 << MBBR->getName() <<
") size("
1099 << MBBR->getParent()->getFunction().getName() <<
")\n");
1109 if (
MI->hasUnmodeledSideEffects() ||
MI->hasOrderedMemoryRef() ||
1111 (
MI->getOpcode() == Hexagon::J2_jump && !
MI->getOperand(0).isMBB()))
1125 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
1138 for (
unsigned R = 1, NR = Hexagon::NUM_TARGET_REGS; R != NR; ++R)
1145void HexagonGlobalSchedulerImpl::MIUseDefSet(MachineInstr *
MI,
1146 std::vector<unsigned> &Defs,
1147 std::vector<unsigned> &
Uses) {
1150 assert(!
MI->isBundle() &&
"Cannot parse regs of a bundle.");
1151 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
1152 const MachineOperand &MO =
MI->getOperand(i);
1158 assert(Register::isPhysicalRegister(
Reg));
1159 std::vector<unsigned> &Refs = MO.
isUse() ?
Uses : Defs;
1160 for (MCRegAliasIterator AI(MO.
getReg(), QRI,
true); AI.isValid(); ++AI)
1161 Refs.push_back(*AI);
1163 for (
unsigned R = 1, NR = Hexagon::NUM_TARGET_REGS;
R != NR; ++
R)
1200bool HexagonGlobalSchedulerImpl::canAddMIToThisPacket(
1210 isJumpOutOfRange(
MI)) &&
1211 !tryAllocateResourcesForConstExt(
MI,
false))
1215 if (!ResourceTracker->canReserveResources(*
MI) || !shouldAddToPacket(*
MI)) {
1220 SmallVector<unsigned, 4> BundleDefs;
1221 SmallVector<unsigned, 8> BundleUses;
1222 SmallVector<unsigned, 4> Defs;
1223 SmallVector<unsigned, 8>
Uses;
1224 MachineInstr *FirstCompound = NULL, *SecondCompound = NULL;
1225 MachineInstr *FirstDuplex = NULL, *SecondDuplex = NULL;
1228 for (SmallVector<MachineInstr *, HEXAGON_PACKET_SIZE>::iterator
1229 BI = Bundle.
begin(),
1236 MachineInstr *Inst1 = *BI;
1237 MachineInstr *Inst2 =
MI;
1250 FirstCompound = *BI;
1252 SecondCompound = *BI;
1253 if (isCompoundPair(FirstCompound, SecondCompound)) {
1254 if (
MI->mayLoad() ||
MI->mayStore()) {
1268 if (
MI->mayLoad() ||
MI->mayStore()) {
1276 for (
unsigned i = 0; i < Defs.
size(); i++) {
1278 for (
unsigned j = 0;
j < BundleDefs.
size();
j++)
1283 if (AliasingRegs(Defs[i], BundleDefs[j]) &&
1285 !(IsDualJumpFirstCandidate(*BI) && IsDualJumpSecondCandidate(
MI))) {
1287 dbgs() <<
"\t"; (*BI)->dump());
1303 for (
unsigned j = 0;
j < BundleUses.
size();
j++)
1304 if (AliasingRegs(Defs[i], BundleUses[j])) {
1305 for (
unsigned k = 0;
k < BundleDefs.
size();
k++)
1306 for (
unsigned l = 0;
l <
Uses.size();
l++) {
1307 if (AliasingRegs(BundleDefs[k],
Uses[l]) &&
1310 dbgs() <<
"\t"; (*BI)->dump());
1317 for (
unsigned i = 0; i <
Uses.size(); i++) {
1319 for (
unsigned j = 0;
j < BundleDefs.
size();
j++)
1320 if (AliasingRegs(
Uses[i], BundleDefs[j]) &&
1324 MI->dump();
dbgs() <<
"\t"; (*BI)->dump());
1336 if ((*BI)->isCall()) {
1338 for (
unsigned i = 0; i < Defs.
size(); i++) {
1339 if (AliasingRegs(Defs[i], *
I)) {
1354 if ((*BI)->isBarrier()) {
1387 (
MI->mayStore() ||
MI->getOpcode() == Hexagon::S2_allocframe ||
1410 if ((QII->
isMemOp(**BI) &&
MI->mayStore()) ||
1411 (QII->
isMemOp(*
MI) && (*BI)->mayStore())) {
1413 dbgs() <<
"\tSlot 0 not available for store because of memop.\n");
1418 if ((
MI->mayLoad() && (*BI)->mayStore()) ||
1419 (
MI->mayStore() && (*BI)->mayLoad()) ||
1420 (
MI->mayStore() && (*BI)->mayStore())) {
1423 dbgs() <<
"\t"; (*BI)->dump());
1429 std::map<MachineInstr *, MachineBasicBlock *>::iterator MIMoved;
1430 MIMoved = SpeculatedIns.find(*BI);
1431 if ((MIMoved != SpeculatedIns.end()) &&
1432 (MIMoved->second != (*BI)->getParent())) {
1434 dbgs() <<
"This packet already contains a speculated instruction";
1450bool HexagonGlobalSchedulerImpl::ReorderDependencyTest(MachineInstr *MIa,
1451 MachineInstr *MIb) {
1452 SmallVector<unsigned, 4> DefsA;
1453 SmallVector<unsigned, 4> DefsB;
1454 SmallVector<unsigned, 8> UsesA;
1455 SmallVector<unsigned, 8> UsesB;
1460 for (SmallVector<unsigned, 4>::iterator IDA = DefsA.
begin(),
1462 IDA != IDAE; ++IDA) {
1463 for (SmallVector<unsigned, 8>::iterator IUB = UsesB.
begin(),
1467 if (AliasingRegs(*IDA, *IUB))
1470 for (SmallVector<unsigned, 4>::iterator IDB = DefsB.
begin(),
1474 if (AliasingRegs(*IDA, *IDB))
1478 for (SmallVector<unsigned, 4>::iterator IDB = DefsB.
begin(),
1480 IDB != IDBE; ++IDB) {
1481 for (SmallVector<unsigned, 8>::iterator IUA = UsesA.
begin(),
1485 if (AliasingRegs(*IDB, *IUA))
1496 for (
unsigned i = 0; i < DefsB.
size(); i++) {
1497 if (AliasingRegs(DefsB[i], *
I))
1504 for (
unsigned i = 0; i < DefsA.
size(); i++) {
1505 if (AliasingRegs(DefsA[i], *
I))
1527bool HexagonGlobalSchedulerImpl::MIsAreDependent(MachineInstr *MIa,
1528 MachineInstr *MIb) {
1532 if (ReorderDependencyTest(MIa, MIb)) {
1541bool HexagonGlobalSchedulerImpl::MIsHaveTrueDependency(MachineInstr *MIa,
1542 MachineInstr *MIb) {
1546 SmallVector<unsigned, 4> DefsA;
1547 SmallVector<unsigned, 4> DefsB;
1548 SmallVector<unsigned, 8> UsesA;
1549 SmallVector<unsigned, 8> UsesB;
1554 for (SmallVector<unsigned, 4>::iterator IDA = DefsA.
begin(),
1556 IDA != IDAE; ++IDA) {
1557 for (SmallVector<unsigned, 8>::iterator IUB = UsesB.
begin(),
1561 if (AliasingRegs(*IDA, *IUB))
1569bool HexagonGlobalSchedulerImpl::canReorderMIs(MachineInstr *MIa,
1570 MachineInstr *MIb) {
1578 for (++MII; MII != MIIE && MII->isInsideBundle(); ++MII) {
1579 if (MII->isDebugInstr())
1581 if (MIsAreDependent(&*MII, MIb))
1586 return !MIsAreDependent(MIa, MIb);
1596 if (
MI->isBranch() ||
MI->isReturn() ||
MI->isCall() ||
MI->isBarrier() ||
1604bool HexagonGlobalSchedulerImpl::MIisDualJumpCandidate(
1610 MachineBasicBlock *FromThisBB =
MI->getParent();
1611 MachineBasicBlock *ToThisBB = WorkPoint->getParent();
1614 << ToThisBB->
getNumber() <<
") From BB("
1618 if (FromThisBB == ToThisBB)
1624 if ((*(FromThisBB->
pred_begin()) != ToThisBB) ||
1635 MachineBasicBlock *ToTBB = NULL, *ToFBB = NULL;
1640 SmallVector<MachineOperand, 4> ToCond;
1641 if (!QII->
analyzeBranch(*ToThisBB, ToTBB, ToFBB, ToCond,
false)) {
1645 if (ToFBB)
dbgs() << ToFBB->getNumber() <<
").\n";
1646 else dbgs() <<
"None"
1648 if (ToTBB == FromThisBB) {
1652 }
else if (ToFBB == FromThisBB || !ToFBB) {
1661 }
else if (ToThisBB->
succ_size() == 1) {
1663 assert(ToFBB == FromThisBB &&
"Bad CFG layout");
1669 return IsDualJumpFirstCandidate(WorkPoint);
1676bool HexagonGlobalSchedulerImpl::canCauseStall(MachineInstr *
MI,
1678 SmallVector<unsigned, 4> DefsMJI;
1679 SmallVector<unsigned, 8> UsesMJI;
1680 SmallVector<unsigned, 4> DefsMI;
1681 SmallVector<unsigned, 8> UsesMI;
1684 for (
auto Use : UsesMI) {
1685 int UseIdx =
MI->findRegisterUseOperandIdx(Use,
nullptr);
1688 bool ShouldBreak =
false;
1689 int BundleCount = 0;
1693 MJI != Begin; --MJI) {
1694 if (MJI->isBundle()) {
1699 for (
auto Def : DefsMJI) {
1700 if (Def == Use || AliasingRegs(Def, Use)) {
1701 int DefIdx = MJI->findRegisterDefOperandIdx(Def,
nullptr);
1717 if (!MJI->isBundled() && !MJI->isDebugInstr())
1728bool HexagonGlobalSchedulerImpl::canThisMIBeMoved(
1730 bool &MovingDependentOp,
int &
Cost) {
1734 MovingDependentOp =
false;
1747 for (--MII; MII->isBundled(); --MII)
1748 if (MII->isBundle())
1752 for (++MII; MII != BBEnd && MII->isInsideBundle() && !MII->isBundle();
1756 if (isCompoundPair(&*MII,
MI)) {
1769 for (--MII; MII->isBundled(); --MII)
1770 if (MII->isBundle())
1774 for (++MII; MII != BBEnd && MII->isInsideBundle() && !MII->isBundle();
1789 if (MIisDualJumpCandidate(
MI, WorkPoint)) {
1794 MovingDependentOp =
true;
1804 unsigned dist_looplabel =
1805 BlockToInstOffset.
find(
MI->getOperand(0).getMBB())->second;
1806 unsigned dist_newloop0 =
1807 BlockToInstOffset.
find(WorkPoint->getParent())->second;
1810 (unsigned)std::abs((
long long)dist_looplabel - dist_newloop0) +
1812 const HexagonInstrInfo *HII = (
const HexagonInstrInfo *)
TII;
1815 << Distance <<
" outside branch range.";);
1818 LLVM_DEBUG(
dbgs() <<
"\nloopN can be moved since Distance: " << Distance
1819 <<
" within branch range.";);
1824 std::map<MachineInstr *, std::vector<unsigned>>::const_iterator DefIter =
1827 for (
unsigned i = 0; DefIter != MIDefSet.end() && i < DefIter->second.size();
1834 if (
MI->isBundled()) {
1843 for (--MII; MII->isBundled(); --MII)
1844 if (MII->isBundle())
1848 for (++MII; MII != BBEnd && MII->isInsideBundle() && !MII->isBundle();
1850 if (MII->isDebugInstr())
1852 if (MIsAreDependent(&*MII,
MI)) {
1861 IsDualJumpSecondCandidate(&*MII) ||
MI->isBranch()) {
1863 MovingDependentOp =
true;
1867 LLVM_DEBUG(
dbgs() <<
"\t\tDependent, and do not allow for now.\n");
1878bool HexagonGlobalSchedulerImpl::doesMIDefinesPredicate(
1879 MachineInstr *
MI, SmallVector<unsigned, 4> &Defs) {
1880 bool defsPredicate =
false;
1883 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
1884 const MachineOperand &MO =
MI->getOperand(i);
1894 assert(Register::isPhysicalRegister(
Reg));
1898 if (RC == &Hexagon::PredRegsRegClass) {
1899 defsPredicate =
true;
1904 return defsPredicate;
1912bool HexagonGlobalSchedulerImpl::NeedToNewify(
1914 MachineInstr *TargetPacket = NULL) {
1916 SmallVector<unsigned, 4> DefsA;
1917 SmallVector<unsigned, 4> DefsB;
1918 SmallVector<unsigned, 8> UsesB;
1929 if (TargetPacket && !TargetPacket->
isBundled()) {
1930 if (doesMIDefinesPredicate(TargetPacket, DefsA)) {
1931 for (SmallVector<unsigned, 4>::iterator IA = DefsA.
begin(),
1934 for (SmallVector<unsigned, 8>::iterator IB = UsesB.
begin(),
1946 for (--MII; MII->isBundled(); --MII)
1947 if (MII->isBundle())
1958 for (++MII; MII != BBEnd && MII->isBundled() && !MII->isBundle(); ++MII) {
1961 if (doesMIDefinesPredicate(&*MII, DefsA)) {
1962 for (SmallVector<unsigned, 4>::iterator IA = DefsA.
begin(),
1965 for (SmallVector<unsigned, 8>::iterator IB = UsesB.
begin(),
1985bool HexagonGlobalSchedulerImpl::CanNewifiedBeUsedInBundle(
1987 MachineInstr *TargetPacket) {
1989 if (!TargetPacket || !TargetPacket->
isBundled())
1993 for (--MII; MII->isBundled(); --MII)
1994 if (MII->isBundle())
1998 for (++MII; MII != BBEnd && MII->isBundled() && !MII->isBundle(); ++MII) {
2003 SmallVector<unsigned, 4> DefsA;
2004 if (!doesMIDefinesPredicate(&*MII, DefsA))
2006 for (
auto &IA : DefsA)
2015void HexagonGlobalSchedulerImpl::setUsedRegs(BitVector &Set,
unsigned Reg) {
2017 for (MCSubRegIterator SubRegs(
Reg, QRI); SubRegs.isValid(); ++SubRegs)
2018 Set.reset(*SubRegs);
2022bool HexagonGlobalSchedulerImpl::AliasingRegs(
unsigned RegA,
unsigned RegB) {
2026 for (MCSubRegIterator SubRegs(RegA, QRI); SubRegs.isValid(); ++SubRegs)
2027 if (RegB == *SubRegs)
2030 for (MCSubRegIterator SubRegs(RegB, QRI); SubRegs.isValid(); ++SubRegs)
2031 if (RegA == *SubRegs)
2039 if (
MI->isDebugInstr())
2042 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
2055 if (
MI->isDebugInstr())
2058 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
2071void HexagonGlobalSchedulerImpl::updateKillAlongThePath(
2072 MachineBasicBlock *HomeBB, MachineBasicBlock *OriginBB,
2077 std::vector<MachineInstr *> &backtrack) {
2079 MachineInstr *
MI = &*Head;
2080 MachineBasicBlock *CurrentBB = OriginBB;
2081 SmallSet<unsigned, 8> KilledUseSet;
2083 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
2084 const MachineOperand &MO =
MI->getOperand(i);
2096 if (KilledUseSet.
empty())
2106 <<
")kills. From BB (" << OriginBB->
getNumber() <<
")\n");
2108 assert(!backtrack.empty() &&
"Empty back track");
2114 for (
signed i = backtrack.size() - 1; i >= 0; --i) {
2116 << backtrack[i]->
getParent()->getNumber() <<
")\t";
2117 backtrack[i]->dump());
2118 if (CurrentBB != backtrack[i]->
getParent()) {
2120 <<
") to(" << backtrack[i]->getParent()->getNumber()
2126 if (*SI == CurrentBB)
2133 E = (*SI)->livein_end();
2135 if (KilledUseSet.
count((*I).PhysReg)) {
2137 <<
") is LiveIn along side exit.\n");
2138 KilledUseSet.
erase((*I).PhysReg);
2141 if (KilledUseSet.
empty())
2145 CurrentBB = backtrack[i]->getParent();
2149 if (backtrack[i] == &*TargetPacket)
2155 if (backtrack[i] == &*SourcePacket)
2159 if (backtrack[i]->isDebugInstr())
2165 SmallVector<unsigned, 4> Defs;
2166 SmallVector<unsigned, 8>
Uses;
2167 MachineInstr *MIU = backtrack[i];
2170 for (SmallVector<unsigned, 8>::iterator IA =
Uses.begin(), IAE =
Uses.end();
2172 if (KilledUseSet.
count(*IA)) {
2184 for (++MII; MII !=
End && MII->isInsideBundle(); ++MII)
2189 KilledUseSet.
erase(*IA);
2192 if (KilledUseSet.
empty())
2200void HexagonGlobalSchedulerImpl::addInstructionToExistingBundle(
2206 std::vector<MachineInstr *> &backtrack) {
2213 if (Outcast->isBundle() && Outcast->isBundledWithSucc())
2214 Outcast->unbundleFromSucc();
2221 if (memShufDisabled)
2229 for (
unsigned i = 0; i < backtrack.size(); ++i)
2230 if (backtrack[i] == &*Outcast)
2231 backtrack[i] = &*Head;
2234 if (NextMI == Outcast)
2237 TargetPacket = Head;
2238 HomeBB->
erase(Outcast);
2243void HexagonGlobalSchedulerImpl::removeInstructionFromExistingBundle(
2248 std::vector<MachineInstr *> &backtrack) {
2250 if (HomeBB->
empty()) {
2256 if (!SourceLocation->isBundle()) {
2257 LLVM_DEBUG(
dbgs() <<
"\t\t\tOriginal instruction was not bundled.\n\t\t\t";
2258 SourceLocation->dump());
2263 for (
unsigned i = 0; i < backtrack.size(); ++i) {
2264 if (backtrack[i] == &*SourceLocation) {
2266 assert((backtrack[i] == backtrack.back()) &&
"Lost back track");
2267 backtrack.pop_back();
2270 if (NextMI == SourceLocation)
2281 LLVM_DEBUG(
dbgs() <<
"\t\t\t[Rem] SourceLocation after bundle update: ";
2287 if (!SourceLocation->isBundledWithSucc()) {
2288 assert(!Head->isBundledWithSucc() && !Head->isBundledWithPred() &&
2294 unsigned BBSizeWithDbg = 0;
2298 for (++
I;
I !=
E &&
I->isBundledWithPred(); ++
I) {
2300 if (!
I->isDebugInstr())
2311 if (Outcast->isBundle() && Outcast->isBundledWithSucc())
2312 Outcast->unbundleFromSucc();
2325 if (memShufDisabled)
2329 }
else if (
Size == 1) {
2331 if (BBSizeWithDbg > 1) {
2335 for (++
I;
I !=
E &&
I->isBundledWithPred(); ++
I) {
2336 I->unbundleFromPred();
2338 if (!
I->isDebugInstr())
2346 if (Head->isBundledWithPred())
2347 Head->unbundleFromPred();
2348 if (Head->isBundledWithSucc())
2349 Head->unbundleFromSucc();
2352 for (MachineOperand &MO : Head->all_uses())
2359 SourceLocation = Head;
2363 for (
unsigned i = 0; i < backtrack.size(); ++i)
2364 if (backtrack[i] == &*Outcast)
2365 backtrack[i] = &*Head;
2368 if (NextMI == Outcast)
2371 HomeBB->
erase(Outcast);
2379 SE =
MBB->succ_end();
2381 LLVM_DEBUG(
dbgs() <<
"\tSuccessor BB (" << (*SI)->getNumber() <<
"):");
2383 E = (*SI)->livein_end();
2398 if (!
MBBI->isDebugInstr())
2408 if (!
MI || !
MI->isBranch() ||
MI->isBundle())
2411 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
2421bool HexagonGlobalSchedulerImpl::AnalyzeBBBranches(MachineBasicBlock *
MBB,
2422 MachineBasicBlock *&
TBB,
2423 MachineInstr *&FirstTerm,
2424 MachineBasicBlock *&FBB,
2425 MachineInstr *&SecondTerm) {
2448 if (MII->isBranch())
2452 while (MII != MIE) {
2453 if (!MII->isBundle() && MII->isBranch()) {
2464 LLVM_DEBUG(
dbgs() <<
"\n\t\tCannot analyze BB with indirect branch.");
2467 if ((FirstTerm && FirstTerm->
getOpcode() == Hexagon::J2_jump &&
2469 (SecondTerm && SecondTerm->
getOpcode() == Hexagon::J2_jump &&
2472 dbgs() <<
"\n\t\tCannot analyze BB with a branch out of function.");
2477 SmallVector<MachineOperand, 4>
Cond;
2479 LLVM_DEBUG(
dbgs() <<
"\t\tFail to analyze with analyzeBranch.\n");
2481 else dbgs() <<
"None\n";);
2498 if (FirstTerm && SecondTerm &&
2507 }
else if (SecondTerm && SecondTerm->
getOpcode() == Hexagon::J2_jump &&
2520 <<
") FBB(" << FBB->
getNumber() <<
").\n");
2535 assert(MBBIter != MF.
end() &&
"I give up.");
2542 else if (FBB ==
S1) {
2548 MBBIter = MF.
begin();
2551 assert(MBBIter != MF.
end() &&
"Malformed BB with invalid successors");
2559 <<
") FBB(" << FBB->
getNumber() <<
").\n");
2563 assert(!FirstTerm &&
"Bad BB");
2567 if (!FBB && SecondTerm) {
2583 LLVM_DEBUG(
dbgs() <<
"Possibly the layout successor is an empty BB");
2587 LLVM_DEBUG(
dbgs() <<
"Malformed branch with useless branch condition";);
2590 }
else if (
TBB && !FBB) {
2606 else dbgs() <<
"\t\tFinal FBB(None)\n";);
2653 Pred->ReplaceUsesOfBlockWith(&
MBB, MFBB);
2664 bool RemoveLSIfPresent =
false;
2666 LLVM_DEBUG(
dbgs() <<
"\nNew firstterm conditional jump added to HomeBB";);
2670 LLVM_DEBUG(
dbgs() <<
"\nNew secondterm conditional jump added to HomeBB";);
2674 LLVM_DEBUG(
dbgs() <<
"\nBranch destination for pulled instruction is BB#"
2675 << Dest->getNumber(););
2680 LLVM_DEBUG(
dbgs() <<
"\nNew firstterm unconditional jump added to HomeBB";);
2683 RemoveLSIfPresent =
true;
2686 dbgs() <<
"\nNew secondterm unconditional jump added to HomeBB";);
2689 RemoveLSIfPresent =
true;
2696 if (RemoveLSIfPresent) {
2701 LLVM_DEBUG(
dbgs() <<
"\nRemoving LayoutSucc BB#" << HomeBBLS->getNumber()
2702 <<
"from list of successors";);
2711MachineInstr *HexagonGlobalSchedulerImpl::MoveAndUpdateLiveness(
2712 BasicBlockRegion *CurrentRegion, MachineBasicBlock *HomeBB,
2713 MachineInstr *InstrToMove,
bool NeedToNewify,
unsigned DepReg,
2714 bool MovingDependentOp, MachineBasicBlock *OriginBB,
2715 MachineInstr *OriginalInstruction, SmallVector<MachineOperand, 4> &
Cond,
2719 std::vector<MachineInstr *> &backtrack) {
2721 dbgs() <<
"\n...............[MoveAndUpdateLiveness]..............\n");
2724 OriginalInstruction->
dump());
2738 HomeBB->
erase(kill_it);
2749 std::list<MachineBasicBlock *> WorkList;
2752 for (std::vector<MachineInstr *>::iterator RI = backtrack.begin(),
2753 RIE = backtrack.end();
2755 WorkList.push_back((*RI)->getParent());
2764 TargetHead->getParent()->instr_end();
2765 bool LastInstructionInBundle =
false;
2767 TargetPacket, &*OutcastFrom, LastInstructionInBundle);
2775 MIBundleBuilder Bundle(&*TargetHead);
2785 if (OriginalInstruction->
getIterator() == TargetTail) {
2792 if (OutcastFrom->isBundledWithSucc()) {
2795 }
else if (OutcastFrom->isBundledWithPred()) {
2796 OutcastFrom->unbundleFromPred();
2798 HomeBB->
splice(MII, OriginBB, OutcastFrom);
2799 if (!MII->isBundledWithPred())
2800 MII->bundleWithPred();
2801 if (!LastInstructionInBundle && !MII->isBundledWithSucc())
2802 MII->bundleWithSucc();
2804 if (!MIIToPred->isBundledWithSucc())
2805 MIIToPred->bundleWithSucc();
2823 updateKillAlongThePath(HomeBB, OriginBB, MII, TargetTail, SourceLocation,
2824 TargetPacket, backtrack);
2833 DemoteToDotOld(&*MII);
2848 assert((DepReg < std::numeric_limits<unsigned>::max()) &&
2849 "Invalid pred reg value");
2851 <<
printReg(DepReg, QRI) <<
").\n");
2853 MII->setDesc(QII->get(NewOpcode));
2858 for (
unsigned i = 0, e = MII->getNumOperands(); i != e; ++i) {
2859 MachineOperand &MO = MII->getOperand(i);
2864 if (DepReg == MO.
getReg())
2868 LLVM_DEBUG(
dbgs() <<
"\t\t\tNew predicated form:\t"; MII->dump());
2871 updateKillAlongThePath(HomeBB, OriginBB, MII, TargetTail, SourceLocation,
2872 TargetPacket, backtrack);
2876 addInstructionToExistingBundle(HomeBB, TargetHead, TargetTail, MII,
2877 TargetPacket, NextMI, backtrack);
2880 removeInstructionFromExistingBundle(OriginBB, ++OriginalHead, OriginalTail,
2881 SourceLocation, NextMI, MovingDependentOp,
2894 QII->
isEndLoopN(OriginalHead->getOpcode())) {
2900 if (OriginBB->
begin() !=
I) {
2902 if (
I->isBundled()) {
2903 if (!
I->isBundledWithSucc())
2904 I->bundleWithSucc();
2905 if (!OriginalHead->isBundledWithPred())
2906 OriginalHead->bundleWithPred();
2911 }
else if (MovingDependentOp &&
2913 if (OriginalHead->isBundled()) {
2915 J != OriginalTail && J->isInsideBundle() && !J->isBundle(); ++J) {
2917 if (MIsHaveTrueDependency(OriginalInstruction, &*J) &&
2920 DemoteToDotOld(&*J);
2925 if (MIsHaveTrueDependency(OriginalInstruction, &*OriginalHead) &&
2928 OriginalHead->dump());
2929 DemoteToDotOld(&*OriginalHead);
2942 for (std::list<MachineBasicBlock *>::iterator BBI = WorkList.begin(),
2943 BBIE = WorkList.end();
2944 BBI != BBIE; BBI++) {
2950 MachineBasicBlock *BB = WorkList.back();
2951 WorkList.pop_back();
2953 }
while (!WorkList.empty());
2956 if (OriginBB == HomeBB)
2957 return &*TargetHead;
2960 MachineBasicBlock *HomeTBB, *HomeFBB;
2961 MachineInstr *FTA = NULL, *STA = NULL;
2962 bool HomeBBAnalyzed = !AnalyzeBBBranches(HomeBB, HomeTBB, FTA, HomeFBB, STA);
2963 if (MII->isBranch()) {
2964 if (HomeBBAnalyzed) {
2965 UpdateCFG(HomeBB, OriginBB, &*MII, HomeTBB, HomeFBB, FTA, STA, MBPI);
2980 EmptyBBs.push_back(OriginBB);
2982 return &*TargetHead;
2986 MachineBasicBlock *CommonFBB = *OriginBB->
succ_begin();
2992 assert((OriginBB->
succ_size() == 2) &&
"Underimplemented 3way branch.");
2993 MachineBasicBlock *OriginTBB, *OriginFBB;
2994 MachineInstr *FTB = NULL, *STB = NULL;
2997 if (HomeBBAnalyzed &&
2998 !AnalyzeBBBranches(OriginBB, OriginTBB, FTB, OriginFBB, STB)) {
2999 assert(OriginFBB &&
"Missing Origin FBB");
3000 if (HomeFBB == OriginBB) {
3002 if (HomeTBB == OriginTBB) {
3005 }
else if (HomeTBB == OriginFBB) {
3016 }
else if (HomeTBB == OriginBB) {
3018 if (HomeFBB == OriginTBB) {
3021 }
else if (HomeFBB == OriginFBB) {
3043 return &*TargetHead;
3049HexagonGlobalSchedulerImpl::findInsertPositionInBundle(
3058 assert(MII->isBundle() &&
"Missing insert location");
3059 bool isDualJumpSecondCandidate = IsDualJumpSecondCandidate(
MI);
3060 LastInBundle =
false;
3062 for (++MII; MII != BBEnd && MII->isInsideBundle() && !MII->isBundle();
3064 if (MII->isBranch() && (FirstBranch == BBEnd))
3068 if (isDualJumpSecondCandidate && IsDualJumpFirstCandidate(&*MII))
3069 DualJumpFirstCandidate = MII;
3070 LastBundledInstruction = MII;
3073 if (DualJumpFirstCandidate != BBEnd) {
3075 ++DualJumpFirstCandidate;
3076 if (DualJumpFirstCandidate == BBEnd ||
3077 DualJumpFirstCandidate == LastBundledInstruction)
3078 LastInBundle =
true;
3079 return DualJumpFirstCandidate;
3080 }
else if (FirstBranch != BBEnd) {
3085 }
else if (LastBundledInstruction != BBEnd) {
3086 LastInBundle =
true;
3087 return ++LastBundledInstruction;
3098 MachineInstr *
MI,
bool DeleteOldCopy) {
3102 assert(CurrentBB &&
"Corrupt instruction");
3109 MachineInstr *NewMI =
MI->getParent()->getParent()->CloneMachineInstr(
MI);
3116 if (DeleteOldCopy) {
3121 CurrentBB->
erase(kill_it);
3128 DemoteToDotOld(NewMI);
3133 if (TargetPacket->getParent() ==
MBB) {
3136 if (MII->isBundled()) {
3137 bool LastInBundle =
false;
3139 findInsertPositionInBundle(TargetPacket, NewMI, LastInBundle);
3140 MIBundleBuilder Bundle(&*TargetPacket);
3141 Bundle.insert(InsertBefore, NewMI);
3148 while (MII->isDebugInstr())
3151 if (MII->isBundled()) {
3152 MIBundleBuilder Bundle(&*MII);
3153 Bundle.insert(++MII, NewMI);
3161bool HexagonGlobalSchedulerImpl::MIsCondAssign(MachineInstr *BMI,
3163 SmallVector<unsigned, 4> &Defs) {
3167 SmallVector<unsigned, 4> CondDefs;
3168 SmallVector<unsigned, 8> CondUses;
3171 for (SmallVector<unsigned, 4>::iterator ID = Defs.
begin(), IDE = Defs.
end();
3173 for (SmallVector<unsigned, 4>::iterator CID = CondDefs.
begin(),
3174 CIDE = CondDefs.
end();
3175 CID != CIDE; ++CID) {
3176 if (AliasingRegs(*CID, *ID)) {
3190template <
typename ElemType,
typename IndexType>
3192 std::map<ElemType, std::vector<IndexType>> &Set1,
3193 std::map<ElemType, std::vector<IndexType>> &Set2,
3194 std::pair<std::vector<IndexType>, std::vector<IndexType>> &UnionSet,
3195 unsigned union_size = 100) {
3197 typename std::map<ElemType, std::vector<IndexType>>
::iterator PosIter_t;
3198 typedef typename std::vector<IndexType>::iterator IndexIter_t;
3199 std::vector<IndexType> &Union1 = UnionSet.first;
3200 std::vector<IndexType> &Union2 = UnionSet.second;
3201 Union1.resize(union_size, 0);
3202 Union2.resize(union_size, 0);
3204 typename std::vector<ElemType>::iterator iter =
Range.begin();
3205 while (iter !=
Range.end()) {
3206 if ((*iter)->isDebugInstr()) {
3211 PosIter_t set1_pos = Set1.find(*iter);
3212 assert(set1_pos != Set1.end() &&
3213 "Set1 should contain an entry for each element in Range.");
3214 IndexIter_t set1idx = set1_pos->second.begin();
3215 while (set1idx != set1_pos->second.end()) {
3216 Union1[*set1idx] = 1;
3219 PosIter_t set2_pos = Set2.find(*iter);
3220 assert(set2_pos != Set2.end() &&
3221 "Set2 should contain an entry for each element in Range.");
3222 IndexIter_t set2idx = set2_pos->second.begin();
3223 while (set2idx != set2_pos->second.end()) {
3224 Union2[*set2idx] = 1;
3241 MI->unbundleFromPred();
3250bool HexagonGlobalSchedulerImpl::canMIBeSpeculated(
3251 MachineInstr *
MI, MachineBasicBlock *ToBB, MachineBasicBlock *FromBB,
3252 std::vector<MachineInstr *> &backtrack) {
3275 if (!
MI->isDereferenceableInvariantLoad())
3280 SmallVector<unsigned, 4> Defs;
3281 SmallVector<unsigned, 8>
Uses;
3285 for (
unsigned R : Defs)
3298 LLVM_DEBUG(
dbgs() <<
"\tTarget succesor BB to check:\n"; (*SI)->dump());
3301 SIE = (*SI)->succ_end();
3302 SII != SIE; ++SII)(*SII)
3305 E = (*SI)->livein_end();
3307 for (SmallVector<unsigned, 4>::iterator ID = Defs.begin(),
3310 if (AliasingRegs((*I).PhysReg, *ID))
3317 E = (*SI)->instr_end();
3319 if (BI->isBundle() || BI->isDebugInstr())
3322 if (MIsCondAssign(&*BI,
MI, Defs))
3330 std::vector<MachineBasicBlock *> PathBB;
3331 for (
unsigned i = 0; i < backtrack.size(); ++i) {
3333 MachineBasicBlock *
MBB = backtrack[i]->getParent();
3334 if ((
MBB != FromBB) &&
3335 (std::find(PathBB.begin(), PathBB.end(),
MBB) == PathBB.end()))
3336 PathBB.push_back(
MBB);
3338 bool WaitingForTargetPacket =
true;
3340 std::vector<MachineInstr *> TraversalRange;
3348 for (
unsigned i = 0; i < PathBB.size(); ++i) {
3349 for (MII = PathBB[i]->instr_begin(); MII != PathBB[i]->instr_end(); ++MII) {
3353 if (backtrack[0] == &*MII)
3354 WaitingForTargetPacket =
false;
3355 if (WaitingForTargetPacket)
3357 if (MII->isBundle())
3364 if (MII->isCall() || MII->isReturn() ||
3365 (MII->getOpcode() == Hexagon::J2_jump && !MII->getOperand(0).isMBB()))
3368 TraversalRange.push_back(&*MII);
3374 std::pair<std::vector<unsigned>, std::vector<unsigned>> RangeDefUse;
3375 Unify(TraversalRange, MIDefSet, MIUseSet, RangeDefUse, QRI->getNumRegs());
3377 for (
unsigned j = 0;
j <
Uses.size(); ++
j)
3378 if (RangeDefUse.first[
Uses[j]]) {
3379 LLVM_DEBUG(
dbgs() <<
"\n\t\tUnresolved dependency along path to HOME for "
3385 for (
unsigned j = 0;
j < Defs.size(); ++
j)
3386 if (RangeDefUse.first[Defs[j]] || RangeDefUse.second[Defs[j]]) {
3387 LLVM_DEBUG(
dbgs() <<
"\n\t\tUnresolved dependency along path to HOME for "
3410bool HexagonGlobalSchedulerImpl::MoveMItoBundle(
3411 BasicBlockRegion *CurrentRegion,
3416 std::vector<MachineInstr *> &backtrack,
bool MovingDependentOp,
3417 bool PathInRegion) {
3418 MachineBasicBlock *HomeBB = TargetPacket->getParent();
3419 MachineBasicBlock *OriginBB = InstrToMove->
getParent();
3420 MachineBasicBlock *CurrentBB = OriginBB;
3421 MachineBasicBlock *CleanupBB = OriginBB;
3422 MachineBasicBlock *PreviousBB = OriginBB;
3423 MachineInstr *OriginalInstructionToMove = &*InstrToMove;
3425 assert(HomeBB &&
"Missing HomeBB");
3426 assert(OriginBB &&
"Missing OriginBB");
3428 LLVM_DEBUG(
dbgs() <<
"\n.........[MoveMItoBundle]..............\n");
3429 LLVM_DEBUG(
dbgs() <<
"\t\tInstrToMove :\t"; InstrToMove->dump());
3436 if (HomeBB == OriginBB) {
3452 for (
unsigned i = 0; i < backtrack.size(); ++i) {
3455 << backtrack[i]->
getParent()->getNumber() <<
")\t";
3456 backtrack[i]->dump());
3460 bool NeedCleanup =
false;
3461 bool NeedToPredicate =
false;
3462 bool MINeedToNewify =
false;
3463 unsigned DepReg = std::numeric_limits<unsigned>::max();
3464 bool isDualJump =
false;
3465 SmallVector<MachineOperand, 4>
Cond;
3466 SmallVector<MachineOperand, 4> PredCond;
3467 std::vector<MachineInstr *> PullUpPath;
3469 PullUpPath = backtrack;
3471 PullUpPath.push_back(&*TargetPacket);
3472 PullUpPath.push_back(&*InstrToMove);
3478 for (std::vector<MachineInstr *>::reverse_iterator RI = backtrack.rbegin(),
3479 RIE = backtrack.rend();
3483 MachineInstr *MIWH = *RI;
3486 InstrToMove->dump());
3488 CleanupBB->
erase(InstrToMove);
3491 if (canCauseStall(&*InstrToMove, MIWH)) {
3493 CleanupBB->
erase(InstrToMove);
3503 bool isBranchMIWH =
isBranch(MIWH);
3504 if (((&*SourceLocation != MIWH) && isBranchMIWH) ||
3508 PreviousBB = CurrentBB;
3512 MachineBasicBlock *PredTBB = NULL;
3513 MachineBasicBlock *PredFBB = NULL;
3524 if (!canMIBeSpeculated(&*InstrToMove, CurrentBB, PreviousBB,
3527 CleanupBB->
erase(InstrToMove);
3531 SpeculatedIns.insert(
3532 std::make_pair(OriginalInstructionToMove, OriginBB));
3533 LLVM_DEBUG(
dbgs() <<
"\nSpeculatedInsToMove"; InstrToMove->dump());
3541 if (NeedToPredicate) {
3543 <<
"\tUnderimplemented pred for speculative move.\n");
3545 CleanupBB->
erase(InstrToMove);
3549 insertTempCopy(CurrentBB, TargetPacket, &*InstrToMove, NeedCleanup);
3551 NeedToPredicate =
false;
3552 assert(!NeedToPredicate &&
"Need to handle predication for this case");
3553 CleanupBB = CurrentBB;
3557 bool LocalNeedPredication =
true;
3559 if (!isBranchMIWH && !PredTBB) {
3560 LLVM_DEBUG(
dbgs() <<
"\tDo not need predicate for this case.\n");
3561 LocalNeedPredication =
false;
3564 if (IsDualJumpSecondCandidate(&*InstrToMove) &&
3565 IsDualJumpFirstCandidate(TargetPacket)) {
3568 }
else if (LocalNeedPredication && (PredFBB != PreviousBB)) {
3574 if (PreviousBB != PredTBB) {
3579 CleanupBB->
erase(InstrToMove);
3584 <<
")InvertCondition("
3585 << (PreviousBB != PredTBB) <<
")\n");
3590 InstrToMove = insertTempCopy(CurrentBB, TargetPacket, &*InstrToMove,
3593 NeedToPredicate =
true;
3594 CleanupBB = CurrentBB;
3596 if (PredCond.
empty() &&
3599 InstrToMove->dump());
3606 isJumpOutOfRange(&*InstrToMove)) &&
3607 !tryAllocateResourcesForConstExt(&*InstrToMove,
false)) {
3610 <<
"\tEI Could not be added to the packet.\n");
3611 CleanupBB->
erase(InstrToMove);
3615 if (!ResourceTracker->canReserveResources(*InstrToMove) ||
3616 !shouldAddToPacket(*InstrToMove)) {
3619 CurrentBB->
erase(InstrToMove);
3624 if (NeedToNewify(InstrToMove, &DepReg, &*TargetPacket)) {
3625 if (isNewifiable(InstrToMove, DepReg, &*TargetPacket)) {
3626 MINeedToNewify =
true;
3628 <<
printReg(DepReg, QRI) <<
").\n");
3631 InstrToMove->dump());
3632 CleanupBB->
erase(InstrToMove);
3641 MIUseSet[OriginalInstructionToMove].push_back(
Cond[1].
getReg());
3645 "Update MIUseSet for new-value compare jumps");
3649 InstrToMove->dump());
3650 bool DistantSpeculation =
false;
3651 std::vector<MachineInstr *> NonPredPullUpPath;
3656 while (btidx < backtrack.size()) {
3657 const MachineBasicBlock *btBB = backtrack[btidx]->getParent();
3658 if ((btBB == PreviousBB) || (btBB == CurrentBB))
3659 NonPredPullUpPath.push_back(backtrack[btidx]);
3663 if (PreviousBB != CurrentBB) {
3664 if (*(PreviousBB->
pred_begin()) != CurrentBB) {
3666 DistantSpeculation =
true;
3668 <<
"\n\tMI not in immediate successor of BB#"
3669 << CurrentBB->
getNumber() <<
", MI is in BB#"
3673 "Region with a side entry");
3676 if (DistantSpeculation ||
3677 InstrToMove->mayLoad() || InstrToMove->mayStore() ||
3678 InstrToMove->hasUnmodeledSideEffects() ||
3679 !canMIBeSpeculated(&*InstrToMove, CurrentBB, PreviousBB,
3680 NonPredPullUpPath)) {
3681 CleanupBB->
erase(InstrToMove);
3685 NeedToPredicate =
false;
3686 SpeculatedIns.insert(
3687 std::make_pair(OriginalInstructionToMove, OriginBB));
3689 InstrToMove->dump());
3696 InstrToMove->dump());
3699 InstrToMove->mayLoad() || InstrToMove->mayStore() ||
3700 InstrToMove->hasUnmodeledSideEffects() ||
3701 !canMIBeSpeculated(&*InstrToMove, CurrentBB, PreviousBB,
3704 CleanupBB->
erase(InstrToMove);
3708 SpeculatedIns.insert(
3709 std::make_pair(OriginalInstructionToMove, OriginBB));
3711 InstrToMove->dump());
3714 InstrToMove = insertTempCopy(CurrentBB, TargetPacket, &*InstrToMove,
3717 CleanupBB = CurrentBB;
3722 <<
"\tCurrentBB:" << CurrentBB->
getNumber()
3723 <<
"\tPreviousBB:" << PreviousBB->
getNumber();
3725 <<
"\tPredFBB:" << PredFBB->
getNumber(););
3729 if (IsDualJumpSecondCandidate(&*InstrToMove)) {
3731 LLVM_DEBUG(
dbgs() <<
"\tUnderimplemented dual jump formation.\n");
3733 CleanupBB->
erase(InstrToMove);
3740 CleanupBB->
erase(InstrToMove);
3743 SpeculatedIns.insert(
3744 std::make_pair(OriginalInstructionToMove, OriginBB));
3746 InstrToMove->dump());
3748 InstrToMove = insertTempCopy(CurrentBB, TargetPacket, &*InstrToMove,
3751 NeedToPredicate =
false;
3752 CleanupBB = CurrentBB;
3760 if (MIWH == backtrack.front()) {
3771 if (!(MovingDependentOp && (MIWH == &*SourceLocation)) &&
3772 !canReorderMIs(MIWH, &*InstrToMove)) {
3774 CleanupBB->
erase(InstrToMove);
3781 isJumpOutOfRange(&*InstrToMove)) {
3782 if (!tryAllocateResourcesForConstExt(&*InstrToMove))
3791 if (MovingDependentOp)
dbgs() <<
"dependent op";
dbgs() <<
": ";
3792 InstrToMove->dump();
dbgs() <<
"To BB:\n"; HomeBB->
dump();
3793 dbgs() <<
"From BB:\n"; OriginBB->
dump());
3797 HexagonNumPullUps++;
3799 HexagonNumDualJumps++;
3805 insertTempCopy(HomeBB, TargetPacket, &*InstrToMove, NeedCleanup);
3813 if (!TargetPacket->isBundle()) {
3816 std::next(InstrToMove));
3823 for (
unsigned i = 0; i < backtrack.size(); ++i)
3824 if (backtrack[i] == &*TargetPacket)
3825 backtrack[i] = &*MII;
3828 if (NextMI == TargetPacket)
3834 MoveAndUpdateLiveness(CurrentRegion, HomeBB, &*InstrToMove, MINeedToNewify,
3835 DepReg, MovingDependentOp, OriginBB,
3836 OriginalInstructionToMove, PredCond, SourceLocation,
3837 TargetPacket, NextMI, backtrack);
3846bool HexagonGlobalSchedulerImpl::isBranchWithinRegion(
3847 BasicBlockRegion *CurrentRegion, MachineInstr *
MI) {
3848 assert(
MI &&
MI->isBranch() &&
"Missing call info");
3852 <<
") Branch instr:\t";
3862 MachineBasicBlock *NextRegionBB;
3863 MachineBasicBlock *
TBB, *FBB;
3864 MachineInstr *FirstTerm = NULL;
3865 MachineInstr *SecondTerm = NULL;
3867 if (AnalyzeBBBranches(
MBB,
TBB, FirstTerm, FBB, SecondTerm)) {
3900 else dbgs() <<
"None\n";);
3912 if (!NextRegionBB) {
3921 if (
MI == FirstTerm) {
3923 <<
") NextBB in the region(" << NextRegionBB->
getNumber()
3925 return (
TBB == NextRegionBB);
3927 assert(FBB &&
"Corrupt BB layout");
3931 if ((
MI != SecondTerm)) {
3932 LLVM_DEBUG(
dbgs() <<
"\t\tDual terminator not matching SecondTerm.\n");
3937 <<
") NextBB in the region(" << NextRegionBB->
getNumber()
3939 return (FBB == NextRegionBB);
3946bool HexagonGlobalSchedulerImpl::isJumpOutOfRange(MachineInstr *UnCond,
3947 MachineInstr *
Cond) {
3948 if (!UnCond || !UnCond->
isBranch())
3951 MachineBasicBlock *UnCondBB = UnCond->
getParent();
3952 MachineBasicBlock *CondBB =
Cond->getParent();
3958 unsigned InstOffset = BlockToInstOffset[UnCondBB];
3959 unsigned Distance = 0;
3966 MachineBasicBlock *
TBB = NULL, *FBB = NULL;
3967 SmallVector<MachineOperand, 4> CondList;
3977 if (
TBB && (
Cond == FirstTerm)) {
3979 (unsigned)std::abs((
long long)InstOffset - BlockToInstOffset[
TBB]) +
3988MachineInstr *HexagonGlobalSchedulerImpl::findBundleAndBranch(
3993 MachineInstr *CondBranch = NULL;
3997 MII != MBBEnd; ++MII) {
3998 MachineInstr *
MI = &*MII;
3999 if (MII->isConditionalBranch()) {
4006 if (!MII->isBundled())
4009 for (--MII; MII->isBundled(); --MII)
4010 if (MII->isBundle()) {
4022bool HexagonGlobalSchedulerImpl::pullUpPeelBBLoop(MachineBasicBlock *PredBB,
4023 MachineBasicBlock *LoopBB) {
4026 if (!LoopBB || !PredBB)
4041 MachineBasicBlock *SuccBB = NULL;
4045 if (*SI != LoopBB) {
4054 MachineInstr *PredCondBranch = NULL;
4055 PredCondBranch = findBundleAndBranch(PredBB, PredBundle);
4056 if (!PredCondBranch)
4058 if (PredBundle == PredBB->
end())
4066 while (FMI->isDebugInstr())
4069 MachineInstr *RegMI = &*FMI;
4072 if (RegMI->
getOpcode() != Hexagon::A2_tfr)
4081 BasicBlockRegion PUR(BasicBlockRegion(
TII, QRI, PredBB));
4086 if (!ResourcesAvailableInBundle(&PUR, PredBundle))
4089 CurrentState.HomeBundle);
4092 MachineBasicBlock *
TBB = NULL, *FBB = NULL;
4093 SmallVector<MachineOperand, 4>
Cond;
4100 MachineBasicBlock *LTBB = NULL, *LFBB = NULL;
4101 SmallVector<MachineOperand, 4> LCond;
4110 MachineInstr *InstrToMove =
4111 &*insertTempCopy(PredBB, PredBundle, RegMI,
false);
4112 if (!canAddMIToThisPacket(InstrToMove, PredBundlePkt)) {
4124 unsigned DepReg = 0;
4125 if (NeedToNewify(InstrToMove->
getIterator(), &DepReg, &*PredBundle) &&
4126 !isNewifiable(InstrToMove->
getIterator(), DepReg, &*PredBundle)) {
4137 InstrToMove->
setDesc(QII->get(NewOpcode));
4138 if (!incrementalAddToPacket(*InstrToMove)) {
4145 MachineInstr *LoopCondBranch = NULL;
4146 LoopCondBranch = findBundleAndBranch(LoopBB, LoopBundle);
4147 if (!LoopCondBranch)
4149 if (LoopBundle == LoopBB->
end())
4155 if (!ResourcesAvailableInBundle(&PUR, LoopBundle))
4158 CurrentState.HomeBundle);
4161 MachineInstr *InstrToSink =
4162 &*insertTempCopy(LoopBB, LoopBundle, RegMI,
false);
4163 if (!canAddMIToThisPacket(InstrToSink, LoopBundlePkt)) {
4177 if (NeedToNewify(InstrToSink->
getIterator(), &DepReg, &*LoopBundle) &&
4178 !isNewifiable(InstrToSink->
getIterator(), DepReg, &*LoopBundle)) {
4188 InstrToSink->
setDesc(QII->get(NewOpcode));
4189 if (!incrementalAddToPacket(*InstrToSink)) {
4211bool HexagonGlobalSchedulerImpl::performPullUpCFG(
MachineFunction &Fn) {
4214 if (std::next(
F.begin()) ==
F.end())
4221 MachineBasicBlock *PrevBlock = NULL;
4222 MachineBasicBlock *JumpBlock = NULL;
4225 MachineBasicBlock *FallBlock = &*
MBB;
4226 if (PrevBlock && JumpBlock) {
4227 Changed |= pullUpPeelBBLoop(PrevBlock, JumpBlock);
4229 PrevBlock = JumpBlock;
4230 JumpBlock = FallBlock;
4236 std::vector<unsigned> Defs;
4237 std::vector<unsigned>
Uses;
4241 MIter != MBBIter->instr_end(); ++MIter) {
4242 if (MIter->isBundle() || MIter->isDebugInstr())
4245 MIUseDefSet(&*MIter, Defs,
Uses);
4247 for (
unsigned i = 0; i < Defs.size(); ++i)
dbgs()
4250 for (
unsigned i = 0; i <
Uses.size(); ++i)
dbgs()
4252 MIDefSet[&*MIter] = Defs;
4253 MIUseSet[&*MIter] =
Uses;
4269MachineBasicBlock *HexagonGlobalSchedulerImpl::optimizeBranches(
4270 MachineBasicBlock *
MBB, MachineBasicBlock *
TBB, MachineInstr *FirstTerm,
4271 MachineBasicBlock *FBB) {
4282 MachineInstr *TBBMIb = &*
TBB->getFirstNonDebugInstr();
4283 if (TBBMIb->
getOpcode() == Hexagon::J2_jump &&
4286 if (
TBB == NewTarget)
4291 int64_t InstOffset =
4293 unsigned Distance = (unsigned)std::abs(
4294 InstOffset - BlockToInstOffset.
find(NewTarget)->second);
4297 <<
" out of range.");
4303 if (!
TBB->hasAddressTaken() && !
TBB->isEHPad() &&
TBB->pred_size() == 1) {
4306 TBB->removeSuccessor(
TBB->succ_begin());
4330 if (FBBMIb->
getOpcode() == Hexagon::J2_jump &&
4339 int64_t InstOffset =
4341 unsigned Distance = (unsigned)std::abs(
4342 InstOffset - BlockToInstOffset.
find(NewTarget)->second);
4345 <<
" out of range.");
4364bool HexagonGlobalSchedulerImpl::performExposedOptimizations(
4371 std::vector<MachineBasicBlock *>::iterator ebb = EmptyBBs.begin();
4372 while (ebb != EmptyBBs.end()) {
4375 <<
") from parent.\n");
4376 (*ebb)->eraseFromParent();
4379 MachineBasicBlock *
TBB = NULL, *FBB = NULL;
4380 MachineInstr *FirstTerm = NULL, *SecondTerm = NULL;
4382 SmallVector<MachineBasicBlock *, 4> Erase;
4384 for (MachineBasicBlock &
MBB : Fn) {
4386 AnalyzeBBBranches(&
MBB,
TBB, FirstTerm, FBB, SecondTerm)) {
4393 if (
TBB && FirstTerm &&
4394 removeRedundantBranches(&
MBB,
TBB, FirstTerm, FBB, SecondTerm)) {
4399 if (FirstTerm && SecondTerm &&
4400 optimizeDualJumps(&
MBB,
TBB, FirstTerm, FBB, SecondTerm)) {
4405 if (
TBB && FBB && FirstTerm && !SecondTerm) {
4406 MachineBasicBlock *MBBToErase =
4407 optimizeBranches(&
MBB,
TBB, FirstTerm, FBB);
4415 for (MachineBasicBlock *
MBB : Erase)
4423bool HexagonGlobalSchedulerImpl::removeRedundantBranches(
4424 MachineBasicBlock *
MBB, MachineBasicBlock *
TBB, MachineInstr *FirstTerm,
4425 MachineBasicBlock *FBB, MachineInstr *SecondTerm) {
4426 bool Analyzed =
false;
4428 MachineInstr *Head = NULL, *ToErase = NULL;
4429 if (!FBB && (FirstTerm->
getOpcode() == Hexagon::J2_jump) &&
4433 dbgs() <<
"\nRemoving Uncond. jump to the layout successor in BB#"
4435 ToErase = FirstTerm;
4436 }
else if (SecondTerm && (
TBB == FBB) &&
4437 (SecondTerm->
getOpcode() == Hexagon::J2_jump)) {
4446 if (++FirstTermIter == SecondTermIter) {
4447 LLVM_DEBUG(
dbgs() <<
"\nRemoving multiple branching to same target in BB#"
4451 ToErase = FirstTerm;
4453 }
else if (SecondTerm && (SecondTerm->
getOpcode() == Hexagon::J2_jump) &&
4459 ToErase = SecondTerm;
4466 LLVM_DEBUG(
dbgs() <<
"\nRemoving Cond. jump to the layout successor in BB#"
4468 ToErase = SecondTerm;
4472 if (ToErase->isBundled()) {
4474 ToErase->eraseFromBundle();
4477 ToErase->eraseFromParent();
4491bool HexagonGlobalSchedulerImpl::optimizeDualJumps(MachineBasicBlock *
MBB,
4492 MachineBasicBlock *
TBB,
4493 MachineInstr *FirstTerm,
4494 MachineBasicBlock *FBB,
4495 MachineInstr *SecondTerm) {
4498 bool Analyzed =
false;
4501 (SecondTerm->
getOpcode() == Hexagon::J2_jump)) {
4513 MachineInstr *
SI = &*SII;
4514 std::map<MachineInstr *, MachineBasicBlock *>::iterator MIMoved;
4515 MIMoved = SpeculatedIns.find(SI);
4516 if ((MIMoved != SpeculatedIns.end()) &&
4517 (MIMoved->second !=
SI->getParent())) {
4530 int64_t InstOffset =
4533 (unsigned)std::abs(InstOffset - BlockToInstOffset.
find(FBB)->second) +
4537 <<
" out of range.");
4551 MachineInstr *SecondHead, *FirstHead;
4562 else if (!FirstHead) {
4566 }
else if (FirstHead == SecondHead) {
4568 assert((FirstHead && SecondHead) &&
"Unbundled Instruction");
4570 if (SecondHead->getBundleSize() < 2)
4584bool HexagonGlobalSchedulerImpl::ResourcesAvailableInBundle(
4585 BasicBlockRegion *CurrentRegion,
4590 if (!TargetPacket->isBundle()) {
4591 if (ignoreInstruction(&*MII) || isSoloInstruction(*MII))
4596 if (MII->isBranch() && !isBranchWithinRegion(CurrentRegion, &*MII))
4602 initPacketizerState();
4603 ResourceTracker->clearResources();
4604 CurrentState.addHomeLocation(MII);
4605 return incrementalAddToPacket(*MII);
4611 initPacketizerState();
4612 ResourceTracker->clearResources();
4613 CurrentState.addHomeLocation(MII);
4615 for (++MII; MII !=
End && MII->isInsideBundle(); ++MII) {
4616 if (MII->getOpcode() == TargetOpcode::DBG_VALUE ||
4617 MII->getOpcode() == TargetOpcode::IMPLICIT_DEF ||
4618 MII->getOpcode() == TargetOpcode::CFI_INSTRUCTION || MII->isEHLabel())
4631 if (MII->isBranch() && !isBranchWithinRegion(CurrentRegion, &*MII))
4634 if (!incrementalAddToPacket(*MII))
4637 return ResourceTracker->canReserveResources(*Nop);
4641bool HexagonGlobalSchedulerImpl::isCompoundPair(MachineInstr *MIa,
4642 MachineInstr *MIb) {
4649 (Opcb == Hexagon::A2_tfr || Opcb == Hexagon::A2_tfrsi))
4653 (Opca == Hexagon::A2_tfr || Opca == Hexagon::A2_tfrsi))
4662inline bool HexagonGlobalSchedulerImpl::multipleBranchesFromToBB(
4663 MachineBasicBlock *BB)
const {
4667 return ((Jumpers.
size() == 1) && !Jumpers[0]->isUnconditionalBranch());
4672bool HexagonGlobalSchedulerImpl::findPullUpCandidates(
4675 std::vector<MachineInstr *> &backtrack,
unsigned MaxCandidates = 1) {
4677 const HexagonInstrInfo *QII = (
const HexagonInstrInfo *)
TII;
4678 MachineBasicBlock *FromThisBB = FromHere->getParent();
4679 bool MovingDependentOp =
false;
4683 if (CurrentState.haveCandidates() >= MaxCandidates)
4689 if (FromHere->isBundle()) {
4691 for (++MII; MII != FromThisBB->
instr_end() && MII->isInsideBundle();
4693 if (MII->isDebugInstr())
4696 << MII->getParent()->getNumber() <<
"): ";
4700 if (!canThisMIBeMoved(&*MII, WorkPoint, MovingDependentOp,
CostBenefit))
4704 if (canAddMIToThisPacket(&*InstrToMove, CurrentState.HomeBundle)) {
4709 if (MII->isCompare())
4712 for (
unsigned i = 0; i < CurrentState.HomeBundle.size(); i++) {
4713 if (QII->
isDuplexPair(*CurrentState.HomeBundle[i], *MII)) {
4717 if (isCompoundPair(CurrentState.HomeBundle[i], &*MII)) {
4723 CurrentState.addPullUpCandidate(InstrToMove, WorkPoint, backtrack,
4732 else if (canThisMIBeMoved(&*FromHere, WorkPoint, MovingDependentOp,
4735 if (canAddMIToThisPacket(&*InstrToMove, CurrentState.HomeBundle)) {
4738 if (InstrToMove->isCompare())
4744 for (
unsigned i = 0; i < CurrentState.HomeBundle.size(); i++) {
4745 if (QII->
isDuplexPair(*CurrentState.HomeBundle[i], *InstrToMove)) {
4749 if (isCompoundPair(CurrentState.HomeBundle[i], &*InstrToMove)) {
4755 CurrentState.addPullUpCandidate(InstrToMove, WorkPoint, backtrack,
4758 LLVM_DEBUG(
dbgs() <<
"\tNo resources for single in the target packet.\n");
4766bool HexagonGlobalSchedulerImpl::tryMultipleInstructions(
4768 std::vector<BasicBlockRegion *>::iterator &CurrentRegion,
4775 bool MovingDependentOp =
false;
4776 std::vector<MachineInstr *> backtrack;
4780 std::sort(CurrentState.PullUpCandidates.begin(),
4781 CurrentState.PullUpCandidates.end(), PullUpCandidateSorter());
4784 for (SmallVector<PullUpCandidate *, 4>::iterator
4785 I = CurrentState.PullUpCandidates.begin(),
4786 E = CurrentState.PullUpCandidates.end();
4788 (*I)->populate(MII, WorkPoint, backtrack, MovingDependentOp);
4790 MachineBasicBlock *FromThisBB = MII->
getParent();
4791 MachineBasicBlock *ToThisBB = WorkPoint->getParent();
4794 LLVM_DEBUG(
dbgs() <<
"\tDependent(" << MovingDependentOp <<
") FromBB("
4796 << ToThisBB->
getNumber() <<
") to this packet:\n";
4800 if (MII->isInsideBundle()) {
4801 while (!FromHereII->isBundle())
4807 if (MoveMItoBundle(*CurrentRegion, MII, NextMI, WorkPoint, FromHere,
4808 backtrack, MovingDependentOp, PathInRegion)) {
4814 FromThisBBEnd = FromThisBB->
end();
4815 ToThisBBEnd = ToThisBB->
end();
4829 if (MoveMItoBundle(*CurrentRegion, MII, NextMI, WorkPoint, FromHere,
4830 backtrack, MovingDependentOp, PathInRegion)) {
4837 FromThisBBEnd = FromThisBB->
end();
4838 ToThisBBEnd = ToThisBB->
end();
4865bool HexagonGlobalSchedulerImpl::performPullUp() {
4866 std::vector<MachineInstr *> backtrack;
4872 for (std::vector<BasicBlockRegion *>::iterator
4873 CurrentRegion = PullUpRegions.begin(),
4874 E = PullUpRegions.end();
4875 CurrentRegion !=
E; ++CurrentRegion) {
4877 LLVM_DEBUG(
dbgs() <<
"\n\nRegion with(" << (*CurrentRegion)->size()
4885 for (
auto ToThisBB = (*CurrentRegion)->getRootMBB(),
4886 LastBBInRegion = (*CurrentRegion)->getLastMBB();
4887 ToThisBB != LastBBInRegion; ++ToThisBB) {
4891 if (multipleBranchesFromToBB(*ToThisBB))
4894 auto FromThisBB = ToThisBB;
4899 << (*ToThisBB)->getNumber() <<
")\n";
4900 (*ToThisBB)->dump());
4903 while (
MI != ToThisBBEnd) {
4909 while (ResourcesAvailableInBundle(*CurrentRegion, WorkPoint)) {
4911 << (*ToThisBB)->getNumber() <<
"):\n";
4925 FromThisBB = ToThisBB;
4926 FromHere = WorkPoint;
4928 FromThisBBEnd = (*FromThisBB)->end();
4935 backtrack.push_back(&*
I);
4937 FromThisBB = ToThisBB;
4939 FromHere = (*FromThisBB)->begin();
4940 FromThisBBEnd = (*FromThisBB)->end();
4947 backtrack.push_back(&*
I);
4954 if (FromHere == FromThisBBEnd) {
4958 LastBBInRegion = (*CurrentRegion)->getLastMBB();
4959 if (FromThisBB == LastBBInRegion)
4963 (*FromThisBB)->dump());
4964 FromThisBBEnd = (*FromThisBB)->end();
4965 FromHere = (*FromThisBB)->begin();
4966 if (FromThisBBEnd == FromHere)
4970 if ((*FromHere).isDebugInstr()) {
4975 backtrack.push_back(&*FromHere);
4976 if (!findPullUpCandidates(WorkPoint, FromHere, backtrack,
4982 if (!tryMultipleInstructions( WorkPoint, CurrentRegion,
MI,
4983 ToThisBBEnd, FromThisBBEnd))
4988 LastBBInRegion = (*CurrentRegion)->getLastMBB();
5001 std::vector<std::pair<MachineBasicBlock *, MachineBasicBlock *>>
5003 UnlikelyWork.reserve((*CurrentRegion)->size());
5004 for (
auto ToIt = (*CurrentRegion)->getRootMBB(),
5005 End = (*CurrentRegion)->getLastMBB();
5006 ToIt !=
End; ++ToIt) {
5007 MachineBasicBlock *ToBB = *ToIt;
5008 MachineBasicBlock *SecondBest = getNextPURBB(ToBB,
true);
5010 UnlikelyWork.emplace_back(ToBB, SecondBest);
5013 for (
auto [ToBB, SecondBest] : UnlikelyWork) {
5018 (*CurrentRegion)->addBBtoRegion(SecondBest);
5026 while (
MI != ToThisBBEnd) {
5032 while (ResourcesAvailableInBundle(*CurrentRegion, WorkPoint)) {
5037 FromHere = SecondBest->
begin();
5038 FromThisBBEnd = SecondBest->
end();
5046 backtrack.push_back(&*
I);
5051 if (FromHere == FromThisBBEnd) {
5053 <<
"\tOnly do one successor for the second try\n");
5056 if ((*FromHere).isDebugInstr()) {
5061 backtrack.push_back(&*FromHere);
5062 if (!findPullUpCandidates(WorkPoint, FromHere, backtrack,
5068 if (!tryMultipleInstructions( WorkPoint, CurrentRegion,
MI,
5069 ToThisBBEnd, FromThisBBEnd,
false))
5078bool HexagonGlobalSchedulerImpl::incrementalAddToPacket(MachineInstr &
MI) {
5080 LLVM_DEBUG(
dbgs() <<
"\t[AddToPacket] (" << CurrentPacketMIs.size()
5084 if (!ResourceTracker->canReserveResources(
MI) || !shouldAddToPacket(
MI))
5087 ResourceTracker->reserveResources(
MI);
5088 CurrentPacketMIs.push_back(&
MI);
5089 CurrentState.HomeBundle.push_back(&
MI);
5092 isJumpOutOfRange(&
MI)) {
5098 if (ResourceTracker->canReserveResources(*Ext)) {
5099 ResourceTracker->reserveResources(*Ext);
5100 LLVM_DEBUG(
dbgs() <<
"\t[AddToPacket] (" << CurrentPacketMIs.size()
5101 <<
") adding:\t immext_i\n");
5102 CurrentPacketMIs.push_back(Ext);
5103 CurrentState.HomeBundle.push_back(Ext);
5113void HexagonGlobalSchedulerImpl::checkBundleCounts(
MachineFunction &Fn) {
5117 unsigned BundleLimit = 4;
5120 MBBi != MBBe; ++MBBi) {
5123 ME = MBBi->instr_end();
5125 if (
MI->isBundle()) {
5131 for (++MII; MII !=
End && MII->isInsideBundle(); ++MII) {
5132 if (MII->getOpcode() == TargetOpcode::DBG_VALUE ||
5133 MII->getOpcode() == TargetOpcode::IMPLICIT_DEF ||
5134 MII->getOpcode() == TargetOpcode::CFI_INSTRUCTION ||
5135 MII->isEHLabel() || QII->
isEndLoopN(MII->getOpcode())) {
5145 assert(0 &&
"Bundle size exceeded");
5154unsigned HexagonGlobalSchedulerImpl::countCompounds(
MachineFunction &Fn) {
5155 unsigned CompoundCount = 0;
5156 [[maybe_unused]]
unsigned DuplexCount = 0;
5157 [[maybe_unused]]
unsigned InstOffset = 0;
5168 if (
MI->isDebugInstr())
5170 if (
MI->isBundle()) {
5173 MachineInstr *FirstCompound = NULL, *SecondCompound = NULL;
5174 MachineInstr *FirstDuplex = NULL, *SecondDuplex = NULL;
5177 for (++MII; MII != MIE && MII->isInsideBundle() && !MII->isBundle();
5179 if (MII->isDebugInstr())
5182 InstOffset += QII->
getSize(*MII);
5184 if (!FirstCompound) {
5185 FirstCompound = &*MII;
5188 SecondCompound = &*MII;
5194 FirstDuplex = &*MII;
5197 SecondDuplex = &*MII;
5204 if (SecondCompound) {
5205 if (isCompoundPair(FirstCompound, SecondCompound)) {
5206 LLVM_DEBUG(
dbgs() <<
"Compound pair (" << CompoundCount <<
")\n");
5227 LLVM_DEBUG(
dbgs() <<
"Total compound(" << CompoundCount <<
") duplex("
5228 << DuplexCount <<
")\n");
5229 return CompoundCount;
5237 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"))
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
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 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 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 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.