2019-04-12 01:16:03 +08:00
|
|
|
==================================================
|
|
|
|
How To Add A Constrained Floating-Point Intrinsic
|
|
|
|
==================================================
|
|
|
|
|
|
|
|
.. contents::
|
|
|
|
:local:
|
|
|
|
|
|
|
|
.. warning::
|
|
|
|
This is a work in progress.
|
|
|
|
|
|
|
|
Add the intrinsic
|
|
|
|
=================
|
|
|
|
|
|
|
|
Multiple files need to be updated when adding a new constrained intrinsic.
|
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
Add the new intrinsic to the table of intrinsics::
|
2019-04-12 01:16:03 +08:00
|
|
|
|
|
|
|
include/llvm/IR/Intrinsics.td
|
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
Add SelectionDAG node types
|
|
|
|
===========================
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
Add the new STRICT version of the node type to the ISD::NodeType enum::
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
include/llvm/CodeGen/ISDOpcodes.h
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-20 15:09:07 +08:00
|
|
|
Strict version name must be a concatenation of prefix ``STRICT_`` and the name
|
2019-11-05 21:42:16 +08:00
|
|
|
of corresponding non-strict node name. For instance, strict version of the
|
|
|
|
node FADD must be STRICT_FADD.
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
Update mappings
|
|
|
|
===============
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
Add new record to the mapping of instructions to constrained intrinsic and
|
|
|
|
DAG nodes::
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
include/llvm/IR/ConstrainedOps.def
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
Follow instructions provided in this file.
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
Update IR components
|
|
|
|
====================
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
Update the IR verifier::
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
lib/IR/Verifier.cpp
|
2019-04-12 01:16:03 +08:00
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
Update Selector components
|
|
|
|
==========================
|
2019-04-12 01:16:03 +08:00
|
|
|
|
|
|
|
Building the SelectionDAG
|
|
|
|
-------------------------
|
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
The function SelectionDAGBuilder::visitConstrainedFPIntrinsic builds DAG nodes
|
|
|
|
using mappings specified in ConstrainedOps.def. If however this default build is
|
|
|
|
not sufficient, the build can be modified, see how it is implemented for
|
|
|
|
STRICT_FP_ROUND. The new STRICT node will eventually be converted
|
2019-04-12 01:16:03 +08:00
|
|
|
to the matching non-STRICT node. For this reason it should have the same
|
|
|
|
operands and values as the non-STRICT version but should also use the chain.
|
|
|
|
This makes subsequent sharing of code for STRICT and non-STRICT code paths
|
2019-11-05 21:42:16 +08:00
|
|
|
easier::
|
2019-04-12 01:16:03 +08:00
|
|
|
|
|
|
|
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
|
|
|
|
|
|
|
|
Most of the STRICT nodes get legalized the same as their matching non-STRICT
|
|
|
|
counterparts. A new STRICT node with this property must get added to the
|
|
|
|
switch in SelectionDAGLegalize::LegalizeOp().::
|
|
|
|
|
|
|
|
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
|
|
|
|
|
|
|
|
Other parts of the legalizer may need to be updated as well. Look for
|
|
|
|
places where the non-STRICT counterpart is legalized and update as needed.
|
|
|
|
Be careful of the chain since STRICT nodes use it but their counterparts
|
2019-04-12 01:30:03 +08:00
|
|
|
often don't.
|
2019-04-12 01:16:03 +08:00
|
|
|
|
|
|
|
The code to do the conversion or mutation of the STRICT node to a non-STRICT
|
2019-11-05 21:42:16 +08:00
|
|
|
version of the node happens in SelectionDAG::mutateStrictFPToFP(). In most cases
|
|
|
|
the function can do the conversion using information from ConstrainedOps.def. Be
|
2019-04-12 01:16:03 +08:00
|
|
|
careful updating this function since some nodes have the same return type
|
|
|
|
as their input operand, but some are different. Both of these cases must
|
2019-11-05 21:42:16 +08:00
|
|
|
be properly handled::
|
2019-04-12 01:16:03 +08:00
|
|
|
|
|
|
|
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
|
|
|
|
|
2019-11-05 21:42:16 +08:00
|
|
|
Whether the mutation may happens or not, depends on how the new node has been
|
|
|
|
registered in TargetLoweringBase::initActions(). By default all strict nodes are
|
|
|
|
registered with Expand action::
|
2019-06-26 00:09:39 +08:00
|
|
|
|
|
|
|
lib/CodeGen/TargetLoweringBase.cpp
|
|
|
|
|
2019-04-12 01:16:03 +08:00
|
|
|
To make debug logs readable it is helpful to update the SelectionDAG's
|
|
|
|
debug logger:::
|
|
|
|
|
|
|
|
lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
|
|
|
|
|
|
|
|
Add documentation and tests
|
|
|
|
===========================
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
docs/LangRef.rst
|