Skip to content

Commit 5e8f461

Browse files
committed
Revert "[BPF] introduce __attribute__((bpf_fastcall)) (#101228)"
This reverts commit e9b2e16. Reverting because of the test failure: https://lab.llvm.org/buildbot/#/builders/187/builds/509
1 parent f76b9b7 commit 5e8f461

16 files changed

+3
-488
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,15 +2200,6 @@ def BTFTypeTag : TypeAttr {
22002200
let LangOpts = [COnly];
22012201
}
22022202

2203-
def BPFFastCall : InheritableAttr,
2204-
TargetSpecificAttr<TargetBPF> {
2205-
let Spellings = [Clang<"bpf_fastcall">];
2206-
let Subjects = SubjectList<[FunctionLike]>;
2207-
let Documentation = [BPFFastCallDocs];
2208-
let LangOpts = [COnly];
2209-
let SimpleHandler = 1;
2210-
}
2211-
22122203
def WebAssemblyExportName : InheritableAttr,
22132204
TargetSpecificAttr<TargetWebAssembly> {
22142205
let Spellings = [Clang<"export_name">];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,25 +2345,6 @@ section.
23452345
}];
23462346
}
23472347

2348-
def BPFFastCallDocs : Documentation {
2349-
let Category = DocCatType;
2350-
let Content = [{
2351-
Functions annotated with this attribute are likely to be inlined by BPF JIT.
2352-
It is assumed that inlined implementation uses less caller saved registers,
2353-
than a regular function.
2354-
Specifically, the following registers are likely to be preserved:
2355-
- ``R0`` if function return value is ``void``;
2356-
- ``R2-R5` if function takes 1 argument;
2357-
- ``R3-R5` if function takes 2 arguments;
2358-
- ``R4-R5` if function takes 3 arguments;
2359-
- ``R5`` if function takes 4 arguments;
2360-
2361-
For such functions Clang generates code pattern that allows BPF JIT
2362-
to recognize and remove unnecessary spills and fills of the preserved
2363-
registers.
2364-
}];
2365-
}
2366-
23672348
def MipsInterruptDocs : Documentation {
23682349
let Category = DocCatFunction;
23692350
let Heading = "interrupt (MIPS)";

clang/lib/CodeGen/CGCall.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,8 +2422,6 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
24222422
FuncAttrs.addAttribute(llvm::Attribute::NoCfCheck);
24232423
if (TargetDecl->hasAttr<LeafAttr>())
24242424
FuncAttrs.addAttribute(llvm::Attribute::NoCallback);
2425-
if (TargetDecl->hasAttr<BPFFastCallAttr>())
2426-
FuncAttrs.addAttribute("bpf_fastcall");
24272425

24282426
HasOptnone = TargetDecl->hasAttr<OptimizeNoneAttr>();
24292427
if (auto *AllocSize = TargetDecl->getAttr<AllocSizeAttr>()) {

clang/test/CodeGen/bpf-attr-bpf-fastcall-1.c

Lines changed: 0 additions & 24 deletions
This file was deleted.

clang/test/Misc/pragma-attribute-supported-attributes-list.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
// CHECK-NEXT: AssumeAligned (SubjectMatchRule_objc_method, SubjectMatchRule_function)
2323
// CHECK-NEXT: Availability ((SubjectMatchRule_record, SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, SubjectMatchRule_function, SubjectMatchRule_namespace, SubjectMatchRule_objc_category, SubjectMatchRule_objc_implementation, SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, SubjectMatchRule_record, SubjectMatchRule_type_alias, SubjectMatchRule_variable))
2424
// CHECK-NEXT: AvailableOnlyInDefaultEvalMethod (SubjectMatchRule_type_alias)
25-
// CHECK-NEXT: BPFFastCall (SubjectMatchRule_hasType_functionType)
2625
// CHECK-NEXT: BPFPreserveAccessIndex (SubjectMatchRule_record)
2726
// CHECK-NEXT: BPFPreserveStaticOffset (SubjectMatchRule_record)
2827
// CHECK-NEXT: BTFDeclTag (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record, SubjectMatchRule_field, SubjectMatchRule_type_alias)

clang/test/Sema/bpf-attr-bpf-fastcall.c

Lines changed: 0 additions & 14 deletions
This file was deleted.

llvm/lib/Target/BPF/BPFCallingConv.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,3 @@ def CC_BPF32 : CallingConv<[
4646
]>;
4747

4848
def CSR : CalleeSavedRegs<(add R6, R7, R8, R9, R10)>;
49-
def CSR_PreserveAll : CalleeSavedRegs<(add R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10)>;

llvm/lib/Target/BPF/BPFISelLowering.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -402,21 +402,6 @@ SDValue BPFTargetLowering::LowerFormalArguments(
402402

403403
const size_t BPFTargetLowering::MaxArgs = 5;
404404

405-
static void resetRegMaskBit(const TargetRegisterInfo *TRI, uint32_t *RegMask,
406-
MCRegister Reg) {
407-
for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg))
408-
RegMask[SubReg / 32] &= ~(1u << (SubReg % 32));
409-
}
410-
411-
static uint32_t *regMaskFromTemplate(const TargetRegisterInfo *TRI,
412-
MachineFunction &MF,
413-
const uint32_t *BaseRegMask) {
414-
uint32_t *RegMask = MF.allocateRegMask();
415-
unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
416-
memcpy(RegMask, BaseRegMask, sizeof(RegMask[0]) * RegMaskSize);
417-
return RegMask;
418-
}
419-
420405
SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
421406
SmallVectorImpl<SDValue> &InVals) const {
422407
SelectionDAG &DAG = CLI.DAG;
@@ -528,22 +513,6 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
528513
for (auto &Reg : RegsToPass)
529514
Ops.push_back(DAG.getRegister(Reg.first, Reg.second.getValueType()));
530515

531-
bool HasFastCall =
532-
(CLI.CB && isa<CallInst>(CLI.CB) && CLI.CB->hasFnAttr("bpf_fastcall"));
533-
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
534-
if (HasFastCall) {
535-
uint32_t *RegMask = regMaskFromTemplate(
536-
TRI, MF, TRI->getCallPreservedMask(MF, CallingConv::PreserveAll));
537-
for (auto const &RegPair : RegsToPass)
538-
resetRegMaskBit(TRI, RegMask, RegPair.first);
539-
if (!CLI.CB->getType()->isVoidTy())
540-
resetRegMaskBit(TRI, RegMask, BPF::R0);
541-
Ops.push_back(DAG.getRegisterMask(RegMask));
542-
} else {
543-
Ops.push_back(
544-
DAG.getRegisterMask(TRI->getCallPreservedMask(MF, CLI.CallConv)));
545-
}
546-
547516
if (InGlue.getNode())
548517
Ops.push_back(InGlue);
549518

llvm/lib/Target/BPF/BPFInstrInfo.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ let isBranch = 1, isTerminator = 1, hasDelaySlot=0, isBarrier = 1 in {
677677
}
678678

679679
// Jump and link
680-
let isCall=1, hasDelaySlot=0, Uses = [R11] in {
680+
let isCall=1, hasDelaySlot=0, Uses = [R11],
681+
// Potentially clobbered registers
682+
Defs = [R0, R1, R2, R3, R4, R5] in {
681683
def JAL : CALL<"call">;
682684
def JALX : CALLX<"callx">;
683685
}

llvm/lib/Target/BPF/BPFMIPeephole.cpp

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include "BPFInstrInfo.h"
2525
#include "BPFTargetMachine.h"
2626
#include "llvm/ADT/Statistic.h"
27-
#include "llvm/CodeGen/LivePhysRegs.h"
28-
#include "llvm/CodeGen/MachineFrameInfo.h"
2927
#include "llvm/CodeGen/MachineFunctionPass.h"
3028
#include "llvm/CodeGen/MachineInstrBuilder.h"
3129
#include "llvm/CodeGen/MachineRegisterInfo.h"
@@ -321,7 +319,6 @@ struct BPFMIPreEmitPeephole : public MachineFunctionPass {
321319
bool in16BitRange(int Num);
322320
bool eliminateRedundantMov();
323321
bool adjustBranch();
324-
bool insertMissingCallerSavedSpills();
325322

326323
public:
327324

@@ -336,7 +333,6 @@ struct BPFMIPreEmitPeephole : public MachineFunctionPass {
336333
Changed = eliminateRedundantMov();
337334
if (SupportGotol)
338335
Changed = adjustBranch() || Changed;
339-
Changed |= insertMissingCallerSavedSpills();
340336
return Changed;
341337
}
342338
};
@@ -600,88 +596,6 @@ bool BPFMIPreEmitPeephole::adjustBranch() {
600596
return Changed;
601597
}
602598

603-
static const unsigned CallerSavedRegs[] = {BPF::R0, BPF::R1, BPF::R2,
604-
BPF::R3, BPF::R4, BPF::R5};
605-
606-
struct BPFFastCall {
607-
MachineInstr *MI;
608-
unsigned LiveCallerSavedRegs;
609-
};
610-
611-
static void collectBPFFastCalls(const TargetRegisterInfo *TRI,
612-
LivePhysRegs &LiveRegs, MachineBasicBlock &BB,
613-
SmallVectorImpl<BPFFastCall> &Calls) {
614-
LiveRegs.init(*TRI);
615-
LiveRegs.addLiveOuts(BB);
616-
Calls.clear();
617-
for (MachineInstr &MI : llvm::reverse(BB)) {
618-
if (MI.isCall()) {
619-
unsigned LiveCallerSavedRegs = 0;
620-
for (MCRegister R : CallerSavedRegs) {
621-
bool DoSpillFill = !MI.definesRegister(R, TRI) && LiveRegs.contains(R);
622-
if (!DoSpillFill)
623-
continue;
624-
LiveCallerSavedRegs |= 1 << R;
625-
}
626-
if (LiveCallerSavedRegs)
627-
Calls.push_back({&MI, LiveCallerSavedRegs});
628-
}
629-
LiveRegs.stepBackward(MI);
630-
}
631-
}
632-
633-
static int64_t computeMinFixedObjOffset(MachineFrameInfo &MFI,
634-
unsigned SlotSize) {
635-
int64_t MinFixedObjOffset = 0;
636-
// Same logic as in X86FrameLowering::adjustFrameForMsvcCxxEh()
637-
for (int I = MFI.getObjectIndexBegin(); I < MFI.getObjectIndexEnd(); ++I) {
638-
if (MFI.isDeadObjectIndex(I))
639-
continue;
640-
MinFixedObjOffset = std::min(MinFixedObjOffset, MFI.getObjectOffset(I));
641-
}
642-
MinFixedObjOffset -=
643-
(SlotSize + MinFixedObjOffset % SlotSize) & (SlotSize - 1);
644-
return MinFixedObjOffset;
645-
}
646-
647-
bool BPFMIPreEmitPeephole::insertMissingCallerSavedSpills() {
648-
MachineFrameInfo &MFI = MF->getFrameInfo();
649-
SmallVector<BPFFastCall, 8> Calls;
650-
LivePhysRegs LiveRegs;
651-
const unsigned SlotSize = 8;
652-
int64_t MinFixedObjOffset = computeMinFixedObjOffset(MFI, SlotSize);
653-
bool Changed = false;
654-
for (MachineBasicBlock &BB : *MF) {
655-
collectBPFFastCalls(TRI, LiveRegs, BB, Calls);
656-
Changed |= !Calls.empty();
657-
for (BPFFastCall &Call : Calls) {
658-
int64_t CurOffset = MinFixedObjOffset;
659-
for (MCRegister Reg : CallerSavedRegs) {
660-
if (((1 << Reg) & Call.LiveCallerSavedRegs) == 0)
661-
continue;
662-
// Allocate stack object
663-
CurOffset -= SlotSize;
664-
MFI.CreateFixedSpillStackObject(SlotSize, CurOffset);
665-
// Generate spill
666-
BuildMI(BB, Call.MI->getIterator(), Call.MI->getDebugLoc(),
667-
TII->get(BPF::STD))
668-
.addReg(Reg)
669-
.addReg(BPF::R10)
670-
.addImm(CurOffset)
671-
.addImm(0);
672-
// Generate fill
673-
BuildMI(BB, ++Call.MI->getIterator(), Call.MI->getDebugLoc(),
674-
TII->get(BPF::LDD))
675-
.addReg(Reg)
676-
.addReg(BPF::R10)
677-
.addImm(CurOffset)
678-
.addImm(0);
679-
}
680-
}
681-
}
682-
return Changed;
683-
}
684-
685599
} // end default namespace
686600

687601
INITIALIZE_PASS(BPFMIPreEmitPeephole, "bpf-mi-pemit-peephole",

llvm/lib/Target/BPF/BPFRegisterInfo.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,6 @@ BPFRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
4040
return CSR_SaveList;
4141
}
4242

43-
const uint32_t *
44-
BPFRegisterInfo::getCallPreservedMask(const MachineFunction &MF,
45-
CallingConv::ID CC) const {
46-
switch (CC) {
47-
default:
48-
return CSR_RegMask;
49-
case CallingConv::PreserveAll:
50-
return CSR_PreserveAll_RegMask;
51-
}
52-
}
53-
5443
BitVector BPFRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
5544
BitVector Reserved(getNumRegs());
5645
markSuperRegs(Reserved, BPF::W10); // [W|R]10 is read only frame pointer

llvm/lib/Target/BPF/BPFRegisterInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ struct BPFRegisterInfo : public BPFGenRegisterInfo {
2626

2727
const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override;
2828

29-
const uint32_t *getCallPreservedMask(const MachineFunction &MF,
30-
CallingConv::ID) const override;
31-
3229
BitVector getReservedRegs(const MachineFunction &MF) const override;
3330

3431
bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj,

llvm/test/CodeGen/BPF/bpf-fastcall-1.ll

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)