Skip to content

[MCA] Use MCInstrAnalysis to analyse call/return instructions #123882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2025
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
16 changes: 8 additions & 8 deletions llvm/lib/MCA/InstrBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,10 @@ static void initializeUsedResources(InstrDesc &ID,
});
}

static void computeMaxLatency(InstrDesc &ID, const MCInstrDesc &MCDesc,
const MCSchedClassDesc &SCDesc,
const MCSubtargetInfo &STI,
unsigned CallLatency) {
if (MCDesc.isCall()) {
static void computeMaxLatency(InstrDesc &ID, const MCSchedClassDesc &SCDesc,
const MCSubtargetInfo &STI, unsigned CallLatency,
bool IsCall) {
if (IsCall) {
// We cannot estimate how long this call will take.
// Artificially set an arbitrarily high latency.
ID.MaxLatency = CallLatency;
Expand Down Expand Up @@ -599,23 +598,24 @@ InstrBuilder::createInstrDescImpl(const MCInst &MCI,
ID->NumMicroOps = SCDesc.NumMicroOps;
ID->SchedClassID = SchedClassID;

if (MCDesc.isCall() && FirstCallInst) {
bool IsCall = MCIA->isCall(MCI);
if (IsCall && FirstCallInst) {
// We don't correctly model calls.
WithColor::warning() << "found a call in the input assembly sequence.\n";
WithColor::note() << "call instructions are not correctly modeled. "
<< "Assume a latency of " << CallLatency << "cy.\n";
FirstCallInst = false;
}

if (MCDesc.isReturn() && FirstReturnInst) {
if (MCIA->isReturn(MCI) && FirstReturnInst) {
WithColor::warning() << "found a return instruction in the input"
<< " assembly sequence.\n";
WithColor::note() << "program counter updates are ignored.\n";
FirstReturnInst = false;
}

initializeUsedResources(*ID, SCDesc, STI, ProcResourceMasks);
computeMaxLatency(*ID, MCDesc, SCDesc, STI, CallLatency);
computeMaxLatency(*ID, SCDesc, STI, CallLatency, IsCall);

if (Error Err = verifyOperands(MCDesc, MCI))
return std::move(Err);
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstrAnalysis.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCStreamer.h"
Expand Down Expand Up @@ -243,6 +244,10 @@ createNullTargetStreamer(MCStreamer &S) {
return new SystemZTargetStreamer(S);
}

static MCInstrAnalysis *createSystemZMCInstrAnalysis(const MCInstrInfo *Info) {
return new MCInstrAnalysis(Info);
}

extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSystemZTargetMC() {
// Register the MCAsmInfo.
TargetRegistry::RegisterMCAsmInfo(getTheSystemZTarget(),
Expand Down Expand Up @@ -283,4 +288,8 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSystemZTargetMC() {
// Register the null streamer
TargetRegistry::RegisterNullTargetStreamer(getTheSystemZTarget(),
createNullTargetStreamer);

// Register the MCInstrAnalysis.
TargetRegistry::RegisterMCInstrAnalysis(getTheSystemZTarget(),
createSystemZMCInstrAnalysis);
}
15 changes: 6 additions & 9 deletions llvm/test/tools/llvm-mca/RISCV/SiFive7/jump.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ ret

# CHECK: Iterations: 1
# CHECK-NEXT: Instructions: 5
# CHECK-NEXT: Total Cycles: 10
# CHECK-NEXT: Total Cycles: 200
# CHECK-NEXT: Total uOps: 5

# CHECK: Dispatch Width: 2
# CHECK-NEXT: uOps Per Cycle: 0.50
# CHECK-NEXT: IPC: 0.50
# CHECK-NEXT: uOps Per Cycle: 0.03
# CHECK-NEXT: IPC: 0.03
# CHECK-NEXT: Block RThroughput: 5.0

# CHECK: Instruction Info:
Expand Down Expand Up @@ -58,13 +58,10 @@ ret
# CHECK-NEXT: - - - 1.00 - - - - ret

# CHECK: Timeline view:
# CHECK-NEXT: Index 0123456789
# CHECK-NEXT: Index 0123

# CHECK: [0,0] DeeE . . j .Ltmp0
# CHECK-NEXT: [0,1] .DeeE. . jal a0, .Ltmp1
# CHECK-NEXT: [0,2] . DeeE . jr a0
# CHECK-NEXT: [0,3] . DeeE. jalr t0, a0
# CHECK-NEXT: [0,4] . .DeeE ret
# CHECK: [0,0] DeeE j .Ltmp0
# CHECK-NEXT: Truncated display due to cycle limit

# CHECK: Average Wait times (based on the timeline view):
# CHECK-NEXT: [0]: Executions
Expand Down
Loading