Skip to content

Commit 216a17e

Browse files
committed
[AVR] TableGen-erate SDNode descriptions
This consolidates node definitions into one place and enables automatic node verification. Part of llvm#119709.
1 parent 6fd3381 commit 216a17e

File tree

6 files changed

+66
-112
lines changed

6 files changed

+66
-112
lines changed

llvm/lib/Target/AVR/AVRISelLowering.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -220,40 +220,6 @@ AVRTargetLowering::AVRTargetLowering(const AVRTargetMachine &TM,
220220
setMinimumJumpTableEntries(UINT_MAX);
221221
}
222222

223-
const char *AVRTargetLowering::getTargetNodeName(unsigned Opcode) const {
224-
#define NODE(name) \
225-
case AVRISD::name: \
226-
return #name
227-
228-
switch (Opcode) {
229-
default:
230-
return nullptr;
231-
NODE(RET_GLUE);
232-
NODE(RETI_GLUE);
233-
NODE(CALL);
234-
NODE(WRAPPER);
235-
NODE(LSL);
236-
NODE(LSLW);
237-
NODE(LSR);
238-
NODE(LSRW);
239-
NODE(ROL);
240-
NODE(ROR);
241-
NODE(ASR);
242-
NODE(ASRW);
243-
NODE(LSLLOOP);
244-
NODE(LSRLOOP);
245-
NODE(ROLLOOP);
246-
NODE(RORLOOP);
247-
NODE(ASRLOOP);
248-
NODE(BRCOND);
249-
NODE(CMP);
250-
NODE(CMPC);
251-
NODE(TST);
252-
NODE(SELECT_CC);
253-
#undef NODE
254-
}
255-
}
256-
257223
EVT AVRTargetLowering::getSetCCResultType(const DataLayout &DL, LLVMContext &,
258224
EVT VT) const {
259225
assert(!VT.isVector() && "No AVR SetCC type for vectors!");

llvm/lib/Target/AVR/AVRISelLowering.h

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,64 +19,6 @@
1919

2020
namespace llvm {
2121

22-
namespace AVRISD {
23-
24-
/// AVR Specific DAG Nodes
25-
enum NodeType {
26-
/// Start the numbering where the builtin ops leave off.
27-
FIRST_NUMBER = ISD::BUILTIN_OP_END,
28-
/// Return from subroutine.
29-
RET_GLUE,
30-
/// Return from ISR.
31-
RETI_GLUE,
32-
/// Represents an abstract call instruction,
33-
/// which includes a bunch of information.
34-
CALL,
35-
/// A wrapper node for TargetConstantPool,
36-
/// TargetExternalSymbol, and TargetGlobalAddress.
37-
WRAPPER,
38-
LSL, ///< Logical shift left.
39-
LSLBN, ///< Byte logical shift left N bits.
40-
LSLWN, ///< Word logical shift left N bits.
41-
LSLHI, ///< Higher 8-bit of word logical shift left.
42-
LSLW, ///< Wide logical shift left.
43-
LSR, ///< Logical shift right.
44-
LSRBN, ///< Byte logical shift right N bits.
45-
LSRWN, ///< Word logical shift right N bits.
46-
LSRLO, ///< Lower 8-bit of word logical shift right.
47-
LSRW, ///< Wide logical shift right.
48-
ASR, ///< Arithmetic shift right.
49-
ASRBN, ///< Byte arithmetic shift right N bits.
50-
ASRWN, ///< Word arithmetic shift right N bits.
51-
ASRLO, ///< Lower 8-bit of word arithmetic shift right.
52-
ASRW, ///< Wide arithmetic shift right.
53-
ROR, ///< Bit rotate right.
54-
ROL, ///< Bit rotate left.
55-
LSLLOOP, ///< A loop of single logical shift left instructions.
56-
LSRLOOP, ///< A loop of single logical shift right instructions.
57-
ROLLOOP, ///< A loop of single left bit rotate instructions.
58-
RORLOOP, ///< A loop of single right bit rotate instructions.
59-
ASRLOOP, ///< A loop of single arithmetic shift right instructions.
60-
/// AVR conditional branches. Operand 0 is the chain operand, operand 1
61-
/// is the block to branch if condition is true, operand 2 is the
62-
/// condition code, and operand 3 is the flag operand produced by a CMP
63-
/// or TEST instruction.
64-
BRCOND,
65-
/// Compare instruction.
66-
CMP,
67-
/// Compare with carry instruction.
68-
CMPC,
69-
/// Test for zero or minus instruction.
70-
TST,
71-
/// Swap Rd[7:4] <-> Rd[3:0].
72-
SWAP,
73-
/// Operand 0 and operand 1 are selection variable, operand 2
74-
/// is condition code and operand 3 is flag operand.
75-
SELECT_CC
76-
};
77-
78-
} // end of namespace AVRISD
79-
8022
class AVRSubtarget;
8123
class AVRTargetMachine;
8224

@@ -95,8 +37,6 @@ class AVRTargetLowering : public TargetLowering {
9537
return MVT::i8;
9638
}
9739

98-
const char *getTargetNodeName(unsigned Opcode) const override;
99-
10040
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
10141

10242
void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,

llvm/lib/Target/AVR/AVRInstrInfo.td

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,67 @@ def SDT_AVRSelectCC
3232
// AVR Specific Node Definitions
3333
//===----------------------------------------------------------------------===//
3434

35+
// Return from subroutine.
3536
def AVRretglue : SDNode<"AVRISD::RET_GLUE", SDTNone,
3637
[SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
38+
39+
// Return from ISR.
3740
def AVRretiglue : SDNode<"AVRISD::RETI_GLUE", SDTNone,
3841
[SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
3942

43+
4044
def AVRcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_AVRCallSeqStart,
4145
[SDNPHasChain, SDNPOutGlue]>;
4246
def AVRcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_AVRCallSeqEnd,
4347
[SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
4448

49+
// Represents an abstract call instruction,
50+
// which includes a bunch of information.
4551
def AVRcall : SDNode<"AVRISD::CALL", SDT_AVRCall,
4652
[SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>;
4753

54+
// A wrapper node for TargetConstantPool,
55+
// TargetExternalSymbol, and TargetGlobalAddress.
4856
def AVRWrapper : SDNode<"AVRISD::WRAPPER", SDT_AVRWrapper>;
4957

58+
// AVR conditional branches. Operand 0 is the chain operand, operand 1
59+
// is the block to branch if condition is true, operand 2 is the
60+
// condition code, and operand 3 is the flag operand produced by a CMP
61+
// or TEST instruction.
5062
def AVRbrcond
5163
: SDNode<"AVRISD::BRCOND", SDT_AVRBrcond, [SDNPHasChain, SDNPInGlue]>;
64+
65+
// Compare instruction.
5266
def AVRcmp : SDNode<"AVRISD::CMP", SDT_AVRCmp, [SDNPOutGlue]>;
67+
68+
// Compare with carry instruction.
5369
def AVRcmpc : SDNode<"AVRISD::CMPC", SDT_AVRCmp, [SDNPInGlue, SDNPOutGlue]>;
70+
71+
// Test for zero or minus instruction.
5472
def AVRtst : SDNode<"AVRISD::TST", SDT_AVRTst, [SDNPOutGlue]>;
73+
74+
// Operand 0 and operand 1 are selection variable, operand 2
75+
// is condition code and operand 3 is flag operand.
5576
def AVRselectcc : SDNode<"AVRISD::SELECT_CC", SDT_AVRSelectCC, [SDNPInGlue]>;
5677

5778
// Shift nodes.
58-
def AVRlsl : SDNode<"AVRISD::LSL", SDTIntUnaryOp>;
59-
def AVRlsr : SDNode<"AVRISD::LSR", SDTIntUnaryOp>;
60-
def AVRrol : SDNode<"AVRISD::ROL", SDTIntUnaryOp>;
61-
def AVRror : SDNode<"AVRISD::ROR", SDTIntUnaryOp>;
62-
def AVRasr : SDNode<"AVRISD::ASR", SDTIntUnaryOp>;
63-
def AVRlslhi : SDNode<"AVRISD::LSLHI", SDTIntUnaryOp>;
64-
def AVRlsrlo : SDNode<"AVRISD::LSRLO", SDTIntUnaryOp>;
65-
def AVRasrlo : SDNode<"AVRISD::ASRLO", SDTIntUnaryOp>;
66-
def AVRlslbn : SDNode<"AVRISD::LSLBN", SDTIntBinOp>;
67-
def AVRlsrbn : SDNode<"AVRISD::LSRBN", SDTIntBinOp>;
68-
def AVRasrbn : SDNode<"AVRISD::ASRBN", SDTIntBinOp>;
69-
def AVRlslwn : SDNode<"AVRISD::LSLWN", SDTIntBinOp>;
70-
def AVRlsrwn : SDNode<"AVRISD::LSRWN", SDTIntBinOp>;
71-
def AVRasrwn : SDNode<"AVRISD::ASRWN", SDTIntBinOp>;
72-
def AVRlslw : SDNode<"AVRISD::LSLW", SDTIntShiftPairOp>;
73-
def AVRlsrw : SDNode<"AVRISD::LSRW", SDTIntShiftPairOp>;
74-
def AVRasrw : SDNode<"AVRISD::ASRW", SDTIntShiftPairOp>;
79+
def AVRlsl : SDNode<"AVRISD::LSL", SDTIntUnaryOp>; // Logical shift left.
80+
def AVRlsr : SDNode<"AVRISD::LSR", SDTIntUnaryOp>; // Logical shift right.
81+
def AVRrol : SDNode<"AVRISD::ROL", SDTIntUnaryOp>; // Bit rotate left.
82+
def AVRror : SDNode<"AVRISD::ROR", SDTIntUnaryOp>; // Bit rotate right.
83+
def AVRasr : SDNode<"AVRISD::ASR", SDTIntUnaryOp>; // Arithmetic shift right.
84+
def AVRlslhi : SDNode<"AVRISD::LSLHI", SDTIntUnaryOp>; // Higher 8-bit of word logical shift left.
85+
def AVRlsrlo : SDNode<"AVRISD::LSRLO", SDTIntUnaryOp>; // Lower 8-bit of word logical shift right.
86+
def AVRasrlo : SDNode<"AVRISD::ASRLO", SDTIntUnaryOp>; // Lower 8-bit of word arithmetic shift right.
87+
def AVRlslbn : SDNode<"AVRISD::LSLBN", SDTIntBinOp>; // Byte logical shift left N bits.
88+
def AVRlsrbn : SDNode<"AVRISD::LSRBN", SDTIntBinOp>; // Byte logical shift right N bits.
89+
def AVRasrbn : SDNode<"AVRISD::ASRBN", SDTIntBinOp>; // Byte arithmetic shift right N bits.
90+
def AVRlslwn : SDNode<"AVRISD::LSLWN", SDTIntBinOp>; // Higher 8-bit of word logical shift left.
91+
def AVRlsrwn : SDNode<"AVRISD::LSRWN", SDTIntBinOp>; // Word logical shift right N bits.
92+
def AVRasrwn : SDNode<"AVRISD::ASRWN", SDTIntBinOp>; // Word arithmetic shift right N bits.
93+
def AVRlslw : SDNode<"AVRISD::LSLW", SDTIntShiftPairOp>; // Wide logical shift left.
94+
def AVRlsrw : SDNode<"AVRISD::LSRW", SDTIntShiftPairOp>; // Wide logical shift right.
95+
def AVRasrw : SDNode<"AVRISD::ASRW", SDTIntShiftPairOp>; // Wide arithmetic shift right.
7596

7697
// Pseudo shift nodes for non-constant shift amounts.
7798
def AVRlslLoop : SDNode<"AVRISD::LSLLOOP", SDTIntShiftOp>;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "AVRSelectionDAGInfo.h"
10+
11+
#define GET_SDNODE_DESC
12+
#include "AVRGenSDNodeInfo.inc"
13+
14+
using namespace llvm;
15+
16+
AVRSelectionDAGInfo::AVRSelectionDAGInfo()
17+
: SelectionDAGGenTargetInfo(AVRGenSDNodeInfo) {}
18+
19+
AVRSelectionDAGInfo::~AVRSelectionDAGInfo() = default;

llvm/lib/Target/AVR/AVRSelectionDAGInfo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@
1515

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

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

2023
/// Holds information about the AVR instruction selection DAG.
21-
class AVRSelectionDAGInfo : public SelectionDAGTargetInfo {
24+
class AVRSelectionDAGInfo : public SelectionDAGGenTargetInfo {
2225
public:
26+
AVRSelectionDAGInfo();
27+
28+
~AVRSelectionDAGInfo() override;
2329
};
2430

2531
} // end namespace llvm

llvm/lib/Target/AVR/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ tablegen(LLVM AVRGenDisassemblerTables.inc -gen-disassembler)
1010
tablegen(LLVM AVRGenInstrInfo.inc -gen-instr-info)
1111
tablegen(LLVM AVRGenMCCodeEmitter.inc -gen-emitter)
1212
tablegen(LLVM AVRGenRegisterInfo.inc -gen-register-info)
13+
tablegen(LLVM AVRGenSDNodeInfo.inc -gen-sd-node-info)
1314
tablegen(LLVM AVRGenSubtargetInfo.inc -gen-subtarget)
1415

1516
add_public_tablegen_target(AVRCommonTableGen)
@@ -23,6 +24,7 @@ add_llvm_target(AVRCodeGen
2324
AVRISelLowering.cpp
2425
AVRMCInstLower.cpp
2526
AVRRegisterInfo.cpp
27+
AVRSelectionDAGInfo.cpp
2628
AVRShiftExpand.cpp
2729
AVRSubtarget.cpp
2830
AVRTargetMachine.cpp

0 commit comments

Comments
 (0)