diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2010-02-05 22:03:18 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2010-02-05 22:03:18 +0000 |
commit | 58e9ee85fda5083e2eea987917e8eab6ba31fe5e (patch) | |
tree | 542d47cbb2c02e5971df3c80b71b290118bd7877 /include/llvm/Transforms | |
parent | 00cb3fe786855ce6545234bc3430223eb9272206 (diff) | |
download | external_llvm-58e9ee85fda5083e2eea987917e8eab6ba31fe5e.zip external_llvm-58e9ee85fda5083e2eea987917e8eab6ba31fe5e.tar.gz external_llvm-58e9ee85fda5083e2eea987917e8eab6ba31fe5e.tar.bz2 |
Teach SimplifyCFG about magic pointer constants.
Weird code sometimes uses pointer constants other than null. This patch
teaches SimplifyCFG to build switch instructions in those cases.
Code like this:
void f(const char *x) {
if (!x)
puts("null");
else if ((uintptr_t)x == 1)
puts("one");
else if (x == (char*)2 || x == (char*)3)
puts("two");
else if ((intptr_t)x == 4)
puts("four");
else
puts(x);
}
Now becomes a switch:
define void @f(i8* %x) nounwind ssp {
entry:
%magicptr23 = ptrtoint i8* %x to i64 ; <i64> [#uses=1]
switch i64 %magicptr23, label %if.else16 [
i64 0, label %if.then
i64 1, label %if.then2
i64 2, label %if.then9
i64 3, label %if.then9
i64 4, label %if.then14
]
Note that LLVM's own DenseMap uses magic pointers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95439 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Transforms')
-rw-r--r-- | include/llvm/Transforms/Utils/Local.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/include/llvm/Transforms/Utils/Local.h b/include/llvm/Transforms/Utils/Local.h index bb91d80..bb6fd56 100644 --- a/include/llvm/Transforms/Utils/Local.h +++ b/include/llvm/Transforms/Utils/Local.h @@ -131,7 +131,7 @@ bool EliminateDuplicatePHINodes(BasicBlock *BB); /// /// WARNING: The entry node of a method may not be simplified. /// -bool SimplifyCFG(BasicBlock *BB); +bool SimplifyCFG(BasicBlock *BB, const TargetData *TD = 0); /// FoldBranchToCommonDest - If this basic block is ONLY a setcc and a branch, /// and if a predecessor branches to us and one of our successors, fold the |