AddingConstrainedIntrinsics.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ==================================================
  2. How To Add A Constrained Floating-Point Intrinsic
  3. ==================================================
  4. .. contents::
  5. :local:
  6. .. warning::
  7. This is a work in progress.
  8. Add the intrinsic
  9. =================
  10. Multiple files need to be updated when adding a new constrained intrinsic.
  11. Add the new intrinsic to the table of intrinsics.::
  12. include/llvm/IR/Intrinsics.td
  13. Update class ConstrainedFPIntrinsic to know about the intrinsics.::
  14. include/llvm/IR/IntrinsicInst.h
  15. Functions like ConstrainedFPIntrinsic::isUnaryOp() or
  16. ConstrainedFPIntrinsic::isTernaryOp() may need to know about the new
  17. intrinsic.::
  18. lib/IR/IntrinsicInst.cpp
  19. Update the IR verifier::
  20. lib/IR/Verifier.cpp
  21. Add SelectionDAG node types
  22. ===========================
  23. Add the new STRICT version of the node type to the ISD::NodeType enum.::
  24. include/llvm/CodeGen/ISDOpcodes.h
  25. In class SDNode update isStrictFPOpcode()::
  26. include/llvm/CodeGen/SelectionDAGNodes.h
  27. A mapping from the STRICT SDnode type to the non-STRICT is done in
  28. TargetLoweringBase::getStrictFPOperationAction(). This allows STRICT
  29. nodes to be legalized similarly to the non-STRICT node type.::
  30. include/llvm/CodeGen/TargetLowering.h
  31. Building the SelectionDAG
  32. -------------------------
  33. The switch statement in SelectionDAGBuilder::visitIntrinsicCall() needs
  34. to be updated to call SelectionDAGBuilder::visitConstrainedFPIntrinsic().
  35. That function, in turn, needs to be updated to know how to create the
  36. SDNode for the intrinsic. The new STRICT node will eventually be converted
  37. to the matching non-STRICT node. For this reason it should have the same
  38. operands and values as the non-STRICT version but should also use the chain.
  39. This makes subsequent sharing of code for STRICT and non-STRICT code paths
  40. easier.::
  41. lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  42. Most of the STRICT nodes get legalized the same as their matching non-STRICT
  43. counterparts. A new STRICT node with this property must get added to the
  44. switch in SelectionDAGLegalize::LegalizeOp().::
  45. lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  46. Other parts of the legalizer may need to be updated as well. Look for
  47. places where the non-STRICT counterpart is legalized and update as needed.
  48. Be careful of the chain since STRICT nodes use it but their counterparts
  49. often don't.
  50. The code to do the conversion or mutation of the STRICT node to a non-STRICT
  51. version of the node happens in SelectionDAG::mutateStrictFPToFP(). Be
  52. careful updating this function since some nodes have the same return type
  53. as their input operand, but some are different. Both of these cases must
  54. be properly handled.::
  55. lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  56. However, the mutation may not happen if the new node has not been registered
  57. in TargetLoweringBase::initActions(). If the corresponding non-STRICT node
  58. is Legal but a target does not know about STRICT nodes then the STRICT
  59. node will default to Legal and mutation will be bypassed with a "Cannot
  60. select" error. Register the new STRICT node as Expand to avoid this bug.::
  61. lib/CodeGen/TargetLoweringBase.cpp
  62. To make debug logs readable it is helpful to update the SelectionDAG's
  63. debug logger:::
  64. lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
  65. Add documentation and tests
  66. ===========================
  67. ::
  68. docs/LangRef.rst