[llvm-dev] Update control flow graph when splitting a machine basic block?

章明 via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 10 04:33:29 PST 2017


Hi, there!




There are situations where a machine basic block has to be split into two machine basic blocks, e.g., to place a constant pool entry or to fix a conditional branch so that its target is within its range (https://reviews.llvm.org/D38918).




However, it doesn't appear to be straightforward how the control flow graph should be updated when a machine basic block is split, especially when the split point is between two branches. In this case, in order to determine the successors of each of the two machine basic block, one needs to know the target of each terminator. If we ignore indirect branches whose targets are not known at compile-time, I wonder whether something like the following is viable or not:




empty mbb.successors

fallthrough = true

for each terminator i in machine basic block mbb

do

    if i is control flow barrier and i is not predicable            // Is this the correct way to determine whether an instruction may fall through?

        fallthrough = false

        break                                          // Instructions after the first non-predicable barrier cannot be executed, right?

    fi

    ignore operands of i if i is a return

    for each operand o of i

    do

        if o is a machine basic block                // Can an instruction other than a jump table instruction target multiple machine basic blocks?

            add o to mbb.successors

        fi

        if o is a jump table index

            add all machine basic blocks in the jump table to mbb.successors

        fi

    done

done

if fallthrough == true

    add the layout successor to mbb.successors, if one exists

fi




Am I missing something?

Please give me some advice.

Thank you!




Ming Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171110/54df5286/attachment.html>


More information about the llvm-dev mailing list