[llvm-dev] how to type-legalize a dag

Krzysztof Parzyszek via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 16 10:36:19 PDT 2016


On 3/15/2016 5:48 PM, Rail Shafigulin wrote:
>
>
> I'd like to ask you another question (if you don't mind). My
> EsenciaISelLowering.cpp contains the following code in the
> EsenciaTargetLowering class constructor:
>
>    setOperationAction(ISD::BR_CC,             MVT::i32, Custom);
>    setOperationAction(ISD::BR_CC,             MVT::f32, Custom);
>    setOperationAction(ISD::BR_JT,             MVT::Other, Expand);
>    setOperationAction(ISD::BRCOND,            MVT::Other, Expand);
>    setOperationAction(ISD::SETCC,             MVT::i32, Expand);
>    setOperationAction(ISD::SETCC,             MVT::f32, Expand);
>    setOperationAction(ISD::SELECT,            MVT::i32, Expand);
>    setOperationAction(ISD::SELECT,            MVT::f32, Expand);
>    setOperationAction(ISD::SELECT_CC,         MVT::i32, Custom);
>    setOperationAction(ISD::SELECT_CC,         MVT::f32, Custom);
>
> I sort of have an intuition what it is doing, but quite nail it.Do you
> mind explaining it? Also I didn't add any of the setOperationAction for
> the MVT::v4i32 and my simple test case worked. How come?


This tells the legalizer how to treat various operations with given 
types.  What the type is of, somewhat depends on the operation.  You can 
look in lib/CodeGen/SelectionDAG/LegalizeDAG.cpp, in function 
SelectionDAGLegalize::LegalizeOp, to see where the type comes from. 
That's where the actions are being looked up.

If the action is "Legal", then there is nothing to be done with it, 
since it's already considered legal.  If the action is "Expand", which 
will convert the operation into some sort of a generic expansion which 
will either be legal or will be legalized further.  A "Custom" action 
causes the legalizer to call LowerOperation in target's ISel lowering 
class.  That function will then be responsible for generating the 
target-specific code for this operation.

-Krzysztof


-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation


More information about the llvm-dev mailing list