Commit Graph

604 Commits

Author SHA1 Message Date
Chris Lattner
aecb0627fa Make this work with renamed intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26482 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-03 01:30:23 +00:00
Andrew Lenharth
2f9859486a fix a bunch of alpha regressions. see bug 709
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26218 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 21:13:37 +00:00
Chris Lattner
e46f6e99a0 add a bunch more optimizations for unary double math functions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25530 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-23 06:24:46 +00:00
Chris Lattner
7070c5f241 Refactor/genericize this, no functionality change
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25525 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-23 05:57:36 +00:00
Chris Lattner
dac58ad983 Make iostream #inclusion explicit
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25514 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-22 23:32:06 +00:00
Chris Lattner
e05cf71616 Make this more efficient in the following ways:
1. Do not statically construct a map when the program starts up, this
   is expensive and cannot be optimized.  Instead, create a list.
2. Do not insert entries for all function in the module into a hashmap
   that lives the full life of the compiler.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25512 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-22 23:10:26 +00:00
Chris Lattner
0f9f8c3759 Several non-functionality changing changes:
1. Use the varargs version of getOrInsertFunction to simplify code.
2. remove #include
3. Reduce the number of #ifdef's.
4. remove extraneous vertical whitespace.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25508 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-22 22:35:08 +00:00
Reid Spencer
aa87e0523d For PR696:
Don't do floor->floorf conversion if floorf is not available. This checks
the compiler's host, not its target, which is incorrect for cross-compilers
Not sure that's important as we don't build many cross-compilers.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25456 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-19 08:36:56 +00:00
Chris Lattner
727552bb89 If not internalizing, don't mark llvm.global[cd]tors const, as a fix for a
hypothetical future boog.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25430 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-19 00:46:54 +00:00
Chris Lattner
ee9e14cb8a Don't internalize llvm.global[cd]tor unless there are uses of it. This
unbreaks front-ends that don't use __main (like the new CFE).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25429 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-19 00:40:39 +00:00
Chris Lattner
f91e97ae81 Clean up the FFS optimization code, and make it correctly create the appropriate
unsigned llvm.cttz.* intrinsic, fixing the 2005-05-11-Popcount-ffs-fls regression
last night.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25398 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-17 18:27:17 +00:00
Chris Lattner
432a205769 Let the inliner update the callgraph to reflect the changes it makes, instead
of doing it ourselves.  This fixes Transforms/Inline/2006-01-14-CallGraphUpdate.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25321 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-14 20:09:18 +00:00
Chris Lattner
ccca3ca85f Permit inlining functions that contain dynamic allocations now that
InlineFunction handles this case safely.  This implements
Transforms/Inline/dynamic_alloca_test.ll.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25288 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 19:35:43 +00:00
Chris Lattner
8acb249725 Fix 80 column violations
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25279 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 18:06:56 +00:00
Chris Lattner
4eb40df1a8 Pull inline methods out of the pass class definition to make it easier to
read the code.

Do not internalize debugger anchors.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25067 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-03 19:13:17 +00:00
Reid Spencer
2f1890792c Improve ResolveFunctions to:
a) use better local variable names (OldMT -> OldFT) where "M" is used to
   mean "Function" (perhaps it was previously "Method"?)
b) print out the module identifier in a warning message so that it is
   possible to track down in which module the error occurred.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24698 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-13 19:56:51 +00:00
Chris Lattner
6b44ba2803 Wrap a long line, never internalize llvm.used.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24602 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-05 05:07:38 +00:00
Nate Begeman
14b0529532 Add support alignment of allocation instructions.
Add support for specifying alignment and size of setjmp jmpbufs.

No targets currently do anything with this information, nor is it presrved
in the bytecode representation.  That's coming up next.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24196 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-05 09:21:28 +00:00
Alkis Evlogimenos
e9c6d36377 Stop using deprecated types
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23973 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-25 11:18:06 +00:00
Chris Lattner
f36aeedaa3 DONT_BUILD_RELINKED is gone and implied by BUILD_ARCHIVE now
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23940 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 02:26:13 +00:00
Chris Lattner
ab0ed3592b Only build .a file versions of these libraries, instead of .a and .o versions.
This should speed up build times.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23933 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 01:59:48 +00:00
Jeff Cohen
66c5fd6c53 When a function takes a variable number of pointer arguments, with a zero
pointer marking the end of the list, the zero *must* be cast to the pointer
type.  An un-cast zero is a 32-bit int, and at least on x86_64, gcc will
not extend the zero to 64 bits, thus allowing the upper 32 bits to be
random junk.

