Mercurial > hg > CbC > CbC_llvm
comparison lib/Target/Hexagon/HexagonExpandCondsets.cpp @ 147:c2174574ed3a
LLVM 10
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 16:55:33 +0900 |
parents | 3a76565eade5 |
children |
comparison
equal
deleted
inserted
replaced
134:3a76565eade5 | 147:c2174574ed3a |
---|---|
1 //===- HexagonExpandCondsets.cpp ------------------------------------------===// | 1 //===- HexagonExpandCondsets.cpp ------------------------------------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 | 8 |
10 // Replace mux instructions with the corresponding legal instructions. | 9 // Replace mux instructions with the corresponding legal instructions. |
11 // It is meant to work post-SSA, but still on virtual registers. It was | 10 // It is meant to work post-SSA, but still on virtual registers. It was |
284 } | 283 } |
285 return false; | 284 return false; |
286 } | 285 } |
287 | 286 |
288 LaneBitmask HexagonExpandCondsets::getLaneMask(unsigned Reg, unsigned Sub) { | 287 LaneBitmask HexagonExpandCondsets::getLaneMask(unsigned Reg, unsigned Sub) { |
289 assert(TargetRegisterInfo::isVirtualRegister(Reg)); | 288 assert(Register::isVirtualRegister(Reg)); |
290 return Sub != 0 ? TRI->getSubRegIndexLaneMask(Sub) | 289 return Sub != 0 ? TRI->getSubRegIndexLaneMask(Sub) |
291 : MRI->getMaxLaneMaskForVReg(Reg); | 290 : MRI->getMaxLaneMaskForVReg(Reg); |
292 } | 291 } |
293 | 292 |
294 void HexagonExpandCondsets::addRefToMap(RegisterRef RR, ReferenceMap &Map, | 293 void HexagonExpandCondsets::addRefToMap(RegisterRef RR, ReferenceMap &Map, |
314 | 313 |
315 void HexagonExpandCondsets::updateKillFlags(unsigned Reg) { | 314 void HexagonExpandCondsets::updateKillFlags(unsigned Reg) { |
316 auto KillAt = [this,Reg] (SlotIndex K, LaneBitmask LM) -> void { | 315 auto KillAt = [this,Reg] (SlotIndex K, LaneBitmask LM) -> void { |
317 // Set the <kill> flag on a use of Reg whose lane mask is contained in LM. | 316 // Set the <kill> flag on a use of Reg whose lane mask is contained in LM. |
318 MachineInstr *MI = LIS->getInstructionFromIndex(K); | 317 MachineInstr *MI = LIS->getInstructionFromIndex(K); |
319 for (auto &Op : MI->operands()) { | 318 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
320 if (!Op.isReg() || !Op.isUse() || Op.getReg() != Reg) | 319 MachineOperand &Op = MI->getOperand(i); |
320 if (!Op.isReg() || !Op.isUse() || Op.getReg() != Reg || | |
321 MI->isRegTiedToDefOperand(i)) | |
321 continue; | 322 continue; |
322 LaneBitmask SLM = getLaneMask(Reg, Op.getSubReg()); | 323 LaneBitmask SLM = getLaneMask(Reg, Op.getSubReg()); |
323 if ((SLM & LM) == SLM) { | 324 if ((SLM & LM) == SLM) { |
324 // Only set the kill flag on the first encountered use of Reg in this | 325 // Only set the kill flag on the first encountered use of Reg in this |
325 // instruction. | 326 // instruction. |
361 } | 362 } |
362 } | 363 } |
363 | 364 |
364 void HexagonExpandCondsets::updateDeadsInRange(unsigned Reg, LaneBitmask LM, | 365 void HexagonExpandCondsets::updateDeadsInRange(unsigned Reg, LaneBitmask LM, |
365 LiveRange &Range) { | 366 LiveRange &Range) { |
366 assert(TargetRegisterInfo::isVirtualRegister(Reg)); | 367 assert(Register::isVirtualRegister(Reg)); |
367 if (Range.empty()) | 368 if (Range.empty()) |
368 return; | 369 return; |
369 | 370 |
370 // Return two booleans: { def-modifes-reg, def-covers-reg }. | 371 // Return two booleans: { def-modifes-reg, def-covers-reg }. |
371 auto IsRegDef = [this,Reg,LM] (MachineOperand &Op) -> std::pair<bool,bool> { | 372 auto IsRegDef = [this,Reg,LM] (MachineOperand &Op) -> std::pair<bool,bool> { |
372 if (!Op.isReg() || !Op.isDef()) | 373 if (!Op.isReg() || !Op.isDef()) |
373 return { false, false }; | 374 return { false, false }; |
374 unsigned DR = Op.getReg(), DSR = Op.getSubReg(); | 375 unsigned DR = Op.getReg(), DSR = Op.getSubReg(); |
375 if (!TargetRegisterInfo::isVirtualRegister(DR) || DR != Reg) | 376 if (!Register::isVirtualRegister(DR) || DR != Reg) |
376 return { false, false }; | 377 return { false, false }; |
377 LaneBitmask SLM = getLaneMask(DR, DSR); | 378 LaneBitmask SLM = getLaneMask(DR, DSR); |
378 LaneBitmask A = SLM & LM; | 379 LaneBitmask A = SLM & LM; |
379 return { A.any(), A == SLM }; | 380 return { A.any(), A == SLM }; |
380 }; | 381 }; |
495 for (unsigned i = 0, e = DefI->getNumOperands(); i != e; ++i) { | 496 for (unsigned i = 0, e = DefI->getNumOperands(); i != e; ++i) { |
496 MachineOperand &Op = DefI->getOperand(i); | 497 MachineOperand &Op = DefI->getOperand(i); |
497 if (!Op.isReg() || !DefRegs.count(Op)) | 498 if (!Op.isReg() || !DefRegs.count(Op)) |
498 continue; | 499 continue; |
499 if (Op.isDef()) { | 500 if (Op.isDef()) { |
500 ImpUses.insert({Op, i}); | 501 // Tied defs will always have corresponding uses, so no extra |
502 // implicit uses are needed. | |
503 if (!Op.isTied()) | |
504 ImpUses.insert({Op, i}); | |
501 } else { | 505 } else { |
502 // This function can be called for the same register with different | 506 // This function can be called for the same register with different |
503 // lane masks. If the def in this instruction was for the whole | 507 // lane masks. If the def in this instruction was for the whole |
504 // register, we can get here more than once. Avoid adding multiple | 508 // register, we can get here more than once. Avoid adding multiple |
505 // implicit uses (or adding an implicit use when an explicit one is | 509 // implicit uses (or adding an implicit use when an explicit one is |
506 // present). | 510 // present). |
507 ImpUses.erase(Op); | 511 if (Op.isTied()) |
512 ImpUses.erase(Op); | |
508 } | 513 } |
509 } | 514 } |
510 if (ImpUses.empty()) | 515 if (ImpUses.empty()) |
511 continue; | 516 continue; |
512 MachineFunction &MF = *DefI->getParent()->getParent(); | 517 MachineFunction &MF = *DefI->getParent()->getParent(); |
543 } | 548 } |
544 | 549 |
545 void HexagonExpandCondsets::updateLiveness(std::set<unsigned> &RegSet, | 550 void HexagonExpandCondsets::updateLiveness(std::set<unsigned> &RegSet, |
546 bool Recalc, bool UpdateKills, bool UpdateDeads) { | 551 bool Recalc, bool UpdateKills, bool UpdateDeads) { |
547 UpdateKills |= UpdateDeads; | 552 UpdateKills |= UpdateDeads; |
548 for (auto R : RegSet) { | 553 for (unsigned R : RegSet) { |
554 if (!Register::isVirtualRegister(R)) { | |
555 assert(Register::isPhysicalRegister(R)); | |
556 // There shouldn't be any physical registers as operands, except | |
557 // possibly reserved registers. | |
558 assert(MRI->isReserved(R)); | |
559 continue; | |
560 } | |
549 if (Recalc) | 561 if (Recalc) |
550 recalculateLiveInterval(R); | 562 recalculateLiveInterval(R); |
551 if (UpdateKills) | 563 if (UpdateKills) |
552 MRI->clearKillFlags(R); | 564 MRI->clearKillFlags(R); |
553 if (UpdateDeads) | 565 if (UpdateDeads) |
565 unsigned HexagonExpandCondsets::getCondTfrOpcode(const MachineOperand &SO, | 577 unsigned HexagonExpandCondsets::getCondTfrOpcode(const MachineOperand &SO, |
566 bool IfTrue) { | 578 bool IfTrue) { |
567 using namespace Hexagon; | 579 using namespace Hexagon; |
568 | 580 |
569 if (SO.isReg()) { | 581 if (SO.isReg()) { |
570 unsigned PhysR; | 582 Register PhysR; |
571 RegisterRef RS = SO; | 583 RegisterRef RS = SO; |
572 if (TargetRegisterInfo::isVirtualRegister(RS.Reg)) { | 584 if (Register::isVirtualRegister(RS.Reg)) { |
573 const TargetRegisterClass *VC = MRI->getRegClass(RS.Reg); | 585 const TargetRegisterClass *VC = MRI->getRegClass(RS.Reg); |
574 assert(VC->begin() != VC->end() && "Empty register class"); | 586 assert(VC->begin() != VC->end() && "Empty register class"); |
575 PhysR = *VC->begin(); | 587 PhysR = *VC->begin(); |
576 } else { | 588 } else { |
577 assert(TargetRegisterInfo::isPhysicalRegister(RS.Reg)); | 589 assert(Register::isPhysicalRegister(RS.Reg)); |
578 PhysR = RS.Reg; | 590 PhysR = RS.Reg; |
579 } | 591 } |
580 unsigned PhysS = (RS.Sub == 0) ? PhysR : TRI->getSubReg(PhysR, RS.Sub); | 592 unsigned PhysS = (RS.Sub == 0) ? PhysR : TRI->getSubReg(PhysR, RS.Sub); |
581 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(PhysS); | 593 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(PhysS); |
582 switch (TRI->getRegSizeInBits(*RC)) { | 594 switch (TRI->getRegSizeInBits(*RC)) { |
639 .addReg(DstR, DstState, DstSR) | 651 .addReg(DstR, DstState, DstSR) |
640 .addReg(PredOp.getReg(), PredState, PredOp.getSubReg()) | 652 .addReg(PredOp.getReg(), PredState, PredOp.getSubReg()) |
641 .add(SrcOp); | 653 .add(SrcOp); |
642 } | 654 } |
643 | 655 |
644 DEBUG(dbgs() << "created an initial copy: " << *MIB); | 656 LLVM_DEBUG(dbgs() << "created an initial copy: " << *MIB); |
645 return &*MIB; | 657 return &*MIB; |
646 } | 658 } |
647 | 659 |
648 /// Replace a MUX instruction MI with a pair A2_tfrt/A2_tfrf. This function | 660 /// Replace a MUX instruction MI with a pair A2_tfrt/A2_tfrf. This function |
649 /// performs all necessary changes to complete the replacement. | 661 /// performs all necessary changes to complete the replacement. |
652 if (TfrLimitActive) { | 664 if (TfrLimitActive) { |
653 if (TfrCounter >= TfrLimit) | 665 if (TfrCounter >= TfrLimit) |
654 return false; | 666 return false; |
655 TfrCounter++; | 667 TfrCounter++; |
656 } | 668 } |
657 DEBUG(dbgs() << "\nsplitting " << printMBBReference(*MI.getParent()) << ": " | 669 LLVM_DEBUG(dbgs() << "\nsplitting " << printMBBReference(*MI.getParent()) |
658 << MI); | 670 << ": " << MI); |
659 MachineOperand &MD = MI.getOperand(0); // Definition | 671 MachineOperand &MD = MI.getOperand(0); // Definition |
660 MachineOperand &MP = MI.getOperand(1); // Predicate register | 672 MachineOperand &MP = MI.getOperand(1); // Predicate register |
661 assert(MD.isDef()); | 673 assert(MD.isDef()); |
662 unsigned DR = MD.getReg(), DSR = MD.getSubReg(); | 674 unsigned DR = MD.getReg(), DSR = MD.getSubReg(); |
663 bool ReadUndef = MD.isUndef(); | 675 bool ReadUndef = MD.isUndef(); |
719 if (HasDef) | 731 if (HasDef) |
720 return false; | 732 return false; |
721 HasDef = true; | 733 HasDef = true; |
722 } | 734 } |
723 for (auto &Mo : MI->memoperands()) | 735 for (auto &Mo : MI->memoperands()) |
724 if (Mo->isVolatile()) | 736 if (Mo->isVolatile() || Mo->isAtomic()) |
725 return false; | 737 return false; |
726 return true; | 738 return true; |
727 } | 739 } |
728 | 740 |
729 /// Find the reaching definition for a predicated use of RD. The RD is used | 741 /// Find the reaching definition for a predicated use of RD. The RD is used |
788 continue; | 800 continue; |
789 RegisterRef RR = Op; | 801 RegisterRef RR = Op; |
790 // For physical register we would need to check register aliases, etc. | 802 // For physical register we would need to check register aliases, etc. |
791 // and we don't want to bother with that. It would be of little value | 803 // and we don't want to bother with that. It would be of little value |
792 // before the actual register rewriting (from virtual to physical). | 804 // before the actual register rewriting (from virtual to physical). |
793 if (!TargetRegisterInfo::isVirtualRegister(RR.Reg)) | 805 if (!Register::isVirtualRegister(RR.Reg)) |
794 return false; | 806 return false; |
795 // No redefs for any operand. | 807 // No redefs for any operand. |
796 if (isRefInMap(RR, Defs, Exec_Then)) | 808 if (isRefInMap(RR, Defs, Exec_Then)) |
797 return false; | 809 return false; |
798 // For defs, there cannot be uses. | 810 // For defs, there cannot be uses. |
876 MachineOperand &MO = MI.getOperand(Ox); | 888 MachineOperand &MO = MI.getOperand(Ox); |
877 if (!MO.isReg() || !MO.isImplicit()) | 889 if (!MO.isReg() || !MO.isImplicit()) |
878 MB.add(MO); | 890 MB.add(MO); |
879 Ox++; | 891 Ox++; |
880 } | 892 } |
881 | 893 MB.cloneMemRefs(MI); |
882 MachineFunction &MF = *B.getParent(); | |
883 MachineInstr::mmo_iterator I = MI.memoperands_begin(); | |
884 unsigned NR = std::distance(I, MI.memoperands_end()); | |
885 MachineInstr::mmo_iterator MemRefs = MF.allocateMemRefsArray(NR); | |
886 for (unsigned i = 0; i < NR; ++i) | |
887 MemRefs[i] = *I++; | |
888 MB.setMemRefs(MemRefs, MemRefs+NR); | |
889 | 894 |
890 MachineInstr *NewI = MB; | 895 MachineInstr *NewI = MB; |
891 NewI->clearKillInfo(); | 896 NewI->clearKillInfo(); |
892 LIS->InsertMachineInstrInMaps(*NewI); | 897 LIS->InsertMachineInstrInMaps(*NewI); |
893 | 898 |
930 std::set<unsigned> &UpdRegs) { | 935 std::set<unsigned> &UpdRegs) { |
931 // TfrI - A2_tfr[tf] Instruction (not A2_tfrsi). | 936 // TfrI - A2_tfr[tf] Instruction (not A2_tfrsi). |
932 unsigned Opc = TfrI.getOpcode(); | 937 unsigned Opc = TfrI.getOpcode(); |
933 (void)Opc; | 938 (void)Opc; |
934 assert(Opc == Hexagon::A2_tfrt || Opc == Hexagon::A2_tfrf); | 939 assert(Opc == Hexagon::A2_tfrt || Opc == Hexagon::A2_tfrf); |
935 DEBUG(dbgs() << "\nattempt to predicate if-" << (Cond ? "true" : "false") | 940 LLVM_DEBUG(dbgs() << "\nattempt to predicate if-" << (Cond ? "true" : "false") |
936 << ": " << TfrI); | 941 << ": " << TfrI); |
937 | 942 |
938 MachineOperand &MD = TfrI.getOperand(0); | 943 MachineOperand &MD = TfrI.getOperand(0); |
939 MachineOperand &MP = TfrI.getOperand(1); | 944 MachineOperand &MP = TfrI.getOperand(1); |
940 MachineOperand &MS = TfrI.getOperand(2); | 945 MachineOperand &MS = TfrI.getOperand(2); |
941 // The source operand should be a <kill>. This is not strictly necessary, | 946 // The source operand should be a <kill>. This is not strictly necessary, |
952 unsigned PredR = MP.getReg(); | 957 unsigned PredR = MP.getReg(); |
953 MachineInstr *DefI = getReachingDefForPred(RT, TfrI, PredR, Cond); | 958 MachineInstr *DefI = getReachingDefForPred(RT, TfrI, PredR, Cond); |
954 if (!DefI || !isPredicable(DefI)) | 959 if (!DefI || !isPredicable(DefI)) |
955 return false; | 960 return false; |
956 | 961 |
957 DEBUG(dbgs() << "Source def: " << *DefI); | 962 LLVM_DEBUG(dbgs() << "Source def: " << *DefI); |
958 | 963 |
959 // Collect the information about registers defined and used between the | 964 // Collect the information about registers defined and used between the |
960 // DefI and the TfrI. | 965 // DefI and the TfrI. |
961 // Map: reg -> bitmask of subregs | 966 // Map: reg -> bitmask of subregs |
962 ReferenceMap Uses, Defs; | 967 ReferenceMap Uses, Defs; |
992 // in the subregisters, which we are keeping track of. Physical | 997 // in the subregisters, which we are keeping track of. Physical |
993 // registers ters no longer have subregisters---their super- and | 998 // registers ters no longer have subregisters---their super- and |
994 // subregisters are other physical registers, and we are not checking | 999 // subregisters are other physical registers, and we are not checking |
995 // that. | 1000 // that. |
996 RegisterRef RR = Op; | 1001 RegisterRef RR = Op; |
997 if (!TargetRegisterInfo::isVirtualRegister(RR.Reg)) | 1002 if (!Register::isVirtualRegister(RR.Reg)) |
998 return false; | 1003 return false; |
999 | 1004 |
1000 ReferenceMap &Map = Op.isDef() ? Defs : Uses; | 1005 ReferenceMap &Map = Op.isDef() ? Defs : Uses; |
1001 if (Op.isDef() && Op.isUndef()) { | 1006 if (Op.isDef() && Op.isUndef()) { |
1002 assert(RR.Sub && "Expecting a subregister on <def,read-undef>"); | 1007 assert(RR.Sub && "Expecting a subregister on <def,read-undef>"); |
1037 // to move DefI down to TfrI. | 1042 // to move DefI down to TfrI. |
1038 if (DefI->mayLoad() || DefI->mayStore()) | 1043 if (DefI->mayLoad() || DefI->mayStore()) |
1039 if (!canMoveMemTo(*DefI, TfrI, true)) | 1044 if (!canMoveMemTo(*DefI, TfrI, true)) |
1040 CanDown = false; | 1045 CanDown = false; |
1041 | 1046 |
1042 DEBUG(dbgs() << "Can move up: " << (CanUp ? "yes" : "no") | 1047 LLVM_DEBUG(dbgs() << "Can move up: " << (CanUp ? "yes" : "no") |
1043 << ", can move down: " << (CanDown ? "yes\n" : "no\n")); | 1048 << ", can move down: " << (CanDown ? "yes\n" : "no\n")); |
1044 MachineBasicBlock::iterator PastDefIt = std::next(DefIt); | 1049 MachineBasicBlock::iterator PastDefIt = std::next(DefIt); |
1045 if (CanUp) | 1050 if (CanUp) |
1046 predicateAt(MD, *DefI, PastDefIt, MP, Cond, UpdRegs); | 1051 predicateAt(MD, *DefI, PastDefIt, MP, Cond, UpdRegs); |
1047 else if (CanDown) | 1052 else if (CanDown) |
1048 predicateAt(MD, *DefI, TfrIt, MP, Cond, UpdRegs); | 1053 predicateAt(MD, *DefI, TfrIt, MP, Cond, UpdRegs); |
1084 } | 1089 } |
1085 return Changed; | 1090 return Changed; |
1086 } | 1091 } |
1087 | 1092 |
1088 bool HexagonExpandCondsets::isIntReg(RegisterRef RR, unsigned &BW) { | 1093 bool HexagonExpandCondsets::isIntReg(RegisterRef RR, unsigned &BW) { |
1089 if (!TargetRegisterInfo::isVirtualRegister(RR.Reg)) | 1094 if (!Register::isVirtualRegister(RR.Reg)) |
1090 return false; | 1095 return false; |
1091 const TargetRegisterClass *RC = MRI->getRegClass(RR.Reg); | 1096 const TargetRegisterClass *RC = MRI->getRegClass(RR.Reg); |
1092 if (RC == &Hexagon::IntRegsRegClass) { | 1097 if (RC == &Hexagon::IntRegsRegClass) { |
1093 BW = 32; | 1098 BW = 32; |
1094 return true; | 1099 return true; |
1133 return false; | 1138 return false; |
1134 if (L1.hasSubRanges() || L2.hasSubRanges()) | 1139 if (L1.hasSubRanges() || L2.hasSubRanges()) |
1135 return false; | 1140 return false; |
1136 bool Overlap = L1.overlaps(L2); | 1141 bool Overlap = L1.overlaps(L2); |
1137 | 1142 |
1138 DEBUG(dbgs() << "compatible registers: (" | 1143 LLVM_DEBUG(dbgs() << "compatible registers: (" |
1139 << (Overlap ? "overlap" : "disjoint") << ")\n " | 1144 << (Overlap ? "overlap" : "disjoint") << ")\n " |
1140 << printReg(R1.Reg, TRI, R1.Sub) << " " << L1 << "\n " | 1145 << printReg(R1.Reg, TRI, R1.Sub) << " " << L1 << "\n " |
1141 << printReg(R2.Reg, TRI, R2.Sub) << " " << L2 << "\n"); | 1146 << printReg(R2.Reg, TRI, R2.Sub) << " " << L2 << "\n"); |
1142 if (R1.Sub || R2.Sub) | 1147 if (R1.Sub || R2.Sub) |
1143 return false; | 1148 return false; |
1144 if (Overlap) | 1149 if (Overlap) |
1145 return false; | 1150 return false; |
1146 | 1151 |
1169 while (L2.begin() != L2.end()) | 1174 while (L2.begin() != L2.end()) |
1170 L2.removeSegment(*L2.begin()); | 1175 L2.removeSegment(*L2.begin()); |
1171 LIS->removeInterval(R2.Reg); | 1176 LIS->removeInterval(R2.Reg); |
1172 | 1177 |
1173 updateKillFlags(R1.Reg); | 1178 updateKillFlags(R1.Reg); |
1174 DEBUG(dbgs() << "coalesced: " << L1 << "\n"); | 1179 LLVM_DEBUG(dbgs() << "coalesced: " << L1 << "\n"); |
1175 L1.verify(); | 1180 L1.verify(); |
1176 | 1181 |
1177 return true; | 1182 return true; |
1178 } | 1183 } |
1179 | 1184 |
1250 TRI = MF.getSubtarget().getRegisterInfo(); | 1255 TRI = MF.getSubtarget().getRegisterInfo(); |
1251 MDT = &getAnalysis<MachineDominatorTree>(); | 1256 MDT = &getAnalysis<MachineDominatorTree>(); |
1252 LIS = &getAnalysis<LiveIntervals>(); | 1257 LIS = &getAnalysis<LiveIntervals>(); |
1253 MRI = &MF.getRegInfo(); | 1258 MRI = &MF.getRegInfo(); |
1254 | 1259 |
1255 DEBUG(LIS->print(dbgs() << "Before expand-condsets\n", | 1260 LLVM_DEBUG(LIS->print(dbgs() << "Before expand-condsets\n", |
1256 MF.getFunction().getParent())); | 1261 MF.getFunction().getParent())); |
1257 | 1262 |
1258 bool Changed = false; | 1263 bool Changed = false; |
1259 std::set<unsigned> CoalUpd, PredUpd; | 1264 std::set<unsigned> CoalUpd, PredUpd; |
1260 | 1265 |
1261 SmallVector<MachineInstr*,16> Condsets; | 1266 SmallVector<MachineInstr*,16> Condsets; |
1278 for (MachineOperand &Op : MI->operands()) | 1283 for (MachineOperand &Op : MI->operands()) |
1279 if (Op.isReg() && Op.isUse()) | 1284 if (Op.isReg() && Op.isUse()) |
1280 if (!CoalUpd.count(Op.getReg())) | 1285 if (!CoalUpd.count(Op.getReg())) |
1281 KillUpd.insert(Op.getReg()); | 1286 KillUpd.insert(Op.getReg()); |
1282 updateLiveness(KillUpd, false, true, false); | 1287 updateLiveness(KillUpd, false, true, false); |
1283 DEBUG(LIS->print(dbgs() << "After coalescing\n", | 1288 LLVM_DEBUG( |
1284 MF.getFunction().getParent())); | 1289 LIS->print(dbgs() << "After coalescing\n", MF.getFunction().getParent())); |
1285 | 1290 |
1286 // First, simply split all muxes into a pair of conditional transfers | 1291 // First, simply split all muxes into a pair of conditional transfers |
1287 // and update the live intervals to reflect the new arrangement. The | 1292 // and update the live intervals to reflect the new arrangement. The |
1288 // goal is to update the kill flags, since predication will rely on | 1293 // goal is to update the kill flags, since predication will rely on |
1289 // them. | 1294 // them. |
1295 // intervals removes kill flags, which were preserved by splitting on | 1300 // intervals removes kill flags, which were preserved by splitting on |
1296 // the source operands of condsets. These kill flags are needed by | 1301 // the source operands of condsets. These kill flags are needed by |
1297 // predication, and after splitting they are difficult to recalculate | 1302 // predication, and after splitting they are difficult to recalculate |
1298 // (because of predicated defs), so make sure they are left untouched. | 1303 // (because of predicated defs), so make sure they are left untouched. |
1299 // Predication does not use live intervals. | 1304 // Predication does not use live intervals. |
1300 DEBUG(LIS->print(dbgs() << "After splitting\n", | 1305 LLVM_DEBUG( |
1301 MF.getFunction().getParent())); | 1306 LIS->print(dbgs() << "After splitting\n", MF.getFunction().getParent())); |
1302 | 1307 |
1303 // Traverse all blocks and collapse predicable instructions feeding | 1308 // Traverse all blocks and collapse predicable instructions feeding |
1304 // conditional transfers into predicated instructions. | 1309 // conditional transfers into predicated instructions. |
1305 // Walk over all the instructions again, so we may catch pre-existing | 1310 // Walk over all the instructions again, so we may catch pre-existing |
1306 // cases that were not created in the previous step. | 1311 // cases that were not created in the previous step. |
1307 for (auto &B : MF) | 1312 for (auto &B : MF) |
1308 Changed |= predicateInBlock(B, PredUpd); | 1313 Changed |= predicateInBlock(B, PredUpd); |
1309 DEBUG(LIS->print(dbgs() << "After predicating\n", | 1314 LLVM_DEBUG(LIS->print(dbgs() << "After predicating\n", |
1310 MF.getFunction().getParent())); | 1315 MF.getFunction().getParent())); |
1311 | 1316 |
1312 PredUpd.insert(CoalUpd.begin(), CoalUpd.end()); | 1317 PredUpd.insert(CoalUpd.begin(), CoalUpd.end()); |
1313 updateLiveness(PredUpd, true, true, true); | 1318 updateLiveness(PredUpd, true, true, true); |
1314 | 1319 |
1315 DEBUG({ | 1320 LLVM_DEBUG({ |
1316 if (Changed) | 1321 if (Changed) |
1317 LIS->print(dbgs() << "After expand-condsets\n", | 1322 LIS->print(dbgs() << "After expand-condsets\n", |
1318 MF.getFunction().getParent()); | 1323 MF.getFunction().getParent()); |
1319 }); | 1324 }); |
1320 | 1325 |
1322 } | 1327 } |
1323 | 1328 |
1324 //===----------------------------------------------------------------------===// | 1329 //===----------------------------------------------------------------------===// |
1325 // Public Constructor Functions | 1330 // Public Constructor Functions |
1326 //===----------------------------------------------------------------------===// | 1331 //===----------------------------------------------------------------------===// |
1327 | |
1328 FunctionPass *llvm::createHexagonExpandCondsets() { | 1332 FunctionPass *llvm::createHexagonExpandCondsets() { |
1329 return new HexagonExpandCondsets(); | 1333 return new HexagonExpandCondsets(); |
1330 } | 1334 } |