[llvm] LivePhysRegs to LiveRegUnits (PR #85162)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 13 17:36:17 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 090edd376e6ae353ab344b84622824ce25454bd3 553849a19ddd2ae8419e74e5334c5bbb828539c8 -- llvm/lib/Target/ARM/ARMConstantIslandPass.cpp llvm/lib/Target/SystemZ/SystemZPostRewrite.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
index 8cd520c4e4..5447f9269c 100644
--- a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
+++ b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
@@ -1029,162 +1029,165 @@ MachineBasicBlock *ARMConstantIslands::splitBlockBeforeInstr(MachineInstr *MI) {
const llvm::BitVector &bitVector = LRs.getBitVector();
for (unsigned RegUnit = 0; RegUnit < bitVector.size(); ++RegUnit) {
if (bitVector.test(RegUnit)) {
- if (!MRI.isReserved(RegUnit))
- NewBB->addLiveIn(RegUnit);
-
- // Update internal data structures to account for the newly inserted MBB.
- // This is almost the same as updateForInsertedWaterBlock, except that
- // the Water goes after OrigBB, not NewBB.
- MF->RenumberBlocks(NewBB);
-
- // Insert an entry into BBInfo to align it properly with the (newly
- // renumbered) block numbers.
- BBUtils->insert(NewBB->getNumber(), BasicBlockInfo());
-
- // Next, update WaterList. Specifically, we need to add OrigMBB as having
- // available water after it (but not if it's already there, which happens
- // when splitting before a conditional branch that is followed by an
- // unconditional branch - in that case we want to insert NewBB).
- water_iterator IP = llvm::lower_bound(WaterList, OrigBB, CompareMBBNumbers);
- MachineBasicBlock* WaterBB = *IP;
- if (WaterBB == OrigBB)
- WaterList.insert(std::next(IP), NewBB);
- else
- WaterList.insert(IP, OrigBB);
- NewWaterList.insert(OrigBB);
+ if (!MRI.isReserved(RegUnit))
+ NewBB->addLiveIn(RegUnit);
+
+ // Update internal data structures to account for the newly inserted MBB.
+ // This is almost the same as updateForInsertedWaterBlock, except that
+ // the Water goes after OrigBB, not NewBB.
+ MF->RenumberBlocks(NewBB);
+
+ // Insert an entry into BBInfo to align it properly with the (newly
+ // renumbered) block numbers.
+ BBUtils->insert(NewBB->getNumber(), BasicBlockInfo());
+
+ // Next, update WaterList. Specifically, we need to add OrigMBB as having
+ // available water after it (but not if it's already there, which happens
+ // when splitting before a conditional branch that is followed by an
+ // unconditional branch - in that case we want to insert NewBB).
+ water_iterator IP =
+ llvm::lower_bound(WaterList, OrigBB, CompareMBBNumbers);
+ MachineBasicBlock *WaterBB = *IP;
+ if (WaterBB == OrigBB)
+ WaterList.insert(std::next(IP), NewBB);
+ else
+ WaterList.insert(IP, OrigBB);
+ NewWaterList.insert(OrigBB);
- // Figure out how large the OrigBB is. As the first half of the original
- // block, it cannot contain a tablejump. The size includes
- // the new jump we added. (It should be possible to do this without
- // recounting everything, but it's very confusing, and this is rarely
- // executed.)
- BBUtils->computeBlockSize(OrigBB);
+ // Figure out how large the OrigBB is. As the first half of the original
+ // block, it cannot contain a tablejump. The size includes
+ // the new jump we added. (It should be possible to do this without
+ // recounting everything, but it's very confusing, and this is rarely
+ // executed.)
+ BBUtils->computeBlockSize(OrigBB);
- // Figure out how large the NewMBB is. As the second half of the original
- // block, it may contain a tablejump.
- BBUtils->computeBlockSize(NewBB);
+ // Figure out how large the NewMBB is. As the second half of the original
+ // block, it may contain a tablejump.
+ BBUtils->computeBlockSize(NewBB);
- // All BBOffsets following these blocks must be modified.
- BBUtils->adjustBBOffsetsAfter(OrigBB);
+ // All BBOffsets following these blocks must be modified.
+ BBUtils->adjustBBOffsetsAfter(OrigBB);
- return NewBB;
-}
+ return NewBB;
+ }
-/// getUserOffset - Compute the offset of U.MI as seen by the hardware
-/// displacement computation. Update U.KnownAlignment to match its current
-/// basic block location.
-unsigned ARMConstantIslands::getUserOffset(CPUser &U) const {
- unsigned UserOffset = BBUtils->getOffsetOf(U.MI);
+ /// getUserOffset - Compute the offset of U.MI as seen by the hardware
+ /// displacement computation. Update U.KnownAlignment to match its current
+ /// basic block location.
+ unsigned ARMConstantIslands::getUserOffset(CPUser & U) const {
+ unsigned UserOffset = BBUtils->getOffsetOf(U.MI);
- SmallVectorImpl<BasicBlockInfo> &BBInfo = BBUtils->getBBInfo();
- const BasicBlockInfo &BBI = BBInfo[U.MI->getParent()->getNumber()];
- unsigned KnownBits = BBI.internalKnownBits();
+ SmallVectorImpl<BasicBlockInfo> &BBInfo = BBUtils->getBBInfo();
+ const BasicBlockInfo &BBI = BBInfo[U.MI->getParent()->getNumber()];
+ unsigned KnownBits = BBI.internalKnownBits();
- // The value read from PC is offset from the actual instruction address.
- UserOffset += (isThumb ? 4 : 8);
+ // The value read from PC is offset from the actual instruction address.
+ UserOffset += (isThumb ? 4 : 8);
- // Because of inline assembly, we may not know the alignment (mod 4) of U.MI.
- // Make sure U.getMaxDisp() returns a constrained range.
- U.KnownAlignment = (KnownBits >= 2);
+ // Because of inline assembly, we may not know the alignment (mod 4) of
+ // U.MI. Make sure U.getMaxDisp() returns a constrained range.
+ U.KnownAlignment = (KnownBits >= 2);
- // On Thumb, offsets==2 mod 4 are rounded down by the hardware for
- // purposes of the displacement computation; compensate for that here.
- // For unknown alignments, getMaxDisp() constrains the range instead.
- if (isThumb && U.KnownAlignment)
- UserOffset &= ~3u;
+ // On Thumb, offsets==2 mod 4 are rounded down by the hardware for
+ // purposes of the displacement computation; compensate for that here.
+ // For unknown alignments, getMaxDisp() constrains the range instead.
+ if (isThumb && U.KnownAlignment)
+ UserOffset &= ~3u;
- return UserOffset;
-}
+ return UserOffset;
+ }
-/// isOffsetInRange - Checks whether UserOffset (the location of a constant pool
-/// reference) is within MaxDisp of TrialOffset (a proposed location of a
-/// constant pool entry).
-/// UserOffset is computed by getUserOffset above to include PC adjustments. If
-/// the mod 4 alignment of UserOffset is not known, the uncertainty must be
-/// subtracted from MaxDisp instead. CPUser::getMaxDisp() does that.
-bool ARMConstantIslands::isOffsetInRange(unsigned UserOffset,
- unsigned TrialOffset, unsigned MaxDisp,
- bool NegativeOK, bool IsSoImm) {
- if (UserOffset <= TrialOffset) {
- // User before the Trial.
- if (TrialOffset - UserOffset <= MaxDisp)
- return true;
- // FIXME: Make use full range of soimm values.
- } else if (NegativeOK) {
- if (UserOffset - TrialOffset <= MaxDisp)
- return true;
- // FIXME: Make use full range of soimm values.
- }
- return false;
-}
+ /// isOffsetInRange - Checks whether UserOffset (the location of a constant
+ /// pool reference) is within MaxDisp of TrialOffset (a proposed location of
+ /// a constant pool entry). UserOffset is computed by getUserOffset above to
+ /// include PC adjustments. If the mod 4 alignment of UserOffset is not
+ /// known, the uncertainty must be subtracted from MaxDisp instead.
+ /// CPUser::getMaxDisp() does that.
+ bool ARMConstantIslands::isOffsetInRange(
+ unsigned UserOffset, unsigned TrialOffset, unsigned MaxDisp,
+ bool NegativeOK, bool IsSoImm) {
+ if (UserOffset <= TrialOffset) {
+ // User before the Trial.
+ if (TrialOffset - UserOffset <= MaxDisp)
+ return true;
+ // FIXME: Make use full range of soimm values.
+ } else if (NegativeOK) {
+ if (UserOffset - TrialOffset <= MaxDisp)
+ return true;
+ // FIXME: Make use full range of soimm values.
+ }
+ return false;
+ }
-/// isWaterInRange - Returns true if a CPE placed after the specified
-/// Water (a basic block) will be in range for the specific MI.
-///
-/// Compute how much the function will grow by inserting a CPE after Water.
-bool ARMConstantIslands::isWaterInRange(unsigned UserOffset,
- MachineBasicBlock* Water, CPUser &U,
- unsigned &Growth) {
- BBInfoVector &BBInfo = BBUtils->getBBInfo();
- const Align CPEAlign = getCPEAlign(U.CPEMI);
- const unsigned CPEOffset = BBInfo[Water->getNumber()].postOffset(CPEAlign);
- unsigned NextBlockOffset;
- Align NextBlockAlignment;
- MachineFunction::const_iterator NextBlock = Water->getIterator();
- if (++NextBlock == MF->end()) {
- NextBlockOffset = BBInfo[Water->getNumber()].postOffset();
- } else {
- NextBlockOffset = BBInfo[NextBlock->getNumber()].Offset;
- NextBlockAlignment = NextBlock->getAlignment();
- }
- unsigned Size = U.CPEMI->getOperand(2).getImm();
- unsigned CPEEnd = CPEOffset + Size;
-
- // The CPE may be able to hide in the alignment padding before the next
- // block. It may also cause more padding to be required if it is more aligned
- // that the next block.
- if (CPEEnd > NextBlockOffset) {
- Growth = CPEEnd - NextBlockOffset;
- // Compute the padding that would go at the end of the CPE to align the next
- // block.
- Growth += offsetToAlignment(CPEEnd, NextBlockAlignment);
-
- // If the CPE is to be inserted before the instruction, that will raise
- // the offset of the instruction. Also account for unknown alignment padding
- // in blocks between CPE and the user.
- if (CPEOffset < UserOffset)
- UserOffset += Growth + UnknownPadding(MF->getAlignment(), Log2(CPEAlign));
- } else
- // CPE fits in existing padding.
- Growth = 0;
-
- return isOffsetInRange(UserOffset, CPEOffset, U);
-}
+ /// isWaterInRange - Returns true if a CPE placed after the specified
+ /// Water (a basic block) will be in range for the specific MI.
+ ///
+ /// Compute how much the function will grow by inserting a CPE after Water.
+ bool ARMConstantIslands::isWaterInRange(unsigned UserOffset,
+ MachineBasicBlock *Water, CPUser &U,
+ unsigned &Growth) {
+ BBInfoVector &BBInfo = BBUtils->getBBInfo();
+ const Align CPEAlign = getCPEAlign(U.CPEMI);
+ const unsigned CPEOffset =
+ BBInfo[Water->getNumber()].postOffset(CPEAlign);
+ unsigned NextBlockOffset;
+ Align NextBlockAlignment;
+ MachineFunction::const_iterator NextBlock = Water->getIterator();
+ if (++NextBlock == MF->end()) {
+ NextBlockOffset = BBInfo[Water->getNumber()].postOffset();
+ } else {
+ NextBlockOffset = BBInfo[NextBlock->getNumber()].Offset;
+ NextBlockAlignment = NextBlock->getAlignment();
+ }
+ unsigned Size = U.CPEMI->getOperand(2).getImm();
+ unsigned CPEEnd = CPEOffset + Size;
+
+ // The CPE may be able to hide in the alignment padding before the next
+ // block. It may also cause more padding to be required if it is more
+ // aligned that the next block.
+ if (CPEEnd > NextBlockOffset) {
+ Growth = CPEEnd - NextBlockOffset;
+ // Compute the padding that would go at the end of the CPE to align the
+ // next block.
+ Growth += offsetToAlignment(CPEEnd, NextBlockAlignment);
+
+ // If the CPE is to be inserted before the instruction, that will raise
+ // the offset of the instruction. Also account for unknown alignment
+ // padding in blocks between CPE and the user.
+ if (CPEOffset < UserOffset)
+ UserOffset +=
+ Growth + UnknownPadding(MF->getAlignment(), Log2(CPEAlign));
+ } else
+ // CPE fits in existing padding.
+ Growth = 0;
+
+ return isOffsetInRange(UserOffset, CPEOffset, U);
+ }
-/// isCPEntryInRange - Returns true if the distance between specific MI and
-/// specific ConstPool entry instruction can fit in MI's displacement field.
-bool ARMConstantIslands::isCPEntryInRange(MachineInstr *MI, unsigned UserOffset,
- MachineInstr *CPEMI, unsigned MaxDisp,
- bool NegOk, bool DoDump) {
- unsigned CPEOffset = BBUtils->getOffsetOf(CPEMI);
-
- if (DoDump) {
- LLVM_DEBUG({
- BBInfoVector &BBInfo = BBUtils->getBBInfo();
- unsigned Block = MI->getParent()->getNumber();
- const BasicBlockInfo &BBI = BBInfo[Block];
- dbgs() << "User of CPE#" << CPEMI->getOperand(0).getImm()
- << " max delta=" << MaxDisp
- << format(" insn address=%#x", UserOffset) << " in "
- << printMBBReference(*MI->getParent()) << ": "
- << format("%#x-%x\t", BBI.Offset, BBI.postOffset()) << *MI
- << format("CPE address=%#x offset=%+d: ", CPEOffset,
- int(CPEOffset - UserOffset));
- });
- }
+ /// isCPEntryInRange - Returns true if the distance between specific MI and
+ /// specific ConstPool entry instruction can fit in MI's displacement field.
+ bool ARMConstantIslands::isCPEntryInRange(
+ MachineInstr * MI, unsigned UserOffset, MachineInstr *CPEMI,
+ unsigned MaxDisp, bool NegOk, bool DoDump) {
+ unsigned CPEOffset = BBUtils->getOffsetOf(CPEMI);
+
+ if (DoDump) {
+ LLVM_DEBUG({
+ BBInfoVector &BBInfo = BBUtils->getBBInfo();
+ unsigned Block = MI->getParent()->getNumber();
+ const BasicBlockInfo &BBI = BBInfo[Block];
+ dbgs() << "User of CPE#" << CPEMI->getOperand(0).getImm()
+ << " max delta=" << MaxDisp
+ << format(" insn address=%#x", UserOffset) << " in "
+ << printMBBReference(*MI->getParent()) << ": "
+ << format("%#x-%x\t", BBI.Offset, BBI.postOffset()) << *MI
+ << format("CPE address=%#x offset=%+d: ", CPEOffset,
+ int(CPEOffset - UserOffset));
+ });
+ }
- return isOffsetInRange(UserOffset, CPEOffset, MaxDisp, NegOk);
-}
+ return isOffsetInRange(UserOffset, CPEOffset, MaxDisp, NegOk);
+ }
#ifndef NDEBUG
/// BBIsJumpedOver - Return true of the specified basic block's only predecessor
diff --git a/llvm/lib/Target/SystemZ/SystemZPostRewrite.cpp b/llvm/lib/Target/SystemZ/SystemZPostRewrite.cpp
index fed801a698..c2cbfe227a 100644
--- a/llvm/lib/Target/SystemZ/SystemZPostRewrite.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZPostRewrite.cpp
@@ -176,93 +176,95 @@ bool SystemZPostRewrite::expandCondMove(MachineBasicBlock &MBB,
if (bitVector.test(RegUnit))
RestMBB->addLiveIn(RegUnit);
- // Create a new block MoveMBB to hold the move instruction.
- MachineBasicBlock *MoveMBB = MF.CreateMachineBasicBlock(BB);
- MF.insert(std::next(MachineFunction::iterator(MBB)), MoveMBB);
- MoveMBB->addLiveIn(SrcReg);
- for (unsigned RegUnit = 0; RegUnit < bitVector.size(); ++RegUnit) {
- if (bitVector.test(RegUnit))
- RestMBB->addLiveIn(RegUnit);
-
- // At the end of MBB, create a conditional branch to RestMBB if the
- // condition is false, otherwise fall through to MoveMBB.
- BuildMI(&MBB, DL, TII->get(SystemZ::BRC))
- .addImm(CCValid).addImm(CCMask ^ CCValid).addMBB(RestMBB);
- MBB.addSuccessor(RestMBB);
- MBB.addSuccessor(MoveMBB);
-
- // In MoveMBB, emit an instruction to move SrcReg into DestReg,
- // then fall through to RestMBB.
- BuildMI(*MoveMBB, MoveMBB->end(), DL, TII->get(SystemZ::COPY), DestReg)
- .addReg(MI.getOperand(2).getReg(), getRegState(MI.getOperand(2)));
- MoveMBB->addSuccessor(RestMBB);
-
- NextMBBI = MBB.end();
- MI.eraseFromParent();
- LOCRMuxJumps++;
- return true;
-}
-
-/// If MBBI references a pseudo instruction that should be selected here,
-/// do it and return true. Otherwise return false.
-bool SystemZPostRewrite::selectMI(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator MBBI,
- MachineBasicBlock::iterator &NextMBBI) {
- MachineInstr &MI = *MBBI;
- unsigned Opcode = MI.getOpcode();
-
- // Note: If this could be done during regalloc in foldMemoryOperandImpl()
- // while also updating the LiveIntervals, there would be no need for the
- // MemFoldPseudo to begin with.
- int TargetMemOpcode = SystemZ::getTargetMemOpcode(Opcode);
- if (TargetMemOpcode != -1) {
- MI.setDesc(TII->get(TargetMemOpcode));
- MI.tieOperands(0, 1);
- Register DstReg = MI.getOperand(0).getReg();
- MachineOperand &SrcMO = MI.getOperand(1);
- if (DstReg != SrcMO.getReg()) {
- BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(SystemZ::COPY), DstReg)
- .addReg(SrcMO.getReg());
- SrcMO.setReg(DstReg);
- MemFoldCopies++;
+ // Create a new block MoveMBB to hold the move instruction.
+ MachineBasicBlock *MoveMBB = MF.CreateMachineBasicBlock(BB);
+ MF.insert(std::next(MachineFunction::iterator(MBB)), MoveMBB);
+ MoveMBB->addLiveIn(SrcReg);
+ for (unsigned RegUnit = 0; RegUnit < bitVector.size(); ++RegUnit) {
+ if (bitVector.test(RegUnit))
+ RestMBB->addLiveIn(RegUnit);
+
+ // At the end of MBB, create a conditional branch to RestMBB if the
+ // condition is false, otherwise fall through to MoveMBB.
+ BuildMI(&MBB, DL, TII->get(SystemZ::BRC))
+ .addImm(CCValid)
+ .addImm(CCMask ^ CCValid)
+ .addMBB(RestMBB);
+ MBB.addSuccessor(RestMBB);
+ MBB.addSuccessor(MoveMBB);
+
+ // In MoveMBB, emit an instruction to move SrcReg into DestReg,
+ // then fall through to RestMBB.
+ BuildMI(*MoveMBB, MoveMBB->end(), DL, TII->get(SystemZ::COPY), DestReg)
+ .addReg(MI.getOperand(2).getReg(), getRegState(MI.getOperand(2)));
+ MoveMBB->addSuccessor(RestMBB);
+
+ NextMBBI = MBB.end();
+ MI.eraseFromParent();
+ LOCRMuxJumps++;
+ return true;
}
- return true;
- }
- switch (Opcode) {
- case SystemZ::LOCRMux:
- selectLOCRMux(MBB, MBBI, NextMBBI, SystemZ::LOCR, SystemZ::LOCFHR);
- return true;
- case SystemZ::SELRMux:
- selectSELRMux(MBB, MBBI, NextMBBI, SystemZ::SELR, SystemZ::SELFHR);
- return true;
- }
-
- return false;
-}
+ /// If MBBI references a pseudo instruction that should be selected here,
+ /// do it and return true. Otherwise return false.
+ bool SystemZPostRewrite::selectMI(MachineBasicBlock & MBB,
+ MachineBasicBlock::iterator MBBI,
+ MachineBasicBlock::iterator & NextMBBI) {
+ MachineInstr &MI = *MBBI;
+ unsigned Opcode = MI.getOpcode();
+
+ // Note: If this could be done during regalloc in foldMemoryOperandImpl()
+ // while also updating the LiveIntervals, there would be no need for the
+ // MemFoldPseudo to begin with.
+ int TargetMemOpcode = SystemZ::getTargetMemOpcode(Opcode);
+ if (TargetMemOpcode != -1) {
+ MI.setDesc(TII->get(TargetMemOpcode));
+ MI.tieOperands(0, 1);
+ Register DstReg = MI.getOperand(0).getReg();
+ MachineOperand &SrcMO = MI.getOperand(1);
+ if (DstReg != SrcMO.getReg()) {
+ BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(SystemZ::COPY), DstReg)
+ .addReg(SrcMO.getReg());
+ SrcMO.setReg(DstReg);
+ MemFoldCopies++;
+ }
+ return true;
+ }
+
+ switch (Opcode) {
+ case SystemZ::LOCRMux:
+ selectLOCRMux(MBB, MBBI, NextMBBI, SystemZ::LOCR, SystemZ::LOCFHR);
+ return true;
+ case SystemZ::SELRMux:
+ selectSELRMux(MBB, MBBI, NextMBBI, SystemZ::SELR, SystemZ::SELFHR);
+ return true;
+ }
+
+ return false;
+ }
-/// Iterate over the instructions in basic block MBB and select any
-/// pseudo instructions. Return true if anything was modified.
-bool SystemZPostRewrite::selectMBB(MachineBasicBlock &MBB) {
- bool Modified = false;
+ /// Iterate over the instructions in basic block MBB and select any
+ /// pseudo instructions. Return true if anything was modified.
+ bool SystemZPostRewrite::selectMBB(MachineBasicBlock & MBB) {
+ bool Modified = false;
- MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
- while (MBBI != E) {
- MachineBasicBlock::iterator NMBBI = std::next(MBBI);
- Modified |= selectMI(MBB, MBBI, NMBBI);
- MBBI = NMBBI;
- }
+ MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
+ while (MBBI != E) {
+ MachineBasicBlock::iterator NMBBI = std::next(MBBI);
+ Modified |= selectMI(MBB, MBBI, NMBBI);
+ MBBI = NMBBI;
+ }
- return Modified;
-}
+ return Modified;
+ }
-bool SystemZPostRewrite::runOnMachineFunction(MachineFunction &MF) {
- TII = MF.getSubtarget<SystemZSubtarget>().getInstrInfo();
+ bool SystemZPostRewrite::runOnMachineFunction(MachineFunction & MF) {
+ TII = MF.getSubtarget<SystemZSubtarget>().getInstrInfo();
- bool Modified = false;
- for (auto &MBB : MF)
- Modified |= selectMBB(MBB);
+ bool Modified = false;
+ for (auto &MBB : MF)
+ Modified |= selectMBB(MBB);
- return Modified;
-}
+ return Modified;
+ }
``````````
</details>
https://github.com/llvm/llvm-project/pull/85162
More information about the llvm-commits
mailing list