The new END_WITH_NULL macro may be used to annotate a such a function
so that GCC (version 4 or newer) will detect the use of un-casted zero
at compile time.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23888 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-23 04:37:20 +00:00
Chris Lattner
a27ea769eb Add an option to this pass. If it is set, we are allowed to internalize
all but main.  If it's not set, we can still internalize, but only if an
explicit symbol list is provided.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23783 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-18 06:29:22 +00:00
Chris Lattner
a48bc53cad Fold isascii into a simple comparison. This speeds up 197.parser by 7.4%,
bringing the LLC time down to the CBE time.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23521 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-29 06:17:27 +00:00
Chris Lattner
e9b6242780 remove a bunch of unneeded stuff, or self evident comments
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23519 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-29 06:16:11 +00:00
Chris Lattner
c330069e20 Implement a couple of memcmp folds from the todo list
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23517 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-29 04:54:20 +00:00
Chris Lattner
9a5582f251 Fix a regression in my previous patch, fixing GlobalOpt/2005-09-27-Crash.ll
and PR632.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23484 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 22:28:11 +00:00
Chris Lattner
a9ec8ab32b Add support for external calls that we know how to constant fold. This implements
ctor-list-opt.ll:CTOR8


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23465 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 05:02:43 +00:00
Chris Lattner
231308c545 Fix a bug where we would evaluate stores into linkonce objects which could be
potentially replaced at link-time.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23463 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 04:50:03 +00:00
Chris Lattner
cd27142cc8 Implement support for static constructors with calls in them. This is useful
because gccas runs globalopt before inlining.

This implements ctor-list-opt.ll:CTOR7


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23462 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 04:45:34 +00:00
Chris Lattner
8a7cc6e71c Refactor this code a bit, no functionality changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23460 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 04:27:01 +00:00
Chris Lattner
ff0c1ef9eb Remove some dead code. ctor evaluation subsumes empty ctor elim
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23453 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 20:38:20 +00:00
Chris Lattner
a22fdb0a37 Add support for alloca, implementing ctor-list-opt.ll:CTOR6
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23452 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 17:07:09 +00:00
Chris Lattner
aae4a1cd3f Add a debug printout, fix a crash on kc++
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23450 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 07:34:35 +00:00
Chris Lattner
798b4d5bb3 Implement loads/stores through GEP's of globals. This implements
ctor-list-opt.ll:CTOR5.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23449 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 06:52:44 +00:00
Chris Lattner
0b142e3920 Replace TraverseGEPInitializer with ConstantFoldLoadThroughGEPConstantExpr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23447 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 05:34:07 +00:00
Chris Lattner
562a055ca7 add a comment
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23442 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 05:16:34 +00:00
Chris Lattner
04de1cfb2b Add support for getelementptr, load, and correctly reject volatile stores.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23441 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 05:15:37 +00:00
Chris Lattner
cdf98bed96 Add support for br/brcond/switch and phi
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23439 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 04:57:38 +00:00
Chris Lattner
79c1101947 Add a simple interpreter to this code, allowing us to statically evaluate
global ctors that are simple enough.  This implements ctor-list-opt.ll:CTOR2.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23437 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 04:44:35 +00:00
Chris Lattner
db973e60ce factor some code into a InstallGlobalCtors method, add comments. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23435 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 02:31:18 +00:00
Chris Lattner
7d8e58f384 Make the global opt optimizer work on modules with a null terminator, by
accepting the null even with a non-65535 init prio


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23434 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 02:19:27 +00:00
Chris Lattner
b1ab458047 Factor this code out into a few methods.
Implement the start of global ctor optimization.  It is currently smart
enough to remove the global ctor for cases like this:

struct foo {
  foo() {}
} x;

... saving a bit of startup time for the program.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23433 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 01:43:45 +00:00
Chris Lattner
aebac50e77 Fix some logic I broke that caused a regression on
SimplifyLibCalls/2005-05-20-sprintf-crash.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23430 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-25 07:06:48 +00:00
Chris Lattner
5d735bf29b Simplify this code a bit by relying on recursive simplification. Support
sprintf("%s", P)'s that have uses.

s/hasNUses(0)/use_empty()/


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23425 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-24 22:17:06 +00:00
Chris Lattner
53249865ec Transform floor((double)FLT) -> (double)floorf(FLT), implementing
Regression/Transforms/SimplifyLibCalls/floor.ll.  This triggers 19 times in
177.mesa.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23017 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-24 17:22:17 +00:00
Chris Lattner
bbf728edeb All stats are "Number of ..."
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22694 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-07 20:02:04 +00:00
Chris Lattner
9cc5f42feb ConstantInt::get only works for arguments < 128.
SimplifyLibCalls probably has to be audited to make sure it does not make
this mistake elsewhere.  Also, if this code knows that the type will be
unsigned, obviously one arm of this is dead.

