Commit Graph

102 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen 2b09bed518 Delete dead code.
llvm-svn: 126801
2011-03-01 23:24:19 +00:00
Jakob Stoklund Olesen 8ef91fc870 Move the value map from LiveIntervalMap to SplitEditor.
The value map is currently not used, all values are 'complex mapped' and
LiveIntervalMap::mapValue is used to dig them out.

This is the first step in a series changes leading to the removal of
LiveIntervalMap. Its data structures can be shared among all the live intervals
created by a split, so it is wasteful to create a copy for each.

llvm-svn: 126800
2011-03-01 23:14:53 +00:00
Jakob Stoklund Olesen 977e3d3c48 Delete dead code.
Local live range splitting is better driven by interference. This code was just
guessing.

llvm-svn: 126799
2011-03-01 23:14:50 +00:00
Jakob Stoklund Olesen ed172998a6 It is safe to ignore LastSplitPoint when the variable is not live out.
No code will be inserted after the split point anyway.

llvm-svn: 126319
2011-02-23 18:26:31 +00:00
Jakob Stoklund Olesen 60a26a6578 Add SplitKit::isOriginalEndpoint and use it to force live range splitting to terminate.
An original endpoint is an instruction that killed or defined the original live
range before any live ranges were split.

When splitting global live ranges, avoid creating local live ranges without any
original endpoints. We may still create global live ranges without original
endpoints, but such a range won't be split again, and live range splitting still
terminates.

llvm-svn: 126151
2011-02-21 23:09:46 +00:00
Jakob Stoklund Olesen f1a60a61ba Give SplitAnalysis a VRM member to access VirtRegMap::getOriginal().
llvm-svn: 126005
2011-02-19 00:53:42 +00:00
Jakob Stoklund Olesen 04aff708fd Missed member rename for naming convention.
llvm-svn: 126003
2011-02-19 00:42:33 +00:00
Jakob Stoklund Olesen 8dafc875bb Delete unused code for analyzing and splitting around loops.
Loop splitting is better handled by the more generic global region splitting
based on the edge bundle graph.

llvm-svn: 125243
2011-02-09 23:56:18 +00:00
Jakob Stoklund Olesen 7cb57b30bd Use the LiveBLocks array for SplitEditor::splitSingleBlocks() as well.
This fixes a bug where splitSingleBlocks() could split a live range after a
terminator instruction.

llvm-svn: 125237
2011-02-09 23:30:25 +00:00
Jakob Stoklund Olesen b1b76adbd9 Move calcLiveBlockInfo() and the BlockInfo struct into SplitAnalysis.
No functional changes intended.

llvm-svn: 125231
2011-02-09 22:50:26 +00:00
Jakob Stoklund Olesen f6e0394d76 Ignore <undef> uses when analyzing and rewriting.
llvm-svn: 125226
2011-02-09 21:52:09 +00:00
Jakob Stoklund Olesen 1749935173 Add SplitEditor::overlapIntv() to create small ranges where both registers are live.
If a live range is used by a terminator instruction, and that live range needs
to leave the block on the stack or in a different register, it can be necessary
to have both sides of the split live at the terminator instruction.

Example:

  %vreg2 = COPY %vreg1
  JMP %vreg1

Becomes after spilling %vreg2:

  SPILL %vreg1
  JMP %vreg1

The spill doesn't kill the register as is normally the case.

llvm-svn: 125102
2011-02-08 18:50:21 +00:00
Jakob Stoklund Olesen 3d11c8eaf2 Add assertion.
llvm-svn: 125101
2011-02-08 18:50:18 +00:00
Jakob Stoklund Olesen 096bd8837f Add LiveIntervals::getLastSplitPoint().
A live range cannot be split everywhere in a basic block. A split must go before
the first terminator, and if the variable is live into a landing pad, the split
must happen before the call that can throw.

llvm-svn: 124894
2011-02-04 19:33:11 +00:00
Jakob Stoklund Olesen 3295a99fe9 Skip unused values.
llvm-svn: 124842
2011-02-04 00:59:23 +00:00
Jakob Stoklund Olesen d8f62e2a62 Add debug output and asserts to the phi-connecting code.
llvm-svn: 124813
2011-02-03 20:29:39 +00:00
Jakob Stoklund Olesen 8c0254870b Fix coloring bug when mapping values in the middle of a live-through block.
If the found value is not live-through the block, we should only add liveness up
to the requested slot index. When the value is live-through, the whole block
should be colored.

Bug found by SSA verification in the machine code verifier.

llvm-svn: 124812
2011-02-03 20:29:36 +00:00
Jakob Stoklund Olesen f12e120743 Return live range end points from SplitEditor::enter*/leave*.
These end points come from the inserted copies, and can be passed directly to
useIntv. This simplifies the coloring code.

