1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 12:02:58 +02:00
Commit Graph

189 Commits

Author SHA1 Message Date
Dale Johannesen
09a45f2ca3 Rewrite tail merging algorithm to handle the
case where there are multiple blocks with a large
number of common tail instructions more efficiently
(compile time optimization).

llvm-svn: 50916
2008-05-09 21:24:35 +00:00
Dan Gohman
d4a670284c Make several variable declarations static.
llvm-svn: 50696
2008-05-06 01:53:16 +00:00
Evan Cheng
1803e20a62 Teach branch folding pass about implicit_def instructions. Unfortunately we can't just eliminate them since register scavenger expects every register use to be defined. However, we can delete them when there are no intra-block uses. Carefully removing some implicit def's which enable more blocks to be optimized away.
llvm-svn: 49461
2008-04-10 02:32:10 +00:00
Evan Cheng
f8b1257d2e Add a quick and dirty "loop aligner pass". x86 uses it to align its loops to 16-byte boundaries.
llvm-svn: 47703
2008-02-28 00:43:03 +00:00
Evan Cheng
e18e5201fc PR1909: Tail merging pass ran wild. It makes no sense to merge blocks in order to save a single instruction since a branch will be inserted for each BB.
llvm-svn: 47301
2008-02-19 02:09:37 +00:00
Dan Gohman
cabaec582f Rename MRegisterInfo to TargetRegisterInfo.
llvm-svn: 46930
2008-02-10 18:45:23 +00:00
Dan Gohman
aad233ea10 Use empty() instead of comparing size() with zero.
llvm-svn: 46514
2008-01-29 13:02:09 +00:00
Chris Lattner
f83aae613c rename TargetInstrDescriptor -> TargetInstrDesc.
Make MachineInstr::getDesc return a reference instead
of a pointer, since it can never be null.

llvm-svn: 45695
2008-01-07 07:27:27 +00:00
Chris Lattner
f7f96d818f Rename MachineInstr::getInstrDescriptor -> getDesc(), which reflects
that it is cheap and efficient to get.

Move a variety of predicates from TargetInstrInfo into 
TargetInstrDescriptor, which makes it much easier to query a predicate
when you don't have TII around.  Now you can use MI->getDesc()->isBranch()
instead of going through TII, and this is much more efficient anyway. Not
all of the predicates have been moved over yet.

Update old code that used MI->getInstrDescriptor()->Flags to use the
new predicates in many places.

llvm-svn: 45674
2008-01-07 01:56:04 +00:00
Chris Lattner
14310afe42 rename isLoad -> isSimpleLoad due to evan's desire to have such a predicate.
llvm-svn: 45667
2008-01-06 23:38:27 +00:00
Chris Lattner
5489888580 rename isStore -> mayStore to more accurately reflect what it captures.
llvm-svn: 45656
2008-01-06 08:36:04 +00:00
Chris Lattner
9e5cc35593 Add new shorter predicates for testing machine operands for various types:
e.g. MO.isMBB() instead of MO.isMachineBasicBlock().  I don't plan on 
switching everything over, so new clients should just start using the 
shorter names.

Remove old long accessors, switching everything over to use the short
accessor: getMachineBasicBlock() -> getMBB(), 
getConstantPoolIndex() -> getIndex(), setMachineBasicBlock -> setMBB(), etc.

llvm-svn: 45464
2007-12-30 23:10:15 +00:00
Chris Lattner
ad9a6ccb83 Remove attribution from file headers, per discussion on llvmdev.
llvm-svn: 45418
2007-12-29 20:36:04 +00:00
Christopher Lamb
5c577eb543 Improve branch folding by recgonizing that explict successor relationships impact the value of fall-through choices.
llvm-svn: 44785
2007-12-10 07:24:06 +00:00
Bill Wendling
27f7cac311 Changed XXX to FIXME, and added comment to the README file
llvm-svn: 43359
2007-10-25 19:49:32 +00:00
Bill Wendling
34d5118422 Added comment explaining why we are doing this check.
llvm-svn: 43353
2007-10-25 18:23:45 +00:00
Bill Wendling
df262eb966 Don't branch fold inline asm statements.
llvm-svn: 43191
2007-10-19 21:09:55 +00:00
Dan Gohman
352de5aeb9 More explicit keywords.
llvm-svn: 40757
2007-08-02 21:21:54 +00:00
Duncan Sands
aa83dc9037 If assertions are not enabled, we should return False here.
llvm-svn: 38535
2007-07-11 08:47:55 +00:00
David Greene
8d77dcca00 Make this work with GLIBCXX_DEBUG.
llvm-svn: 38516
2007-07-10 22:00:30 +00:00
David Greene
ad230f223f Fix misue of iterator pointing to erased object. Uncovered by
_GLIBCXX_DEBUG.

