[llvm] [RFC][BPF] Add support for asm gotol_or_nop and nop_or_gotol insns (PR #75110)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 16:12:33 PDT 2024
https://github.com/yonghong-song updated https://github.com/llvm/llvm-project/pull/75110
>From 938222eccff9fa0409e5a76385123c5d82023e92 Mon Sep 17 00:00:00 2001
From: Yonghong Song <yonghong.song at linux.dev>
Date: Mon, 24 Jun 2024 15:45:49 -0700
Subject: [PATCH] [BPF] Avoid potential long compilation time without -g
Alastair Robertson reported a huge compilation time increase
without -g for bpf target when comparing to x86 ([1]). In my setup,
with '-O0', for x86, a large basic block compilation takes 0.19s
while bpf target takes 2.46s. The top function which contributes
to the compile time is eliminateFrameIndex().
Such long compilation time without -g is caused by commit
05de2e481811 ("[bpf] error when BPF stack size exceeds 512 bytes")
The compiler tries to get some debug loc by iterating all insns
in the basic block which will be used when compiler warns
larger-than-512 stack size. Even without -g, such iterating also
happens which cause unnecessary compile time increase.
To fix the issue, let us move the related code when the compiler
is about to warn stack limit violation. This fixed the
compile time regression, and on my system, the compile time
is reduced from 2.46s to 0.35s.
[1] https://github.com/bpftrace/bpftrace/issues/3257
---
llvm/lib/Target/BPF/BPFRegisterInfo.cpp | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/llvm/lib/Target/BPF/BPFRegisterInfo.cpp b/llvm/lib/Target/BPF/BPFRegisterInfo.cpp
index 8761e4aa258c2..84af6806abb36 100644
--- a/llvm/lib/Target/BPF/BPFRegisterInfo.cpp
+++ b/llvm/lib/Target/BPF/BPFRegisterInfo.cpp
@@ -47,9 +47,17 @@ BitVector BPFRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
return Reserved;
}
-static void WarnSize(int Offset, MachineFunction &MF, DebugLoc& DL)
-{
+static void WarnSize(int Offset, MachineFunction &MF, DebugLoc& DL,
+ MachineBasicBlock& MBB) {
if (Offset <= -BPFStackSizeOption) {
+ if (!DL)
+ /* try harder to get some debug loc */
+ for (auto &I : MBB)
+ if (I.getDebugLoc()) {
+ DL = I.getDebugLoc();
+ break;
+ }
+
const Function &F = MF.getFunction();
DiagnosticInfoUnsupported DiagStackSize(
F,
@@ -73,14 +81,6 @@ bool BPFRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
MachineFunction &MF = *MBB.getParent();
DebugLoc DL = MI.getDebugLoc();
- if (!DL)
- /* try harder to get some debug loc */
- for (auto &I : MBB)
- if (I.getDebugLoc()) {
- DL = I.getDebugLoc();
- break;
- }
-
while (!MI.getOperand(i).isFI()) {
++i;
assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
@@ -93,7 +93,7 @@ bool BPFRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
if (MI.getOpcode() == BPF::MOV_rr) {
int Offset = MF.getFrameInfo().getObjectOffset(FrameIndex);
- WarnSize(Offset, MF, DL);
+ WarnSize(Offset, MF, DL, MBB);
MI.getOperand(i).ChangeToRegister(FrameReg, false);
Register reg = MI.getOperand(i - 1).getReg();
BuildMI(MBB, ++II, DL, TII.get(BPF::ADD_ri), reg)
@@ -108,7 +108,7 @@ bool BPFRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
if (!isInt<32>(Offset))
llvm_unreachable("bug in frame offset");
- WarnSize(Offset, MF, DL);
+ WarnSize(Offset, MF, DL, MBB);
if (MI.getOpcode() == BPF::FI_ri) {
// architecture does not really support FI_ri, replace it with
More information about the llvm-commits
mailing list