llvm-svn: 124799
2011-02-03 17:04:16 +00:00
Eric Christopher ede6267993 Reapply this.
llvm-svn: 124779
2011-02-03 06:18:29 +00:00
Eric Christopher 21933539f2 Temporarily revert 124765 in an attempt to find the cycle breaking bootstrap.
llvm-svn: 124778
2011-02-03 05:40:54 +00:00
Jakob Stoklund Olesen dca2917e25 Defer SplitKit value mapping until all defs are available.
The greedy register allocator revealed some problems with the value mapping in
SplitKit. We would sometimes start mapping values before all defs were known,
and that could change a value from a simple 1-1 mapping to a multi-def mapping
that requires ssa update.

The new approach collects all defs and register assignments first without
filling in any live intervals. Only when finish() is called, do we compute
liveness and mapped values. At this time we know with certainty which values map
to multiple values in a split range.

This also has the advantage that we can compute live ranges based on the
remaining uses after rematerializing at split points.

The current implementation has many opportunities for compile time optimization.

llvm-svn: 124765
2011-02-03 00:54:23 +00:00
Jakob Stoklund Olesen b308902024 Rename member variables to follow the rest of LLVM.
No functional change.

llvm-svn: 124257
2011-01-26 00:50:53 +00:00
Jakob Stoklund Olesen 04e6b3bd21 Add LiveIntervalMap::dumpCache() to print out the cache used by the ssa update algorithm.
llvm-svn: 123925
2011-01-20 17:45:20 +00:00
Jakob Stoklund Olesen 9fb04015ff Implement RAGreedy::splitAroundRegion and remove loop splitting.
Region splitting includes loop splitting as a subset, and it is more generic.
The splitting heuristics for variables that are live in more than one block are
now:

1. Try to create a region that covers multiple basic blocks.
2. Try to create a new live range for each block with multiple uses.
3. Spill.

Steps 2 and 3 are similar to what the standard spiller is doing.

llvm-svn: 123853
2011-01-19 22:11:48 +00:00
Jakob Stoklund Olesen 267f6c1ab2 Add RAGreedy methods for splitting live ranges around regions.
Analyze the live range's behavior entering and leaving basic blocks. Compute an
interference pattern for each allocation candidate, and use SpillPlacement to
find an optimal region where that register can be live.

This code is still not enabled.

llvm-svn: 123774
2011-01-18 21:13:27 +00:00
Jakob Stoklund Olesen f96ae684c4 Turn the EdgeBundles class into a stand-alone machine CFG analysis pass.
The analysis will be needed by both the greedy register allocator and the
X86FloatingPoint pass. It only needs to be computed once when the CFG doesn't
change.

This pass is very fast, usually showing up as 0.0% wall time.

llvm-svn: 122832
2011-01-04 21:10:05 +00:00
Jakob Stoklund Olesen 29836e6572 Include a shadow of the original CFG edges in the edge bundle graph.
llvm-svn: 122444
2010-12-22 22:01:28 +00:00
Jakob Stoklund Olesen 2530cd2a4c Add EdgeBundles to SplitKit.
Edge bundles is an annotation on the CFG that turns it into a bipartite directed
graph where each basic block is connected to an outgoing and an ingoing bundle.
These bundles are useful for identifying regions of the CFG for live range
splitting.

llvm-svn: 122301
2010-12-21 01:50:21 +00:00
Jakob Stoklund Olesen 7971a3eaff Check that the register is live-in to the loop header before inserting copies in
the loop predecessors.

The register can be live-out from a predecessor without being live-in to the
loop header if there is a critical edge from the predecessor.

llvm-svn: 122123
2010-12-18 01:06:19 +00:00
Jakob Stoklund Olesen 1066ef6b24 Fix build.
llvm-svn: 121872
2010-12-15 18:07:48 +00:00
Jakob Stoklund Olesen 28e769cc54 Detect and enumerate bypass loops.
Bypass loops have the current live range live through, but contain no uses or
defs. Splitting around a bypass loop can free registers for other uses inside
the loop by spilling the split range.

llvm-svn: 121871
2010-12-15 17:49:52 +00:00
Jakob Stoklund Olesen 4391f34aba Separate SplitAnalysis::getSplitLoops().
This method returns the set of loops with uses that are candidates for
splitting.

llvm-svn: 121870
2010-12-15 17:41:19 +00:00
Jakob Stoklund Olesen 3cb87f4c31 No need to add liveness that's already there.
llvm-svn: 118742
2010-11-10 23:56:00 +00:00
Jakob Stoklund Olesen 6ee7d9aade Basic rematerialization during splitting.
Whenever splitting wants to insert a copy, it checks if the value can be
rematerialized cheaply instead.

Missing features:
- Delete instructions when all uses have been rematerialized.
- Truncate live ranges to the remaining uses after rematerialization.

