Skip to content

Commit c940bfd

Browse files
authored
[BPF] TableGen-erate SDNode descriptions (llvm#166499)
This allows SDNodes to be validated against their expected type profiles and reduces the number of changes required to add a new node. Fix BR_CC/MEMCPY descriptions to match C++ code that creates the nodes (an error detected by the enabled verification functionality). Also remove redundant `SDNPOutGlue` on `BPFISD::MEMCPY`. Part of llvm#119709.
1 parent 94a52cb commit c940bfd

File tree

6 files changed

+21
-48
lines changed

6 files changed

+21
-48
lines changed

llvm/lib/Target/BPF/BPFISelLowering.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -803,26 +803,6 @@ SDValue BPFTargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) const {
803803
return getAddr(N, DAG);
804804
}
805805

806-
const char *BPFTargetLowering::getTargetNodeName(unsigned Opcode) const {
807-
switch ((BPFISD::NodeType)Opcode) {
808-
case BPFISD::FIRST_NUMBER:
809-
break;
810-
case BPFISD::RET_GLUE:
811-
return "BPFISD::RET_GLUE";
812-
case BPFISD::CALL:
813-
return "BPFISD::CALL";
814-
case BPFISD::SELECT_CC:
815-
return "BPFISD::SELECT_CC";
816-
case BPFISD::BR_CC:
817-
return "BPFISD::BR_CC";
818-
case BPFISD::Wrapper:
819-
return "BPFISD::Wrapper";
820-
case BPFISD::MEMCPY:
821-
return "BPFISD::MEMCPY";
822-
}
823-
return nullptr;
824-
}
825-
826806
static SDValue getTargetNode(ConstantPoolSDNode *N, const SDLoc &DL, EVT Ty,
827807
SelectionDAG &DAG, unsigned Flags) {
828808
return DAG.getTargetConstantPool(N->getConstVal(), Ty, N->getAlign(),

llvm/lib/Target/BPF/BPFISelLowering.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@
2020

2121
namespace llvm {
2222
class BPFSubtarget;
23-
namespace BPFISD {
24-
enum NodeType : unsigned {
25-
FIRST_NUMBER = ISD::BUILTIN_OP_END,
26-
RET_GLUE,
27-
CALL,
28-
SELECT_CC,
29-
BR_CC,
30-
Wrapper,
31-
MEMCPY
32-
};
33-
}
3423

3524
class BPFTargetLowering : public TargetLowering {
3625
public:
@@ -39,9 +28,6 @@ class BPFTargetLowering : public TargetLowering {
3928
// Provide custom lowering hooks for some operations.
4029
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
4130

42-
// This method returns the name of a target specific DAG node.
43-
const char *getTargetNodeName(unsigned Opcode) const override;
44-
4531
// This method decides whether folding a constant offset
4632
// with the given GlobalAddress is legal.
4733
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;

llvm/lib/Target/BPF/BPFInstrInfo.td

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ def BPFcallseq_start: SDNode<"ISD::CALLSEQ_START", SDT_BPFCallSeqStart,
4141
[SDNPHasChain, SDNPOutGlue]>;
4242
def BPFcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_BPFCallSeqEnd,
4343
[SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
44-
def BPFbrcc : SDNode<"BPFISD::BR_CC", SDT_BPFBrCC,
45-
[SDNPHasChain, SDNPOutGlue, SDNPInGlue]>;
44+
def BPFbrcc : SDNode<"BPFISD::BR_CC", SDT_BPFBrCC, [SDNPHasChain]>;
4645

4746
def BPFselectcc : SDNode<"BPFISD::SELECT_CC", SDT_BPFSelectCC>;
4847
def BPFWrapper : SDNode<"BPFISD::Wrapper", SDT_BPFWrapper>;
4948
def BPFmemcpy : SDNode<"BPFISD::MEMCPY", SDT_BPFMEMCPY,
50-
[SDNPHasChain, SDNPInGlue, SDNPOutGlue,
51-
SDNPMayStore, SDNPMayLoad]>;
49+
[SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
5250
def BPFIsLittleEndian : Predicate<"Subtarget->isLittleEndian()">;
5351
def BPFIsBigEndian : Predicate<"!Subtarget->isLittleEndian()">;
5452
def BPFHasALU32 : Predicate<"Subtarget->getHasAlu32()">;

llvm/lib/Target/BPF/BPFSelectionDAGInfo.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "BPFSelectionDAGInfo.h"
1314
#include "BPFTargetMachine.h"
1415
#include "llvm/CodeGen/SelectionDAG.h"
16+
17+
#define GET_SDNODE_DESC
18+
#include "BPFGenSDNodeInfo.inc"
19+
1520
using namespace llvm;
1621

1722
#define DEBUG_TYPE "bpf-selectiondag-info"
1823

24+
BPFSelectionDAGInfo::BPFSelectionDAGInfo()
25+
: SelectionDAGGenTargetInfo(BPFGenSDNodeInfo) {}
26+
1927
SDValue BPFSelectionDAGInfo::EmitTargetCodeForMemcpy(
2028
SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
2129
SDValue Size, Align Alignment, bool isVolatile, bool AlwaysInline,
@@ -31,11 +39,7 @@ SDValue BPFSelectionDAGInfo::EmitTargetCodeForMemcpy(
3139
if (StoresNumEstimate > getCommonMaxStoresPerMemFunc())
3240
return SDValue();
3341

34-
SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue);
35-
36-
Dst = DAG.getNode(BPFISD::MEMCPY, dl, VTs, Chain, Dst, Src,
37-
DAG.getConstant(CopyLen, dl, MVT::i64),
38-
DAG.getConstant(Alignment.value(), dl, MVT::i64));
39-
40-
return Dst.getValue(0);
42+
return DAG.getNode(BPFISD::MEMCPY, dl, MVT::Other, Chain, Dst, Src,
43+
DAG.getConstant(CopyLen, dl, MVT::i64),
44+
DAG.getConstant(Alignment.value(), dl, MVT::i64));
4145
}

llvm/lib/Target/BPF/BPFSelectionDAGInfo.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515

1616
#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
1717

18+
#define GET_SDNODE_ENUM
19+
#include "BPFGenSDNodeInfo.inc"
20+
1821
namespace llvm {
1922

20-
class BPFSelectionDAGInfo : public SelectionDAGTargetInfo {
23+
class BPFSelectionDAGInfo : public SelectionDAGGenTargetInfo {
2124
public:
25+
BPFSelectionDAGInfo();
26+
2227
SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, const SDLoc &dl,
2328
SDValue Chain, SDValue Dst, SDValue Src,
2429
SDValue Size, Align Alignment,
@@ -27,9 +32,8 @@ class BPFSelectionDAGInfo : public SelectionDAGTargetInfo {
2732
MachinePointerInfo SrcPtrInfo) const override;
2833

2934
unsigned getCommonMaxStoresPerMemFunc() const { return 128; }
30-
3135
};
3236

33-
}
37+
} // namespace llvm
3438

3539
#endif

llvm/lib/Target/BPF/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ tablegen(LLVM BPFGenDisassemblerTables.inc -gen-disassembler)
1010
tablegen(LLVM BPFGenInstrInfo.inc -gen-instr-info)
1111
tablegen(LLVM BPFGenMCCodeEmitter.inc -gen-emitter)
1212
tablegen(LLVM BPFGenRegisterInfo.inc -gen-register-info)
13+
tablegen(LLVM BPFGenSDNodeInfo.inc -gen-sd-node-info)
1314
tablegen(LLVM BPFGenSubtargetInfo.inc -gen-subtarget)
1415
tablegen(LLVM BPFGenGlobalISel.inc -gen-global-isel)
1516
tablegen(LLVM BPFGenRegisterBank.inc -gen-register-bank)

0 commit comments

Comments
 (0)