llvm-svn: 37793
2007-06-29 02:45:24 +00:00
Evan Cheng
978058bcd7 Move CorrectExtraCFGEdges() from BranchFolding.cpp to a MachineBasicBlock method.
llvm-svn: 37633
2007-06-18 22:43:58 +00:00
Dale Johannesen
74ffb6ffb3 Make throttle a hidden parameter, per review.
llvm-svn: 37511
2007-06-08 01:08:52 +00:00
Dale Johannesen
0903dd4e52 Throttle tail merging; handling blocks with large numbers of predecessors
is too slow.

llvm-svn: 37509
2007-06-08 00:34:27 +00:00
Dale Johannesen
a68662e4a4 Tail merging wasn't working for predecessors of landing pads. PR 1496.
llvm-svn: 37427
2007-06-04 23:52:54 +00:00
Evan Cheng
0dbe4d04db Move ReplaceUsesOfBlockWith() out of BranchFolding into a MachineBasicBlock general facility.
llvm-svn: 37408
2007-06-04 06:44:01 +00:00
Dale Johannesen
63d49a09aa Fix CorrectExtraCFGEdges to allow for multiple LandingPad targets.
llvm-svn: 37394
2007-06-02 00:08:15 +00:00
Dale Johannesen
fd7f1ad2f7 Implement smarter algorithm for choosing which blocks to tail-merge.
See test/CodeGen/X86/test-pic-jtbl.ll for a case where it works well;
shaves another 10K off our favorite benchmark.  I was hesitant about
this because of compile speed, but seems to do OK on a bootstrap.

llvm-svn: 37392
2007-06-01 23:02:45 +00:00
Dale Johannesen
4ca6f07cf0 Arrange for only 1 of multiple branches to landing pad to be kept.
Do not remove empty landing pads (EH table needs to be updated)

llvm-svn: 37375
2007-05-31 21:54:00 +00:00
Dale Johannesen
b306dfb861 Changed per review comment.
llvm-svn: 37355
2007-05-30 00:32:01 +00:00
Dale Johannesen
1ba04f7d87 Make stable_sort in tail merging actually be stable (it never was, but didn't
matter until my last change).  Reenable tail merging by default.

llvm-svn: 37354
2007-05-29 23:47:50 +00:00
Dale Johannesen
86fb3a132a Blocks that cond-br and uncond-br/fallthrough to same block should have
only one successor.

llvm-svn: 37324
2007-05-24 18:31:55 +00:00
Dale Johannesen
ecaa8a0fb4 Fix for PR1444: do not create two successors to the same block.
Temporarily, this breaks CodeGen/Generic/2006-02-12-InsertLibraryCall.ll
by exposing an unrelated latent problem; working on that.

llvm-svn: 37323
2007-05-24 17:39:32 +00:00
Dale Johannesen
d0b7bbe261 Two tail merging improvements:
When considering blocks with more than 2 predecessors, merge the block with
the largest number of matching insns, rather than the first block found.
Considering that 1 matching insn is enough to show a win for candidates that
already end with a branch.

llvm-svn: 37315
2007-05-23 21:07:20 +00:00
Dale Johannesen
fe0fe14411 Make tail merging the default, except on powerPC. There was no prior art
for a target-dependent default with a command-line override; this way
should be generally usable.

