Skip to content

Commit

Permalink
[SOL] disable llvm.bpf.load.* intrinsics on SBF (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrod authored Jan 7, 2022
1 parent 421b949 commit 321d9c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 22 additions & 1 deletion llvm/lib/Target/BPF/BPFISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/IntrinsicsBPF.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -79,6 +80,8 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);

setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);

for (auto VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i32, MVT::i64}) {
if (Subtarget->isSolana()) {
// Implement custom lowering for all atomic operations
Expand Down Expand Up @@ -367,10 +370,28 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
case ISD::ATOMIC_LOAD_UMIN:
case ISD::ATOMIC_LOAD_XOR:
return LowerATOMICRMW(Op, DAG);
case ISD::INTRINSIC_W_CHAIN: {
unsigned IntNo = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue();
switch (IntNo) {
case Intrinsic::bpf_load_byte:
case Intrinsic::bpf_load_half:
case Intrinsic::bpf_load_word:
if (Subtarget->isSolana()) {
report_fatal_error(
"llvm.bpf.load.* intrinsics are not supported in SBF", false);
}
break;
default:
break;
}

// continue the expansion as defined with tablegen
return SDValue();
}
case ISD::DYNAMIC_STACKALLOC:
report_fatal_error("Unsupported dynamic stack allocation");
default:
llvm_unreachable("unimplemented atomic operand");
llvm_unreachable("unimplemented operation");
}
}

Expand Down
3 changes: 3 additions & 0 deletions llvm/test/CodeGen/BPF/intrinsics.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
; RUN: llc < %s -march=bpfel -show-mc-encoding | FileCheck --check-prefix=CHECK-EL %s
; RUN: llc < %s -march=bpfeb -show-mc-encoding | FileCheck --check-prefix=CHECK-EB %s
; RUN: not --crash llc -march=sbf <%s 2>&1 | FileCheck --check-prefix=CHECK-SBF %s

; CHECK-SBF: LLVM ERROR: llvm.bpf.load.* intrinsics are not supported in SBF

; Function Attrs: nounwind uwtable
define i32 @ld_b(i64 %foo, i64* nocapture %bar, i8* %ctx, i8* %ctx2) #0 {
Expand Down

0 comments on commit 321d9c0

Please sign in to comment.