Skip to content

Commit 6dcc325

Browse files
committed
[M68k][MIR](2/8) Changes in the target-independent MIR part
- Add new callback in `TargetInstrInfo` -- `isPCRelRegisterOperandLegal` -- to query whether pc-rel register MachineOperand is legal. - Add new function to search DebugLoc in a reverse ordering Authors: myhsu, m4yers, glaubitz Differential Revision: https://reviews.llvm.org/D88386
1 parent 5033431 commit 6dcc325

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,13 +895,29 @@ class MachineBasicBlock
895895
return findDebugLoc(MBBI.getInstrIterator());
896896
}
897897

898+
/// Has exact same behavior as @ref findDebugLoc (it also
899+
/// searches from the first to the last MI of this MBB) except
900+
/// that this takes reverse iterator.
901+
DebugLoc rfindDebugLoc(reverse_instr_iterator MBBI);
902+
DebugLoc rfindDebugLoc(reverse_iterator MBBI) {
903+
return rfindDebugLoc(MBBI.getInstrIterator());
904+
}
905+
898906
/// Find the previous valid DebugLoc preceding MBBI, skipping and DBG_VALUE
899907
/// instructions. Return UnknownLoc if there is none.
900908
DebugLoc findPrevDebugLoc(instr_iterator MBBI);
901909
DebugLoc findPrevDebugLoc(iterator MBBI) {
902910
return findPrevDebugLoc(MBBI.getInstrIterator());
903911
}
904912

913+
/// Has exact same behavior as @ref findPrevDebugLoc (it also
914+
/// searches from the last to the first MI of this MBB) except
915+
/// that this takes reverse iterator.
916+
DebugLoc rfindPrevDebugLoc(reverse_instr_iterator MBBI);
917+
DebugLoc rfindPrevDebugLoc(reverse_iterator MBBI) {
918+
return rfindPrevDebugLoc(MBBI.getInstrIterator());
919+
}
920+
905921
/// Find and return the merged DebugLoc of the branch instructions of the
906922
/// block. Return UnknownLoc if there is none.
907923
DebugLoc findBranchDebugLoc();

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,19 @@ class TargetInstrInfo : public MCInstrInfo {
951951
llvm_unreachable("Target didn't implement TargetInstrInfo::copyPhysReg!");
952952
}
953953

954+
/// Allow targets to tell MachineVerifier whether a specific register
955+
/// MachineOperand can be used as part of PC-relative addressing.
956+
/// PC-relative addressing modes in many CISC architectures contain
957+
/// (non-PC) registers as offsets or scaling values, which inherently
958+
/// tags the corresponding MachineOperand with OPERAND_PCREL.
959+
///
960+
/// @param MO The MachineOperand in question. MO.isReg() should always
961+
/// be true.
962+
/// @return Whether this operand is allowed to be used PC-relatively.
963+
virtual bool isPCRelRegisterOperandLegal(const MachineOperand &MO) const {
964+
return false;
965+
}
966+
954967
protected:
955968
/// Target-dependent implementation for IsCopyInstr.
956969
/// If the specific machine instruction is a instruction that moves/copies

llvm/lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,14 @@ MachineBasicBlock::findDebugLoc(instr_iterator MBBI) {
14011401
return {};
14021402
}
14031403

1404+
DebugLoc MachineBasicBlock::rfindDebugLoc(reverse_instr_iterator MBBI) {
1405+
// Skip debug declarations, we don't want a DebugLoc from them.
1406+
MBBI = skipDebugInstructionsBackward(MBBI, instr_rbegin());
1407+
if (!MBBI->isDebugInstr())
1408+
return MBBI->getDebugLoc();
1409+
return {};
1410+
}
1411+
14041412
/// Find the previous valid DebugLoc preceding MBBI, skipping and DBG_VALUE
14051413
/// instructions. Return UnknownLoc if there is none.
14061414
DebugLoc MachineBasicBlock::findPrevDebugLoc(instr_iterator MBBI) {
@@ -1411,6 +1419,16 @@ DebugLoc MachineBasicBlock::findPrevDebugLoc(instr_iterator MBBI) {
14111419
return {};
14121420
}
14131421

1422+
DebugLoc MachineBasicBlock::rfindPrevDebugLoc(reverse_instr_iterator MBBI) {
1423+
if (MBBI == instr_rend())
1424+
return {};
1425+
// Skip debug declarations, we don't want a DebugLoc from them.
1426+
MBBI = next_nodbg(MBBI, instr_rend());
1427+
if (MBBI != instr_rend())
1428+
return MBBI->getDebugLoc();
1429+
return {};
1430+
}
1431+
14141432
/// Find and return the merged DebugLoc of the branch instructions of the block.
14151433
/// Return UnknownLoc if there is none.
14161434
DebugLoc

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,9 +1762,12 @@ MachineVerifier::visitMachineOperand(const MachineOperand *MO, unsigned MONum) {
17621762
if (MCOI.OperandType == MCOI::OPERAND_REGISTER &&
17631763
!MO->isReg() && !MO->isFI())
17641764
report("Expected a register operand.", MO, MONum);
1765-
if ((MCOI.OperandType == MCOI::OPERAND_IMMEDIATE ||
1766-
MCOI.OperandType == MCOI::OPERAND_PCREL) && MO->isReg())
1767-
report("Expected a non-register operand.", MO, MONum);
1765+
if (MO->isReg()) {
1766+
if (MCOI.OperandType == MCOI::OPERAND_IMMEDIATE ||
1767+
(MCOI.OperandType == MCOI::OPERAND_PCREL &&
1768+
!TII->isPCRelRegisterOperandLegal(*MO)))
1769+
report("Expected a non-register operand.", MO, MONum);
1770+
}
17681771
}
17691772

17701773
int TiedTo = MCID.getOperandConstraint(MONum, MCOI::TIED_TO);

0 commit comments

Comments
 (0)