Skip to content

Commit

Permalink
[SOL] Push stack args to the bottom of the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay authored and LucasSte committed Aug 19, 2024
1 parent e084e41 commit 37daba6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Target/BPF/BPFISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ SDValue BPFTargetLowering::LowerFormalArguments(

// Arguments relative to BPF::R5
unsigned reg = MF.addLiveIn(BPF::R5, &BPF::GPRRegClass);
SDValue Const = DAG.getConstant(VA.getLocMemOffset() + 8, DL, MVT::i64);
SDValue Const = DAG.getConstant(2047 - VA.getLocMemOffset(), DL, MVT::i64);
SDValue SDV = DAG.getCopyFromReg(Chain, DL, reg, getPointerTy(MF.getDataLayout()));
SDV = DAG.getNode(ISD::SUB, DL, PtrVT, SDV, Const);
SDV = DAG.getLoad(LocVT, DL, Chain, SDV, MachinePointerInfo(), 0);
Expand Down Expand Up @@ -488,7 +488,7 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
if (HasStackArgs) {
SDValue FramePtr = DAG.getCopyFromReg(Chain, CLI.DL, BPF::R10, getPointerTy(MF.getDataLayout()));

// Stack arguments have to walked in reverse order by inserting
// Stack arguments have to be walked in reverse order by inserting
// chained stores, this ensures their order is not changed by the scheduler
// and that the push instruction sequence generated is correct, otherwise they
// can be freely intermixed.
Expand All @@ -500,7 +500,7 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
assert(VA.isMemLoc());

EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout());
SDValue Const = DAG.getConstant(VA.getLocMemOffset() + 8, CLI.DL, MVT::i64);
SDValue Const = DAG.getConstant(2047 - VA.getLocMemOffset(), CLI.DL, MVT::i64);
SDValue PtrOff = DAG.getNode(ISD::SUB, CLI.DL, PtrVT, FramePtr, Const);
Chain = DAG.getStore(Chain, CLI.DL, Arg, PtrOff, MachinePointerInfo());
}
Expand Down
9 changes: 3 additions & 6 deletions llvm/lib/Target/BPF/BPFRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ static void WarnSize(int Offset, MachineFunction &MF, DebugLoc& DL)
{
if (Offset <= -2048) {
const Function &F = MF.getFunction();
DiagnosticInfoUnsupported DiagStackSize(
F,
"Looks like the BPF stack limit is exceeded. "
"Please move large on stack variables into BPF per-cpu array map. For "
"non-kernel uses, the stack can be increased using -mllvm "
"-bpf-stack-size.\n",
DiagnosticInfoUnsupported DiagStackSize(F,
"Looks like the BPF stack limit of 2048 bytes is exceeded. "
"Please move large on stack variables into BPF per-cpu array map.\n",
DL);
F.getContext().diagnose(DiagStackSize);
}
Expand Down

0 comments on commit 37daba6

Please sign in to comment.