Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,18 @@ struct ExtAddrMode {
///
class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
protected:
const TargetRegisterInfo &TRI;

/// Subtarget specific sub-array of MCInstrInfo's RegClassByHwModeTables
/// (i.e. the table for the active HwMode). This should be indexed by
/// MCOperandInfo's RegClass field for LookupRegClassByHwMode operands.
const int16_t *const RegClassByHwMode;

TargetInstrInfo(unsigned CFSetupOpcode = ~0u, unsigned CFDestroyOpcode = ~0u,
unsigned CatchRetOpcode = ~0u, unsigned ReturnOpcode = ~0u,
TargetInstrInfo(const TargetRegisterInfo &TRI, unsigned CFSetupOpcode = ~0u,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should the argument be TargetSubtargetInfo?

unsigned CFDestroyOpcode = ~0u, unsigned CatchRetOpcode = ~0u,
unsigned ReturnOpcode = ~0u,
const int16_t *const RegClassByHwModeTable = nullptr)
: RegClassByHwMode(RegClassByHwModeTable),
: TRI(TRI), RegClassByHwMode(RegClassByHwModeTable),
CallFrameSetupOpcode(CFSetupOpcode),
CallFrameDestroyOpcode(CFDestroyOpcode), CatchRetOpcode(CatchRetOpcode),
ReturnOpcode(ReturnOpcode) {}
Expand All @@ -131,6 +134,8 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
TargetInstrInfo &operator=(const TargetInstrInfo &) = delete;
virtual ~TargetInstrInfo();

const TargetRegisterInfo &getRegisterInfo() const { return TRI; }

static bool isGenericOpcode(unsigned Opc) {
return Opc <= TargetOpcode::GENERIC_OP_END;
}
Expand Down
68 changes: 27 additions & 41 deletions llvm/lib/CodeGen/TargetInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TargetInstrInfo::~TargetInstrInfo() = default;

const TargetRegisterClass *
TargetInstrInfo::getRegClass(const MCInstrDesc &MCID, unsigned OpNum,
const TargetRegisterInfo *TRI) const {
const TargetRegisterInfo * /*RemoveMe*/) const {
if (OpNum >= MCID.getNumOperands())
return nullptr;

Expand All @@ -69,14 +69,14 @@ TargetInstrInfo::getRegClass(const MCInstrDesc &MCID, unsigned OpNum,

// TODO: Remove isLookupPtrRegClass in favor of isLookupRegClassByHwMode
if (OpInfo.isLookupPtrRegClass())
return TRI->getPointerRegClass(RegClass);
return TRI.getPointerRegClass(RegClass);

// Instructions like INSERT_SUBREG do not have fixed register classes.
if (RegClass < 0)
return nullptr;

// Otherwise just look it up normally.
return TRI->getRegClass(RegClass);
return TRI.getRegClass(RegClass);
}

/// insertNoop - Insert a noop into the instruction stream at the specified
Expand Down Expand Up @@ -223,13 +223,11 @@ MachineInstr *TargetInstrInfo::commuteInstructionImpl(MachineInstr &MI,
// %1.sub = INST %1.sub(tied), %0.sub, implicit-def %1
SmallVector<unsigned> UpdateImplicitDefIdx;
if (HasDef && MI.hasImplicitDef()) {
const TargetRegisterInfo *TRI =
MI.getMF()->getSubtarget().getRegisterInfo();
for (auto [OpNo, MO] : llvm::enumerate(MI.implicit_operands())) {
Register ImplReg = MO.getReg();
if ((ImplReg.isVirtual() && ImplReg == Reg0) ||
(ImplReg.isPhysical() && Reg0.isPhysical() &&
TRI->isSubRegisterEq(ImplReg, Reg0)))
TRI.isSubRegisterEq(ImplReg, Reg0)))
UpdateImplicitDefIdx.push_back(OpNo + MI.getNumExplicitOperands());
}
}
Expand Down Expand Up @@ -425,37 +423,35 @@ bool TargetInstrInfo::getStackSlotRange(const TargetRegisterClass *RC,
unsigned SubIdx, unsigned &Size,
unsigned &Offset,
const MachineFunction &MF) const {
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
if (!SubIdx) {
Size = TRI->getSpillSize(*RC);
Size = TRI.getSpillSize(*RC);
Offset = 0;
return true;
}
unsigned BitSize = TRI->getSubRegIdxSize(SubIdx);
unsigned BitSize = TRI.getSubRegIdxSize(SubIdx);
// Convert bit size to byte size.
if (BitSize % 8)
return false;

int BitOffset = TRI->getSubRegIdxOffset(SubIdx);
int BitOffset = TRI.getSubRegIdxOffset(SubIdx);
if (BitOffset < 0 || BitOffset % 8)
return false;

Size = BitSize / 8;
Offset = (unsigned)BitOffset / 8;

assert(TRI->getSpillSize(*RC) >= (Offset + Size) && "bad subregister range");
assert(TRI.getSpillSize(*RC) >= (Offset + Size) && "bad subregister range");

if (!MF.getDataLayout().isLittleEndian()) {
Offset = TRI->getSpillSize(*RC) - (Offset + Size);
Offset = TRI.getSpillSize(*RC) - (Offset + Size);
}
return true;
}

void TargetInstrInfo::reMaterialize(MachineBasicBlock &MBB,
MachineBasicBlock::iterator I,
Register DestReg, unsigned SubIdx,
const MachineInstr &Orig,
const TargetRegisterInfo &TRI) const {
void TargetInstrInfo::reMaterialize(
MachineBasicBlock &MBB, MachineBasicBlock::iterator I, Register DestReg,
unsigned SubIdx, const MachineInstr &Orig,
const TargetRegisterInfo & /*Remove me*/) const {
MachineInstr *MI = MBB.getParent()->CloneMachineInstr(&Orig);
MI->substituteRegister(MI->getOperand(0).getReg(), DestReg, SubIdx, TRI);
MBB.insert(I, MI);
Expand Down Expand Up @@ -726,7 +722,6 @@ MachineInstr *TargetInstrInfo::foldMemoryOperand(MachineInstr &MI,
// actual load size is.
int64_t MemSize = 0;
const MachineFrameInfo &MFI = MF.getFrameInfo();
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();

if (Flags & MachineMemOperand::MOStore) {
MemSize = MFI.getObjectSize(FI);
Expand All @@ -735,7 +730,7 @@ MachineInstr *TargetInstrInfo::foldMemoryOperand(MachineInstr &MI,
int64_t OpSize = MFI.getObjectSize(FI);

if (auto SubReg = MI.getOperand(OpIdx).getSubReg()) {
unsigned SubRegSize = TRI->getSubRegIdxSize(SubReg);
unsigned SubRegSize = TRI.getSubRegIdxSize(SubReg);
if (SubRegSize > 0 && !(SubRegSize % 8))
OpSize = SubRegSize / 8;
}
Expand Down Expand Up @@ -800,11 +795,11 @@ MachineInstr *TargetInstrInfo::foldMemoryOperand(MachineInstr &MI,
// code.
BuildMI(*MBB, Pos, MI.getDebugLoc(), get(TargetOpcode::KILL)).add(MO);
} else {
storeRegToStackSlot(*MBB, Pos, MO.getReg(), MO.isKill(), FI, RC, TRI,
storeRegToStackSlot(*MBB, Pos, MO.getReg(), MO.isKill(), FI, RC, &TRI,
Register());
}
} else
loadRegFromStackSlot(*MBB, Pos, MO.getReg(), FI, RC, TRI, Register());
loadRegFromStackSlot(*MBB, Pos, MO.getReg(), FI, RC, &TRI, Register());

return &*--Pos;
}
Expand Down Expand Up @@ -880,8 +875,8 @@ static void transferImplicitOperands(MachineInstr *MI,
}
}

void TargetInstrInfo::lowerCopy(MachineInstr *MI,
const TargetRegisterInfo *TRI) const {
void TargetInstrInfo::lowerCopy(
MachineInstr *MI, const TargetRegisterInfo * /*Remove me*/) const {
if (MI->allDefsAreDead()) {
MI->setDesc(get(TargetOpcode::KILL));
return;
Expand Down Expand Up @@ -911,7 +906,7 @@ void TargetInstrInfo::lowerCopy(MachineInstr *MI,
SrcMO.getReg().isPhysical() ? SrcMO.isRenamable() : false);

if (MI->getNumOperands() > 2)
transferImplicitOperands(MI, TRI);
transferImplicitOperands(MI, &TRI);
MI->eraseFromParent();
}

Expand Down Expand Up @@ -1327,8 +1322,7 @@ void TargetInstrInfo::reassociateOps(
MachineFunction *MF = Root.getMF();
MachineRegisterInfo &MRI = MF->getRegInfo();
const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
const TargetRegisterClass *RC = Root.getRegClassConstraint(0, TII, TRI);
const TargetRegisterClass *RC = Root.getRegClassConstraint(0, TII, &TRI);

MachineOperand &OpA = Prev.getOperand(OperandIndices[1]);
MachineOperand &OpB = Root.getOperand(OperandIndices[2]);
Expand Down Expand Up @@ -1704,8 +1698,7 @@ bool TargetInstrInfo::isSchedulingBoundary(const MachineInstr &MI,
// stack slot reference to depend on the instruction that does the
// modification.
const TargetLowering &TLI = *MF.getSubtarget().getTargetLowering();
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
return MI.modifiesRegister(TLI.getStackPointerRegisterToSaveRestore(), TRI);
return MI.modifiesRegister(TLI.getStackPointerRegisterToSaveRestore(), &TRI);
}

// Provide a global flag for disabling the PreRA hazard recognizer that targets
Expand Down Expand Up @@ -1738,11 +1731,11 @@ CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II,
// Default implementation of getMemOperandWithOffset.
bool TargetInstrInfo::getMemOperandWithOffset(
const MachineInstr &MI, const MachineOperand *&BaseOp, int64_t &Offset,
bool &OffsetIsScalable, const TargetRegisterInfo *TRI) const {
bool &OffsetIsScalable, const TargetRegisterInfo * /*RemoveMe*/) const {
SmallVector<const MachineOperand *, 4> BaseOps;
LocationSize Width = LocationSize::precise(0);
if (!getMemOperandsWithOffsetWidth(MI, BaseOps, Offset, OffsetIsScalable,
Width, TRI) ||
Width, &TRI) ||
BaseOps.size() != 1)
return false;
BaseOp = BaseOps.front();
Expand Down Expand Up @@ -1863,7 +1856,6 @@ std::optional<ParamLoadedValue>
TargetInstrInfo::describeLoadedValue(const MachineInstr &MI,
Register Reg) const {
const MachineFunction *MF = MI.getMF();
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
DIExpression *Expr = DIExpression::get(MF->getFunction().getContext(), {});
int64_t Offset;
bool OffsetIsScalable;
Expand Down Expand Up @@ -1894,7 +1886,6 @@ TargetInstrInfo::describeLoadedValue(const MachineInstr &MI,
// Only describe memory which provably does not escape the function. As
// described in llvm.org/PR43343, escaped memory may be clobbered by the
// callee (or by another thread).
const auto &TII = MF->getSubtarget().getInstrInfo();
const MachineFrameInfo &MFI = MF->getFrameInfo();
const MachineMemOperand *MMO = MI.memoperands()[0];
const PseudoSourceValue *PSV = MMO->getPseudoValue();
Expand All @@ -1905,8 +1896,7 @@ TargetInstrInfo::describeLoadedValue(const MachineInstr &MI,
return std::nullopt;

const MachineOperand *BaseOp;
if (!TII->getMemOperandWithOffset(MI, BaseOp, Offset, OffsetIsScalable,
TRI))
if (!getMemOperandWithOffset(MI, BaseOp, Offset, OffsetIsScalable, &TRI))
return std::nullopt;

// FIXME: Scalable offsets are not yet handled in the offset code below.
Expand Down Expand Up @@ -2045,7 +2035,7 @@ bool TargetInstrInfo::getInsertSubregInputs(
// Returns a MIRPrinter comment for this machine operand.
std::string TargetInstrInfo::createMIROperandComment(
const MachineInstr &MI, const MachineOperand &Op, unsigned OpIdx,
const TargetRegisterInfo *TRI) const {
const TargetRegisterInfo * /*RemoveMe*/) const {

if (!MI.isInlineAsm())
return "";
Expand Down Expand Up @@ -2078,12 +2068,8 @@ std::string TargetInstrInfo::createMIROperandComment(
OS << F.getKindName();

unsigned RCID;
if (!F.isImmKind() && !F.isMemKind() && F.hasRegClassConstraint(RCID)) {
if (TRI) {
OS << ':' << TRI->getRegClassName(TRI->getRegClass(RCID));
} else
OS << ":RC" << RCID;
}
if (!F.isImmKind() && !F.isMemKind() && F.hasRegClassConstraint(RCID))
OS << ':' << TRI.getRegClassName(TRI.getRegClass(RCID));

if (F.isMemKind()) {
InlineAsm::ConstraintCode MCID = F.getMemoryConstraintID();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static cl::opt<unsigned> GatherOptSearchLimit(
"machine-combiner gather pattern optimization"));

AArch64InstrInfo::AArch64InstrInfo(const AArch64Subtarget &STI)
: AArch64GenInstrInfo(STI, AArch64::ADJCALLSTACKDOWN,
: AArch64GenInstrInfo(STI, RI, AArch64::ADJCALLSTACKDOWN,
AArch64::ADJCALLSTACKUP, AArch64::CATCHRET),
RI(STI.getTargetTriple(), STI.getHwMode()), Subtarget(STI) {}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/R600InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace llvm;
#include "R600GenInstrInfo.inc"

R600InstrInfo::R600InstrInfo(const R600Subtarget &ST)
: R600GenInstrInfo(ST, -1, -1), RI(), ST(ST) {}
: R600GenInstrInfo(ST, RI, -1, -1), RI(), ST(ST) {}

bool R600InstrInfo::isVector(const MachineInstr &MI) const {
return get(MI.getOpcode()).TSFlags & R600_InstFlag::VECTOR;
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ static cl::opt<bool> Fix16BitCopies(
cl::ReallyHidden);

SIInstrInfo::SIInstrInfo(const GCNSubtarget &ST)
: AMDGPUGenInstrInfo(ST, AMDGPU::ADJCALLSTACKUP, AMDGPU::ADJCALLSTACKDOWN),
: AMDGPUGenInstrInfo(ST, RI, AMDGPU::ADJCALLSTACKUP,
AMDGPU::ADJCALLSTACKDOWN),
RI(ST), ST(ST) {
SchedModel.init(&ST);
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/ARC/ARCInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ enum TSFlagsConstants {
void ARCInstrInfo::anchor() {}

ARCInstrInfo::ARCInstrInfo(const ARCSubtarget &ST)
: ARCGenInstrInfo(ST, ARC::ADJCALLSTACKDOWN, ARC::ADJCALLSTACKUP), RI(ST) {}
: ARCGenInstrInfo(ST, RI, ARC::ADJCALLSTACKDOWN, ARC::ADJCALLSTACKUP),
RI(ST) {}

static bool isZeroImm(const MachineOperand &Op) {
return Op.isImm() && Op.getImm() == 0;
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ static const ARM_MLxEntry ARM_MLxTable[] = {
{ ARM::VMLSslfq, ARM::VMULslfq, ARM::VSUBfq, false, true },
};

ARMBaseInstrInfo::ARMBaseInstrInfo(const ARMSubtarget &STI)
: ARMGenInstrInfo(STI, ARM::ADJCALLSTACKDOWN, ARM::ADJCALLSTACKUP),
ARMBaseInstrInfo::ARMBaseInstrInfo(const ARMSubtarget &STI,
const ARMBaseRegisterInfo &TRI)
: ARMGenInstrInfo(STI, TRI, ARM::ADJCALLSTACKDOWN, ARM::ADJCALLSTACKUP),
Subtarget(STI) {
for (unsigned i = 0, e = std::size(ARM_MLxTable); i != e; ++i) {
if (!MLxEntryMap.insert(std::make_pair(ARM_MLxTable[i].MLxOpc, i)).second)
Expand Down
9 changes: 7 additions & 2 deletions llvm/lib/Target/ARM/ARMBaseInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ARMBaseInstrInfo : public ARMGenInstrInfo {

protected:
// Can be only subclassed.
explicit ARMBaseInstrInfo(const ARMSubtarget &STI);
explicit ARMBaseInstrInfo(const ARMSubtarget &STI,
const ARMBaseRegisterInfo &TRI);

void expandLoadStackGuardBase(MachineBasicBlock::iterator MI,
unsigned LoadImmOpc, unsigned LoadOpc) const;
Expand Down Expand Up @@ -125,7 +126,11 @@ class ARMBaseInstrInfo : public ARMGenInstrInfo {
// if there is not such an opcode.
virtual unsigned getUnindexedOpcode(unsigned Opc) const = 0;

virtual const ARMBaseRegisterInfo &getRegisterInfo() const = 0;
const ARMBaseRegisterInfo &getRegisterInfo() const {
return static_cast<const ARMBaseRegisterInfo &>(
TargetInstrInfo::getRegisterInfo());
}

const ARMSubtarget &getSubtarget() const { return Subtarget; }

ScheduleHazardRecognizer *
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/ARM/ARMInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#include "llvm/MC/MCInst.h"
using namespace llvm;

ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI) : ARMBaseInstrInfo(STI) {}
ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI)
: ARMBaseInstrInfo(STI, RI) {}

/// Return the noop instruction to use for a noop.
MCInst ARMInstrInfo::getNop() const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/ARMInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ARMInstrInfo : public ARMBaseInstrInfo {
/// such, whenever a client has an instance of instruction info, it should
/// always be able to get register info as well (through this method).
///
const ARMRegisterInfo &getRegisterInfo() const override { return RI; }
const ARMRegisterInfo &getRegisterInfo() const { return RI; }

private:
void expandLoadStackGuard(MachineBasicBlock::iterator MI) const override;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/Thumb1InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
using namespace llvm;

Thumb1InstrInfo::Thumb1InstrInfo(const ARMSubtarget &STI)
: ARMBaseInstrInfo(STI), RI(STI) {}
: ARMBaseInstrInfo(STI, RI), RI(STI) {}

/// Return the noop instruction to use for a noop.
MCInst Thumb1InstrInfo::getNop() const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/Thumb1InstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Thumb1InstrInfo : public ARMBaseInstrInfo {
/// such, whenever a client has an instance of instruction info, it should
/// always be able to get register info as well (through this method).
///
const ThumbRegisterInfo &getRegisterInfo() const override { return RI; }
const ThumbRegisterInfo &getRegisterInfo() const { return RI; }

void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
const DebugLoc &DL, Register DestReg, Register SrcReg,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/Thumb2InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ PreferNoCSEL("prefer-no-csel", cl::Hidden,
cl::init(false));

Thumb2InstrInfo::Thumb2InstrInfo(const ARMSubtarget &STI)
: ARMBaseInstrInfo(STI), RI(STI) {}
: ARMBaseInstrInfo(STI, RI), RI(STI) {}

/// Return the noop instruction to use for a noop.
MCInst Thumb2InstrInfo::getNop() const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/Thumb2InstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Thumb2InstrInfo : public ARMBaseInstrInfo {
/// such, whenever a client has an instance of instruction info, it should
/// always be able to get register info as well (through this method).
///
const ThumbRegisterInfo &getRegisterInfo() const override { return RI; }
const ThumbRegisterInfo &getRegisterInfo() const { return RI; }

MachineInstr *optimizeSelect(MachineInstr &MI,
SmallPtrSetImpl<MachineInstr *> &SeenMIs,
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AVR/AVRInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
namespace llvm {

AVRInstrInfo::AVRInstrInfo(const AVRSubtarget &STI)
: AVRGenInstrInfo(STI, AVR::ADJCALLSTACKDOWN, AVR::ADJCALLSTACKUP), RI(),
STI(STI) {}
: AVRGenInstrInfo(STI, RI, AVR::ADJCALLSTACKDOWN, AVR::ADJCALLSTACKUP),
RI(), STI(STI) {}

void AVRInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI,
Expand Down
Loading
Loading