Skip to content

Commit fb07afe

Browse files
yonghong-songYonghong Song
andauthored
[BPF] Avoid potential long compilation time without -g (#96575)
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 05de2e4 ("[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] bpftrace/bpftrace#3257 Co-authored-by: Yonghong Song <[email protected]>
1 parent dca49d7 commit fb07afe

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

llvm/lib/Target/BPF/BPFRegisterInfo.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ BitVector BPFRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
4747
return Reserved;
4848
}
4949

50-
static void WarnSize(int Offset, MachineFunction &MF, DebugLoc& DL)
51-
{
50+
static void WarnSize(int Offset, MachineFunction &MF, DebugLoc& DL,
51+
MachineBasicBlock& MBB) {
5252
if (Offset <= -BPFStackSizeOption) {
53+
if (!DL)
54+
/* try harder to get some debug loc */
55+
for (auto &I : MBB)
56+
if (I.getDebugLoc()) {
57+
DL = I.getDebugLoc();
58+
break;
59+
}
60+
5361
const Function &F = MF.getFunction();
5462
DiagnosticInfoUnsupported DiagStackSize(
5563
F,
@@ -73,14 +81,6 @@ bool BPFRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
7381
MachineFunction &MF = *MBB.getParent();
7482
DebugLoc DL = MI.getDebugLoc();
7583

76-
if (!DL)
77-
/* try harder to get some debug loc */
78-
for (auto &I : MBB)
79-
if (I.getDebugLoc()) {
80-
DL = I.getDebugLoc();
81-
break;
82-
}
83-
8484
while (!MI.getOperand(i).isFI()) {
8585
++i;
8686
assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
@@ -93,7 +93,7 @@ bool BPFRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
9393
if (MI.getOpcode() == BPF::MOV_rr) {
9494
int Offset = MF.getFrameInfo().getObjectOffset(FrameIndex);
9595

96-
WarnSize(Offset, MF, DL);
96+
WarnSize(Offset, MF, DL, MBB);
9797
MI.getOperand(i).ChangeToRegister(FrameReg, false);
9898
Register reg = MI.getOperand(i - 1).getReg();
9999
BuildMI(MBB, ++II, DL, TII.get(BPF::ADD_ri), reg)
@@ -108,7 +108,7 @@ bool BPFRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
108108
if (!isInt<32>(Offset))
109109
llvm_unreachable("bug in frame offset");
110110

111-
WarnSize(Offset, MF, DL);
111+
WarnSize(Offset, MF, DL, MBB);
112112

113113
if (MI.getOpcode() == BPF::FI_ri) {
114114
// architecture does not really support FI_ri, replace it with

0 commit comments

Comments
 (0)