[llvm] 6dcc325 - [M68k][MIR](2/8) Changes in the target-independent MIR part
Min-Yih Hsu via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 8 12:33:44 PST 2021
Author: Min-Yih Hsu
Date: 2021-03-08T12:30:57-08:00
New Revision: 6dcc325ce04541a766bef8217d7063ab2063caf0
URL: https://github.com/llvm/llvm-project/commit/6dcc325ce04541a766bef8217d7063ab2063caf0
DIFF: https://github.com/llvm/llvm-project/commit/6dcc325ce04541a766bef8217d7063ab2063caf0.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/CodeGen/MachineBasicBlock.h
llvm/include/llvm/CodeGen/TargetInstrInfo.h
llvm/lib/CodeGen/MachineBasicBlock.cpp
llvm/lib/CodeGen/MachineVerifier.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index 04fba218c656..3446903626a1 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -895,6 +895,14 @@ class MachineBasicBlock
return findDebugLoc(MBBI.getInstrIterator());
}
+ /// Has exact same behavior as @ref findDebugLoc (it also
+ /// searches from the first to the last MI of this MBB) except
+ /// that this takes reverse iterator.
+ DebugLoc rfindDebugLoc(reverse_instr_iterator MBBI);
+ DebugLoc rfindDebugLoc(reverse_iterator MBBI) {
+ return rfindDebugLoc(MBBI.getInstrIterator());
+ }
+
/// Find the previous valid DebugLoc preceding MBBI, skipping and DBG_VALUE
/// instructions. Return UnknownLoc if there is none.
DebugLoc findPrevDebugLoc(instr_iterator MBBI);
@@ -902,6 +910,14 @@ class MachineBasicBlock
return findPrevDebugLoc(MBBI.getInstrIterator());
}
+ /// Has exact same behavior as @ref findPrevDebugLoc (it also
+ /// searches from the last to the first MI of this MBB) except
+ /// that this takes reverse iterator.
+ DebugLoc rfindPrevDebugLoc(reverse_instr_iterator MBBI);
+ DebugLoc rfindPrevDebugLoc(reverse_iterator MBBI) {
+ return rfindPrevDebugLoc(MBBI.getInstrIterator());
+ }
+
/// Find and return the merged DebugLoc of the branch instructions of the
/// block. Return UnknownLoc if there is none.
DebugLoc findBranchDebugLoc();
diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
index bbd1ca35af3c..a7d5c2e6059f 100644
--- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -951,6 +951,19 @@ class TargetInstrInfo : public MCInstrInfo {
llvm_unreachable("Target didn't implement TargetInstrInfo::copyPhysReg!");
}
+ /// Allow targets to tell MachineVerifier whether a specific register
+ /// MachineOperand can be used as part of PC-relative addressing.
+ /// PC-relative addressing modes in many CISC architectures contain
+ /// (non-PC) registers as offsets or scaling values, which inherently
+ /// tags the corresponding MachineOperand with OPERAND_PCREL.
+ ///
+ /// @param MO The MachineOperand in question. MO.isReg() should always
+ /// be true.
+ /// @return Whether this operand is allowed to be used PC-relatively.
+ virtual bool isPCRelRegisterOperandLegal(const MachineOperand &MO) const {
+ return false;
+ }
+
protected:
/// Target-dependent implementation for IsCopyInstr.
/// If the specific machine instruction is a instruction that moves/copies
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 8ed1701dd751..f31eae937235 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1401,6 +1401,14 @@ MachineBasicBlock::findDebugLoc(instr_iterator MBBI) {
return {};
}
+DebugLoc MachineBasicBlock::rfindDebugLoc(reverse_instr_iterator MBBI) {
+ // Skip debug declarations, we don't want a DebugLoc from them.
+ MBBI = skipDebugInstructionsBackward(MBBI, instr_rbegin());
+ if (!MBBI->isDebugInstr())
+ return MBBI->getDebugLoc();
+ return {};
+}
+
/// Find the previous valid DebugLoc preceding MBBI, skipping and DBG_VALUE
/// instructions. Return UnknownLoc if there is none.
DebugLoc MachineBasicBlock::findPrevDebugLoc(instr_iterator MBBI) {
@@ -1411,6 +1419,16 @@ DebugLoc MachineBasicBlock::findPrevDebugLoc(instr_iterator MBBI) {
return {};
}
+DebugLoc MachineBasicBlock::rfindPrevDebugLoc(reverse_instr_iterator MBBI) {
+ if (MBBI == instr_rend())
+ return {};
+ // Skip debug declarations, we don't want a DebugLoc from them.
+ MBBI = next_nodbg(MBBI, instr_rend());
+ if (MBBI != instr_rend())
+ return MBBI->getDebugLoc();
+ return {};
+}
+
/// Find and return the merged DebugLoc of the branch instructions of the block.
/// Return UnknownLoc if there is none.
DebugLoc
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 8bae5ab0bde3..57eb9443a8dd 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1762,9 +1762,12 @@ MachineVerifier::visitMachineOperand(const MachineOperand *MO, unsigned MONum) {
if (MCOI.OperandType == MCOI::OPERAND_REGISTER &&
!MO->isReg() && !MO->isFI())
report("Expected a register operand.", MO, MONum);
- if ((MCOI.OperandType == MCOI::OPERAND_IMMEDIATE ||
- MCOI.OperandType == MCOI::OPERAND_PCREL) && MO->isReg())
- report("Expected a non-register operand.", MO, MONum);
+ if (MO->isReg()) {
+ if (MCOI.OperandType == MCOI::OPERAND_IMMEDIATE ||
+ (MCOI.OperandType == MCOI::OPERAND_PCREL &&
+ !TII->isPCRelRegisterOperandLegal(*MO)))
+ report("Expected a non-register operand.", MO, MONum);
+ }
}
int TiedTo = MCID.getOperandConstraint(MONum, MCOI::TIED_TO);
More information about the llvm-commits
mailing list