Skip to content
Merged
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
8 changes: 8 additions & 0 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,16 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
return MI->isTerminator() && isUnspillableTerminatorImpl(MI);
}

/// Sum the sizes of instructions inside of a BUNDLE, by calling \ref
/// getInstSizeInBytes on each. This is a utility function for implementations
/// of \ref getInstSizeInBytes to use.
unsigned getInstBundleSize(const MachineInstr &MI) const;

/// Returns the size in bytes of the specified MachineInstr, or ~0U
/// when this function is not implemented by a target.

/// For BUNDLE instructions, target implementations are responsible for
/// accounting for the size of all bundled instructions.
virtual unsigned getInstSizeInBytes(const MachineInstr &MI) const {
return ~0U;
}
Expand Down
7 changes: 0 additions & 7 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2289,13 +2289,6 @@ void AsmPrinter::emitFunctionBody() {
TII->getInstSizeVerifyMode(MI);
if (Mode != TargetInstrInfo::InstSizeVerifyMode::NoVerify) {
unsigned ExpectedSize = TII->getInstSizeInBytes(MI);
if (MI.isBundled()) {
// Bundled instructions are emitted together.
auto It = MI.getIterator(), End = MBB.instr_end();
for (++It; It != End && It->isInsideBundle(); ++It)
ExpectedSize += TII->getInstSizeInBytes(*It);
}

MCFragment *NewFragment = OutStreamer->getCurrentFragment();
unsigned ActualSize;
if (OldFragment == NewFragment) {
Expand Down
12 changes: 12 additions & 0 deletions llvm/lib/CodeGen/TargetInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ unsigned TargetInstrInfo::getInlineAsmLength(
return Length;
}

unsigned TargetInstrInfo::getInstBundleSize(const MachineInstr &MI) const {
unsigned Size = 0;
MachineBasicBlock::const_instr_iterator I = MI.getIterator();
MachineBasicBlock::const_instr_iterator E = MI.getParent()->instr_end();
while (++I != E && I->isInsideBundle()) {
assert(!I->isBundle() && "No nested bundle!");
Size += getInstSizeInBytes(*I);
}

return Size;
}

/// ReplaceTailWithBranchTo - Delete the instruction OldInst and everything
/// after it, replacing it with an unconditional branch to NewDest.
void
Expand Down
13 changes: 1 addition & 12 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,13 @@ unsigned AArch64InstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
NumBytes = MI.getOperand(1).getImm();
break;
case TargetOpcode::BUNDLE:
NumBytes = getInstBundleLength(MI);
NumBytes = getInstBundleSize(MI);
break;
}

return NumBytes;
}

unsigned AArch64InstrInfo::getInstBundleLength(const MachineInstr &MI) const {
unsigned Size = 0;
MachineBasicBlock::const_instr_iterator I = MI.getIterator();
MachineBasicBlock::const_instr_iterator E = MI.getParent()->instr_end();
while (++I != E && I->isInsideBundle()) {
assert(!I->isBundle() && "No nested bundle!");
Size += getInstSizeInBytes(*I);
}
return Size;
}

static void parseCondBranch(MachineInstr *LastInst, MachineBasicBlock *&Target,
SmallVectorImpl<MachineOperand> &Cond) {
// Block ends with fall-through condbranch.
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,6 @@ class AArch64InstrInfo final : public AArch64GenInstrInfo {
isCopyLikeInstrImpl(const MachineInstr &MI) const override;

private:
unsigned getInstBundleLength(const MachineInstr &MI) const;

/// Sets the offsets on outlined instructions in \p MBB which use SP
/// so that they will be valid post-outlining.
///
Expand Down
12 changes: 0 additions & 12 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9902,18 +9902,6 @@ Register SIInstrInfo::isStoreToStackSlot(const MachineInstr &MI,
return Register();
}

unsigned SIInstrInfo::getInstBundleSize(const MachineInstr &MI) const {
unsigned Size = 0;
MachineBasicBlock::const_instr_iterator I = MI.getIterator();
MachineBasicBlock::const_instr_iterator E = MI.getParent()->instr_end();
while (++I != E && I->isInsideBundle()) {
assert(!I->isBundle() && "No nested bundle!");
Size += getInstSizeInBytes(*I);
}

return Size;
}

unsigned SIInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
unsigned Opc = MI.getOpcode();
const MCInstrDesc &Desc = getMCOpcodeFromPseudo(Opc);
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/AMDGPU/SIInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,6 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex,
TypeSize &MemBytes) const override;

unsigned getInstBundleSize(const MachineInstr &MI) const;
unsigned getInstSizeInBytes(const MachineInstr &MI) const override;

bool mayAccessFlatAddressSpace(const MachineInstr &MI) const;
Expand Down
13 changes: 1 addition & 12 deletions llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ unsigned ARMBaseInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
// example.
return MCID.getSize();
case TargetOpcode::BUNDLE:
return getInstBundleLength(MI);
return getInstBundleSize(MI);
case TargetOpcode::COPY:
if (!MF->getInfo<ARMFunctionInfo>()->isThumbFunction())
return 4;
Expand All @@ -645,17 +645,6 @@ unsigned ARMBaseInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
}
}

