Skip to content

Commit 6d78736

Browse files
committed
[BPF] TableGen-erate SDNode descriptions
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. Part of #119709.
1 parent 0c73009 commit 6d78736

File tree

6 files changed

+17
-38
lines changed

6 files changed

+17
-38
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +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,
49+
[SDNPHasChain, SDNPOutGlue,
5150
SDNPMayStore, SDNPMayLoad]>;
5251
def BPFIsLittleEndian : Predicate<"Subtarget->isLittleEndian()">;
5352
def BPFIsBigEndian : Predicate<"!Subtarget->isLittleEndian()">;

llvm/lib/Target/BPF/BPFSelectionDAGInfo.cpp

Lines changed: 8 additions & 0 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,

llvm/lib/Target/BPF/BPFSelectionDAGInfo.h

Lines changed: 6 additions & 1 deletion
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,

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)