Where does the type legalization of MachineNodes take place?

I added a StandardPseudoInstruction in Target.td file and created a MachineNode for this instruction using getMachineNode(…) function in SelectionDAGBuilder.cpp file. I am getting a crash because llvm is not able to promote integer-type operands of my MachineNode during the type legalization phase.

1.Can someone please guide me to the file where type legalization for MachineNode takes place? So far, all the code I’ve seen handles the nodes mostly from ISD::NodeType enum, but I haven’t added my node in that enum.

2.Do I have to add my node in that enum and then write code for legalization?

MachineNodes are not type legalized, they are the selected output. The generic SDNodes undergo type legalization. You generally should not be trying to introduce machine nodes in SelectionDAGBuilder. If you wanted a target specific operation, you should create it with the correct type to begin with. You can also define a target custom pre-selected node.