[LLVMdev] CFG entry and exit blocks
Trevor Harmon
trevor.w.harmon at nasa.gov
Wed Mar 31 11:59:47 PDT 2010
On Mar 30, 2010, at 7:51 PM, John Criswell wrote:
> I'm too lazy to convert your .dot file into a graph file
What format should I have posted? (I'm not sure what you mean by
"graph file".) I had thought that .dot was the preferred format here,
since that's what LLVM generates (e.g., "opt -dot-cfg ...").
> First, LLVM does not guarantee that a function has a single exit
> block.
> Multiple basic blocks can have a return instruction as their
> terminator
> instruction.
Any suggestions on what kind of source code pattern would cause this
to happen? I've tried feeding C++ code with multiple return statements
to LLVM, but it always spits out a CFG with a single return block. All
of the blocks for the return statements simply branch to this final
return block.
> There is a pass (Unify Function Exit nodes i.e.,
> -mergereturn <http://llvm.org/docs/Passes.html#mergereturn>) that
> transform a function to have only 1 return instruction.
That sounds like a good approach, except that this pass does not
appear to produce a CFG with exactly one return block, but rather one
or zero return blocks. The distinction is important because if the
pass's getReturnBlock function returns null (see
UnifyFunctionExitNodes.h), I'm back to square one of not having a
single exit block.
I'm wondering what would cause a CFG not to have a return block. The
comments in UnifyFunctionExitNodes.cpp say: "If there are no return
stmts in the Function, a null pointer is returned." But this doesn't
make sense; even an empty void function has a return block with a ret
instruction inside it. Is there some other kind of source code pattern
that would cause an absence of a return block?
Thanks,
Trevor
More information about the llvm-dev
mailing list