Skip to content

Commit

Permalink
Remove load builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed May 1, 2024
1 parent 1dd7575 commit d408674
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 177 deletions.
57 changes: 0 additions & 57 deletions llvm/lib/Target/SBF/SBFISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "llvm/CodeGen/SelectionDAGISel.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/IntrinsicsBPF.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorHandling.h"
Expand Down Expand Up @@ -77,7 +76,6 @@ class SBFDAGToDAGISel : public SelectionDAGISel {

// Node preprocessing cases
void PreprocessLoad(SDNode *Node, SelectionDAG::allnodes_iterator &I);
void PreprocessTrunc(SDNode *Node, SelectionDAG::allnodes_iterator &I);

// Find constants from a constant structure
typedef std::vector<unsigned char> val_vec_type;
Expand Down Expand Up @@ -206,26 +204,6 @@ void SBFDAGToDAGISel::Select(SDNode *Node) {
}
break;
}
case ISD::INTRINSIC_W_CHAIN: {
unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
switch (IntNo) {
case Intrinsic::bpf_load_byte:
case Intrinsic::bpf_load_half:
case Intrinsic::bpf_load_word: {
SDLoc DL(Node);
SDValue Chain = Node->getOperand(0);
SDValue N1 = Node->getOperand(1);
SDValue Skb = Node->getOperand(2);
SDValue N3 = Node->getOperand(3);

SDValue R6Reg = CurDAG->getRegister(SBF::R6, MVT::i64);
Chain = CurDAG->getCopyToReg(Chain, DL, R6Reg, Skb, SDValue());
Node = CurDAG->UpdateNodeOperands(Node, Chain, N1, R6Reg, N3);
break;
}
}
break;
}

case ISD::FrameIndex: {
int FI = cast<FrameIndexSDNode>(Node)->getIndex();
Expand Down Expand Up @@ -377,8 +355,6 @@ void SBFDAGToDAGISel::PreprocessISelDAG() {
unsigned Opcode = Node->getOpcode();
if (Opcode == ISD::LOAD)
PreprocessLoad(Node, I);
else if (Opcode == ISD::AND)
PreprocessTrunc(Node, I);
}
}

Expand Down Expand Up @@ -508,39 +484,6 @@ bool SBFDAGToDAGISel::fillConstantStruct(const DataLayout &DL,
return true;
}

void SBFDAGToDAGISel::PreprocessTrunc(SDNode *Node,
SelectionDAG::allnodes_iterator &I) {
ConstantSDNode *MaskN = dyn_cast<ConstantSDNode>(Node->getOperand(1));
if (!MaskN)
return;

// The Reg operand should be a virtual register, which is defined
// outside the current basic block. DAG combiner has done a pretty
// good job in removing truncating inside a single basic block except
// when the Reg operand comes from bpf_load_[byte | half | word] for
// which the generic optimizer doesn't understand their results are
// zero extended.
SDValue BaseV = Node->getOperand(0);
if (BaseV.getOpcode() != ISD::INTRINSIC_W_CHAIN)
return;

unsigned IntNo = cast<ConstantSDNode>(BaseV->getOperand(1))->getZExtValue();
uint64_t MaskV = MaskN->getZExtValue();

if (!((IntNo == Intrinsic::bpf_load_byte && MaskV == 0xFF) ||
(IntNo == Intrinsic::bpf_load_half && MaskV == 0xFFFF) ||
(IntNo == Intrinsic::bpf_load_word && MaskV == 0xFFFFFFFF)))
return;

LLVM_DEBUG(dbgs() << "Remove the redundant AND operation in: ";
Node->dump(); dbgs() << '\n');

I--;
CurDAG->ReplaceAllUsesWith(SDValue(Node, 0), BaseV);
I++;
CurDAG->DeleteNode(Node);
}

FunctionPass *llvm::createSBFISelDag(SBFTargetMachine &TM) {
return new SBFDAGToDAGISel(TM);
}
18 changes: 1 addition & 17 deletions llvm/lib/Target/SBF/SBFISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/IntrinsicsBPF.h" // TODO: jle.
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
Expand Down Expand Up @@ -367,24 +366,9 @@ SDValue SBFTargetLowering::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;
}

case ISD::INTRINSIC_W_CHAIN:
// continue the expansion as defined with tablegen
return SDValue();
}
case ISD::DYNAMIC_STACKALLOC:
report_fatal_error("Unsupported dynamic stack allocation");
default:
Expand Down
3 changes: 0 additions & 3 deletions llvm/test/CodeGen/BPF/intrinsics.ll
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
; 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 llc < %s -march=sbf 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, ptr nocapture %bar, ptr %ctx, ptr %ctx2) #0 {
Expand Down
100 changes: 0 additions & 100 deletions llvm/test/CodeGen/SBF/intrinsics.ll

This file was deleted.

0 comments on commit d408674

Please sign in to comment.