aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineOperand.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:11 +0000
commite3b557809604d036af6e00c60f012c2025b59a5e (patch)
tree8a11ba2269a3b669601e2fd41145b174008f4da8 /llvm/lib/CodeGen/MachineOperand.cpp
parent08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff)
Diffstat (limited to 'llvm/lib/CodeGen/MachineOperand.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineOperand.cpp97
1 files changed, 72 insertions, 25 deletions
diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp
index 46ad1de78c46..0a7b12e9ccb9 100644
--- a/llvm/lib/CodeGen/MachineOperand.cpp
+++ b/llvm/lib/CodeGen/MachineOperand.cpp
@@ -18,6 +18,7 @@
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/CodeGen/StableHashing.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/Config/llvm-config.h"
@@ -28,6 +29,7 @@
#include "llvm/MC/MCDwarf.h"
#include "llvm/Target/TargetIntrinsicInfo.h"
#include "llvm/Target/TargetMachine.h"
+#include <optional>
using namespace llvm;
@@ -45,6 +47,7 @@ static const MachineFunction *getMFIfAvailable(const MachineOperand &MO) {
return MF;
return nullptr;
}
+
static MachineFunction *getMFIfAvailable(MachineOperand &MO) {
return const_cast<MachineFunction *>(
getMFIfAvailable(const_cast<const MachineOperand &>(MO)));
@@ -115,7 +118,7 @@ void MachineOperand::setIsDef(bool Val) {
bool MachineOperand::isRenamable() const {
assert(isReg() && "Wrong MachineOperand accessor");
- assert(Register::isPhysicalRegister(getReg()) &&
+ assert(getReg().isPhysical() &&
"isRenamable should only be checked on physical registers");
if (!IsRenamable)
return false;
@@ -133,7 +136,7 @@ bool MachineOperand::isRenamable() const {
void MachineOperand::setIsRenamable(bool Val) {
assert(isReg() && "Wrong MachineOperand accessor");
- assert(Register::isPhysicalRegister(getReg()) &&
+ assert(getReg().isPhysical() &&
"setIsRenamable should only be called on physical registers");
IsRenamable = Val;
}
@@ -233,6 +236,19 @@ void MachineOperand::ChangeToTargetIndex(unsigned Idx, int64_t Offset,
setTargetFlags(TargetFlags);
}
+void MachineOperand::ChangeToDbgInstrRef(unsigned InstrIdx, unsigned OpIdx,
+ unsigned TargetFlags) {
+ assert((!isReg() || !isTied()) &&
+ "Cannot change a tied operand into a DbgInstrRef");
+
+ removeRegFromUses();
+
+ OpKind = MO_DbgInstrRef;
+ setInstrRefInstrIndex(InstrIdx);
+ setInstrRefOpIndex(OpIdx);
+ setTargetFlags(TargetFlags);
+}
+
/// ChangeToRegister - Replace this operand with a new register operand of
/// the specified value. If an operand is known to be an register already,
/// the setReg method should be used.
@@ -323,10 +339,8 @@ bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
return true;
if (const MachineFunction *MF = getMFIfAvailable(*this)) {
- // Calculate the size of the RegMask
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
- unsigned RegMaskSize = (TRI->getNumRegs() + 31) / 32;
-
+ unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
// Deep compare of the two RegMasks
return std::equal(RegMask, RegMask + RegMaskSize, OtherRegMask);
}
@@ -336,6 +350,9 @@ bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
}
case MachineOperand::MO_MCSymbol:
return getMCSymbol() == Other.getMCSymbol();
+ case MachineOperand::MO_DbgInstrRef:
+ return getInstrRefInstrIndex() == Other.getInstrRefInstrIndex() &&
+ getInstrRefOpIndex() == Other.getInstrRefOpIndex();
case MachineOperand::MO_CFIIndex:
return getCFIIndex() == Other.getCFIIndex();
case MachineOperand::MO_Metadata:
@@ -382,12 +399,27 @@ hash_code llvm::hash_value(const MachineOperand &MO) {
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getBlockAddress(),
MO.getOffset());
case MachineOperand::MO_RegisterMask:
- case MachineOperand::MO_RegisterLiveOut:
- return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getRegMask());
+ case MachineOperand::MO_RegisterLiveOut: {
+ if (const MachineFunction *MF = getMFIfAvailable(MO)) {
+ const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
+ unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
+ const uint32_t *RegMask = MO.getRegMask();
+ std::vector<stable_hash> RegMaskHashes(RegMask, RegMask + RegMaskSize);
+ return hash_combine(MO.getType(), MO.getTargetFlags(),
+ stable_hash_combine_array(RegMaskHashes.data(),
+ RegMaskHashes.size()));
+ }
+
+ assert(0 && "MachineOperand not associated with any MachineFunction");
+ return hash_combine(MO.getType(), MO.getTargetFlags());
+ }
case MachineOperand::MO_Metadata:
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMetadata());
case MachineOperand::MO_MCSymbol:
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMCSymbol());
+ case MachineOperand::MO_DbgInstrRef:
+ return hash_combine(MO.getType(), MO.getTargetFlags(),
+ MO.getInstrRefInstrIndex(), MO.getInstrRefOpIndex());
case MachineOperand::MO_CFIIndex:
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCFIIndex());
case MachineOperand::MO_IntrinsicID:
@@ -445,7 +477,7 @@ static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS,
return;
}
- if (Optional<unsigned> Reg = TRI->getLLVMRegNum(DwarfReg, true))
+ if (std::optional<unsigned> Reg = TRI->getLLVMRegNum(DwarfReg, true))
OS << printReg(*Reg, TRI);
else
OS << "<badreg>";
@@ -458,7 +490,7 @@ static void printIRBlockReference(raw_ostream &OS, const BasicBlock &BB,
printLLVMNameWithoutPrefix(OS, BB.getName());
return;
}
- Optional<int> Slot;
+ std::optional<int> Slot;
if (const Function *F = BB.getParent()) {
if (F == MST.getCurrentFunction()) {
Slot = MST.getLocalSlot(&BB);
@@ -519,7 +551,7 @@ static void printFrameIndex(raw_ostream& OS, int FrameIndex, bool IsFixed,
void MachineOperand::printSubRegIdx(raw_ostream &OS, uint64_t Index,
const TargetRegisterInfo *TRI) {
OS << "%subreg.";
- if (TRI)
+ if (TRI && Index != 0 && Index < TRI->getNumSubRegIndices())
OS << TRI->getSubRegIndexName(Index);
else
OS << Index;
@@ -736,15 +768,16 @@ void MachineOperand::print(raw_ostream &OS, LLT TypeToPrint,
const TargetIntrinsicInfo *IntrinsicInfo) const {
tryToGetTargetInfo(*this, TRI, IntrinsicInfo);
ModuleSlotTracker DummyMST(nullptr);
- print(OS, DummyMST, TypeToPrint, None, /*PrintDef=*/false,
+ print(OS, DummyMST, TypeToPrint, std::nullopt, /*PrintDef=*/false,
/*IsStandalone=*/true,
/*ShouldPrintRegisterTies=*/true,
/*TiedOperandIdx=*/0, TRI, IntrinsicInfo);
}
void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
- LLT TypeToPrint, Optional<unsigned> OpIdx, bool PrintDef,
- bool IsStandalone, bool ShouldPrintRegisterTies,
+ LLT TypeToPrint, std::optional<unsigned> OpIdx,
+ bool PrintDef, bool IsStandalone,
+ bool ShouldPrintRegisterTies,
unsigned TiedOperandIdx,
const TargetRegisterInfo *TRI,
const TargetIntrinsicInfo *IntrinsicInfo) const {
@@ -767,13 +800,13 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
OS << "undef ";
if (isEarlyClobber())
OS << "early-clobber ";
- if (Register::isPhysicalRegister(getReg()) && isRenamable())
+ if (getReg().isPhysical() && isRenamable())
OS << "renamable ";
// isDebug() is exactly true for register operands of a DBG_VALUE. So we
// simply infer it when parsing and do not need to print it.
const MachineRegisterInfo *MRI = nullptr;
- if (Register::isVirtualRegister(Reg)) {
+ if (Reg.isVirtual()) {
if (const MachineFunction *MF = getMFIfAvailable(*this)) {
MRI = &MF->getRegInfo();
}
@@ -788,7 +821,7 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
OS << ".subreg" << SubReg;
}
// Print the register class / bank.
- if (Register::isVirtualRegister(Reg)) {
+ if (Reg.isVirtual()) {
if (const MachineFunction *MF = getMFIfAvailable(*this)) {
const MachineRegisterInfo &MRI = MF->getRegInfo();
if (IsStandalone || !PrintDef || MRI.def_empty(Reg)) {
@@ -928,6 +961,11 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
case MachineOperand::MO_MCSymbol:
printSymbol(OS, *getMCSymbol());
break;
+ case MachineOperand::MO_DbgInstrRef: {
+ OS << "dbg-instr-ref(" << getInstrRefInstrIndex() << ", "
+ << getInstrRefOpIndex() << ')';
+ break;
+ }
case MachineOperand::MO_CFIIndex: {
if (const MachineFunction *MF = getMFIfAvailable(*this))
printCFI(OS, MF->getFrameInstructions()[getCFIIndex()], TRI);
@@ -1102,15 +1140,24 @@ void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
OS << "dereferenceable ";
if (isInvariant())
OS << "invariant ";
- if (getFlags() & MachineMemOperand::MOTargetFlag1)
- OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag1)
- << "\" ";
- if (getFlags() & MachineMemOperand::MOTargetFlag2)
- OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag2)
- << "\" ";
- if (getFlags() & MachineMemOperand::MOTargetFlag3)
- OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag3)
- << "\" ";
+ if (TII) {
+ if (getFlags() & MachineMemOperand::MOTargetFlag1)
+ OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag1)
+ << "\" ";
+ if (getFlags() & MachineMemOperand::MOTargetFlag2)
+ OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag2)
+ << "\" ";
+ if (getFlags() & MachineMemOperand::MOTargetFlag3)
+ OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag3)
+ << "\" ";
+ } else {
+ if (getFlags() & MachineMemOperand::MOTargetFlag1)
+ OS << "\"MOTargetFlag1\" ";
+ if (getFlags() & MachineMemOperand::MOTargetFlag2)
+ OS << "\"MOTargetFlag2\" ";
+ if (getFlags() & MachineMemOperand::MOTargetFlag3)
+ OS << "\"MOTargetFlag3\" ";
+ }
assert((isLoad() || isStore()) &&
"machine memory operand must be a load or store (or both)");