Commit Graph

6413 Commits

Author SHA1 Message Date
Tanya Lattner a6820d6704 Updating my versions of ModuloScheduling in cvs. Still not complete.
llvm-svn: 13424
2004-05-08 16:12:10 +00:00
Brian Gaeke 1096ba9422 Add support for widening integral casts.
Flesh out the SetCC support... which currently ends in a little bit
of unfinished code (which is probably completely hilarious) for
generating the condition value splitting the basic block up into 4
blocks, like this (clearly a better API is needed for this!):

       BB
   cond. branch
     /         /          R1=1    R2=0
     \      /
      \    /
    R=phi(R1,R2)

Other minor edits.

llvm-svn: 13423
2004-05-08 06:36:14 +00:00
Brian Gaeke 91bf7cb79b Add a bunch more branches
llvm-svn: 13422
2004-05-08 06:08:29 +00:00
Brian Gaeke 7a66e5fff9 Flesh out GEP support
llvm-svn: 13421
2004-05-08 05:27:20 +00:00
Brian Gaeke d18b330605 Add ADD with immediate
llvm-svn: 13420
2004-05-08 05:26:55 +00:00
Brian Gaeke b56f1c9c10 Add forms of CMP, SUBCC, and a few branches, and some comments.
llvm-svn: 13419
2004-05-08 04:21:32 +00:00
Brian Gaeke f3a479f04a Add stub support for GEPs.
Add support for branches (based loosely on X86/InstSelectSimple).
Add support for not visiting phi nodes in the first pass.
Add support for loading bools.
Flesh out support for stores.

