Skip to content

Commit e8b2c31

Browse files
authored
[M68k] TableGen-erate SDNode descriptions (#139449)
This consolidates node definitions into one place and enables automatic node verification. Part of #119709.
1 parent d46458c commit e8b2c31

File tree

9 files changed

+99
-142
lines changed

9 files changed

+99
-142
lines changed

llvm/lib/Target/M68k/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tablegen(LLVM M68kGenGlobalISel.inc -gen-global-isel)
66
tablegen(LLVM M68kGenRegisterInfo.inc -gen-register-info)
77
tablegen(LLVM M68kGenRegisterBank.inc -gen-register-bank)
88
tablegen(LLVM M68kGenInstrInfo.inc -gen-instr-info)
9+
tablegen(LLVM M68kGenSDNodeInfo.inc -gen-sd-node-info)
910
tablegen(LLVM M68kGenSubtargetInfo.inc -gen-subtarget)
1011
tablegen(LLVM M68kGenMCCodeEmitter.inc -gen-emitter)
1112
tablegen(LLVM M68kGenMCPseudoLowering.inc -gen-pseudo-lowering)
@@ -32,6 +33,7 @@ add_llvm_target(M68kCodeGen
3233
M68kMachineFunction.cpp
3334
M68kMCInstLower.cpp
3435
M68kRegisterInfo.cpp
36+
M68kSelectionDAGInfo.cpp
3537
M68kSubtarget.cpp
3638
M68kTargetMachine.cpp
3739
M68kTargetObjectFile.cpp

llvm/lib/Target/M68k/M68kISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include "M68kMachineFunction.h"
1717
#include "M68kRegisterInfo.h"
18+
#include "M68kSelectionDAGInfo.h"
1819
#include "M68kTargetMachine.h"
19-
2020
#include "llvm/CodeGen/MachineConstantPool.h"
2121
#include "llvm/CodeGen/MachineFrameInfo.h"
2222
#include "llvm/CodeGen/MachineFunction.h"

llvm/lib/Target/M68k/M68kISelLowering.cpp

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "M68kISelLowering.h"
1616
#include "M68kCallingConv.h"
1717
#include "M68kMachineFunction.h"
18+
#include "M68kSelectionDAGInfo.h"
1819
#include "M68kSubtarget.h"
1920
#include "M68kTargetMachine.h"
2021
#include "M68kTargetObjectFile.h"
@@ -3641,64 +3642,6 @@ SDValue M68kTargetLowering::PerformDAGCombine(SDNode *N,
36413642
return SDValue();
36423643
}
36433644

3644-
//===----------------------------------------------------------------------===//
3645-
// M68kISD Node Names
3646-
//===----------------------------------------------------------------------===//
3647-
const char *M68kTargetLowering::getTargetNodeName(unsigned Opcode) const {
3648-
switch (Opcode) {
3649-
case M68kISD::CALL:
3650-
return "M68kISD::CALL";
3651-
case M68kISD::TAIL_CALL:
3652-
return "M68kISD::TAIL_CALL";
3653-
case M68kISD::RET:
3654-
return "M68kISD::RET";
3655-
case M68kISD::TC_RETURN:
3656-
return "M68kISD::TC_RETURN";
3657-
case M68kISD::ADD:
3658-
return "M68kISD::ADD";
3659-
case M68kISD::SUB:
3660-
return "M68kISD::SUB";
3661-
case M68kISD::ADDX:
3662-
return "M68kISD::ADDX";
3663-
case M68kISD::SUBX:
3664-
return "M68kISD::SUBX";
3665-
case M68kISD::SMUL:
3666-
return "M68kISD::SMUL";
3667-
case M68kISD::UMUL:
3668-
return "M68kISD::UMUL";
3669-
case M68kISD::OR:
3670-
return "M68kISD::OR";
3671-
case M68kISD::XOR:
3672-
return "M68kISD::XOR";
3673-
case M68kISD::AND:
3674-
return "M68kISD::AND";
3675-
case M68kISD::CMP:
3676-
return "M68kISD::CMP";
3677-
case M68kISD::BTST:
3678-
return "M68kISD::BTST";
3679-
case M68kISD::SELECT:
3680-
return "M68kISD::SELECT";
3681-
case M68kISD::CMOV:
3682-
return "M68kISD::CMOV";
3683-
case M68kISD::BRCOND:
3684-
return "M68kISD::BRCOND";
3685-
case M68kISD::SETCC:
3686-
return "M68kISD::SETCC";
3687-
case M68kISD::SETCC_CARRY:
3688-
return "M68kISD::SETCC_CARRY";
3689-
case M68kISD::GLOBAL_BASE_REG:
3690-
return "M68kISD::GLOBAL_BASE_REG";
3691-
case M68kISD::Wrapper:
3692-
return "M68kISD::Wrapper";
3693-
case M68kISD::WrapperPC:
3694-
return "M68kISD::WrapperPC";
3695-
case M68kISD::SEG_ALLOCA:
3696-
return "M68kISD::SEG_ALLOCA";
3697-
default:
3698-
return NULL;
3699-
}
3700-
}
3701-
37023645
CCAssignFn *M68kTargetLowering::getCCAssignFn(CallingConv::ID CC, bool Return,
37033646
bool IsVarArg) const {
37043647
if (Return)

llvm/lib/Target/M68k/M68kISelLowering.h

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -25,77 +25,6 @@
2525
#include <deque>
2626

2727
namespace llvm {
28-
namespace M68kISD {
29-
30-
/// M68k Specific DAG nodes
31-
enum NodeType {
32-
/// Start the numbering from where ISD NodeType finishes.
33-
FIRST_NUMBER = ISD::BUILTIN_OP_END,
34-
35-
CALL,
36-
RET,
37-
TAIL_CALL,
38-
TC_RETURN,
39-
40-
/// M68k compare and logical compare instructions. Subtracts the source
41-
/// operand from the destination data register and sets the condition
42-
/// codes according to the result. Immediate always goes first.
43-
CMP,
44-
45-
/// M68k bit-test instructions.
46-
BTST,
47-
48-
/// M68k Select
49-
SELECT,
50-
51-
/// M68k SetCC. Operand 0 is condition code, and operand 1 is the CCR
52-
/// operand, usually produced by a CMP instruction.
53-
SETCC,
54-
55-
// Same as SETCC except it's materialized with a subx and the value is all
56-
// one's or all zero's.
57-
SETCC_CARRY, // R = carry_bit ? ~0 : 0
58-
59-
/// M68k conditional moves. Operand 0 and operand 1 are the two values
60-
/// to select from. Operand 2 is the condition code, and operand 3 is the
61-
/// flag operand produced by a CMP or TEST instruction. It also writes a
62-
/// flag result.
63-
CMOV,
64-
65-
/// M68k conditional branches. Operand 0 is the chain operand, operand 1
66-
/// is the block to branch if condition is true, operand 2 is the
67-
/// condition code, and operand 3 is the flag operand produced by a CMP
68-
/// or TEST instruction.
69-
BRCOND,
70-
71-
// Arithmetic operations with CCR results.
72-
ADD,
73-
SUB,
74-
ADDX,
75-
SUBX,
76-
SMUL,
77-
UMUL,
78-
OR,
79-
XOR,
80-
AND,
81-
82-
// GlobalBaseReg,
83-
GLOBAL_BASE_REG,
84-
85-
/// A wrapper node for TargetConstantPool,
86-
/// TargetExternalSymbol, and TargetGlobalAddress.
87-
Wrapper,
88-
89-
/// Special wrapper used under M68k PIC mode for PC
90-
/// relative displacements.
91-
WrapperPC,
92-
93-
// For allocating variable amounts of stack space when using
94-
// segmented stacks. Check if the current stacklet has enough space, and
95-
// falls back to heap allocation if not.
96-
SEG_ALLOCA,
97-
};
98-
} // namespace M68kISD
9928

10029
/// Define some predicates that are used for node matching.
10130
namespace M68k {
@@ -124,8 +53,6 @@ class M68kTargetLowering : public TargetLowering {
12453
static const M68kTargetLowering *create(const M68kTargetMachine &TM,
12554
const M68kSubtarget &STI);
12655

127-
const char *getTargetNodeName(unsigned Opcode) const override;
128-
12956
/// Return the value type to use for ISD::SETCC.
13057
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
13158
EVT VT) const override;

llvm/lib/Target/M68k/M68kInstrInfo.td

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,18 @@ def MxRet : SDNode<"M68kISD::RET", MxSDT_Ret,
112112
def MxTCRet : SDNode<"M68kISD::TC_RETURN", MxSDT_TCRet,
113113
[SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
114114

115+
def MxGlobalBaseReg : SDNode<"M68kISD::GLOBAL_BASE_REG",
116+
SDTypeProfile<1, 0, [SDTCisVT<0, iPTR>]>>;
117+
118+
// A wrapper node for TargetConstantPool,
119+
// TargetExternalSymbol, and TargetGlobalAddress.
115120
def MxWrapper : SDNode<"M68kISD::Wrapper", MxSDT_Wrapper>;
121+
122+
// Special wrapper used under M68k PIC mode for PC
123+
// relative displacements.
116124
def MxWrapperPC : SDNode<"M68kISD::WrapperPC", MxSDT_Wrapper>;
117125

126+
// Arithmetic operations with CCR results.
118127
def MxAdd : SDNode<"M68kISD::ADD", MxSDT_BiArithCCROut, [SDNPCommutative]>;
119128
def MxSub : SDNode<"M68kISD::SUB", MxSDT_BiArithCCROut>;
120129
def MxOr : SDNode<"M68kISD::OR", MxSDT_BiArithCCROut, [SDNPCommutative]>;
@@ -127,15 +136,37 @@ def MxSubX : SDNode<"M68kISD::SUBX", MxSDT_BiArithCCRInOut>;
127136
def MxSMul : SDNode<"M68kISD::SMUL", MxSDT_BiArithCCROut, [SDNPCommutative]>;
128137
def MxUMul : SDNode<"M68kISD::UMUL", MxSDT_BiArithCCROut, [SDNPCommutative]>;
129138

139+
// M68k compare and logical compare instructions. Subtracts the source
140+
// operand from the destination data register and sets the condition
141+
// codes according to the result. Immediate always goes first.
130142
def MxCmp : SDNode<"M68kISD::CMP", MxSDT_CmpTest>;
143+
144+
// M68k bit-test instructions.
131145
def MxBtst : SDNode<"M68kISD::BTST", MxSDT_CmpTest>;
132146

147+
// M68k conditional moves. Operand 0 and operand 1 are the two values
148+
// to select from. Operand 2 is the condition code, and operand 3 is the
149+
// flag operand produced by a CMP or TEST instruction. It also writes a
150+
// flag result.
133151
def MxCmov : SDNode<"M68kISD::CMOV", MxSDT_Cmov>;
152+
153+
// M68k conditional branches. Operand 0 is the chain operand, operand 1
154+
// is the block to branch if condition is true, operand 2 is the
155+
// condition code, and operand 3 is the flag operand produced by a CMP
156+
// or TEST instruction.
134157
def MxBrCond : SDNode<"M68kISD::BRCOND", MxSDT_BrCond, [SDNPHasChain]>;
158+
159+
// M68k SetCC. Operand 0 is condition code, and operand 1 is the CCR
160+
// operand, usually produced by a CMP instruction.
135161
def MxSetCC : SDNode<"M68kISD::SETCC", MxSDT_SetCC>;
136-
def MxSetCC_C : SDNode<"M68kISD::SETCC_CARRY", MxSDT_SetCC_C>;
137162

163+
// Same as SETCC except it's materialized with a subx and the value is all
164+
// one's or all zero's.
165+
def MxSetCC_C : SDNode<"M68kISD::SETCC_CARRY", MxSDT_SetCC_C>;
138166

167+
// For allocating variable amounts of stack space when using
168+
// segmented stacks. Check if the current stacklet has enough space, and
169+
// falls back to heap allocation if not.
139170
def MxSegAlloca : SDNode<"M68kISD::SEG_ALLOCA", MxSDT_SEG_ALLOCA,
140171
[SDNPHasChain]>;
141172

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 "M68kSelectionDAGInfo.h"
10+
11+
#define GET_SDNODE_DESC
12+
#include "M68kGenSDNodeInfo.inc"
13+
14+
using namespace llvm;
15+
16+
M68kSelectionDAGInfo::M68kSelectionDAGInfo()
17+
: SelectionDAGGenTargetInfo(M68kGenSDNodeInfo) {}
18+
19+
M68kSelectionDAGInfo::~M68kSelectionDAGInfo() = default;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
#ifndef LLVM_LIB_TARGET_M68K_M68KSELECTIONDAGINFO_H
10+
#define LLVM_LIB_TARGET_M68K_M68KSELECTIONDAGINFO_H
11+
12+
#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
13+
14+
#define GET_SDNODE_ENUM
15+
#include "M68kGenSDNodeInfo.inc"
16+
17+
namespace llvm {
18+
19+
class M68kSelectionDAGInfo : public SelectionDAGGenTargetInfo {
20+
public:
21+
M68kSelectionDAGInfo();
22+
23+
~M68kSelectionDAGInfo() override;
24+
};
25+
26+
} // namespace llvm
27+
28+
#endif // LLVM_LIB_TARGET_M68K_M68KSELECTIONDAGINFO_H

llvm/lib/Target/M68k/M68kSubtarget.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
#include "GISel/M68kCallLowering.h"
1616
#include "GISel/M68kLegalizerInfo.h"
1717
#include "GISel/M68kRegisterBankInfo.h"
18-
1918
#include "M68k.h"
2019
#include "M68kMachineFunction.h"
2120
#include "M68kRegisterInfo.h"
21+
#include "M68kSelectionDAGInfo.h"
2222
#include "M68kTargetMachine.h"
23-
2423
#include "llvm/CodeGen/MachineJumpTableInfo.h"
2524
#include "llvm/IR/Attributes.h"
2625
#include "llvm/IR/Function.h"
@@ -50,10 +49,12 @@ void M68kSubtarget::anchor() {}
5049

5150
M68kSubtarget::M68kSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
5251
const M68kTargetMachine &TM)
53-
: M68kGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), TM(TM), TSInfo(),
52+
: M68kGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), TM(TM),
5453
InstrInfo(initializeSubtargetDependencies(CPU, TT, FS, TM)),
5554
FrameLowering(*this, this->getStackAlignment()), TLInfo(TM, *this),
5655
TargetTriple(TT) {
56+
TSInfo = std::make_unique<M68kSelectionDAGInfo>();
57+
5758
CallLoweringInfo.reset(new M68kCallLowering(*getTargetLowering()));
5859
Legalizer.reset(new M68kLegalizerInfo(*this));
5960

@@ -62,6 +63,12 @@ M68kSubtarget::M68kSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
6263
InstSelector.reset(createM68kInstructionSelector(TM, *this, *RBI));
6364
}
6465

66+
M68kSubtarget::~M68kSubtarget() = default;
67+
68+
const SelectionDAGTargetInfo *M68kSubtarget::getSelectionDAGInfo() const {
69+
return TSInfo.get();
70+
}
71+
6572
const CallLowering *M68kSubtarget::getCallLowering() const {
6673
return CallLoweringInfo.get();
6774
}

llvm/lib/Target/M68k/M68kSubtarget.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
2323
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
2424
#include "llvm/CodeGen/RegisterBankInfo.h"
25-
#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
2625
#include "llvm/CodeGen/TargetSubtargetInfo.h"
2726
#include "llvm/IR/DataLayout.h"
2827
#include "llvm/MC/MCInstrItineraries.h"
@@ -63,7 +62,6 @@ class M68kSubtarget : public M68kGenSubtargetInfo {
6362

6463
const M68kTargetMachine &TM;
6564

66-
SelectionDAGTargetInfo TSInfo;
6765
M68kInstrInfo InstrInfo;
6866
M68kFrameLowering FrameLowering;
6967
M68kTargetLowering TLInfo;
@@ -80,6 +78,8 @@ class M68kSubtarget : public M68kGenSubtargetInfo {
8078
M68kSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
8179
const M68kTargetMachine &_TM);
8280

81+
~M68kSubtarget() override;
82+
8383
/// Parses features string setting specified subtarget options. Definition
8484
/// of function is auto generated by tblgen.
8585
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
@@ -148,10 +148,6 @@ class M68kSubtarget : public M68kGenSubtargetInfo {
148148
StringRef FS,
149149
const M68kTargetMachine &TM);
150150

151-
const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
152-
return &TSInfo;
153-
}
154-
155151
const M68kInstrInfo *getInstrInfo() const override { return &InstrInfo; }
156152

157153
const M68kFrameLowering *getFrameLowering() const override {
@@ -171,13 +167,17 @@ class M68kSubtarget : public M68kGenSubtargetInfo {
171167
}
172168

173169
protected:
170+
// SelectionDAGISel related APIs.
171+
std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
172+
174173
// GlobalISel related APIs.
175174
std::unique_ptr<CallLowering> CallLoweringInfo;
176175
std::unique_ptr<InstructionSelector> InstSelector;
177176
std::unique_ptr<LegalizerInfo> Legalizer;
178177
std::unique_ptr<RegisterBankInfo> RegBankInfo;
179178

180179
public:
180+
const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;
181181
const CallLowering *getCallLowering() const override;
182182
InstructionSelector *getInstructionSelector() const override;
183183
const LegalizerInfo *getLegalizerInfo() const override;

0 commit comments

Comments
 (0)