llvm-svn: 37285
2007-05-22 17:14:46 +00:00
Dale Johannesen
ca37006ffb Remove some unneeded branches. (spotted by Evan, thanks)
llvm-svn: 37198
2007-05-18 01:28:58 +00:00
Dale Johannesen
78ae2e1acb Remove extra CFG edges before doing these passes; it makes them happier.
llvm-svn: 37089
2007-05-15 21:19:17 +00:00
Dale Johannesen
2f28ffc5fd Do not generate branches to entry block. This fixes several test suite
failures on PPC (can happen only when prologue code is null)

llvm-svn: 36979
2007-05-10 23:59:23 +00:00
Dale Johannesen
4f9661688c Make tail merging handle many more cases (all it can, I think).
llvm-svn: 36966
2007-05-10 01:01:49 +00:00
Dale Johannesen
c884abe112 Handle some non-exit blocks in tail merging.
llvm-svn: 36907
2007-05-07 20:57:21 +00:00
Devang Patel
cd45427a87 Drop 'const'
llvm-svn: 36662
2007-05-03 01:11:54 +00:00
Devang Patel
8ee9065162 Use 'static const char' instead of 'static const int'.
Due to darwin gcc bug, one version of darwin linker coalesces
static const int, which defauts PassID based pass identification.

llvm-svn: 36652
2007-05-02 21:39:20 +00:00
Devang Patel
38a66bc82e Do not use typeinfo to identify pass in pass manager.
llvm-svn: 36632
2007-05-01 21:15:47 +00:00
Chris Lattner
8da69f853c Fix PR1228 and CodeGen/Generic/2007-04-30-LandingPadBranchFolding.ll
llvm-svn: 36602
2007-04-30 23:35:00 +00:00
Dale Johannesen
50a22f6fe6 maintain LiveIn when splitting blocks (register scavenging needs it)
llvm-svn: 35226
2007-03-20 21:35:06 +00:00
Jim Laskey
8c79f0f892 Remove isAccessable.
llvm-svn: 34497
2007-02-22 16:39:03 +00:00
Jim Laskey
b56b6a7042 Make branch folding behave in the presence of landing pads.
llvm-svn: 34476
2007-02-21 22:42:20 +00:00
Dale Johannesen
960bd79f88 Fixes PR 1200
llvm-svn: 34359
2007-02-17 00:44:34 +00:00
Jim Laskey
64f4242072 Change the MachineDebugInfo to MachineModuleInfo to better reflect usage
for debugging and exception handling.

llvm-svn: 33550
2007-01-26 21:22:28 +00:00
Jim Laskey
23ed7d2625 Make LABEL a builtin opcode.
llvm-svn: 33537
2007-01-26 14:34:52 +00:00
Chris Lattner
a975b95adb Eliminate static ctors from Statistics
llvm-svn: 32698
2006-12-19 22:41:21 +00:00
Chris Lattner
a531ce882e Detemplatize the Statistic class. The only type it is instantiated with
is 'unsigned'.

llvm-svn: 32279
2006-12-06 17:46:33 +00:00
Chris Lattner
4946ae54df Don't transform in another bad case: if the block is empty, it should be
simplified before we do this xform so that our cost model is accurate.

llvm-svn: 31864
2006-11-18 22:25:39 +00:00
Chris Lattner
b101c06bce Fix another case we *don't* want to do this xform.
llvm-svn: 31861
2006-11-18 21:56:39 +00:00
Chris Lattner
514fc3de5c make the previous change more aggressive, moving any block with no fallthrough.
This speeds up yacr2 by 7% on a core2.

llvm-svn: 31856
2006-11-18 21:30:35 +00:00
Chris Lattner
bddc114cfb Minor code layout tweak: if we have something like this:
if (cond) goto BB2
BB1:
    ...
    return;
BB2:
   ...

Move BB1 to the end of the function so that the code falls through in the
non-return case.  This has the effect of moving assert (and other no-return
call) bodies and return blocks out of loops.

llvm-svn: 31855
2006-11-18 20:47:54 +00:00
Chris Lattner
f71921c79d optimize single MBB loops better. In particular, produce:
LBB1_57:        #bb207.i
        movl 72(%esp), %ecx
        movb (%ecx,%eax), %cl
        movl 80(%esp), %edx
        movb %cl, 1(%edx,%eax)
        incl %eax
        cmpl $143, %eax
        jne LBB1_57     #bb207.i
        jmp LBB1_64     #cond_next255.i