llvm-svn: 13418
2004-05-08 04:21:17 +00:00
Alkis Evlogimenos 2a54b5d3e1 Add required header
llvm-svn: 13417
2004-05-08 03:50:03 +00:00
Alkis Evlogimenos 54a89b7c72 Remove unneeded header
llvm-svn: 13416
2004-05-08 03:49:35 +00:00
Chris Lattner 5f667a6f58 Implement folding of GEP's like:
%tmp.0 = getelementptr [50 x sbyte]* %ar, uint 0, int 5         ; <sbyte*> [#uses=2]
        %tmp.7 = getelementptr sbyte* %tmp.0, int 8             ; <sbyte*> [#uses=1]

together.  This patch actually allows us to simplify and generalize the code.

llvm-svn: 13415
2004-05-07 22:09:22 +00:00
Brian Gaeke 584308b71a Add support for copying bool constants to registers.
Disable the code that copies long constants to registers - it looks fishy.
Implement some simple casts: integral, smaller than longs, and equal-width
 or narrowing only.

llvm-svn: 13413
2004-05-07 21:39:30 +00:00
Chris Lattner a2dc6bf6e6 Codegen floating point stores of constants into integer instructions. This
allows us to compile:

store float 10.0, float* %P

into:
        mov DWORD PTR [%EAX], 1092616192

instead of:

.CPItest_0:                                     # float 0x4024000000000000
.long   1092616192      # float 10
...
        fld DWORD PTR [.CPItest_0]
        fstp DWORD PTR [%EAX]

llvm-svn: 13409
2004-05-07 21:18:15 +00:00
Chris Lattner cecf3f94a4 Make comparisons against the null pointer as efficient as integer comparisons
against zero.  In particular, don't emit:

        mov %ESI, 0
        cmp %ECX, %ESI

instead, emit:

       test %ECX, %ECX

llvm-svn: 13407
2004-05-07 19:55:55 +00:00
Chris Lattner d9e5813821 Fix PR336: The instcombine pass asserts when visiting load instruction
llvm-svn: 13400
2004-05-07 15:35:56 +00:00
John Criswell 2af0fd3ca8 Don't call getForwardedType() twice, as recommended by Chris.
llvm-svn: 13391
2004-05-06 22:15:47 +00:00
Chris Lattner a60f355c87 Implement the new cl::PositionalEatsArgs flag, refactor code a bit
llvm-svn: 13388
2004-05-06 22:04:31 +00:00
John Criswell f6709bc579 Fix for PR#330.
When looking at getelementptr instructions, make sure to use a forwarded
type.  We want to do this because a DerivedType may drop its uses and then
refine its users, who may then use another user who hasn't been refined yet.
By getting the forwarded type, we always ensure that we're looking at a
Type that isn't in a halfway refined state.

Now, I should be able to put this stuff in PATypeHandle, but it doesn't work
for some reason.  This should do for now.

llvm-svn: 13386
2004-05-06 21:18:08 +00:00
Chris Lattner 991425ae70 numeric_limits::infinity() apparently does not work on all systems. As a
workaround, use the C HUGE_VAL macro instead.

llvm-svn: 13377
2004-05-06 16:25:59 +00:00
Brian Gaeke e330adf842 Move the stuff that fixes the size, orientation & fonts of graphs to
the debugging functions that call "dot". These fixed settings have
various problems: for example, the fixed size that is set in the graph
traits classes is not appropriate for turning the dot file into a PNG,
and if TrueType font rendering is being used, the 'Courier' TrueType font
may not be installed. It seems easy enough to specify these things on the
command line, anyhow.

llvm-svn: 13366
2004-05-05 06:10:06 +00:00
Brian Gaeke 706bd5bf2b Apply simplification suggested by Chris: why assign() when operator = will do?
llvm-svn: 13364
2004-05-04 22:02:41 +00:00
John Criswell 987ad1945d Fixed inconsistent indentation.
llvm-svn: 13363
2004-05-04 21:46:05 +00:00
Brian Gaeke d26074eef1 Missing piece of fix for Bug 333
llvm-svn: 13362
2004-05-04 21:41:45 +00:00
Brian Gaeke f2ff5dd442 Correctly mangle function names when they are used as part of a
constant pool member's name.
This is intended to address Bug 333.

Also, fix an anachronistic usage of "M" as a parameter of type Function *.

llvm-svn: 13357
2004-05-04 21:09:02 +00:00
Brian Gaeke b3a9a0fcbd Add "Args" optional argument to AbstractInterpreter factory methods, which
fills in a ToolArgs vector in the AbstractInterpreter if it is set. This
ToolArgs vector is used to pass additional arguments to LLI and/or LLC.
This is intended to address Bug 40.

Also, make -debug-only=toolrunner work for the LLC and CBE
AbstractInterpreters.

llvm-svn: 13356
2004-05-04 21:09:01 +00:00
Chris Lattner c6f601310f Remove unneeded check
llvm-svn: 13355
2004-05-04 19:35:11 +00:00
Chris Lattner 22df9a59b4 Improve signed division by power of 2 *dramatically* from this:
div:
        mov %EDX, DWORD PTR [%ESP + 4]
        mov %ECX, 64
        mov %EAX, %EDX
        sar %EDX, 31
        idiv %ECX
        ret

to this:

div:
        mov %EAX, DWORD PTR [%ESP + 4]
        mov %ECX, %EAX
        sar %ECX, 5
        shr %ECX, 26
        mov %EDX, %EAX
        add %EDX, %ECX
        sar %EAX, 6
        ret

Note that the intel compiler is currently making this:

div:
        movl      4(%esp), %edx                                 #3.5
        movl      %edx, %eax                                    #4.14
        sarl      $5, %eax                                      #4.14
        shrl      $26, %eax                                     #4.14
        addl      %edx, %eax                                    #4.14
        sarl      $6, %eax                                      #4.14
        ret                                                     #4.14

Which has one less register->register copy.  (hint hint alkis :)

llvm-svn: 13354
2004-05-04 19:33:58 +00:00
Brian Gaeke 600f2045a9 Add stub support for reading BBTraces.
llvm-svn: 13352
2004-05-04 17:11:14 +00:00
Chris Lattner 9490849028 Do not mark instructions in unreachable sections of the function as live.
This fixes PR332 and ADCE/2004-05-04-UnreachableBlock.llx

llvm-svn: 13349
2004-05-04 17:00:46 +00:00
Brian Gaeke 34c13fbe94 Share ProfilingType enum with the C profiling runtime libraries.
llvm-svn: 13346
2004-05-04 16:53:07 +00:00
Chris Lattner 8c22ece232 Improve code generated for integer multiplications by 2,3,5,9
llvm-svn: 13342
2004-05-04 15:47:14 +00:00
Chris Lattner dd1a86d858 Minor efficiency tweak, suggested by Patrick Meredith
llvm-svn: 13341
2004-05-04 15:19:33 +00:00
Brian Gaeke 5237476f75 Fix typo
llvm-svn: 13340
2004-05-03 23:52:07 +00:00
Brian Gaeke e96196081e In InsertProfilingInitCall(), make it legal to pass in a null array, in
which case you'll get a null array and zero passed to the profiling function.

llvm-svn: 13336
2004-05-03 22:06:33 +00:00
Brian Gaeke 088dd3e121 Add initial implementation of basic-block tracing instrumentation pass.
llvm-svn: 13335
2004-05-03 22:06:32 +00:00
Chris Lattner 6942946132 Fix a problem with double freeing memory. For some reason, CallGraph is not
acting like a normal pass.  :(

llvm-svn: 13318
2004-05-02 16:06:18 +00:00
Chris Lattner 929291aabb Plug a minor memory leak
llvm-svn: 13317
2004-05-02 07:31:34 +00:00
Chris Lattner be6f06818c Do not clone arbitrary condition instructions.
llvm-svn: 13316
2004-05-02 05:19:36 +00:00
Chris Lattner 51a6dbcb65 Do not infinitely "unroll" single BB loops.
llvm-svn: 13315
2004-05-02 05:02:03 +00:00
Chris Lattner 1e94ed606e Dont' merge terminators that are needed to select PHI node values.
llvm-svn: 13312
2004-05-02 01:00:44 +00:00
Chris Lattner 2e93c4275e Implement SimplifyCFG/branch-cond-merge.ll
Turning "if (A < B && B < C)" into "if (A < B & B < C)"

llvm-svn: 13311
2004-05-01 23:35:43 +00:00
Chris Lattner 63d75af920 Make sure to reprocess instructions used by deleted instructions to avoid
missing opportunities for combination.

llvm-svn: 13309
2004-05-01 23:27:23 +00:00
Chris Lattner b643a9e675 Make sure the instruction combiner doesn't lose track of instructions
when replacing them, missing the opportunity to do simplifications

llvm-svn: 13308
2004-05-01 23:19:52 +00:00
Chris Lattner 4cbd160b45 Fix my missing parens
llvm-svn: 13307
2004-05-01 22:41:51 +00:00
Chris Lattner 88da6f7b52 Implement SimplifyCFG/branch-cond-prop.ll
llvm-svn: 13306
2004-05-01 22:36:37 +00:00
Chris Lattner 7b0a2046d4 Remove unused #include
llvm-svn: 13304
2004-05-01 21:29:16 +00:00
Chris Lattner acbf0c84de Iterate over the Machine CFG that Brian added instead of the LLVM CFG.
Look at all of the pretty minuses. :)

llvm-svn: 13303
2004-05-01 21:27:53 +00:00
Chris Lattner 8c0bc68910 Operate on the Machine CFG instead of on the LLVM CFG
llvm-svn: 13302
2004-05-01 21:24:39 +00:00
Chris Lattner c49a9a5d76 Stop LiveVariables from using BasicBlocks as part of the mapping, instead
use MachineBasicBlocks.  To do this, we traverse the Machine CFG instead of
the LLVM CFG, which is also *MUCH* more efficient by having fewer levels of
indirections and mappings.

llvm-svn: 13301
2004-05-01 21:24:24 +00:00
Chris Lattner 490e804a4e Add a constructor that got lost
llvm-svn: 13297
2004-05-01 11:17:13 +00:00
Brian Gaeke 2d7efbbb93 Generalize the strlen size_t hack, for the benefit of the other external
functions with wrappers that either take or return size_ts.

llvm-svn: 13296
2004-05-01 06:42:15 +00:00
Tanya Lattner 6ebf67f8b6 Removing MachineResource class.
llvm-svn: 13291
2004-04-30 20:40:38 +00:00
Chris Lattner 652064e3b8 Fix a major pessimization in the instcombiner. If an allocation instruction
is only used by a cast, and the casted type is the same size as the original
allocation, it would eliminate the cast by folding it into the allocation.

Unfortunately, it was placing the new allocation instruction right before
the cast, which could pull (for example) alloca instructions into the body
of a function.  This turns statically allocatable allocas into expensive
dynamically allocated allocas, which is bad bad bad.

This fixes the problem by placing the new allocation instruction at the same
place the old one was, duh. :)

llvm-svn: 13289
2004-04-30 04:37:52 +00:00
Misha Brukman 372d5bc9ab Wrapped code and comments at 80 cols; doxygenified some comments.
llvm-svn: 13264
2004-04-29 04:05:30 +00:00
Misha Brukman a70ae90722 Reorder #includes as per style guide.
llvm-svn: 13263
2004-04-29 04:04:47 +00:00
Misha Brukman da546eac70 class AssemblyWriter:
* Make contained ostream pointer, not reference
* Allow setting of that ostream via setStream()

class CachedWriter:
* setStream() in turn calls setStream() on the AssemblyWriter

llvm-svn: 13247
2004-04-28 19:24:28 +00:00
Misha Brukman 7e66438579 Send text and numbers directly to CachedWriter's contained ostream.
llvm-svn: 13243
2004-04-28 18:52:43 +00:00
Misha Brukman 1846321345 Squelch compile-time warning (profile build).
llvm-svn: 13228
2004-04-28 15:32:09 +00:00
Misha Brukman 4685e26bc7 * Add ability to print out type as symbolic
* Add Module accessor to AssemblyWriter

llvm-svn: 13227
2004-04-28 15:31:21 +00:00
Brian Gaeke 4390e4a7fc Make RequiresFPRegKill() take a MachineBasicBlock arg.
In InsertFPRegKills(), just check the MachineBasicBlock for successors
instead of its corresponding BasicBlock.

llvm-svn: 13213
2004-04-28 04:45:55 +00:00
Brian Gaeke 33ff118407 In InsertFPRegKills(), use the machine-CFG itself rather than the
LLVM CFG when trying to find the successors of BB.

llvm-svn: 13212
2004-04-28 04:34:16 +00:00
Brian Gaeke 24ec85689b Update the machine-CFG edges whenever we see a branch.
llvm-svn: 13211
2004-04-28 04:19:37 +00:00
Brian Gaeke 444a03b77a Integrate the rest of my random sparcv9 scribblings into this file
llvm-svn: 13204
2004-04-27 22:04:03 +00:00
Chris Lattner f011b7dfe6 Fix warning building in optimized mode
llvm-svn: 13190
2004-04-27 18:24:38 +00:00
Chris Lattner 2d3a7a6ff0 Changes to fix up the inst_iterator to pass to boost iterator checks. This
patch was graciously contributed by Vladimir Prus.

llvm-svn: 13185
2004-04-27 15:13:33 +00:00
Brian Gaeke 104341f31e Add functions that return instances of these printer passes
llvm-svn: 13175
2004-04-26 16:27:08 +00:00
Chris Lattner f374b3f304 If an object is not in the scalar map then it must be a global from another
graph.

llvm-svn: 13173
2004-04-26 14:44:08 +00:00
Chris Lattner e20c334e65 Instcombine X/-1 --> 0-X
llvm-svn: 13172
2004-04-26 14:01:59 +00:00
Brian Gaeke 03cac379bd Fix file header comments and include guards -- many files have been moved or
renamed since they were last spiffed up, or they just never had proper comments
in the first place.

llvm-svn: 13148
2004-04-25 07:04:49 +00:00
Brian Gaeke 42d321ab66 Add a getRegisterInfo() accessor just like on the X86 target.
llvm-svn: 13147
2004-04-25 06:32:28 +00:00
Brian Gaeke 4ec08db77c Regularize file header comment and include guard.
Include SparcV9RegisterInfo.h.
Add a getRegisterInfo() accessor and SparcV9RegisterInfo instance, just like
on the X86 target.

llvm-svn: 13146
2004-04-25 06:32:16 +00:00
Brian Gaeke f70544c583 Add MRegisterInfo subclass for the SparcV9 target (containing only stub
functions for now). This automatically turns on the printing of machine
registers using their own real names, instead of goofy things like %mreg(42),
and allows us to migrate code incrementally to the new interface as we see fit.

The register file description it uses is hand-written, so that the register
numbers will match the ones that the SparcV9 target already uses.
Perhaps someday we'll tablegen it.

llvm-svn: 13145
2004-04-25 06:32:05 +00:00
Misha Brukman 3596f0a180 * Allow aggregating extracted function arguments (controlled by flag)
* Commandline option (for now) controls that flag that is passed in

llvm-svn: 13141
2004-04-23 23:54:17 +00:00
Brian Gaeke ced65e8792 Fix a typo.
llvm-svn: 13136
2004-04-23 21:45:02 +00:00
Chris Lattner 83cd87efcd Move the scev expansion code into this pass, where it belongs. There is
still room for cleanup, but at least the code modification is out of the
analysis now.

llvm-svn: 13135
2004-04-23 21:29:48 +00:00
Chris Lattner 05ef97f994 Eliminate all of the SCEV Expansion code which is really part of the
IndVars pass, not part of SCEV *analysis*.

llvm-svn: 13134
2004-04-23 21:29:03 +00:00
Brian Gaeke 0b65f8f582 Merge TargetRegInfo.h into SparcV9RegInfo.h, which is its only subclass.
This prepares us to be able to de-virtualize and de-abstract it, and
take the register allocator bits out and move them into the register allocator
proper...

llvm-svn: 13127
2004-04-23 18:15:48 +00:00
Brian Gaeke 71509a98c5 Include SparcV9RegInfo.h instead of TargetRegInfo.h.
llvm-svn: 13126
2004-04-23 18:15:47 +00:00
Brian Gaeke a411e07db0 Include SparcV9RegInfo.h instead of TargetRegInfo.h. This serves as a bit of
documentation that this module needs to be made independent of the
register file description of the current target.

llvm-svn: 13125
2004-04-23 18:15:46 +00:00
Brian Gaeke fbd43e43a7 Get rid of the old byte-at-a-time emission code used when the Sparc JIT was
being tested on X86, as per Chris's request.

llvm-svn: 13124
2004-04-23 18:10:38 +00:00
Brian Gaeke ad373c8576 Go back to the interpreter main loop after performing intrinsic lowering,
because 1) the first instruction might not be a call site, and
2) CS and SF.Caller were not getting set to point to the new call site
anyway (resulting in a crash on e.g. call %llvm.memset).

