[LLVMdev] SwitchInst handling in backend
johnso87 at crhc.illinois.edu
Mon Feb 27 13:05:30 PST 2012
On 02/27/2012 02:52 PM, Nico wrote:
> if I want to know how switch instructions are handled in the backend, where do I have to look first?
> I'm not familiar with the backend framework and I couldn't figure out the interface between the LLVM instruction 'SwitchInst' and whatever there is in the backend.
LLVM IR gets passed to the backend as a SelectionDAG, which is
constructed by peephole expansion of the IR (see
). The relevant code for 'select' instructions in IR is the
visitSelect() function in
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp; a select gets expanded
into a ISD::SELECT (for scalar types) or ISD::VECTOR (for vector types)
for each select operand, plus a ISD::MERGE_VALUES to multiplex them all
For the MIPS backend handling code, see
lib/Target/Mips/MipsISelLowering.cpp. In particular,
setOperation(ISD::SELECT, <typename>, Custom) means that the MIPS
backend lowers SELECTS in C++ rather than a simple tablegen pattern. In
LowerSELECT() in that same file, you can see that MIPS will create a
conditional move if the select condition is set by a floating point
comparison, and the "return Op;" it does otherwise means that other
cases should be handled by the default machinery rather than custom
The "default machinery" requires quite a bit of background knowledge to
understand, but the Code Generator doc gives a good broad overview, and
the above is the extent of custom select-handling code in the MIPS backend.
> I would be very happy about every hint where I have to look to find the entry point of switch instructions in the backend (in particular in the MIPS backend.
> Thanks a lot and kind regards,
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev