Legalizing SelectionDAG
In the preceding topic, we saw how an IR is converted to SelectionDAG
. The whole process didn't involve any knowledge of target architecture for which we are trying to generate code. A DAG node might be illegal for the given target architecture. For example, the X86 architecture doesn't support the sdiv
instruction. Instead, it supports sdivrem
instruction. This target specific information is conveyed to the SelectionDAG
phase by the TargetLowering
interface. Targets implement this interface to describe how LLVM IR instructions should be lowered to legal SelectionDAG
operations.
In our IR case, we need to 'expand' the sdiv
instruction to 'sdivrem'
instruction. In the function void SelectionDAGLegalize::LegalizeOp(SDNode ...
Get LLVM Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.