intead of:

LBB1_57:        #bb207.i
        movl 72(%esp), %ecx
        movb (%ecx,%eax), %cl
        movl 80(%esp), %edx
        movb %cl, 1(%edx,%eax)
        incl %eax
        cmpl $143, %eax
        je LBB1_64      #cond_next255.i
        jmp LBB1_57     #bb207.i

This eliminates a branch per iteration of the loop.  This hurted PPC
particularly, because the extra branch meant another dispatch group for each
iteration of the loop.

llvm-svn: 31530
2006-11-08 01:03:21 +00:00
Jeff Cohen
e1003da1a2 Unbreak VC++ build.
llvm-svn: 31464
2006-11-05 19:31:28 +00:00
Reid Spencer
4bafa71dc1 For PR786:
Turn on -Wunused and -Wno-unused-parameter. Clean up most of the resulting
fall out by removing unused variables. Remaining warnings have to do with
unused functions (I didn't want to delete code without review) and unused
variables in generated code. Maintainers should clean up the remaining
issues when they see them. All changes pass DejaGnu tests and Olden.

llvm-svn: 31380
2006-11-02 20:25:50 +00:00
Chris Lattner
f20968bc33 give branch folding a simple heuristic to decide which block to split so that
it inserts an uncond branch where it is less likely to cause a problem.  This
fixes some perf issues on ppc.

llvm-svn: 31354
2006-11-01 19:36:29 +00:00
Chris Lattner
b459c08384 make tail merging more aggressive. If two blocks share a common tail, but the
tail is not an entire block for either of them, pick one, split it, then
merge the common part.

llvm-svn: 31336
2006-11-01 01:16:12 +00:00
Chris Lattner
5651528580 enable branch folding with an option
llvm-svn: 31335
2006-11-01 00:38:31 +00:00
Chris Lattner
e1b2b2127b Make CanFallThrough more intelligent (so it can handle blocks with (e.g.) no
successors), and make island block movement more general.

This compiles CodeGen/X86/2006-04-27-ISelFoldingBug.ll to:

_loadAndRLEsource_no_exit_2E_1_label_2E_0:
        subl $8, %esp
        movl %esi, 4(%esp)
        movl %ebx, (%esp)
        movl 16(%esp), %eax
        movl 12(%esp), %ecx
LBB1_3: #label.0
        movl _last, %edx
        movl %edx, %esi
        incl %esi
        movl %esi, _last
        movl %ecx, %ebx
        # TRUNCATE movb %bl, %bl
        movl _block, %esi
        movb %bl, 1(%esi,%edx)
        cmpl %eax, _last
        jge LBB1_2      #codeRepl5.exitStub
LBB1_4: #label.0
        cmpl $257, %ecx
        je LBB1_2       #codeRepl5.exitStub
LBB1_1: #label.0.no_exit.1_crit_edge.exitStub
        movl $1, %eax
        movl (%esp), %ebx
        movl 4(%esp), %esi
        addl $8, %esp
        ret
LBB1_2: #codeRepl5.exitStub
        xorl %eax, %eax
        movl (%esp), %ebx
        movl 4(%esp), %esi
        addl $8, %esp
        ret

instead of:

_loadAndRLEsource_no_exit_2E_1_label_2E_0:
        subl $8, %esp
        movl %esi, 4(%esp)
        movl %ebx, (%esp)
        movl 16(%esp), %eax
        movl 12(%esp), %ecx
        jmp LBB1_3      #label.0
LBB1_1: #label.0.no_exit.1_crit_edge.exitStub
        movl $1, %eax
        movl (%esp), %ebx
        movl 4(%esp), %esi
        addl $8, %esp
        ret
LBB1_2: #codeRepl5.exitStub
        xorl %eax, %eax
        movl (%esp), %ebx
        movl 4(%esp), %esi
        addl $8, %esp
        ret
LBB1_3: #label.0
        movl _last, %edx
        movl %edx, %esi
        incl %esi
        movl %esi, _last
        movl %ecx, %ebx
        # TRUNCATE movb %bl, %bl
        movl _block, %esi
        movb %bl, 1(%esi,%edx)
        cmpl %eax, _last
        jge LBB1_2      #codeRepl5.exitStub
LBB1_4: #label.0
        cmpl $257, %ecx
        jne LBB1_1      #label.0.no_exit.1_crit_edge.exitStub
        jmp LBB1_2      #codeRepl5.exitStub

... which is much better layout :)

