Go to the previous, next section.

Multi-way Branch Instructions

Fortran computed goto statements and C switch statements are represented in SUIF by multi-way branch (mbr) instructions. These are easier to analyze than the equivalent series of conditional branches, and they can easily be used to generate efficient jump table code. The in_mbr class holds these multi-way branch instructions.

The in_mbr class contains a field with a pointer to an array of label symbols. The num_labs method returns the number of labels in the array. The size of the array can be changed at any time using the set_num_labs method; if necessary the array will be reallocated. A particular element within the array can be accessed using the label and set_label methods. You must specify the array index, and, as usual, the elements are numbered beginning with zero.

A multi-way branch instruction transfers control to one of the target labels depending on the value in the source operand. This operand must have an integer type. It can be accessed using the src_op and set_src methods. The value of the source operand is combined with an integer offset to determine the target label. The offset can be accessed with the lower and set_lower methods. The offset is subtracted from the value in the source operand and the result is used to index into the array of target labels. If the index is within the range of the array, the instruction branches to the label at that position in the array; otherwise, it branches to the default target label. The default_lab and set_default_lab methods access this default label field. The destination operand of a multi-way branch is unused and trying to set it will cause an error. The result type should always be the SUIF void type.

Go to the previous, next section.