unsigned ARMBaseInstrInfo::getInstBundleLength(const MachineInstr &MI) const {
unsigned Size = 0;
MachineBasicBlock::const_instr_iterator I = MI.getIterator();
MachineBasicBlock::const_instr_iterator E = MI.getParent()->instr_end();
while (++I != E && I->isInsideBundle()) {
assert(!I->isBundle() && "No nested bundle!");
Size += getInstSizeInBytes(*I);
}
return Size;
}

void ARMBaseInstrInfo::copyFromCPSR(MachineBasicBlock &MBB,
MachineBasicBlock::iterator I,
MCRegister DestReg, bool KillSrc,
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/ARM/ARMBaseInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,6 @@ class ARMBaseInstrInfo : public ARMGenInstrInfo {
bool checkAndUpdateStackOffset(MachineInstr *MI, int64_t Fixup,
bool Updt) const;

unsigned getInstBundleLength(const MachineInstr &MI) const;

std::optional<unsigned> getVLDMDefCycle(const InstrItineraryData *ItinData,
const MCInstrDesc &DefMCID,
unsigned DefClass, unsigned DefIdx,
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/CSKY/CSKYInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ unsigned CSKYInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
const MachineFunction *MF = MI.getParent()->getParent();
const char *AsmStr = MI.getOperand(0).getSymbolName();
return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
case TargetOpcode::BUNDLE:
return getInstBundleSize(MI);
}
}
}
2 changes: 2 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ unsigned LoongArchInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
case TargetOpcode::PATCHABLE_TAIL_CALL:
// Size of xray sled (branch + 11 nops).
return 12 * 4;
case TargetOpcode::BUNDLE:
return getInstBundleSize(MI);
}
return NumBytes;
}
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/MSP430/MSP430InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ unsigned MSP430InstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
return TII.getInlineAsmLength(MI.getOperand(0).getSymbolName(),
*MF->getTarget().getMCAsmInfo());
}
case TargetOpcode::BUNDLE:
return getInstBundleSize(MI);
}

return Desc.getSize();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Mips/MipsBranchExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void MipsBranchExpansion::initMBBInfo() {
MachineBasicBlock *MBB = MFp->getBlockNumbered(I);

// Compute size of MBB.
for (MachineInstr &MI : MBB->instrs())
for (MachineInstr &MI : *MBB)
MBBInfos[I].Size += TII->getInstSizeInBytes(MI);
}
}
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/Mips/MipsInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ unsigned MipsInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
const char *AsmStr = MI.getOperand(0).getSymbolName();
return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
}
case TargetOpcode::BUNDLE:
return getInstBundleSize(MI);
case TargetOpcode::PATCHABLE_FUNCTION_ENTER:
case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
case TargetOpcode::PATCHABLE_TAIL_CALL:
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,8 @@ unsigned PPCInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
bool IsConditional = RetOpcode == PPC::BCCLR;
return (8 + IsConditional) * 4;
}
case TargetOpcode::BUNDLE:
return getInstBundleSize(MI);
default:
return get(Opcode).getSize();
}
Expand Down
13 changes: 1 addition & 12 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,7 @@ unsigned RISCVInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
}

if (Opcode == TargetOpcode::BUNDLE)
return getInstBundleLength(MI);
return getInstBundleSize(MI);

if (MI.getParent() && MI.getParent()->getParent()) {
if (isCompressibleInst(MI, STI))
Expand Down Expand Up @@ -2104,17 +2104,6 @@ unsigned RISCVInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
}
}

unsigned RISCVInstrInfo::getInstBundleLength(const MachineInstr &MI) const {
unsigned Size = 0;
MachineBasicBlock::const_instr_iterator I = MI.getIterator();
MachineBasicBlock::const_instr_iterator E = MI.getParent()->instr_end();
while (++I != E && I->isInsideBundle()) {
assert(!I->isBundle() && "No nested bundle!");
Size += getInstSizeInBytes(*I);
}
return Size;
}

bool RISCVInstrInfo::isAsCheapAsAMove(const MachineInstr &MI) const {
const unsigned Opcode = MI.getOpcode();
switch (Opcode) {
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,6 @@ class RISCVInstrInfo : public RISCVGenInstrInfo {
const RISCVSubtarget &STI;

private:
unsigned getInstBundleLength(const MachineInstr &MI) const;

bool isVectorAssociativeAndCommutative(const MachineInstr &MI,
bool Invert = false) const;
bool areRVVInstsReassociable(const MachineInstr &MI1,
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/Sparc/SparcInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ unsigned SparcInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
}

if (Opcode == TargetOpcode::BUNDLE)
return getInstBundleSize(MI);

if (MI.getOpcode() == SP::GETPCX) {
const TargetMachine &TM = MI.getParent()->getParent()->getTarget();
if (TM.isPositionIndependent())
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,8 @@ unsigned SystemZInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
return 18;
if (MI.getOpcode() == TargetOpcode::PATCHABLE_RET)
return 18 + (MI.getOperand(0).getImm() == SystemZ::CondReturn ? 4 : 0);
if (MI.getOpcode() == TargetOpcode::BUNDLE)
return getInstBundleSize(MI);

return MI.getDesc().getSize();
}
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/Xtensa/XtensaInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ unsigned XtensaInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
const char *AsmStr = MI.getOperand(0).getSymbolName();
return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
}
case TargetOpcode::BUNDLE:
return getInstBundleSize(MI);
default:
return MI.getDesc().getSize();
}
Expand Down
Loading