Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 1 | ================================================== |
| 2 | How To Add A Constrained Floating-Point Intrinsic |
| 3 | ================================================== |
| 4 | |
| 5 | .. contents:: |
| 6 | :local: |
| 7 | |
| 8 | .. warning:: |
| 9 | This is a work in progress. |
| 10 | |
| 11 | Add the intrinsic |
| 12 | ================= |
| 13 | |
| 14 | Multiple files need to be updated when adding a new constrained intrinsic. |
| 15 | |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 16 | Add the new intrinsic to the table of intrinsics:: |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 17 | |
| 18 | include/llvm/IR/Intrinsics.td |
| 19 | |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 20 | Add SelectionDAG node types |
| 21 | =========================== |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 22 | |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 23 | Add the new STRICT version of the node type to the ISD::NodeType enum:: |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 24 | |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 25 | include/llvm/CodeGen/ISDOpcodes.h |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 26 | |
Fangrui Song | 7d980319 | 2019-11-19 23:09:07 -0800 | [diff] [blame] | 27 | Strict version name must be a concatenation of prefix ``STRICT_`` and the name |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 28 | of corresponding non-strict node name. For instance, strict version of the |
| 29 | node FADD must be STRICT_FADD. |
| 30 | |
| 31 | Update mappings |
| 32 | =============== |
| 33 | |
| 34 | Add new record to the mapping of instructions to constrained intrinsic and |
| 35 | DAG nodes:: |
| 36 | |
| 37 | include/llvm/IR/ConstrainedOps.def |
| 38 | |
| 39 | Follow instructions provided in this file. |
| 40 | |
| 41 | Update IR components |
| 42 | ==================== |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 43 | |
| 44 | Update the IR verifier:: |
| 45 | |
| 46 | lib/IR/Verifier.cpp |
| 47 | |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 48 | Update Selector components |
| 49 | ========================== |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 50 | |
| 51 | Building the SelectionDAG |
| 52 | ------------------------- |
| 53 | |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 54 | The function SelectionDAGBuilder::visitConstrainedFPIntrinsic builds DAG nodes |
| 55 | using mappings specified in ConstrainedOps.def. If however this default build is |
| 56 | not sufficient, the build can be modified, see how it is implemented for |
| 57 | STRICT_FP_ROUND. The new STRICT node will eventually be converted |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 58 | to the matching non-STRICT node. For this reason it should have the same |
| 59 | operands and values as the non-STRICT version but should also use the chain. |
| 60 | This makes subsequent sharing of code for STRICT and non-STRICT code paths |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 61 | easier:: |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 62 | |
| 63 | lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp |
| 64 | |
| 65 | Most of the STRICT nodes get legalized the same as their matching non-STRICT |
| 66 | counterparts. A new STRICT node with this property must get added to the |
| 67 | switch in SelectionDAGLegalize::LegalizeOp().:: |
| 68 | |
| 69 | lib/CodeGen/SelectionDAG/LegalizeDAG.cpp |
| 70 | |
| 71 | Other parts of the legalizer may need to be updated as well. Look for |
| 72 | places where the non-STRICT counterpart is legalized and update as needed. |
| 73 | Be careful of the chain since STRICT nodes use it but their counterparts |
Zachary Turner | 528b01e | 2019-04-11 17:30:03 +0000 | [diff] [blame] | 74 | often don't. |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 75 | |
| 76 | The code to do the conversion or mutation of the STRICT node to a non-STRICT |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 77 | version of the node happens in SelectionDAG::mutateStrictFPToFP(). In most cases |
| 78 | the function can do the conversion using information from ConstrainedOps.def. Be |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 79 | careful updating this function since some nodes have the same return type |
| 80 | as their input operand, but some are different. Both of these cases must |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 81 | be properly handled:: |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 82 | |
| 83 | lib/CodeGen/SelectionDAG/SelectionDAG.cpp |
| 84 | |
Serge Pavlov | 0c50c0b | 2019-11-05 20:42:16 +0700 | [diff] [blame] | 85 | Whether the mutation may happens or not, depends on how the new node has been |
| 86 | registered in TargetLoweringBase::initActions(). By default all strict nodes are |
| 87 | registered with Expand action:: |
Kevin P. Neal | d0f96be | 2019-06-25 16:09:39 +0000 | [diff] [blame] | 88 | |
| 89 | lib/CodeGen/TargetLoweringBase.cpp |
| 90 | |
Kevin P. Neal | 339594e | 2019-04-11 17:16:03 +0000 | [diff] [blame] | 91 | To make debug logs readable it is helpful to update the SelectionDAG's |
| 92 | debug logger::: |
| 93 | |
| 94 | lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp |
| 95 | |
| 96 | Add documentation and tests |
| 97 | =========================== |
| 98 | |
| 99 | :: |
| 100 | |
| 101 | docs/LangRef.rst |