summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix a typo (the the => the)Sylvestre Ledru2012-07-231-1/+1
| | | | llvm-svn: 160621
* Move llvm/Support/MDBuilder.h to llvm/MDBuilder.h, to live withChandler Carruth2012-07-151-1/+1
| | | | | | | | | | | IRBuilder, DIBuilder, etc. This is the proper layering as MDBuilder can't be used (or implemented) without the Core Metadata representation. Patches to Clang and Dragonegg coming up. llvm-svn: 160237
* Make helper functions static.Benjamin Kramer2012-07-131-1/+1
| | | | llvm-svn: 160173
* Revert "IntRange:" as it appears to be breaking self hosting.Eric Christopher2012-07-021-85/+148
| | | | | | This reverts commit b2833d9dcba88c6f0520cad760619200adc0442c. llvm-svn: 159618
* IntRange:Stepan Dyatkovskiy2012-07-021-148/+85
| | | | | | | | | | | | | | | | | | | | | | - Changed isSingleNumber method behaviour. Now this flag is calculated on demand. IntegersSubsetMapping - Optimized diff operation. - Replaced type of Items field from std::list with std::map. - Added new methods: bool isOverlapped(self &RHS) void add(self& RHS, SuccessorClass *S) void detachCase(self& NewMapping, SuccessorClass *Succ) void removeCase(SuccessorClass *Succ) SuccessorClass *findSuccessor(const IntTy& Val) const IntTy* getCaseSingleNumber(SuccessorClass *Succ) IntegersSubsetTest - DiffTest: Added checks for successors. SimplifyCFG Updated SwitchInst usage (now it is case-ragnes compatible) for - SimplifyEqualityComparisonWithOnlyPredecessor - FoldValueComparisonIntoPredecessors llvm-svn: 159527
* Move llvm/Support/IRBuilder.h -> llvm/IRBuilder.hChandler Carruth2012-06-291-7/+7
| | | | | | | | | | | | | | | | | This was always part of the VMCore library out of necessity -- it deals entirely in the IR. The .cpp file in fact was already part of the VMCore library. This is just a mechanical move. I've tried to go through and re-apply the coding standard's preferred header sort, but at 40-ish files, I may have gotten some wrong. Please let me know if so. I'll be committing the corresponding updates to Clang and Polly, and Duncan has DragonEgg. Thanks to Bill and Eric for giving the green light for this bit of cleanup. llvm-svn: 159421
* Remove dyn_cast + dereference pattern by replacing it with a cast and changingNick Lewycky2012-06-241-3/+3
| | | | | | | the safety check to look for the same type we're going to actually cast to. Fixes PR13180! llvm-svn: 159110
* SimplifyCFG: fold unconditional branch to its predecessor if profitable.Manman Ren2012-06-131-24/+180
| | | | | | | | | | This patch extends FoldBranchToCommonDest to fold unconditional branches. For unconditional branches, we fold them if it is easy to update the phi nodes in the common successors. rdar://10554090 llvm-svn: 158392
* SimplifyCFG: Turn the ad-hoc std::pair that represents switch cases into an ↵Benjamin Kramer2012-05-261-39/+54
| | | | | | explicit struct. llvm-svn: 157516
* Add support for branch weight metadata to MDBuilder and use it in various ↵Benjamin Kramer2012-05-261-6/+5
| | | | | | places. llvm-svn: 157515
* Always compute all the bits in ComputeMaskedBits.Rafael Espindola2012-04-041-1/+1
| | | | | | | | This allows us to keep passing reduced masks to SimplifyDemandedBits, but know about all the bits if SimplifyDemandedBits fails. This allows instcombine to simplify cases like the one in the included testcase. llvm-svn: 154011
* llvm::SwitchInstStepan Dyatkovskiy2012-03-111-13/+13
| | | | | | | Renamed methods caseBegin, caseEnd and caseDefault with case_begin, case_end, and case_default. Added some notes relative to case iterators. llvm-svn: 152532
* Taken into account Duncan's comments for r149481 dated by 2nd Feb 2012:Stepan Dyatkovskiy2012-03-081-35/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120130/136146.html Implemented CaseIterator and it solves almost all described issues: we don't need to mix operand/case/successor indexing anymore. Base iterator class is implemented as a template since it may be initialized either from "const SwitchInst*" or from "SwitchInst*". ConstCaseIt is just a read-only iterator. CaseIt is read-write iterator; it allows to change case successor and case value. Usage of iterator allows totally remove resolveXXXX methods. All indexing convertions done automatically inside the iterator's getters. Main way of iterator usage looks like this: SwitchInst *SI = ... // intialize it somehow for (SwitchInst::CaseIt i = SI->caseBegin(), e = SI->caseEnd(); i != e; ++i) { BasicBlock *BB = i.getCaseSuccessor(); ConstantInt *V = i.getCaseValue(); // Do something. } If you want to convert case number to TerminatorInst successor index, just use getSuccessorIndex iterator's method. If you want initialize iterator from TerminatorInst successor index, use CaseIt::fromSuccessorIndex(...) method. There are also related changes in llvm-clients: klee and clang. llvm-svn: 152297
* [unwind removal] We no longer have 'unwind' instructions being generated, soBill Wendling2012-02-061-52/+3
| | | | | | remove the code that handles them. llvm-svn: 149901
* SwitchInst refactoring.Stepan Dyatkovskiy2012-02-011-28/+35
| | | | | | | | | | | | | | | | | The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want. What was done: 1. Changed semantics of index inside the getCaseValue method: getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous. 2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned. 3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment. 4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst. 4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor. 4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor. Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang. llvm-svn: 149481
* Gracefully degrade precision in branch probability numbers.Nick Lewycky2012-01-251-17/+72
| | | | llvm-svn: 148946
* Actually, this code handles wrapped sets just fine. Noticed by inspection.Nick Lewycky2012-01-191-3/+1
| | | | llvm-svn: 148487
* Fix SpeculativelyExecuteBB to either speculate all or none of the phisDan Gohman2012-01-051-140/+148
| | | | | | | | | | | | present in the bottom of the CFG triangle, as the transformation isn't ever valuable if the branch can't be eliminated. Also, unify some heuristics between SimplifyCFG's multiple if-converters, for consistency. This fixes rdar://10627242. llvm-svn: 147630
* Revert r56315. When the instruction to speculate is a load, thisDan Gohman2012-01-051-26/+2
| | | | | | | | code can incorrectly move the load across a store. This never happens in practice today, but only because the current heuristics accidentally preclude it. llvm-svn: 147623
* Demystify this comment.Nick Lewycky2011-12-281-5/+16
| | | | llvm-svn: 147307
* Use false not zero, as a bool.Nick Lewycky2011-12-271-2/+2
| | | | llvm-svn: 147292
* Teach simplifycfg to recompute branch weights when merging some branches, andNick Lewycky2011-12-271-0/+67
| | | | | | | to discard weights when appropriate. Still more to do (and a new TODO), but it's a start! llvm-svn: 147286
* Update the branch weight metadata when reversing the order of a branch.Nick Lewycky2011-12-261-4/+1
| | | | llvm-svn: 147280
* Sort includes, canonicalize whitespace, fix typos. No functionality change.Nick Lewycky2011-12-261-12/+12
| | | | llvm-svn: 147279
* Make some intrinsics safe to speculatively execute.Nick Lewycky2011-12-211-0/+1
| | | | llvm-svn: 147036
* Revert r146822 at Pete Cooper's request as it broke clang self hosting.Kevin Enderby2011-12-171-42/+0
| | | | | | Hope I did this correctly :) llvm-svn: 146834
* SimplifyCFG now predicts some conditional branches to true or false ↵Pete Cooper2011-12-171-0/+42
| | | | | | | | | | | | | depending on previous branch on same comparison operands. For example, if (a == b) { if (a > b) // this is false Fixes some of the issues on <rdar://problem/10554090> llvm-svn: 146822
* Move Instruction::isSafeToSpeculativelyExecute out of VMCore andDan Gohman2011-12-141-2/+2
| | | | | | | | | into Analysis as a standalone function, since there's no need for it to be in VMCore. Also, update it to use isKnownNonZero and other goodies available in Analysis, making it more precise, enabling more aggressive optimization. llvm-svn: 146610
* Delete trivial landing pads that just continue unwinding the caughtDuncan Sands2011-09-051-0/+49
| | | | | | exception. llvm-svn: 139117
* Address review comments.Benjamin Kramer2011-08-261-9/+8
| | | | | | | | - Reword comments. - Allow undefined behavior interfering with undefined behavior. - Add address space checks. llvm-svn: 138619
* SimplifyCFG: If we have a PHI node that can evaluate to NULL and do a load ↵Benjamin Kramer2011-08-261-0/+69
| | | | | | | | | | or store to the address returned by the PHI node then we can consider this incoming value as dead and remove the edge pointing there, unless there are instructions that can affect control flow executed in between. In theory this could be extended to other instructions, eg. division by zero, but it's likely that it will "miscompile" some code because people depend on div by zero not trapping. NULL pointer dereference usually leads to a crash so we should be on the safe side. This shrinks the size of a Release clang by 16k on x86_64. llvm-svn: 138618
* I think there was some confusion about what I meant. :-) Replacing the comment.Bill Wendling2011-08-161-1/+4
| | | | llvm-svn: 137743
* After talking with Bill, it seems like the LandingPad handling here is likelyEli Friedman2011-08-161-4/+1
| | | | | | to be wrong (or at least somewhat suspect). Leave a FIXME for Bill. llvm-svn: 137694
* Minor comment fixes.Eli Friedman2011-08-161-1/+1
| | | | llvm-svn: 137693
* Update SimplifyCFG for atomic operations.Eli Friedman2011-08-151-10/+26
| | | | | | | | This commit includes a mention of the landingpad instruction, but it's not changing the behavior around it. I think the current behavior is correct, though. Bill, can you double-check that? llvm-svn: 137691
* land David Blaikie's patch to de-constify Type, with a few tweaks.Chris Lattner2011-07-181-1/+1
| | | | llvm-svn: 135375
* Convert CallInst and InvokeInst APIs to use ArrayRef.Jay Foad2011-07-151-4/+2
| | | | llvm-svn: 135265
* Add r134057 back, but splice the predecessor after the successors phiRafael Espindola2011-06-301-1/+1
| | | | | | | | | nodes. Original message: Let simplify cfg simplify bb with only debug and lifetime intrinsics. llvm-svn: 134182
* Temporarily revert r134057: "Let simplify cfg simplify bb with only debug and Chad Rosier2011-06-291-1/+1
| | | | | | lifetime intrinsics" due to buildbot failures. llvm-svn: 134071
* Let simplify cfg simplify bb with only debug and lifetime intrinsics.Rafael Espindola2011-06-291-1/+1
| | | | llvm-svn: 134057
* Fix PR10103: Less code for enum type translation.Hans Wennborg2011-06-181-0/+74
| | | | | | | | | | | In cases such as the attached test, where the case value for a switch destination is used in a phi node that follows the destination, it might be better to replace that value with the condition value of the switch, so that more blocks can be folded away with TryToSimplifyUncondBranchFromEmptyBlock because there are less conflicts in the phi node. llvm-svn: 133344
* If the block that we're threading through is jumped to by an indirect branch,Bill Wendling2011-06-041-1/+3
| | | | | | | | | | | | then we don't want to set the destination in the indirect branch to the destination. This is because the indirect branch needs its destinations to have had their block addresses taken. This isn't so of the new critical edge that's split during this process. If it turns out that the destination block has only one predecessor, and that being a BB with an indirect branch, then it won't be marked as 'used' and may be removed. PR10072 llvm-svn: 132638
* Add a parameter to ConstantFoldTerminator() that callers can use to ask it ↵Frits van Bommel2011-05-221-1/+1
| | | | | | | | to also clean up the condition of any conditional terminator it folds to be unconditional, if that turns the condition into dead code. This just means it calls RecursivelyDeleteTriviallyDeadInstructions() in strategic spots. It defaults to the old behavior. I also changed -simplifycfg, -jump-threading and -codegenprepare to use this to produce slightly better code without any extra cleanup passes (AFAICT this was the only place in -simplifycfg where now-dead conditions of replaced terminators weren't being cleaned up). The only other user of this function is -sccp, but I didn't read that thoroughly enough to figure out whether it might be holding pointers to instructions that could be deleted by this. llvm-svn: 131855
* Reapply r131605. This time with a fix, which is to use NoFolder.Devang Patel2011-05-191-30/+34
| | | | llvm-svn: 131673
* revert 131605 to fix PR9946.Rafael Espindola2011-05-191-36/+31
| | | | llvm-svn: 131620
* Use IRBuilder.Devang Patel2011-05-191-2/+2
| | | | llvm-svn: 131609
* Use IRBuilder while simplifying unreachable.Devang Patel2011-05-191-7/+8
| | | | llvm-svn: 131607
* Use IRBuilder while simplifying conditional branch.Devang Patel2011-05-181-31/+36
| | | | llvm-svn: 131605
* Use IRBuilder while simplifying branch.Devang Patel2011-05-181-12/+13
| | | | llvm-svn: 131598
* Use IRBuilder while simplifying return instruction.Devang Patel2011-05-181-11/+13
| | | | llvm-svn: 131580
OpenPOWER on IntegriCloud