Index: llvm/include/llvm/CodeGen/MachineBasicBlock.h =================================================================== --- llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -852,6 +852,13 @@ DebugLoc findDebugLoc(iterator MBBI) { 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. @@ -859,6 +866,13 @@ DebugLoc findPrevDebugLoc(iterator MBBI) { 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. Index: llvm/include/llvm/CodeGen/TargetInstrInfo.h =================================================================== --- llvm/include/llvm/CodeGen/TargetInstrInfo.h +++ llvm/include/llvm/CodeGen/TargetInstrInfo.h @@ -944,6 +944,19 @@ 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 Index: llvm/lib/CodeGen/MachineBasicBlock.cpp =================================================================== --- llvm/lib/CodeGen/MachineBasicBlock.cpp +++ llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -1364,6 +1364,13 @@ return MBBI->getDebugLoc(); 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. @@ -1374,6 +1381,15 @@ if (!MBBI->isDebugInstr()) return MBBI->getDebugLoc(); 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. Index: llvm/lib/CodeGen/MachineVerifier.cpp =================================================================== --- llvm/lib/CodeGen/MachineVerifier.cpp +++ llvm/lib/CodeGen/MachineVerifier.cpp @@ -1685,9 +1685,12 @@ 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);