Chris Lattner
d07f899691
Fix CodeExtractor/2004-03-17-UpdatePHIsOutsideRegion.ll
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12489 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-18 05:38:31 +00:00
Chris Lattner
5cc8ca6420
Seriously simplify and correct the PHI node handling code.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12487 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-18 05:28:49 +00:00
Chris Lattner
04229c192b
Fix CodeExtractor/2004-03-17-OutputMismatch.ll
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12486 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-18 04:12:05 +00:00
Chris Lattner
b5c1dbf503
Fix several bugs in the extractor:
...
1. Names were not put on the new arguments created (ok, this just helps sanity :)
2. Fix outgoing pointer values
3. Do not insert stores for values that had not been computed
4. Fix some wierd problems with the outset calculation
This fixes CodeExtractor/2004-03-14-DominanceProblem.ll, making the extractor
work on at least one simple case!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12484 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-18 03:49:40 +00:00
Chris Lattner
33e197b777
Prune #includes, moving the module interface to the front. Note that this
...
exposed the fact that the header was not self-contained. There is a reason
we do things :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12481 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-18 03:15:29 +00:00
Chris Lattner
7acd1ccb8a
Fix compilation of mesa, which I broke earlier today
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12465 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-17 02:02:47 +00:00
Chris Lattner
c1a0623e86
This code was both incredibly complex and incredibly broken. Fix it.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12456 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-16 23:23:11 +00:00
Chris Lattner
4bebf08d15
Do not copy gigantic switch instructions
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12441 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-16 19:45:22 +00:00
Chris Lattner
85ebd541fa
Fix a regression from this patch:
...
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040308/013095.html
Basically, this patch only updated the immediate dominatees of the header node
to tell them that the preheader also dominated them. In practice, ALL
dominatees of the header node are also dominated by the preheader.
This fixes: LoopSimplify/2004-03-15-IncorrectDomUpdate.
and PR293
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12434 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-16 06:00:15 +00:00
Chris Lattner
15d443b566
Mostly cosmetic improvements. Do fix the bug where a global value was considered an input.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12406 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-15 01:26:44 +00:00
Chris Lattner
0de632bfae
Assert that input blocks meet the invariants we expect
...
Simplify the input/output finder. All elements of a basic block are
instructions. Any used arguments are also inputs. An instruction can only
be used by another instruction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12405 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-15 01:18:23 +00:00
Chris Lattner
65826bf435
No correctness fixes here, just minor qoi fixes:
...
* Don't insert a branch to the switch instruction after the call, just
make it a single block.
* Insert the new alloca instructions in the entry block of the original
function instead of having them execute dynamically
* Don't make the default edge of the switch instruction go back to the switch.
The loop extractor shouldn't create new loops!
* Give meaningful names to the alloca slots and the reload instructions
* Some minor code simplifications
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12402 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-14 23:43:24 +00:00
Chris Lattner
12f390e9c0
Simplify code a bit, and fix bug CodeExtractor/2004-03-14-NoSwitchSupport.ll
...
This also implements a two minor improvements:
* Don't insert live-out stores IN the region, insert them on the code path
that exits the region
* If the region is exited to the same block from multiple paths, share the
switch statement entry, live-out store code, and the basic block.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12401 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-14 23:05:49 +00:00
Chris Lattner
0e06674287
Simplify the code a bit by making the collection of basic blocks to extract
...
a member of the class. While we're at it, turn the collection into a set
instead of a vector to improve efficiency and make queries simpler.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12400 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-14 22:34:55 +00:00
Chris Lattner
bf9eaddfb0
Do not create empty basic blocks when the lowerswitch pass expects blocks to
...
be non-empty! This fixes LowerSwitch/2004-03-13-SwitchIsDefaultCrash.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12384 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-14 04:14:31 +00:00
Chris Lattner
bb41156c0c
Minor random cleanups
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12382 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-14 04:01:47 +00:00
Chris Lattner
2ef703ec42
If a block is dead, dominators will not be calculated for it. Because of this
...
loop information won't see it, and we could have unreachable blocks pointing to
the non-header node of blocks in a natural loop. This isn't tidy, so have the
loopsimplify pass clean it up.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12380 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-14 03:59:22 +00:00
Chris Lattner
ffada93273
Verify functions as they are produced if -debug is specified. Reduce
...
curly braceage
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12378 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-14 03:17:22 +00:00
Chris Lattner
c3c8703c3b
Move to the IPO library. Utils shouldn't contain passes.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12372 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-14 02:32:27 +00:00
Chris Lattner
a2dc727ac4
DemoteRegToStack got moved from DemoteRegToStack.h to Local.h
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12368 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-14 02:13:38 +00:00
Chris Lattner
786c5646e9
This little patch speeds up the loop used to update the dominator set analysis.
...
On the testcase from GCC PR12440, which has a LOT of loops (1392 of which require
preheaders to be inserted), this speeds up the loopsimplify pass from 1.931s to
0.1875s. The loop in question goes from 1.65s -> 0.0097s, which isn't bad. All of
these times are a debug build.
This adds a dependency on DominatorTree analysis that was not there before, but
we always had dominatortree available anyway, because LICM requires both loop
simplify and DT, so this doesn't add any extra analysis in practice.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12362 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-13 22:01:26 +00:00
Chris Lattner
17fd273512
Add constant folding wrapper support for select instructions.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12319 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-12 05:53:03 +00:00
Chris Lattner
0a94348fb9
Don't emit things like malloc(16*1). Allocation instructions are fixed arity now.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12086 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-03 01:40:53 +00:00
Misha Brukman
0256e4bbf9
Implement ExtractCodeRegion()
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12070 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-02 00:20:57 +00:00
Misha Brukman
38b8fd1078
Make a note that this is usually used via bugpoint.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12068 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-02 00:19:09 +00:00
Misha Brukman
b97fce5252
* Add implementation of ExtractBasicBlock()
...
* Add comments to ExtractLoop()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12053 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-01 18:28:34 +00:00
Chris Lattner
99cca7d3aa
Disable tail duplication in a case that breaks on Olden/tsp
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12021 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-01 01:12:13 +00:00
Chris Lattner
06887c9a2a
Fix bug: test/Regression/Transforms/LowerInvoke/2004-02-29-PHICrash.llx
...
... which tickled the lowerinvoke pass because it used the BCE routines.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12012 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-29 22:24:41 +00:00
Chris Lattner
542f149f00
Implement switch->br and br->switch folding by ripping out the switch->switch
...
and br->br code and generalizing it. This allows us to compile code like this:
int test(Instruction *I) {
if (isa<CastInst>(I))
return foo(7);
else if (isa<BranchInst>(I))
return foo(123);
else if (isa<UnwindInst>(I))
return foo(1241);
else if (isa<SetCondInst>(I))
return foo(1);
else if (isa<VAArgInst>(I))
return foo(42);
return foo(-1);
}
into:
int %_Z4testPN4llvm11InstructionE("struct.llvm::Instruction"* %I) {
entry:
%tmp.1.i.i.i.i.i.i.i = getelementptr "struct.llvm::Instruction"* %I, long 0, ubyte 4 ; <uint*> [#uses=1]
%tmp.2.i.i.i.i.i.i.i = load uint* %tmp.1.i.i.i.i.i.i.i ; <uint> [#uses=2]
%tmp.2.i.i.i.i.i.i = seteq uint %tmp.2.i.i.i.i.i.i.i, 27 ; <bool> [#uses=0]
switch uint %tmp.2.i.i.i.i.i.i.i, label %endif.0 [
uint 27, label %then.0
uint 2, label %then.1
uint 5, label %then.2
uint 14, label %then.3
uint 15, label %then.3
uint 16, label %then.3
uint 17, label %then.3
uint 18, label %then.3
uint 19, label %then.3
uint 32, label %then.4
]
...
As well as handling the cases in 176.gcc and many other programs more effectively.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11964 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-28 21:28:10 +00:00
Chris Lattner
b99df4f8c2
if there is already a prototype for malloc/free, use it, even if it's incorrect.
...
Do not just inject a new prototype.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11951 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-28 18:51:45 +00:00
Misha Brukman
9e4a642c03
Right, it's really Extractor, not Extraction.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11939 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-28 03:37:58 +00:00
Misha Brukman
9401deb320
A pass that uses the generic CodeExtractor to rip out *every* loop in every
...
function, as long as the loop isn't the only one in that function. This should
help debugging passes easier with BugPoint.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11936 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-28 03:33:01 +00:00
Misha Brukman
e6336031b8
A generic code extractor: given a list of BasicBlocks, it will rip them out into
...
a new function, taking care of inputs and outputs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11935 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-28 03:26:20 +00:00
Chris Lattner
f2dbf50efa
turn things like:
...
if (X == 0 || X == 2)
...where the comparisons and branches are in different blocks... into a switch
instruction. This comes up a lot in various programs, and works well with
the switch/switch merging code I checked earlier. For example, this testcase:
int switchtest(int C) {
return C == 0 ? f(123) :
C == 1 ? f(3123) :
C == 4 ? f(312) :
C == 5 ? f(1234): f(444);
}
is converted into this:
switch int %C, label %cond_false.3 [
int 0, label %cond_true.0
int 1, label %cond_true.1
int 4, label %cond_true.2
int 5, label %cond_true.3
]
instead of a whole bunch of conditional branches.
Admittedly the code is ugly, and incomplete. To be complete, we need to add
br -> switch merging and switch -> br merging. For example, this testcase:
struct foo { int Q, R, Z; };
#define A (X->Q+X->R * 123)
int test(struct foo *X) {
return A == 123 ? X1() :
A == 12321 ? X2():
(A == 111 || A == 222) ? X3() :
A == 875 ? X4() : X5();
}
Gets compiled to this:
switch int %tmp.7, label %cond_false.2 [
int 123, label %cond_true.0
int 12321, label %cond_true.1
int 111, label %cond_true.2
int 222, label %cond_true.2
]
...
cond_false.2: ; preds = %entry
%tmp.52 = seteq int %tmp.7, 875 ; <bool> [#uses=1]
br bool %tmp.52, label %cond_true.3, label %cond_false.3
where the branch could be folded into the switch.
This kind of thing occurs *ALL OF THE TIME*, especially in programs like
176.gcc, which is a horrible mess of code. It contains stuff like *shudder*:
#define SWITCH_TAKES_ARG(CHAR) \
( (CHAR) == 'D' \
|| (CHAR) == 'U' \
|| (CHAR) == 'o' \
|| (CHAR) == 'e' \
|| (CHAR) == 'u' \
|| (CHAR) == 'I' \
|| (CHAR) == 'm' \
|| (CHAR) == 'L' \
|| (CHAR) == 'A' \
|| (CHAR) == 'h' \
|| (CHAR) == 'z')
and
#define CONST_OK_FOR_LETTER_P(VALUE, C) \
((C) == 'I' ? SMALL_INTVAL (VALUE) \
: (C) == 'J' ? SMALL_INTVAL (-(VALUE)) \
: (C) == 'K' ? (unsigned)(VALUE) < 32 \
: (C) == 'L' ? ((VALUE) & 0xffff) == 0 \
: (C) == 'M' ? integer_ok_for_set (VALUE) \
: (C) == 'N' ? (VALUE) < 0 \
: (C) == 'O' ? (VALUE) == 0 \
: (C) == 'P' ? (VALUE) >= 0 \
: 0)
and
#define LEGITIMIZE_ADDRESS(X,OLDX,MODE,WIN) \
{ \
if (GET_CODE (X) == PLUS && CONSTANT_ADDRESS_P (XEXP (X, 1))) \
(X) = gen_rtx (PLUS, SImode, XEXP (X, 0), \
copy_to_mode_reg (SImode, XEXP (X, 1))); \
if (GET_CODE (X) == PLUS && CONSTANT_ADDRESS_P (XEXP (X, 0))) \
(X) = gen_rtx (PLUS, SImode, XEXP (X, 1), \
copy_to_mode_reg (SImode, XEXP (X, 0))); \
if (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 0)) == MULT) \
(X) = gen_rtx (PLUS, SImode, XEXP (X, 1), \
force_operand (XEXP (X, 0), 0)); \
if (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == MULT) \
(X) = gen_rtx (PLUS, SImode, XEXP (X, 0), \
force_operand (XEXP (X, 1), 0)); \
if (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 0)) == PLUS) \
(X) = gen_rtx (PLUS, Pmode, force_operand (XEXP (X, 0), NULL_RTX),\
XEXP (X, 1)); \
if (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == PLUS) \
(X) = gen_rtx (PLUS, Pmode, XEXP (X, 0), \
force_operand (XEXP (X, 1), NULL_RTX)); \
if (GET_CODE (X) == SYMBOL_REF || GET_CODE (X) == CONST \
|| GET_CODE (X) == LABEL_REF) \
(X) = legitimize_address (flag_pic, X, 0, 0); \
if (memory_address_p (MODE, X)) \
goto WIN; }
and others. These macros get used multiple times of course. These are such
lovely candidates for macros, aren't they? :)
This code also nicely handles LLVM constructs that look like this:
if (isa<CastInst>(I))
...
else if (isa<BranchInst>(I))
...
else if (isa<SetCondInst>(I))
...
else if (isa<UnwindInst>(I))
...
else if (isa<VAArgInst>(I))
...
where the isa can obviously be a dyn_cast as well. Switch instructions are a
good thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11870 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-26 07:13:46 +00:00
Chris Lattner
940ff563f7
Fix incorrect debug code
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11821 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-25 15:15:04 +00:00
Chris Lattner
8e509dd5e8
If a block is made dead, make sure to promptly remove it.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11799 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 16:09:21 +00:00
Chris Lattner
d52c261cf8
Implement SimplifyCFG/switch_switch_fold.ll
...
This case occurs many times in various benchmarks, especially when combined
with the previous patch. This allows it to get stuff like:
if (X == 4 || X == 3)
if (X == 5 || X == 8)
and
switch (X) {
case 4: case 5: case 6:
if (X == 4 || X == 5)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11797 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 07:23:58 +00:00
Chris Lattner
e14ea0804a
Rearrange code a bit
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11793 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 05:54:22 +00:00
Chris Lattner
0d56008f53
Implement: test/Regression/Transforms/SimplifyCFG/switch_create.ll
...
This turns code like this:
if (X == 4 | X == 7)
and
if (X != 4 & X != 7)
into switch instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11792 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 05:38:11 +00:00
Chris Lattner
57cb9883aa
Fix PR245: Linking weak and strong global variables is dependent on link order
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11565 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-17 21:56:04 +00:00
Chris Lattner
19831ec853
Implement test/Regression/Transforms/SimplifyCFG/UncondBranchToReturn.ll,
...
see the testcase for the reasoning.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11496 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-16 06:35:48 +00:00
Chris Lattner
860a16143c
Instead of producing calls to setjmp/longjmp, produce uses of the
...
llvm.setjmp/llvm.longjmp intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11482 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-15 22:24:27 +00:00
Chris Lattner
de512b5b2e
Adjustments to support the new ConstantAggregateZero class
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11474 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-15 05:55:15 +00:00
Chris Lattner
494b6920b0
Fix compilation of 126.gcc: intrinsic functions cannot throw, so they are not
...
allowed in invoke instructions. Thus, if we are inlining a call to an intrinsic
function into an invoke site, we don't need to turn the call into an invoke!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11384 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-13 16:47:35 +00:00
Chris Lattner
cefc18e7d9
Expose a pass ID that can be 'required'
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11376 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-13 16:16:16 +00:00
Chris Lattner
723c66d4c0
Implement SimplifyCFG/PhiEliminate.ll
...
Having a proper 'select' instruction would allow the elimination of a lot
of the special case cruft in this patch, but we don't have one yet.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11307 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-11 03:36:04 +00:00
Chris Lattner
2355f948c5
The hasConstantReferences predicate always returns false.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11301 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-11 01:17:07 +00:00
Chris Lattner
f1d0d3519f
Only add the global variable with the abort message if an unwind actually
...
occurs in the program.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11249 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-09 22:48:47 +00:00
Misha Brukman
b9806e0101
Fix grammar-o.
...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11210 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-08 22:27:33 +00:00
Chris Lattner
501825e08a
Improve compatibility with programs that already have a prototype for 'write',
...
even if it is wierd in some way.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11207 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-08 22:14:44 +00:00