Reid, can you take a look into this further?


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22566 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-01 16:52:50 +00:00
Jeff Cohen
00b16889ab Eliminate all remaining tabs and trailing spaces.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22523 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-27 06:12:32 +00:00
John Criswell
46b8db2ec6 Doh! Forgot to LLVMify the style.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22312 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-29 15:57:50 +00:00
John Criswell
1d231ec0b0 Basic fix for PR#591; don't convert an fprintf() to an fwrite() if there
is a mismatch in their character type pointers (i.e. fprintf() prints an
array of ubytes while fwrite() takes an array of sbytes).
We can probably do better than this (such as casting the ubyte to an
sbyte).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22310 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-29 15:03:18 +00:00
Chris Lattner
543a02704e add a debug type
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22277 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-24 16:00:46 +00:00
Reid Spencer
134d2e4af8 Fix a problem with the strcmp optimization checking the wrong string and
not casting to the correct type.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22250 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-18 17:46:28 +00:00
Chris Lattner
d286b245be Fix PR575, patch provided by John Mellor-Crummey. Thanks!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22223 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-15 22:49:30 +00:00
Chris Lattner
553ca52623 Do not promote globals only used by main to locals if there are constantexprs
or other uses hanging off of them.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22219 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-15 21:11:48 +00:00
Chris Lattner
5633cd13e2 Fix a problem on 64-bit targets where we passed (int)0 through ... instead of
(void*)0.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22205 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-09 02:59:00 +00:00
Reid Spencer
89026028d1 Make the registration hash_map static. No other module needs it. Also,
document what its for a little better.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22164 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-21 01:27:04 +00:00
Reid Spencer
0660f754df Adjust the file comment to read a little easier.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22163 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-21 00:57:44 +00:00
Reid Spencer
b82baf04ec Make sure ... arguments are casted to sbyte* where needed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22162 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-21 00:39:30 +00:00
Reid Spencer
5845623148 Add a "brief" comment for CastToCStr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22161 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-21 00:23:23 +00:00
Chris Lattner
9375135999 Fix mismatched type problem that crashed on cases like this:
sprintf(P, "%s", X);

Where X is not an sbyte*.  This fixes the bug JohnMC reported on llvm-bugs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22159 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-20 22:22:25 +00:00
Chris Lattner
49fbff4568 teach the inliner about coldcc and noreturn functions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22113 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-18 04:30:33 +00:00
Reid Spencer
c3f6abdd85 Don't look for __builtin_ffs, we'll never see it from llvm-gcc and there's
not reason to include it for other front ends.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22070 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-15 21:27:34 +00:00
Reid Spencer
f74eb3fa2a Provide this optimization as well:
ffs(x) -> (x == 0 ? 0 : 1+llvm.cttz(x))


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22068 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-15 21:19:45 +00:00
Reid Spencer
c64e3e77f9 Duh .. you actually have to #include Config/config.h before you can test
for one of the values that it defines!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22058 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-15 17:20:47 +00:00
Reid Spencer
c29b13d648 Changes for ffs lib call simplification:
* Check for availability of ffsll call in configure script
* Support ffs, ffsl, and ffsll conversion to constant value if the argument
  is constant.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22027 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-14 16:42:52 +00:00
Chris Lattner
f201dbc1a4 Preserve calling conventions when doing IPO
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21798 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-09 01:05:50 +00:00
Chris Lattner
fb217adf92 Convert non-address taken functions with C calling conventions to fastcc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21791 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 22:18:06 +00:00
Reid Spencer
789082af03 * Add two strlen optimizations:
strlen(x) != 0 -> *x != 0
    strlen(x) == 0 -> *x == 0
* Change nested statistics to use style of other LLVM statistics so that
  only the name of the optimization (simplify-libcalls) is used as the
  statistic name, and the description indicates which specific all is
  optimized. Cuts down on some redundancy and saves a few bytes of space.