llvm-svn: 118702
2010-11-10 19:31:50 +00:00
Jakob Stoklund Olesen cbbd819248 Tag debug output as regalloc
llvm-svn: 118193
2010-11-03 20:39:23 +00:00
Jakob Stoklund Olesen 1e32688e4c When inserting copies during splitting, always use the parent register as the
source, and let rewrite() clean it up.

This way, kill flags on the inserted copies are fixed as well during rewrite().

We can't just assume that all the copies we insert are going to be kills since
critical edges into loop headers sometimes require both source and dest to be
live out of a block.

llvm-svn: 117980
2010-11-01 23:59:48 +00:00
Jakob Stoklund Olesen a5d4b4ffa2 Update kill flags while rewriting instructions after splitting.
llvm-svn: 117959
2010-11-01 21:51:29 +00:00
Jakob Stoklund Olesen 0cfc497f19 Make sure copies are inserted after any exception handling labels at the top of
a basic block.

llvm-svn: 117764
2010-10-30 01:26:16 +00:00
Jakob Stoklund Olesen 140542fcea Don't transfer unused values to the new intervals formed by splitting.
llvm-svn: 117673
2010-10-29 17:47:49 +00:00
Benjamin Kramer 25ed920b0e Silence Release build warnings.
llvm-svn: 117671
2010-10-29 17:40:05 +00:00
Jakob Stoklund Olesen 2cdca45861 Never propagate the idom value out of a block that defines its own value.
llvm-svn: 117669
2010-10-29 17:37:25 +00:00
Jakob Stoklund Olesen c9f90c2a32 Replace SplitKit SSA update with an iterative algorithm very similar to the one
in SSAUpdaterImpl.h

Verifying live intervals revealed that the old method was completely wrong, and
we need an iterative approach to calculating PHI placemant. Fortunately, we have
MachineDominators available, so we don't have to compute that over and over
like SSAUpdaterImpl.h must.

Live-out values are cached between calls to mapValue() and computed in a greedy
way, so most calls will be working with very small block sets.

Thanks to Bob for explaining how this should work.

llvm-svn: 117599
2010-10-28 20:34:52 +00:00
Jakob Stoklund Olesen e172a8b794 Make MachineDominators available for SplitEditor. We are going to need it for
proper SSA updating.

This doesn't cause MachineDominators to be recomputed since we are already
requiring MachineLoopInfo which uses dominators as well.

llvm-svn: 117598
2010-10-28 20:34:50 +00:00
Jakob Stoklund Olesen 79e1407c11 Handle critical loop predecessors by making both inside and outside registers
live out.

This doesn't prevent us from inserting a loop preheader later on, if that is
better.

llvm-svn: 117424
2010-10-27 00:39:07 +00:00
Jakob Stoklund Olesen 795ed98180 Compute critical loop predecessors in the same way as critical loop exits.
Critical edges going into a loop are not as bad as critical exits. We can handle
them by splitting the critical edge, or by having both inside and outside
registers live out of the predecessor.

llvm-svn: 117423
2010-10-27 00:39:05 +00:00
Jakob Stoklund Olesen e4f3317cda After splitting, compute connected components of all new registers, not just for
the remainder register.

Example:

bb0:
  x = 1
bb1:
  use(x)
  ...
  x = 2
  jump bb1

When x is isolated in bb1, the inner part breaks into two components, x1 and x2:

bb0:
  x0 = 1
bb1:
  x1 = x0
  use(x1)
  ...
  x2 = 2
  x0 = x2
  jump bb1

llvm-svn: 117408
2010-10-26 22:36:09 +00:00
Jakob Stoklund Olesen 022e7795cf Call RenumberValues for all new registers created during splitting. This is
necessary to get correct hasPHIKill flags.

llvm-svn: 117406
2010-10-26 22:36:05 +00:00
Jakob Stoklund Olesen 4453324e5b Preserve PHIDef bits in cloned values during splitting.
llvm-svn: 117405
2010-10-26 22:36:02 +00:00
Jakob Stoklund Olesen 4cf8fe31bb Be more strict about detecting multi-use blocks for isolation.
When a block has exactly two uses and the register is both live-in and live-out,
don't isolate the block. We would be inserting two copies, so we haven't really
made any progress.

If the live-in and live-out values separate into disconnected components after
splitting, we would be making progress. We can't detect that for now.

llvm-svn: 117169
2010-10-22 22:48:56 +00:00
Jakob Stoklund Olesen 2d60075590 Be more strict when detecting critical edges before loop splitting.
An exit block with a critical edge must only have predecessors in the loop, or
just before the loop. This guarantees that the inserted copies in the loop
predecessors dominate the exit block.

llvm-svn: 117144
2010-10-22 20:28:23 +00:00