The infrastructure part has been merged, here is the promised
Migration Guide
Please see the Draft PR for concrete examples.
Replace XX with your target’s name below.
- Add the following line to
CMakeLists.txt:tablegen(LLVM XXGenSDNodeInfo.inc -gen-sd-node-info) - Implement
XXSelectionDAGInfoby deriving it fromSelectionDAGGenTargetInfo(noteGen). - Implement
XXSubtarget::getSelectionDAGInfo(). - Add the following lines to
XXISelLowering.h, beforeXXISD::NodeTypeenum, outside llvm namespace:#define GET_SDNODE_ENUM #include "XXGenSDNodeInfo.inc" - Remove duplicate enum members suggested by an LSP server / compiler. In the ideal case, all enum members will be removed (along with the enum).
- Navigate to
XXTargetLowering::getTargetNodeName()and remove switch cases referring to the removed enum members. Usingswitch (static_cast<XXISD::NodeType>(Opcode))will help identify the cases that should be removed. If all enum members were removed, just delete the metod. - Move the include added in step 4 and the
XXISD::NodeTypeenum (if it still exists) toXXSelectionDAGInfo.h. - Include
XXSelectionDAGInfo.hfromXXISelLowering.cpp,XXISelDAGToDAG.cpp, and/or from other files that need the node enumeration. - Add the following lines to
XXSelectionDAGInfo.cpp, outside llvm namespace:#define GET_SDNODE_DESC #include "XXGenSDNodeInfo.inc" - Implement
XXSelectionDAGInfoconstructor like this:XXSelectionDAGInfo::XXSelectionDAGInfo() : SelectionDAGGenTargetInfo(XXGenSDNodeInfo) {} - If
XXTargetLowering::getTargetNodeName()wasn’t deleted, move its contents to overriddenXXSelectionDAGInfo::getTargetNodeName(). In the new method, delegate toSelectionDAGGenTargetInfo::getTargetNodeName()on the default code path.
For simple targets, this is all that should be necessary.
Troubleshooting & Tips
-
If you relied on relative order of enum members (e.g. for doing range checks), you can rewrite the code to use switch / series of equality comparisons, or (better) use
SDNode::TSFlagsfield to add properties to nodes that can be queried from C++ code. SeeRISCVSelectionDAGInfo::hasPassthruOp()in the draft for an example. -
It is possible that the backend will start throwing errors from
SelectionDAGGenTargetInfo::verifyTargetNode(), which verifies a newly created SDNode against its definition in a*.tdfile. In most cases the bugfix would be simple, but as a temporary measure you can override the method to suppress checks for specific nodes. -
If your target had implemented
isTargetStrictFPOpcode(), it can now be replaced with the generic version. Just make sure the nodes haveSDNode::IsStrictFPbit set. Similarly, the generic version ofisTargetMemoryOpcode()picks upSDNPMemOperandproperty. -
Consider describing all SDNodes in
*.tdfiles. This will enable the verification functionality for them and will allow removing overrides ofTargetSelectionDAGInfomethods.