llvm-svn: 13122
2004-04-23 18:05:28 +00:00
Brian Gaeke 6e102a7edd Use emitWordAt() to emit forward-branch fixups.
llvm-svn: 13120
2004-04-23 17:11:16 +00:00
Brian Gaeke fe277c2809 Emit SPARC machine code a word at a time instead of a byte at a time.
Use emitWordAt() to emit forward-branch fixups.

llvm-svn: 13119
2004-04-23 17:11:15 +00:00
Brian Gaeke 0c4fb283f3 Implement emitWordAt() for the JIT emitter.
llvm-svn: 13118
2004-04-23 17:11:14 +00:00
Brian Gaeke 4aaa9c603a Implement emitWordAt() for the debug emitter and the file printer emitter. (I
am not so sure about the file printer emitter, but the debug emitter change
should be harmless.)

llvm-svn: 13117
2004-04-23 17:11:13 +00:00
Misha Brukman 98aa516a9c Clarify the logic: the flag is renamed to `deleteFn' to signify it will delete
the function instead of isolating it. This also means the condition is reversed.

llvm-svn: 13112
2004-04-22 23:00:51 +00:00
Misha Brukman e0682426f0 Add a flag to choose between isolating a function or deleting the function from
the Module. The default behavior keeps functionality as before: the chosen
function is the one that remains.

llvm-svn: 13111
2004-04-22 22:52:22 +00:00
Chris Lattner c27302c79f Disable a previous patch that was causing indvars to loop infinitely :(
llvm-svn: 13108
2004-04-22 15:12:36 +00:00
Chris Lattner c1a682dda0 Fix an extremely serious thinko I made in revision 1.60 of this file.
llvm-svn: 13106
2004-04-22 14:59:40 +00:00
Chris Lattner af532f27e7 Implement a todo, rewriting all possible scev expressions inside of the
loop.  This eliminates the extra add from the previous case, but it's
not clear that this will be a performance win overall.  Tommorows test
results will tell. :)

llvm-svn: 13103
2004-04-21 23:36:08 +00:00
Chris Lattner fb9a299f68 This code really wants to iterate over the OPERANDS of an instruction, not
over its USES.  If it's dead it doesn't have any uses!  :)

Thanks to the fabulous and mysterious Bill Wendling for pointing this out.  :)

llvm-svn: 13102
2004-04-21 22:29:37 +00:00
Chris Lattner dc7cc35088 Implement a fixme. The helps loops that have induction variables of different
types in them.  Instead of creating an induction variable for all types, it
creates a single induction variable and casts to the other sizes.  This generates
this code:

no_exit:                ; preds = %entry, %no_exit
        %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ]            ; <uint> [#uses=4]
***     %j.0.0 = cast uint %indvar to short             ; <short> [#uses=1]
        %indvar = cast uint %indvar to int              ; <int> [#uses=1]
        %tmp.7 = getelementptr short* %P, uint %indvar          ; <short*> [#uses=1]
        store short %j.0.0, short* %tmp.7
        %inc.0 = add int %indvar, 1             ; <int> [#uses=2]
        %tmp.2 = setlt int %inc.0, %N           ; <bool> [#uses=1]
        %indvar.next = add uint %indvar, 1              ; <uint> [#uses=1]
        br bool %tmp.2, label %no_exit, label %loopexit

instead of:

no_exit:                ; preds = %entry, %no_exit
        %indvar = phi ushort [ %indvar.next, %no_exit ], [ 0, %entry ]          ; <ushort> [#uses=2]
***     %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ]            ; <uint> [#uses=3]
        %indvar = cast uint %indvar to int              ; <int> [#uses=1]
        %indvar = cast ushort %indvar to short          ; <short> [#uses=1]
        %tmp.7 = getelementptr short* %P, uint %indvar          ; <short*> [#uses=1]
        store short %indvar, short* %tmp.7
        %inc.0 = add int %indvar, 1             ; <int> [#uses=2]
        %tmp.2 = setlt int %inc.0, %N           ; <bool> [#uses=1]
        %indvar.next = add uint %indvar, 1
***     %indvar.next = add ushort %indvar, 1
        br bool %tmp.2, label %no_exit, label %loopexit

This is an improvement in register pressure, but probably doesn't happen that
often.

The more important fix will be to get rid of the redundant add.

llvm-svn: 13101
2004-04-21 22:22:01 +00:00
Chris Lattner be8bb804c5 Fix an incredibly nasty iterator invalidation problem. I am too spoiled by ilists :)
Eventually it would be nice if CallGraph maintained an ilist of CallGraphNode's instead
of a vector of pointers to them, but today is not that day.

llvm-svn: 13100
2004-04-21 20:44:33 +00:00
Misha Brukman 3bcead7201 I'm allergic to the word `stuff'.
llvm-svn: 13096
2004-04-21 18:27:56 +00:00
Brian Gaeke 376ac1bed5 Make SparcV9RegInfo::getRegType() return the right answer for registers
of IntCC, FloatCC, and Special types.

Make SparcV9RegInfo::getRegClassIDOfRegType() return the right answer
if you ask for the class corresponding to SpecialRegType.