llvm-svn: 31282
2006-10-29 21:05:41 +00:00
Chris Lattner
95eed3bd09 Teach branch folding to fold identical jump tables together and to delete
jump tables that are dead.

llvm-svn: 31273
2006-10-28 18:34:47 +00:00
Chris Lattner
af9b4c33c2 improve deletion of blocks that just contain branches by knowing that
the pred block doesn't fall through into them if it's a jumptable.

llvm-svn: 31263
2006-10-28 17:32:47 +00:00
Chris Lattner
2258020df2 simplify code
llvm-svn: 31188
2006-10-25 22:21:37 +00:00
Chris Lattner
df59442a74 turn off tail merging for now
llvm-svn: 31180
2006-10-25 18:08:50 +00:00
Chris Lattner
533b205309 move single basic blocks that are neither fallen into nor fall out of into
a place more useful.  In particular, if we can put them in a place where code
will be able to fall into it, do so.  Otherwise, put it in a place it can fall
through into a successor.  Otherwise, if preventing a fallthrough, move to the
end of the function, out of the way.

This deletes several hundred unconditional branches from spass.

llvm-svn: 31149
2006-10-24 01:12:32 +00:00
Chris Lattner
0c3fabc9a4 Enable tail merging by default.
llvm-svn: 31140
2006-10-23 22:10:12 +00:00
Jim Laskey
f6a28d7161 More complete solution to deleting blocks and debug info.
llvm-svn: 31129
2006-10-23 14:56:37 +00:00
Chris Lattner
9e7d74961b don't break infinite loops
llvm-svn: 31102
2006-10-21 06:11:43 +00:00
Chris Lattner
210d322b1f Use branch reversal to do stuff like this:
call L_strcmp$stub
        testl %eax, %eax
-       jne LBB26_208   #cond_true6020
-       jmp LBB26_227   #bb7119
+       je LBB26_227    #bb7119
 LBB26_208:     #cond_true6020
        movl $l31_str14, 4(%esp)

        testl %eax, %eax
-       jne LBB26_704   #cond_true13042
-       jmp LBB26_713   #bb13151
+       je LBB26_713    #bb13151
 LBB26_704:     #cond_true13042
        movl $_str52, 4(%esp)

        cmpl 76(%ecx), %eax
-       jge LBB26_1628  #cond_false63.i.i
-       jmp LBB26_1769  #_Z8makeGridP13mrSurfaceListidiidd.exit.i
+       jl LBB26_1769   #_Z8makeGridP13mrSurfaceListidiidd.exit.i
 LBB26_1628:    #cond_false63.i.i
        movl $0, 48964(%esp)

llvm-svn: 31100
2006-10-21 05:54:00 +00:00
Chris Lattner
cf7f500cfd Transform code like:
jle FOO
  jmp BAR
BAR:

into:

  jle FOO
BAR:

... whoa!

llvm-svn: 31098
2006-10-21 05:43:30 +00:00
Chris Lattner
d4cb8dc857 Three changes:
1. Remove a bunch of ifdef'd code.
2. When a block just contains an uncond branch, change all blocks branching
   to it to jump to the destination instead.
3. If branch analysis tells us some edges in the machinecfg are not actually
   possible, remove them.

#2 triggers a suprisingly large number of times.

llvm-svn: 31094
2006-10-21 05:08:28 +00:00
Chris Lattner
52a4558cf2 Add an experimental cross-jumping implementation.
This is currently disabled by default and limited in several ways, but does
have a positive effect.

llvm-svn: 31090
2006-10-21 00:47:49 +00:00
Chris Lattner
cd00328fad Teach the branch folder to update debug info if it removes blocks with line
# notes in it.

