[llvm-commits] [llvm] r46387 - in /llvm/trunk: lib/Transforms/Scalar/SimplifyCFG.cpp test/CFrontend/2008-01-25-EmptyFunction.c
Chris Lattner
clattner at apple.com
Fri Jan 25 19:26:56 PST 2008
On Jan 25, 2008, at 5:43 PM, Bill Wendling wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=46387&view=rev
> Log:
> If we have a function like this:
>
> This is bad on some platforms (like PPC) because it will generate
> the label for
> the function but no body. The label could end up being associated
> with some
> non-code related stuff, like a section. This places a "trap"
> instruction if the
> SimplifyCFG pass removed all code from the function leaving only one
> "unreachable" instruction.
This is a darwin-specific hack, so it needs to be conditionalized on
the target. Second, this should only be done if there are zero
machineinstrs, not zero llvm instrs.
> // If there are unreachable blocks in the CFG...
> - if (Reachable.size() == F.size())
> + if (Reachable.size() == F.size()) {
> + if (F.size() == 1) {
F.size() is linear time, so you shouldn't call it here if you don't
need it. Why are you doing this in the Reachable.size() == F.size()
case?
> + // If the function has only one block with an "unreachable"
> instruction,
> + // then we should create *some* code for it. Issue a "trap"
> instead.
> + BasicBlock &BB = F.front();
> +
> + if (BB.size() == 1 && dyn_cast<UnreachableInst>(&BB.front()))
Only use dyn_cast if you want the result: use isa in this case.
BB.size() is also linear time.
Finally, the testcase you added was for llvm-gcc, this is a codegen
thing so it should be in test/CodeGen/* and should only run llc.
-Chris
More information about the llvm-commits
mailing list