llvm-svn: 13095
2004-04-21 17:53:58 +00:00
Alkis Evlogimenos f68f40ea42 Include cerrno (gcc-3.4 fix)
llvm-svn: 13091
2004-04-21 16:11:40 +00:00
Chris Lattner a9691fe70d Fix typeo
llvm-svn: 13089
2004-04-21 14:23:18 +00:00
Chris Lattner c87784f1fc REALLY fix PR324: don't delete linkonce functions until after the SCC traversal
is done, which avoids invalidating iterators in the SCC traversal routines

llvm-svn: 13088
2004-04-20 22:06:53 +00:00
Chris Lattner 99504890b7 Pass the callgraph not the module
llvm-svn: 13087
2004-04-20 21:52:26 +00:00
Chris Lattner 8d0838130c Add the ability for SCC passes to initialize and finalize themselves
llvm-svn: 13084
2004-04-20 21:30:06 +00:00
Chris Lattner c1aa21f5a7 Fix PR325
llvm-svn: 13081
2004-04-20 20:26:03 +00:00
Chris Lattner 514934051a Fix PR324 and testcase: Inline/2004-04-20-InlineLinkOnce.llx
llvm-svn: 13080
2004-04-20 20:20:59 +00:00
Brian Gaeke a2f66db6c4 Make it legal to ask for the type of a specialreg
llvm-svn: 13078
2004-04-20 20:12:57 +00:00
Chris Lattner 2b2d7a99be Add support for the select instruction
llvm-svn: 13076
2004-04-20 16:43:21 +00:00
Brian Gaeke 6c272a93bb Make it legal to request a load or store of %fsr.
llvm-svn: 13073
2004-04-19 19:12:12 +00:00
Brian Gaeke 755651df27 Regularize include guards and remove some excess whitespace.
llvm-svn: 13071
2004-04-19 18:53:44 +00:00
Brian Gaeke 2fd2536ea8 Tighten up SparcV9FloatCCRegClass::getRegName()'s assertion - if you ask it for
the name of %fsr (as the comment in SparcV9RegClassInfo.h used to suggest)
you would walk off the end of the FloatCCRegName array.

llvm-svn: 13070
2004-04-19 18:53:43 +00:00
Brian Gaeke 85cb77737c Regularize include guards, remove some excess whitespace and fix some comments.
Remove the extra %fsr register from SparcV9FloatCCRegClass.

llvm-svn: 13069
2004-04-19 18:53:42 +00:00
Chris Lattner f48f777d4c Initial checkin of a simple loop unswitching pass. It still needs work,
but it's a start, and seems to do it's basic job.

llvm-svn: 13068
2004-04-19 18:07:02 +00:00
Chris Lattner 663ebc3ec6 It's not just a printer, it's actually an analysis too
llvm-svn: 13064
2004-04-19 03:42:32 +00:00
Chris Lattner 32447c55fe Remove code to update loop depths
llvm-svn: 13058
2004-04-19 03:02:09 +00:00
Chris Lattner bc02177fdc Add #include
llvm-svn: 13057
2004-04-19 03:01:23 +00:00
Chris Lattner fc44a25bcb Move isLoopInvariant to the Loop class
llvm-svn: 13051
2004-04-18 22:46:08 +00:00
Chris Lattner 26ba2f5fe8 Add new method
llvm-svn: 13050
2004-04-18 22:45:27 +00:00
Chris Lattner 827826320d Correct rewriting of exit blocks after my last patch
llvm-svn: 13048
2004-04-18 22:27:10 +00:00
Chris Lattner d6ce359d3b Fix computation of exit blocks
llvm-svn: 13047
2004-04-18 22:21:41 +00:00
Chris Lattner 35eaa55cfc Loop exit sets are no longer explicitly held, they are dynamically computed on demand.
llvm-svn: 13046
2004-04-18 22:15:13 +00:00
Chris Lattner d72c3eb54e Change the ExitBlocks list from being explicitly contained in the Loop
structure to being dynamically computed on demand.  This makes updating
loop information MUCH easier.

llvm-svn: 13045
2004-04-18 22:14:10 +00:00
Chris Lattner d15250240c Reduce the unrolling limit
llvm-svn: 13040
2004-04-18 18:06:14 +00:00
Chris Lattner 30ae18155d If the preheader of the loop was the entry block of the function, make sure
that the exit block of the loop becomes the new entry block of the function.

This was causing a verifier assertion on 252.eon.

llvm-svn: 13039
2004-04-18 17:38:42 +00:00
Chris Lattner 230bcb6b35 Be much more careful about how we update instructions outside of the loop
using instructions inside of the loop.  This should fix the MishaTest failure
from last night.

llvm-svn: 13038
2004-04-18 17:32:39 +00:00
Chris Lattner e375a4fdc2 Implement method
llvm-svn: 13036
2004-04-18 06:54:48 +00:00
Chris Lattner 4d52e1e401 After unrolling our single basic block loop, fold it into the preheader and exit
block.  The primary motivation for doing this is that we can now unroll nested loops.

This makes a pretty big difference in some cases.  For example, in 183.equake,
we are now beating the native compiler with the CBE, and we are a lot closer
with LLC.

I'm now going to play around a bit with the unroll factor and see what effect
it really has.

llvm-svn: 13034
2004-04-18 06:27:43 +00:00
Chris Lattner f2cc841619 Fix a bug: this does not preserve the CFG!
While we're at it, add support for updating loop information correctly.

llvm-svn: 13033
2004-04-18 05:38:37 +00:00
Chris Lattner 1472c63fb9 Add a new method, add a check missing that caused a segfault if a loop didn't
have a canonical indvar

llvm-svn: 13032
2004-04-18 05:38:05 +00:00
Chris Lattner 946b255977 Initial checkin of a simple loop unroller. This pass is extremely basic and
limited.  Even in it's extremely simple state (it can only *fully* unroll single
basic block loops that execute a constant number of times), it already helps improve
performance a LOT on some benchmarks, particularly with the native code generators.

llvm-svn: 13028
2004-04-18 05:20:17 +00:00
Chris Lattner c14da9600b Make the tail duplication threshold accessible from the command line instead of hardcoded
llvm-svn: 13025
2004-04-18 00:52:43 +00:00
Chris Lattner ca96cee67b Fix a memory leak. We leaked the vector holding the entries in switch tables.
llvm-svn: 13023
2004-04-17 23:49:15 +00:00
Chris Lattner dd73047673 Add the ability to compute exit values for complex loop using unanalyzable
operations.  This allows us to compile this testcase:

int main() {
        int h = 1;
         do h = 3 * h + 1; while (h <= 256);
        printf("%d\n", h);
        return 0;
}

into this:

