diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-11 07:41:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-11 07:41:27 +0000 |
commit | 5b1964b5f97f447cdff2e6dd02494212934f25fa (patch) | |
tree | 949beca7fe5ff809d1ada73f1e264a02d9e4cf5f /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | aaaa199ad1bd0ea57fc25c113ce6a5244ad5c516 (diff) | |
download | bcm5719-llvm-5b1964b5f97f447cdff2e6dd02494212934f25fa.tar.gz bcm5719-llvm-5b1964b5f97f447cdff2e6dd02494212934f25fa.zip |
short circuit && and || when possible. This substantially reduces
the size of the -O0 output on some cases. For example, on expr.c from
176.gcc, it shrinks the .ll file from 43164 to 42835 lines, and removed
references to two external symbols.
llvm-svn: 59034
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 427f6457bb7..1a26610d752 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -163,6 +163,36 @@ bool CodeGenFunction::isDummyBlock(const llvm::BasicBlock *BB) { return false; } +/// ContainsLabel - Return true if the statement contains a label in it. If +/// this statement is not executed normally, it not containing a label means +/// that we can just remove the code. +bool CodeGenFunction::ContainsLabel(const Stmt *S, bool IgnoreCaseStmts) { + // Null statement, not a label! + if (S == 0) return false; + + // If this is a label, we have to emit the code, consider something like: + // if (0) { ... foo: bar(); } goto foo; + if (isa<LabelStmt>(S)) + return true; + + // If this is a case/default statement, and we haven't seen a switch, we have + // to emit the code. + if (isa<SwitchCase>(S) && !IgnoreCaseStmts) + return true; + + // If this is a switch statement, we want to ignore cases below it. + if (isa<SwitchStmt>(S)) + IgnoreCaseStmts = true; + + // Scan subexpressions for verboten labels. + for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end(); + I != E; ++I) + if (ContainsLabel(*I, IgnoreCaseStmts)) + return true; + + return false; +} + /// getCGRecordLayout - Return record layout info. const CGRecordLayout *CodeGenFunction::getCGRecordLayout(CodeGenTypes &CGT, QualType Ty) { |