llvm-svn: 31026
2006-10-17 23:17:27 +00:00
Chris Lattner
ef7c2e1dc8 Enable deleting branches to successor blocks. With the previous patches,
branch folding can now compile stuff like this:

void foo(int W, int X, int Y, int Z) {
  if (W & 1) {
    for (; X;--X) bar();
  } else if (W & 2) {
    for (; Y;--Y) bar();
  } else if (W & 4) {
    for (; Z;--Z) bar();
  } else if (W & 8) {
    for (; W;--W) bar();
  }

  if (W) {
    bar();
  }
}

contrived testcase where loops exits all end up merging together.  To have
the loop merges be:

...
        cmplw cr0, r30, r27
        bne cr0, LBB1_14        ;bb38
LBB1_16:        ;cond_next48.loopexit
        mr r27, r29
LBB1_20:        ;cond_next48
        cmplwi cr0, r27, 0
        beq cr0, LBB1_22        ;UnifiedReturnBlock
...

instead of:


...
        cmplw cr0, r30, r27
        bne cr0, LBB1_14        ;bb38
LBB1_16:        ;cond_next48.loopexit
        mr r27, r29
        b LBB1_20       ;cond_next48
LBB1_17:        ;cond_next48.loopexit1
        b LBB1_20       ;cond_next48
LBB1_18:        ;cond_next48.loopexit2
        b LBB1_20       ;cond_next48
LBB1_19:        ;cond_next48.loopexit3
LBB1_20:        ;cond_next48
        cmplwi cr0, r27, 0
        beq cr0, LBB1_22        ;UnifiedReturnBlock
...


This is CodeGen/PowerPC/branch-opt.ll

llvm-svn: 31006
2006-10-17 18:16:40 +00:00
Chris Lattner
8464c7e3e1 Reenable this pass, fixing the bugs in it.
It now correctly deletes unreachable blocks and blocks that are empty.

llvm-svn: 31000
2006-10-17 17:13:52 +00:00
Chris Lattner
c4be6ee8b8 disable this pass for now, it's causing issues
llvm-svn: 30951
2006-10-14 00:30:06 +00:00
Chris Lattner
1c35d27fc4 falling off the end of a function is ok with an unreachable instruction.
llvm-svn: 30950
2006-10-14 00:21:48 +00:00
Chris Lattner
ae19ea4b2a disable some objectionable code, maybe we can bring this pass to life
llvm-svn: 30939
2006-10-13 20:43:10 +00:00
Misha Brukman
774e55c446 Remove trailing whitespace
llvm-svn: 21420
2005-04-21 22:36:52 +00:00
Reid Spencer
c4abcbefb1 Changes For Bug 352
Move include/Config and include/Support into include/llvm/Config,
include/llvm/ADT and include/llvm/Support. From here on out, all LLVM
public header files must be under include/llvm/.

llvm-svn: 16137
2004-09-01 22:55:40 +00:00
Chris Lattner
786c788d12 Dereferencing end() is bad.
llvm-svn: 15402
2004-08-01 09:51:42 +00:00
Alkis Evlogimenos
1dd3ea5515 Make OptimizeBlock take a MachineFunction::iterator instead of a
MachineBasicBlock* as a parameter so that nxext() and prior() helper
functions can work naturally on it.

llvm-svn: 15376
2004-07-31 19:24:41 +00:00
Chris Lattner
ecca71ce92 Next on a pointer increments the pointer, not an iterator
llvm-svn: 15375
2004-07-31 18:40:36 +00:00
Alkis Evlogimenos
b28bc78d0a Use next() helper to make code more readable. Use
MachineFunction::iterator instead of MachineBasicBlock* to avoid
dereferencing end iterators.

llvm-svn: 15373
2004-07-31 15:14:29 +00:00
Alkis Evlogimenos
143aeb646c Use MachineFunction::iterator instead of a MachineBasicBlock* because
FallThrough maybe == to MF.end().

llvm-svn: 15372
2004-07-31 15:03:52 +00:00
Chris Lattner
7b12b8a13e Implement a simple target-independent CFG cleanup pass
llvm-svn: 15368
2004-07-31 10:01:27 +00:00