int %main() {
entry:
        call void %__main( )
        %tmp.6 = call int (sbyte*, ...)* %printf( sbyte* getelementptr ([4 x sbyte]*  %.str_1, long 0, long 0), int 364 )        ; <int> [#uses=0]
        ret int 0
}

This testcase was taken directly from 256.bzip2, believe it or not.

This code is not as general as I would like.  Next up is to refactor it
a bit to handle more cases.

llvm-svn: 13019
2004-04-17 22:58:41 +00:00
Chris Lattner a814080025 If the loop executes a constant number of times, try a bit harder to replace
exit values.

llvm-svn: 13018
2004-04-17 18:44:09 +00:00
Chris Lattner 4021d1af5a Add the ability to compute trip counts that are only controlled by constants
even if the loop is using expressions that we can't compute as a closed-form.
This allows us to calculate that this function always returns 55:

int test() {
  double X;
  int Count = 0;
  for (X = 100; X > 1; X = sqrt(X), ++Count)
    /*empty*/;
  return Count;
}

And allows us to compute trip counts for loops like:

        int h = 1;
         do h = 3 * h + 1; while (h <= 256);

(which occurs in bzip2), and for this function, which occurs after inlining
and other optimizations:

int popcount()
{
   int x = 666;
  int result = 0;
  while (x != 0) {
    result = result + (x & 0x1);
    x = x >> 1;
  }
  return result;
}

We still cannot compute the exit values of result or h in the two loops above,
which means we cannot delete the loop, but we are getting closer.  Being able to
compute a constant trip count for these two loops will allow us to unroll them
completely though.

llvm-svn: 13017
2004-04-17 18:36:24 +00:00
Chris Lattner 1e9ac1a45e Fix a HUGE pessimization on X86. The indvars pass was taking this
(familiar) function:

int _strlen(const char *str) {
    int len = 0;
    while (*str++) len++;
    return len;
}

And transforming it to use a ulong induction variable, because the type of
the pointer index was left as a constant long.  This is obviously very bad.

The fix is to shrink long constants in getelementptr instructions to intptr_t,
making the indvars pass insert a uint induction variable, which is much more
efficient.

Here's the before code for this function:

int %_strlen(sbyte* %str) {
entry:
        %tmp.13 = load sbyte* %str              ; <sbyte> [#uses=1]
        %tmp.24 = seteq sbyte %tmp.13, 0                ; <bool> [#uses=1]
        br bool %tmp.24, label %loopexit, label %no_exit

no_exit:                ; preds = %entry, %no_exit
***     %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ]            ; <uint> [#uses=2]
***     %indvar = phi ulong [ %indvar.next, %no_exit ], [ 0, %entry ]           ; <ulong> [#uses=2]
        %indvar1 = cast ulong %indvar to uint           ; <uint> [#uses=1]
        %inc.02.sum = add uint %indvar1, 1              ; <uint> [#uses=1]
        %inc.0.0 = getelementptr sbyte* %str, uint %inc.02.sum          ; <sbyte*> [#uses=1]
        %tmp.1 = load sbyte* %inc.0.0           ; <sbyte> [#uses=1]
        %tmp.2 = seteq sbyte %tmp.1, 0          ; <bool> [#uses=1]
        %indvar.next = add ulong %indvar, 1             ; <ulong> [#uses=1]
        %indvar.next = add uint %indvar, 1              ; <uint> [#uses=1]
        br bool %tmp.2, label %loopexit.loopexit, label %no_exit

loopexit.loopexit:              ; preds = %no_exit
        %indvar = cast uint %indvar to int              ; <int> [#uses=1]
        %inc.1 = add int %indvar, 1             ; <int> [#uses=1]
        ret int %inc.1

loopexit:               ; preds = %entry
        ret int 0
}


Here's the after code:

int %_strlen(sbyte* %str) {
entry:
        %inc.02 = getelementptr sbyte* %str, uint 1             ; <sbyte*> [#uses=1]
        %tmp.13 = load sbyte* %str              ; <sbyte> [#uses=1]
        %tmp.24 = seteq sbyte %tmp.13, 0                ; <bool> [#uses=1]
        br bool %tmp.24, label %loopexit, label %no_exit

no_exit:                ; preds = %entry, %no_exit
***     %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ]            ; <uint> [#uses=3]
        %indvar = cast uint %indvar to int              ; <int> [#uses=1]
        %inc.0.0 = getelementptr sbyte* %inc.02, uint %indvar           ; <sbyte*> [#uses=1]
        %inc.1 = add int %indvar, 1             ; <int> [#uses=1]
        %tmp.1 = load sbyte* %inc.0.0           ; <sbyte> [#uses=1]
        %tmp.2 = seteq sbyte %tmp.1, 0          ; <bool> [#uses=1]
        %indvar.next = add uint %indvar, 1              ; <uint> [#uses=1]
        br bool %tmp.2, label %loopexit, label %no_exit

loopexit:               ; preds = %entry, %no_exit
        %len.0.1 = phi int [ 0, %entry ], [ %inc.1, %no_exit ]          ; <int> [#uses=1]
        ret int %len.0.1
}

llvm-svn: 13016
2004-04-17 18:16:10 +00:00
Chris Lattner 885a6eb74d Even if there are not any induction variables in the loop, if we can compute
the trip count for the loop, insert one so that we can canonicalize the exit
condition.

llvm-svn: 13015
2004-04-17 18:08:33 +00:00
Chris Lattner a43312d30b Add support for evaluation of exp/log/log10/pow
llvm-svn: 13011
2004-04-16 22:35:33 +00:00
Chris Lattner 284d3b0311 Fix some really nasty dominance bugs that were exposed by my patch to
make the verifier more strict.  This fixes building zlib

llvm-svn: 13002
2004-04-16 18:08:07 +00:00
Misha Brukman ede10c9185 Fix retriving parent Function.
llvm-svn: 13001
2004-04-16 17:37:12 +00:00
Brian Gaeke 174633b078 Include <cmath> for compatibility with gcc 3.0.x (the system compiler on
Debian.)

llvm-svn: 12986
2004-04-16 15:57:32 +00:00
Misha Brukman 0af4a9c12b Assert if deleting BasicBlock before removing it from Function.
llvm-svn: 12983
2004-04-16 15:47:21 +00:00
Chris Lattner 9e9b2b7474 Fix some of the strange CBE-only failures that happened last night.
llvm-svn: 12980
2004-04-16 06:03:17 +00:00
Chris Lattner 0377e4384f Make sure to check for a very bad class of errors: an instruction
that does not dominate all of its users, but is in the same basic block as
its users.  This class of error is what caused the mysterious CBE only
failures last night.

llvm-svn: 12979
2004-04-16 05:51:47 +00:00
Chris Lattner 82876bdb2a Bugpoint was not correctly capturing stderr! This caused it to "find" bugs
that didn't exist, missing the ones that do :(

llvm-svn: 12978
2004-04-16 05:35:58 +00:00
Chris Lattner 0328d75c83 Fix Inline/2004-04-15-InlineDeletesCall.ll
Basically we were using SimplifyCFG as a huge sledgehammer for a simple
optimization.  Because simplifycfg does so many things, we can't use it
for this purpose.

llvm-svn: 12977
2004-04-16 05:17:59 +00:00
Chris Lattner d7a559e353 Fix a bug in the previous checkin: if the exit block is not the same as
the back-edge block, we must check the preincremented value.

llvm-svn: 12968
2004-04-15 20:26:22 +00:00
Brian Gaeke 5bee0f3068 Give SparcV9CodeEmitter a head-of-file comment and a PassName.
llvm-svn: 12967
2004-04-15 20:23:13 +00:00
Chris Lattner 0cec5cb92c Change the canonical induction variable that we insert.
Instead of producing code like this:

Loop:
  X = phi 0, X2
  ...

  X2 = X + 1
  if (X != N-1) goto Loop

We now generate code that looks like this:

Loop:
  X = phi 0, X2
  ...

  X2 = X + 1
  if (X2 != N) goto Loop

This has two big advantages:
  1. The trip count of the loop is now explicit in the code, allowing
     the direct implementation of Loop::getTripCount()
  2. This reduces register pressure in the loop, and allows X and X2 to be
     put into the same register.

As a consequence of the second point, the code we generate for loops went
from:

.LBB2:  # no_exit.1
	...
        mov %EDI, %ESI
        inc %EDI
        cmp %ESI, 2
        mov %ESI, %EDI
        jne .LBB2 # PC rel: no_exit.1

To:

.LBB2:  # no_exit.1
	...
        inc %ESI
        cmp %ESI, 3
        jne .LBB2 # PC rel: no_exit.1

... which has two fewer moves, and uses one less register.

llvm-svn: 12961
2004-04-15 15:21:43 +00:00
Chris Lattner d9dc425376 add some helpful methods. Rearrange #includes to proper order
llvm-svn: 12960
2004-04-15 15:16:02 +00:00
Chris Lattner b4f681b42b Factor a bunch of classes out into a public header
llvm-svn: 12958
2004-04-15 15:07:24 +00:00
Chris Lattner a4e4a63856 Unbreak the build
llvm-svn: 12956
2004-04-15 14:17:43 +00:00
Chris Lattner d420fe63ea Implement a FIXME: if we're going to insert a cast, we might as well only
insert it once!

llvm-svn: 12955
2004-04-14 22:01:22 +00:00
John Criswell e3e2c91997 Remove code to adjust the iterator for llvm.readio and llvm.writeio.
The iterator is pointing at the next instruction which should not disappear
when doing the load/store replacement.

llvm-svn: 12954
2004-04-14 21:27:56 +00:00
Brian Gaeke 0174347d9a Fix typo.
llvm-svn: 12953
2004-04-14 21:21:56 +00:00
Chris Lattner 8a9fd94cfe This is a trivial tweak to the addrec insertion code: insert the increment
at the bottom of the loop instead of the top.  This reduces the number of
overlapping live ranges a lot, for example, eliminating a spill in an important
loop in 183.equake with linear scan.

I still need to make the exit comparison of the loop use the post-incremented
version of this variable, but this is an easy first step.

llvm-svn: 12952
2004-04-14 21:11:25 +00:00
Brian Gaeke aec2bcd63b Add a TargetData to the PassManager regardless of the TargetMachine.
This should unbreak the Sparc JIT again.

llvm-svn: 12949
2004-04-14 17:45:52 +00:00
John Criswell c4e72c9a0a Remove the return type check for llvm.readio. This check is done for all
functions and is not needed here.
Simplify the pointer type check per Chris's suggestions.

llvm-svn: 12945
2004-04-14 15:06:48 +00:00
John Criswell 0c654c6a4e Added code to verify that llvm.readio's pointer argument returns something
that matches its return type.

llvm-svn: 12944
2004-04-14 14:49:36 +00:00
John Criswell 23c48d63d6 Finish adding the llvm.readio and llvm.writeio intrinsics.
Sorry these didn't get in yesterday.

llvm-svn: 12942
2004-04-14 13:46:52 +00:00
Chris Lattner 6679e46b59 ADd a trivial instcombine: load null -> null
llvm-svn: 12940
2004-04-14 03:28:36 +00:00
Chris Lattner 0dc099c2b5 This is the real fix for Codegen/X86/2004-04-13-FPCMOV-Crash.llx which works
even when the "optimization" I added before is turned off.  It generates this
extremely pointless code:

test:
        fld QWORD PTR [%ESP + 4]
        mov %AL, 0
        test %AL, %AL
        fcmove %ST(0), %ST(0)
        ret

Good thing the optimizer will have removed this before code generation
anyway.  :)

llvm-svn: 12939
2004-04-14 02:42:32 +00:00
John Criswell beded72a08 Added support for the llvm.readio and llvm.writeio intrinsics.
On x86, memory operations occur in-order, so these are just lowered into
volatile loads and stores.

llvm-svn: 12936
2004-04-13 22:13:14 +00:00
Chris Lattner 9042e381d8 Implement a small optimization, which papers over the problem in
X86/2004-04-13-FPCMOV-Crash.llx

A more robust fix is to follow.

llvm-svn: 12935
2004-04-13 21:56:09 +00:00
Chris Lattner ff9362a8da Add SCCP support for constant folding calls, implementing:
test/Regression/Transforms/SCCP/calltest.ll

llvm-svn: 12921
2004-04-13 19:43:54 +00:00
Chris Lattner ca52d0468e Add a simple call constant propagation interface.
llvm-svn: 12919
2004-04-13 19:28:52 +00:00
Chris Lattner d0dc6d5295 Constant propagation should remove the dead instructions
llvm-svn: 12917
2004-04-13 19:28:20 +00:00
Brian Gaeke 6f6e4b9f59 I don't think we have to have 4 extra allocated (but unused) bytes on the stack.
llvm-svn: 12905
2004-04-13 18:28:37 +00:00
Brian Gaeke 969795b4ea I started working on casts, but I don't have anything compilable yet.
llvm-svn: 12903
2004-04-13 18:27:46 +00:00
Chris Lattner c71b096672 Emit the immediate form of in/out when possible.
Fix several bugs in the intrinsics:
  1. Make sure to copy the input registers before the instructions that use them
  2. Make sure to copy the value returned by 'in' out of EAX into the register
     it is supposed to be in.

This fixes assertions when using in/out and linear scan.

llvm-svn: 12896
2004-04-13 17:20:37 +00:00
Chris Lattner a340febe52 Add immediate forms of in/out. Use let to shorten lines
llvm-svn: 12895
2004-04-13 17:19:31 +00:00
Chris Lattner eaa28a29ae Add support for new instruction type
llvm-svn: 12894
2004-04-13 17:18:51 +00:00
Chris Lattner 27b2e2cdc0 Add support for the printImplicitDefsBefore flag
llvm-svn: 12893
2004-04-13 17:18:39 +00:00
Chris Lattner 89e959bb1f Fix LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll
LoopSimplify was not updating dominator frontiers correctly in some cases.

llvm-svn: 12890
2004-04-13 16:23:25 +00:00
Chris Lattner a6e22814ab Refactor code a bit to make it simpler and eliminate the goto
llvm-svn: 12888
2004-04-13 15:21:18 +00:00
Chris Lattner 8417052938 This patch addresses PR35: Loop simplify should reconstruct nested loops.
This is fairly straight-forward, but was a real nightmare to get just
perfect.  aarg.  :)

llvm-svn: 12884
2004-04-13 05:05:33 +00:00
Brian Gaeke bb0f2db881 We don't need to insert TargetData into the PassManager here.
llvm-svn: 12874
2004-04-12 21:46:31 +00:00
Alkis Evlogimenos 8f2df3aa3c Fix bug introduced in previous commit.
llvm-svn: 12872
2004-04-12 20:26:39 +00:00
Chris Lattner 55b7ef5a81 Add some methods that are useful for updating loop information.
llvm-svn: 12871
2004-04-12 20:26:17 +00:00
Alkis Evlogimenos 0ede7ec4f8 Correctly compute spill weights
llvm-svn: 12869
2004-04-12 17:39:20 +00:00
Alkis Evlogimenos b753c8c9c5 Print def lists a bit more compactly
llvm-svn: 12866
2004-04-12 15:57:58 +00:00
Chris Lattner be43544429 Actually update the call graph as the inliner changes it. This allows us to
execute other CallGraphSCCPasses after the inliner without crashing.

llvm-svn: 12861
2004-04-12 05:37:29 +00:00
Chris Lattner 8b6db18ac3 Change the call graph class to have TWO external nodes, making call graph
SCC passes much more useful.  In particular, this should fix the incredibly
stupid missed inlining opportunities that the inliner suffered from.

llvm-svn: 12860
2004-04-12 05:36:32 +00:00
Chris Lattner c9e37d7cc9 Hrm, operator new and new[] do not belong here. We should not CSE them! :)
llvm-svn: 12859
2004-04-12 05:16:42 +00:00
Chris Lattner 494a685449 Add support for removing invoke instructions
llvm-svn: 12858
2004-04-12 05:15:13 +00:00
Chris Lattner 08f201bee5 Stop printing Function*
llvm-svn: 12857
2004-04-12 04:06:56 +00:00
Chris Lattner d041dcd92f Simplify code a bit, and be sure to mark the external node as potentially throwing
llvm-svn: 12856
2004-04-12 04:06:38 +00:00
Chris Lattner a24f986333 Fix issues that the local allocator has dealing with instructions that implicitly use ST(0)
llvm-svn: 12855
2004-04-12 03:02:48 +00:00
Chris Lattner 2e2b0ceab9 No really, fix printing for LLC. I gotta get a way for CVS to whine at me if
I have unsaved emacs buffers, geeze...

llvm-svn: 12854
2004-04-12 01:52:04 +00:00
Chris Lattner ba1038e0f3 Correct printing for LLC and the encoding for the JIT
llvm-svn: 12853
2004-04-12 01:50:04 +00:00
Chris Lattner e407dbe9ff Use the fucomi[p] instructions to perform floating point comparisons instead
of the fucom[p][p] instructions.  This allows us to code generate this function

bool %test(double %X, double %Y) {
        %C = setlt double %Y, %X
        ret bool %C
}

... into:

test:
        fld QWORD PTR [%ESP + 4]
        fld QWORD PTR [%ESP + 12]
        fucomip %ST(1)
        fstp %ST(0)
        setb %AL
        movsx %EAX, %AL
        ret

where before we generated:

test:
        fld QWORD PTR [%ESP + 4]
        fld QWORD PTR [%ESP + 12]
        fucompp
**      fnstsw
**      sahf
        setb %AL
        movsx %EAX, %AL
        ret

The two marked instructions (which are the ones eliminated) are very bad,
because they serialize execution of the processor.  These instructions are
available on the PPRO and later, but since we already use cmov's we aren't
losing any portability.

I retained the old code for the day when we decide we want to support back
to the 386.

llvm-svn: 12852
2004-04-12 01:43:36 +00:00
Chris Lattner d1c7545322 Add support for the FUCOMIr instruction
llvm-svn: 12851
2004-04-12 01:39:15 +00:00
Chris Lattner 6c84d4ca44 Add two new instructions
llvm-svn: 12850
2004-04-12 01:38:55 +00:00
Chris Lattner 0fe57da8fa Fix a bug in my load/cast folding patch.
llvm-svn: 12849
2004-04-12 00:23:04 +00:00
Chris Lattner dc0105467a Adjust some comments, fix a bug in my previous patch
llvm-svn: 12848
2004-04-12 00:12:04 +00:00
Chris Lattner 07c1c11511 On X86, casting an integer to floating point requires going through memory.
If the source of the cast is a load, we can just use the source memory location,
without having to create a temporary stack slot entry.

Before we code generated this:

double %int(int* %P) {
        %V = load int* %P
        %V2 = cast int %V to double
        ret double %V2
}

into:

int:
        sub %ESP, 4
        mov %EAX, DWORD PTR [%ESP + 8]
        mov %EAX, DWORD PTR [%EAX]
        mov DWORD PTR [%ESP], %EAX
        fild DWORD PTR [%ESP]
        add %ESP, 4
        ret

Now we produce this:

int:
        mov %EAX, DWORD PTR [%ESP + 4]
        fild DWORD PTR [%EAX]
        ret

... which is nicer.

llvm-svn: 12846
2004-04-11 23:21:26 +00:00
Chris Lattner d4af820aad Implement folding of loads into floating point operations. This implements:
test/Regression/CodeGen/X86/fp_load_fold.llx

llvm-svn: 12844
2004-04-11 22:05:45 +00:00
Chris Lattner dcb750f015 Unify all of the code for floating point +,-,*,/ into one function
llvm-svn: 12842
2004-04-11 21:23:56 +00:00
Chris Lattner 80ba401602 This implements folding of constant operands into floating point operations
for mul and div.

Instead of generating this:

test_divr:
        fld QWORD PTR [%ESP + 4]
        fld QWORD PTR [.CPItest_divr_0]
        fdivrp %ST(1)
        ret

We now generate this:

test_divr:
        fld QWORD PTR [%ESP + 4]
        fdivr QWORD PTR [.CPItest_divr_0]
        ret

This code desperately needs refactoring, which will come in the next
patch.

llvm-svn: 12841
2004-04-11 21:09:14 +00:00
Chris Lattner e1efbc7c6c Restructure the mul/div/rem handling code to follow the pattern the other
instructions use.  This doesn't change any functionality except that long
constant expressions of these operations will now magically start working.

llvm-svn: 12840
2004-04-11 20:56:28 +00:00
Chris Lattner f7ed7df539 Codegen FP adds and subtracts with a constant more efficiently, generating:
fld QWORD PTR [%ESP + 4]
        fadd QWORD PTR [.CPItest_add_0]

instead of:

        fld QWORD PTR [%ESP + 4]
        fld QWORD PTR [.CPItest_add_0]
        faddp %ST(1)

I also intend to do this for mul & div, but it appears that I have to
refactor a bit of code before I can do so.

This is tested by: test/Regression/CodeGen/X86/fp_constant_op.llx

llvm-svn: 12839
2004-04-11 20:26:20 +00:00
Chris Lattner b6e0b58fbc Add some new instructions
llvm-svn: 12838
2004-04-11 20:24:15 +00:00
Chris Lattner 5b44472200 Relax assertion to make this function work with a broader class of instructions
llvm-svn: 12836
2004-04-11 20:21:06 +00:00
Chris Lattner 3f912a6f43 Two changes:
1. If an incoming argument is dead, don't load it from the stack
  2. Do not code gen noop copies at all (ie, cast int -> uint), not even to
     a move.  This should reduce register pressure for allocators that are
     unable to coallesce away these copies in some cases.

llvm-svn: 12835
2004-04-11 19:21:59 +00:00
Chris Lattner 403abb824f operator new & operator new[] do not kill any legal memory locations.
llvm-svn: 12833
2004-04-11 18:16:34 +00:00
Chris Lattner c5fad355f8 Allow clients to be more efficient.
llvm-svn: 12831
2004-04-11 16:43:07 +00:00
Chris Lattner 24cf0200c7 Fix a bug in my select transformation
llvm-svn: 12826
2004-04-11 01:39:19 +00:00
Chris Lattner 192e326cd3 Add a missing break, which caused a crash in an obscure situation
llvm-svn: 12825
2004-04-11 01:29:30 +00:00
Chris Lattner f16fe7206c Update the value numbering interface.
llvm-svn: 12824
2004-04-10 22:33:34 +00:00
Chris Lattner 623fba1107 Implement InstCombine/select.ll:test13*
llvm-svn: 12821
2004-04-10 22:21:27 +00:00
Chris Lattner cf4a996cba Implement InstCombine/add.ll:test20
Canonicalize add of sign bit constant into a xor

llvm-svn: 12819
2004-04-10 22:01:55 +00:00
Chris Lattner 69c4900512 Rewrite the GCSE pass to be *substantially* simpler, a bit more efficient,
and a bit more powerful

llvm-svn: 12817
2004-04-10 21:11:11 +00:00
Chris Lattner f9d9665138 Fix spurious warning in release mode
llvm-svn: 12816
2004-04-10 19:15:56 +00:00
Chris Lattner d450df05ba Silence a spurious warning
llvm-svn: 12815
2004-04-10 18:32:01 +00:00
Chris Lattner d95ef7eff0 Simplify code a bit, and fix a bug that was breaking perlbmk
llvm-svn: 12814
2004-04-10 18:06:21 +00:00
Chris Lattner 7ebfe61dc1 Fix a bug in my checkin last night that was breaking programs using invoke.
llvm-svn: 12813
2004-04-10 16:53:29 +00:00
Chris Lattner 5093213c40 Fix previous patch
llvm-svn: 12811
2004-04-10 07:27:48 +00:00
Chris Lattner 6149ac8991 Correctly update counters
llvm-svn: 12810
2004-04-10 07:02:02 +00:00
Chris Lattner 4a1b03c773 Add a couple of more functions that cannot access memory (the intrinsics) and
don't write to memory

llvm-svn: 12808
2004-04-10 06:55:27 +00:00
Chris Lattner cfa1adcdb8 Simplify code a bit, and use alias analysis to allow us to delete unused
call and invoke instructions that are known to not write to memory.

llvm-svn: 12807
2004-04-10 06:53:09 +00:00
Chris Lattner 56e4d3d8ad Implement select.ll:test12*
This transforms code like this:

   %C = or %A, %B
   %D = select %cond, %C, %A
into:
   %C = select %cond, %B, 0
   %D = or %A, %C

Since B is often a constant, the select can often be eliminated.  In any case,
this reduces the usage count of A, allowing subsequent optimizations to happen.

This xform applies when the operator is any of:
  add, sub, mul, or, xor, and, shl, shr

llvm-svn: 12800
2004-04-09 23:46:01 +00:00
Chris Lattner 0aa565647c Fold code like:
if (C)
    V1 |= V2;

into:
  Vx = V1 | V2;
  V1 = select C, V1, Vx

when the expression can be evaluated unconditionally and is *cheap* to
execute.  This limited form of if conversion is quite handy in lots of cases.
For example, it turns this testcase into straight-line code:

int in0 ; int in1 ; int in2 ; int in3 ;
int in4 ; int in5 ; int in6 ; int in7 ;
int in8 ; int in9 ; int in10; int in11;
int in12; int in13; int in14; int in15;
long output;

void mux(void) {
  output =
      (in0   ?  0x00000001 : 0) | (in1   ?  0x00000002 : 0) |
      (in2   ?  0x00000004 : 0) | (in3   ?  0x00000008 : 0) |
      (in4   ?  0x00000010 : 0) | (in5   ?  0x00000020 : 0) |
      (in6   ?  0x00000040 : 0) | (in7   ?  0x00000080 : 0) |
      (in8   ?  0x00000100 : 0) | (in9   ?  0x00000200 : 0) |
      (in10  ?  0x00000400 : 0) | (in11  ?  0x00000800 : 0) |
      (in12  ?  0x00001000 : 0) | (in13  ?  0x00002000 : 0) |
      (in14  ?  0x00004000 : 0) | (in15  ?  0x00008000 : 0) ;
}

llvm-svn: 12798
2004-04-09 22:50:22 +00:00
John Criswell 2b4c96e758 Reversed the order of the llvm.writeport() operands so that the value
is listed first and the address is listed second.

llvm-svn: 12795
2004-04-09 19:09:14 +00:00
Chris Lattner 183b336a54 Fold binary operators with a constant operand into select instructions
that have a constant operand.  This implements
add.ll:test19, shift.ll:test15*, and others that are not tested

llvm-svn: 12794
2004-04-09 19:05:30 +00:00
Chris Lattner cf7baf3519 Implement select.ll:test11
llvm-svn: 12793
2004-04-09 18:19:44 +00:00
Alkis Evlogimenos 237f203ca9 Add definition list to each live interval.
llvm-svn: 12791
2004-04-09 18:07:57 +00:00
John Criswell 2fc9983852 Changed assertions to error messages.
llvm-svn: 12787
2004-04-09 15:10:15 +00:00
John Criswell c28c3b625f Changes recommended by Chris:
InstSelectSimple.cpp:
  Change the checks for proper I/O port address size into an exit() instead
  of an assertion.  Assertions aren't used in Release builds, and handling
  this error should be graceful (not that this counts as graceful, but it's
  more graceful).

  Modified the generation of the IN/OUT instructions to have 0 arguments.
X86InstrInfo.td:
  Added the OpSize attribute to the 16 bit IN and OUT instructions.

llvm-svn: 12786
2004-04-08 22:39:13 +00:00
Chris Lattner e228ee5870 Implement InstCombine/cast-propagate.ll
llvm-svn: 12784
2004-04-08 20:39:49 +00:00
John Criswell 10db062d41 Added the llvm.readport and llvm.writeport intrinsics for x86. These do
I/O port instructions on x86.  The specific code sequence is tailored to
the parameters and return value of the intrinsic call.
Added the ability for implicit defintions to be printed in the Instruction
Printer.
Added the ability for RawFrm instruction to print implict uses and
defintions with correct comma output.  This required adjustment to some
methods so that a leading comma would or would not be printed.

llvm-svn: 12782
2004-04-08 20:31:47 +00:00
John Criswell 5201004ef9 Added the llvm.readport and llvm.writeport intrinsics.
The Verifier ensures that their parameters are of integral types and have
the correct sign, but it does not enforce any size restrictions because
such restrictions are platform dependent.

llvm-svn: 12781
2004-04-08 20:27:38 +00:00
Chris Lattner 3b3861d305 Implement ScalarRepl/select_promote.ll
llvm-svn: 12779
2004-04-08 19:59:34 +00:00
Chris Lattner 4d25c86b52 Remove the "really gross hacks" that are there to deal with recursive functions.
Now we collect all of the call sites we are interested in inlining, then inline
them.  This entirely avoids issues with trying to inline a call site we got by
inlining another call site.  This also eliminates iterator invalidation issues.

llvm-svn: 12770
2004-04-08 06:34:31 +00:00
Chris Lattner 1c631e813d Implement InstCombine/select.ll:test[7-10]
llvm-svn: 12769
2004-04-08 04:43:23 +00:00
Brian Gaeke 69ee7e1353 Don't include InstrSelectionSupport.h.
llvm-svn: 12766
2004-04-07 20:55:32 +00:00
Brian Gaeke c125664927 Move ChooseRegOrImmed() prototype here, from InstrSelectionSupport.h.
llvm-svn: 12765
2004-04-07 20:38:57 +00:00
Brian Gaeke 5c80118367 Don't include InstrSelectionSupport.h.
llvm-svn: 12764
2004-04-07 20:38:56 +00:00
Chris Lattner 2b2412d0c8 Implement test/Regression/Transforms/InstCombine/getelementptr_index.ll
llvm-svn: 12762
2004-04-07 18:38:20 +00:00
Brian Gaeke 8931345fe5 Fix insertion of SelectInsts.
llvm-svn: 12760
2004-04-07 18:31:47 +00:00
Brian Gaeke 85521d70dd Don't print [%reg + 0], just print [%reg]
llvm-svn: 12759
2004-04-07 17:33:56 +00:00
Brian Gaeke 6d62df5422 First version of code to handle loads. Stub function for handling stores.
llvm-svn: 12758
2004-04-07 17:29:37 +00:00
Brian Gaeke 989c04ab58 Support loading arguments from %I0...%I5 into virtual registers in
function prologues, and fix an off-by-one in visitCallInst that was
putting call args into the wrong registers.

llvm-svn: 12757
2004-04-07 17:04:09 +00:00
Brian Gaeke 7985e56cf9 It's setting up the call args right now, but on the callee side, it's
trying to get incoming args off the stack, instead of the %i0...%i6 regs,
which is wrong.

llvm-svn: 12756
2004-04-07 16:41:22 +00:00
Chris Lattner 74498e1066 Fix a bug Brian found.
llvm-svn: 12754
2004-04-07 16:16:11 +00:00
Chris Lattner bd58b3fbe9 This is a start on handling setcc instructions. As the comment notes, we
have no good way of handling this until the code generator is improved.
We should probably just emit V9 instructions in the meantime.

llvm-svn: 12745
2004-04-07 05:04:51 +00:00
Chris Lattner bb22d5a564 andd subcc instructions which is used to create the 'cmp' pseudo instruction
llvm-svn: 12744
2004-04-07 05:04:01 +00:00
Chris Lattner f6245bc8e9 Avoid emitting an extra copy on each 32-bit operation
llvm-svn: 12743
2004-04-07 04:36:53 +00:00
Brian Gaeke 4aac81435f Make generation of stack-slot loads and copies less ugly.
llvm-svn: 12742
2004-04-07 04:29:14 +00:00
Brian Gaeke 3675c30873 Fix bug in printing loads.
llvm-svn: 12741
2004-04-07 04:29:03 +00:00
Chris Lattner 42ffd2e32c Add support for shift instructions, wrap some long lines
llvm-svn: 12740
2004-04-07 04:27:16 +00:00
Chris Lattner 8406cf3046 Fix encoding of existing shift instructions, add rr shifts
llvm-svn: 12739
2004-04-07 04:26:57 +00:00
Chris Lattner fcdf82a19f Add a bunch more instructions
llvm-svn: 12737
2004-04-07 04:06:46 +00:00
Chris Lattner fd8212ef54 Merge my changes with brians
llvm-svn: 12736
2004-04-07 04:05:49 +00:00
Brian Gaeke 37f92b534f Add in some things I forgot, which Chris helpfully reminded me of...
llvm-svn: 12735
2004-04-07 04:05:12 +00:00
Brian Gaeke 322423181b Add support for the "Y" register, used by MUL & DIV.
llvm-svn: 12734
2004-04-07 04:01:11 +00:00