* Make note of stpcpy optimization that could be done.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21766 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-07 20:15:59 +00:00
Reid Spencer
673c1a9170 Don't increment the counter unless the debug flag is set.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21762 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-07 04:59:45 +00:00
Chris Lattner
1430ef134d preserve the tail marker
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21734 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 06:46:58 +00:00
Chris Lattner
19bdc03adc Wrap long lines
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21720 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 05:34:40 +00:00
Chris Lattner
3987abdfe3 Fix a bug compimling Ruby, fixing this testcase:
LowerSetJmp/2005-05-05-OldUses.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21696 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-05 15:47:43 +00:00
Reid Spencer
cea6559f60 Implement the IsDigitOptimization for simplifying calls to the isdigit
library function:
  isdigit(chr) -> 0 or 1 if chr is constant
  isdigit(chr) -> chr - '0' <= 9 otherwise

Although there are many calls to isdigit in llvm-test, most of them are
compiled away by macros leaving only this:

2 MultiSource/Applications/hexxagon


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21688 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-04 18:58:28 +00:00
Reid Spencer
58b563ce43 * Correct the function prototypes for some of the functions to match the
actual spec (int -> uint)
* Add the ability to get/cache the strlen function prototype.
* Make sure generated values are appropriately named for debugging purposes
* Add the SPrintFOptimiation for 4 casts of sprintf optimization:
    sprintf(str,cstr) -> llvm.memcpy(str,cstr) (if cstr has no %)
    sprintf(str,"")   -> store sbyte 0, str
    sprintf(str,"%s",src) -> llvm.memcpy(str,src) (if src is constant)
    sprintf(str,"%c",chr) -> store chr, str   ; store sbyte 0, str+1

The sprintf optimization didn't fire as much as I had hoped:

  2 MultiSource/Applications/SPASS
  5 MultiSource/Benchmarks/McCat/18-imp
 22 MultiSource/Benchmarks/Prolangs-C/TimberWolfMC
  1 MultiSource/Benchmarks/Prolangs-C/assembler
  6 MultiSource/Benchmarks/Prolangs-C/unix-smail
  2 MultiSource/Benchmarks/mediabench/mpeg2/mpeg2dec


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21679 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-04 03:20:21 +00:00
Reid Spencer
21506ff821 Implement optimizations for the strchr and llvm.memset library calls.
Neither of these activated as many times as was hoped:

strchr:
9 MultiSource/Applications/siod
1 MultiSource/Applications/d
2 MultiSource/Prolangs-C/archie-client
1 External/SPEC/CINT2000/176.gcc/176.gcc

llvm.memset:
no hits


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21669 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-03 07:23:44 +00:00
Reid Spencer
9974ddab2b Avoid garbage output in the statistics display by ensuring that the
strings passed to Statistic's constructor are not destructable. The stats
are printed during static destruction and the SimplifyLibCalls module was
getting destructed before the statistics.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21661 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-03 02:54:54 +00:00
Reid Spencer
e6ec8cc8c6 Add the StrNCmpOptimization which is similar to strcmp.
Unfortunately, this optimization didn't trigger on any llvm-test tests.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21660 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-03 01:43:45 +00:00
Reid Spencer
a1b4390938 Implement the fprintf optimization which converts calls like this:
fprintf(F,"hello") -> fwrite("hello",strlen("hello"),1,F)
  fprintf(F,"%s","hello") -> fwrite("hello",strlen("hello"),1,F)
  fprintf(F,"%c",'x') -> fputc('c',F)

This optimization fires severals times in llvm-test:

313 MultiSource/Applications/Burg
302 MultiSource/Benchmarks/Prolangs-C/TimberWolfMC
189 MultiSource/Benchmarks/Prolangs-C/mybison
175 MultiSource/Benchmarks/Prolangs-C/football
130 MultiSource/Benchmarks/Prolangs-C/unix-tbl


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21657 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-02 23:59:26 +00:00
Reid Spencer
63a7513ac1 Fix a comment that stated the wrong thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21638 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-30 06:45:47 +00:00
Reid Spencer
9f56b1feeb * Don't depend on "guessing" what a FILE* is, just require that the actual
type be obtained from a CallInst we're optimizing.
* Make it possible for getConstantStringLength to return the ConstantArray
  that it extracts in case the content is needed by an Optimization.
* Implement the strcmp optimization
* Implement the toascii optimization

This pass is now firing several to many times in the following MultiSource
tests:

