Skip to content

Commit c4ef7a3

Browse files
alessandrodLucasSte
authored andcommitted
[SOL] disable llvm.bpf.load.* intrinsics on SBF (#24)
1 parent 2d40886 commit c4ef7a3

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

llvm/lib/Target/BPF/BPFISelLowering.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/CodeGen/ValueTypes.h"
2626
#include "llvm/IR/DiagnosticInfo.h"
2727
#include "llvm/IR/DiagnosticPrinter.h"
28+
#include "llvm/IR/IntrinsicsBPF.h"
2829
#include "llvm/Support/Debug.h"
2930
#include "llvm/Support/ErrorHandling.h"
3031
#include "llvm/Support/MathExtras.h"
@@ -81,6 +82,8 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
8182
setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
8283
setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
8384

85+
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);
86+
8487
for (auto VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i32, MVT::i64}) {
8588
if (Subtarget->isSolana()) {
8689
// Implement custom lowering for all atomic operations
@@ -404,10 +407,28 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
404407
case ISD::ATOMIC_LOAD_UMIN:
405408
case ISD::ATOMIC_LOAD_XOR:
406409
return LowerATOMICRMW(Op, DAG);
410+
case ISD::INTRINSIC_W_CHAIN: {
411+
unsigned IntNo = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue();
412+
switch (IntNo) {
413+
case Intrinsic::bpf_load_byte:
414+
case Intrinsic::bpf_load_half:
415+
case Intrinsic::bpf_load_word:
416+
if (Subtarget->isSolana()) {
417+
report_fatal_error(
418+
"llvm.bpf.load.* intrinsics are not supported in SBF", false);
419+
}
420+
break;
421+
default:
422+
break;
423+
}
424+
425+
// continue the expansion as defined with tablegen
426+
return SDValue();
427+
}
407428
case ISD::DYNAMIC_STACKALLOC:
408429
report_fatal_error("Unsupported dynamic stack allocation");
409430
default:
410-
llvm_unreachable("unimplemented atomic operand");
431+
llvm_unreachable("unimplemented operation");
411432
}
412433
}
413434

llvm/test/CodeGen/BPF/intrinsics.ll

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
; RUN: llc < %s -march=bpfel -show-mc-encoding | FileCheck --check-prefix=CHECK-EL %s
22
; RUN: llc < %s -march=bpfeb -show-mc-encoding | FileCheck --check-prefix=CHECK-EB %s
3+
; RUN: not --crash llc -march=sbf <%s 2>&1 | FileCheck --check-prefix=CHECK-SBF %s
4+
5+
; CHECK-SBF: LLVM ERROR: llvm.bpf.load.* intrinsics are not supported in SBF
36

47
; Function Attrs: nounwind uwtable
58
define i32 @ld_b(i64 %foo, ptr nocapture %bar, ptr %ctx, ptr %ctx2) #0 {

0 commit comments

Comments
 (0)