brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · 41e7dec Raw
102 lines · plain
1==================================================2How To Add A Constrained Floating-Point Intrinsic3==================================================4 5.. contents::6   :local:7 8.. warning::9  This is a work in progress.10 11Add the intrinsic12=================13 14Multiple files need to be updated when adding a new constrained intrinsic.15 16Add the new intrinsic to the table of intrinsics::17 18  include/llvm/IR/Intrinsics.td19 20Add SelectionDAG node types21===========================22 23Add the new ``STRICT`` version of the node type to the ``ISD::NodeType`` enum::24 25  include/llvm/CodeGen/ISDOpcodes.h26 27Strict version name must be a concatenation of prefix ``STRICT_`` and the name28of the corresponding non-strict node name. For instance, strict version of the29node ``FADD`` must be ``STRICT_FADD``.30 31Update mappings32===============33 34Add new record to the mapping of instructions to constrained intrinsics and35DAG nodes::36 37  include/llvm/IR/ConstrainedOps.def38 39Follow instructions provided in this file.40 41Update IR components42====================43 44Update the IR verifier::45 46  lib/IR/Verifier.cpp47 48Update Selector components49==========================50 51Building the SelectionDAG52-------------------------53 54The ``SelectionDAGBuilder::visitConstrainedFPIntrinsic`` function builds DAG nodes55using mappings specified in ``ConstrainedOps.def``. If however this default build is56not sufficient, the build can be modified, see how it is implemented for57``STRICT_FP_ROUND``. The new ``STRICT`` node will eventually be converted58to the matching non-``STRICT`` node. For this reason it should have the same59operands and values as the non-``STRICT`` version but should also use the chain.60This makes subsequent sharing of code for ``STRICT`` and non-``STRICT`` code paths61easier::62 63  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp64 65Most of the ``STRICT`` nodes get legalized the same as their matching non-``STRICT``66counterparts. A new ``STRICT`` node with this property must get added to the67switch in ``SelectionDAGLegalize::LegalizeOp()``::68 69  lib/CodeGen/SelectionDAG/LegalizeDAG.cpp70 71Other parts of the legalizer may need to be updated as well. Look for72places where the non-``STRICT`` counterpart is legalized and update as needed.73Be careful of the chain since ``STRICT`` nodes use it but their counterparts74often don't.75 76The conversion or mutation of the ``STRICT`` node to a non-``STRICT``77version of the node happens in ``SelectionDAG::mutateStrictFPToFP()``. In most cases78the function can do the conversion using information from ConstrainedOps.def. Be79careful updating this function since some nodes have the same return type80as their input operand, but some are different. Both of these cases must81be properly handled::82 83  lib/CodeGen/SelectionDAG/SelectionDAG.cpp84 85Whether the mutation happens or not depends on how the new node has been86registered in ``TargetLoweringBase::initActions()``. By default, all strict nodes are87registered with Expand action::88 89  lib/CodeGen/TargetLoweringBase.cpp90 91To make debug logs readable, it is helpful to update the SelectionDAG's92debug logger:::93 94  lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp95 96Add documentation and tests97===========================98 99::100 101  docs/LangRef.rst102