Applications/Burg      -   7 (strcat,strcpy)
Applications/siod      -  13 (strcat,strcpy,strlen)
Applications/spiff     - 120 (exit,fputs,strcat,strcpy,strlen)
Applications/treecc    -  66 (exit,fputs,strcat,strcpy)
Applications/kimwitu++ -  34 (strcmp,strcpy,strlen)
Applications/SPASS     - 588 (exit,fputs,strcat,strcpy,strlen)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21626 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-30 03:17:54 +00:00
Reid Spencer
ff5525daf3 Implement the optimizations for "pow" and "fputs" library calls.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21618 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-29 09:39:47 +00:00
Jeff Cohen
5882b92360 Consistently use 'class' to silence VC++
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21612 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-29 03:05:44 +00:00
Reid Spencer
5624c75f9f Remove from the TODO list those optimizations that are already handled by
constant folding implemented in lib/Transforms/Utils/Local.cpp.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21604 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-28 18:05:16 +00:00
Reid Spencer
8441a01146 Document additional libcall transformations that need to be written.
Help Wanted!

There's a lot of them to write.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21603 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-28 04:40:06 +00:00
Reid Spencer
716f49e5a2 Doxygenate.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21602 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 21:29:20 +00:00
Chris Lattner
209a0aea22 remove 'statement with no effect' warning
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21600 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 20:12:17 +00:00
Reid Spencer
3f7d8c65bb More Cleanup:
* Name the instructions by appending to name of original
* Factor common part out of a switch statement.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21597 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 17:46:54 +00:00
Reid Spencer
a16d5a5185 This is a cleanup commit:
* Correct stale documentation in a few places
* Re-order the file to better associate things and reduce line count
* Make the pass thread safe by caching the Function* objects needed by the
  optimizers in the pass object instead of globally.
* Provide the SimplifyLibCalls pass object to the optimizer classes so they
  can access cached Function* objects and TargetData info
* Make sure the pass resets its cache if the Module passed to runOnModule
  changes
* Rename CallOptimizer LibCallOptimization. All the classes are named
  *Optimization while the objects are *Optimizer.
* Don't cache Function* in the optimizer objects because they could be used
  by multiple PassManager's running in multiple threads
* Add an optimization for strcpy which is similar to strcat
* Add a "TODO" list at the end of the file for ideas on additional libcall
  optimizations that could be added (get ideas from other compilers).

Sorry for the huge diff. Its mostly reorganization of code. That won't
happen again as I believe the design and infrastructure for this pass is
now done or close to it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21589 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 07:54:40 +00:00
Chris Lattner
d651f441ae detect functions that never return, and turn the instruction following a
call to them into an 'unreachable' instruction.

This triggers a bunch of times, particularly on gcc:

gzip: 36
gcc: 601
eon: 12
bzip: 38


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21587 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 04:52:23 +00:00
Reid Spencer
026a87a868 Prefix the debug statistics so they group together.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21583 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 00:20:23 +00:00
Reid Spencer
1ea099c5fd In debug builds, make a statistic for each kind of call optimization. This
helps track down what gets triggered in the pass so its easier to identify
good test cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21582 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 00:05:45 +00:00
Chris Lattner
bc9fa589ef This analysis doesn't take 'throwing' into consideration, it looks at
'unwinding'


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21581 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 23:53:25 +00:00
Reid Spencer
0ddf0d6bec Fix up the debug statement to actually use a newline .. radical concept.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21580 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 23:07:08 +00:00
Reid Spencer
ef99ea318e Uh, this isn't argpromotion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21579 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 23:05:17 +00:00
Reid Spencer
8f13261863 Add some debugging output so we can tell which calls are getting triggered
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21578 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 23:02:16 +00:00
Reid Spencer
47a3785062 No, seriously folks, memcpy really does return void.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21575 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 22:49:48 +00:00
Reid Spencer
a525f6d8f5 memcpy returns void!!!!!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21574 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 22:46:23 +00:00
Reid Spencer
43fd4d077f Fix some bugs found by running on llvm-test:
* MemCpyOptimization can only be optimized if the 3rd and 4th arguments are
  constants and we weren't checking for that.
* The result of llvm.memcpy (and llvm.memmove) is void* not sbyte*, put in
  a cast.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21570 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 19:55:57 +00:00
Reid Spencer
fcbdb9c85b Changes From Review Feedback:
* Have the SimplifyLibCalls pass acquire the TargetData and pass it down to
  the optimization classes so they can use it to make better choices for
  the signatures of functions, etc.
* Rearrange the code a little so the utility functions are closer to their
  usage and keep the core of the pass near the top of the files.
* Adjust the StrLen pass to get/use the correct prototype depending on the
  TargetData::getIntPtrType() result. The result of strlen is size_t which
  could be either uint or ulong depending on the platform.
* Clean up some coding nits (cast vs. dyn_cast, remove redundant items from
  a switch, etc.)
* Implement the MemMoveOptimization as a twin of MemCpyOptimization (they
  only differ in name).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21569 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 19:13:17 +00:00