Skip to content

Commit 321d9c0

Browse files
authored
[SOL] disable llvm.bpf.load.* intrinsics on SBF (#24)
1 parent 421b949 commit 321d9c0

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/raw_ostream.h"
@@ -79,6 +80,8 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
7980
setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
8081
setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
8182

83+
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);
84+
8285
for (auto VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i32, MVT::i64}) {
8386
if (Subtarget->isSolana()) {
8487
// Implement custom lowering for all atomic operations
@@ -367,10 +370,28 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
367370
case ISD::ATOMIC_LOAD_UMIN:
368371
case ISD::ATOMIC_LOAD_XOR:
369372
return LowerATOMICRMW(Op, DAG);
373+
case ISD::INTRINSIC_W_CHAIN: {
374+
unsigned IntNo = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue();
375+
switch (IntNo) {
376+
case Intrinsic::bpf_load_byte:
377+
case Intrinsic::bpf_load_half:
378+
case Intrinsic::bpf_load_word:
379+
if (Subtarget->isSolana()) {
380+
report_fatal_error(
381+
"llvm.bpf.load.* intrinsics are not supported in SBF", false);
382+
}
383+
break;
384+
default:
385+
break;
386+
}
387+
388+
// continue the expansion as defined with tablegen
389+
return SDValue();
390+
}
370391
case ISD::DYNAMIC_STACKALLOC:
371392
report_fatal_error("Unsupported dynamic stack allocation");
372393
default:
373-
llvm_unreachable("unimplemented atomic operand");
394+
llvm_unreachable("unimplemented operation");
374395
}
375396
}
376397

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, i64* nocapture %bar, i8* %ctx, i8* %ctx2) #0 {

0 commit comments

Comments
 (0)