Commit Graph

4033 Commits

Author SHA1 Message Date
Devang Patel 28f167699a There is no need to use separate dir name for AT_comp_dir attribute. Using absolute path for filename allows clients to query complete file location info from gdb breakpoints. Save constructed full file name.
llvm-svn: 109263
2010-07-23 20:38:37 +00:00
Douglas Gregor 5cc2c8b9c3 Vectors are not integer types, so the type system should not classify
them as such. Type::is(Signed|Unsigned|)IntegerType() now return false
for vector types, and new functions
has(Signed|Unsigned|)IntegerRepresentation() cover integer types and
vector-of-integer types. This fixes a bunch of latent bugs.

Patch from Anton Yartsev!

llvm-svn: 109229
2010-07-23 15:58:24 +00:00
Devang Patel 0884a60eb5 Keep track of artificial scopes introduced by line directives. For example,
#line 41 "bar.c"
  dummy (1, i);
#line 24 "bar.h"
  i = f2 (i);
#line 44 "bar.c"

This is tested by step-line.exp in gdb testsuite.

llvm-svn: 109189
2010-07-22 22:29:16 +00:00
John McCall 775f9f9919 Turn off EH cleanups for __block variables; they caused some internal buildbot
failures.  There's a radar tracking this.

llvm-svn: 109170
2010-07-22 21:25:44 +00:00
Fariborz Jahanian 6e7e8cc19d atch for implementation of objective-c's -Wselector
warning flag in clang. Little more to do
for a PCH issue. Radar 6507158.

llvm-svn: 109129
2010-07-22 18:24:20 +00:00
Devang Patel 222f4be834 ObjCId is special "struct objc_object". Make this explicit in debug info.
This is tested by objc-rbreak.exp in gdb testsuite.

llvm-svn: 109050
2010-07-21 22:41:25 +00:00
Devang Patel 65497583b5 Fix regression caused by r108911.
Do not override known debug loc with unknown debug loc.
This is tested by sections.exp in gdb testsuite.

llvm-svn: 109022
2010-07-21 18:08:50 +00:00
David Chisnall 4715d161c0 Don't crash when sending a message inside a block with the non-fragile ABI (GNU runtime).
llvm-svn: 109012
2010-07-21 15:28:28 +00:00
David Chisnall 7fa204edc7 Mark the load after calling objc_msg_lookup_sender() so that it doesn't get optimised away (GNU runtime).
llvm-svn: 109010
2010-07-21 12:55:25 +00:00
John McCall cda666ccd8 Rename LazyCleanup -> Cleanup. No functionality change for these last three
commits.

llvm-svn: 109000
2010-07-21 07:22:38 +00:00
John McCall 20141f2d8c Rip out EHCleanupScope.
llvm-svn: 108999
2010-07-21 07:11:21 +00:00
John McCall 7535ee0352 Kill the CleanupBlock API.
llvm-svn: 108998
2010-07-21 07:04:01 +00:00
John McCall 65bea08879 Switch the fragile-ABI @finally/@synchronized cleanup over to using a lazy
cleanup.

llvm-svn: 108997
2010-07-21 06:59:36 +00:00
John McCall 0d42a41a63 Code simplification.
llvm-svn: 108996
2010-07-21 06:45:54 +00:00
John McCall fb442ae7b9 Switch the main possibly-conditional temporary cleanup over to being lazy.
llvm-svn: 108995
2010-07-21 06:44:28 +00:00
John McCall 8680f87d99 Switch the destructor for a temporary arising from a reference binding over to
using a lazy cleanup.

llvm-svn: 108994
2010-07-21 06:29:51 +00:00
John McCall da650e091f Switch the __cxa_guard_abort cleanup to being a lazy cleanup.
llvm-svn: 108993
2010-07-21 06:20:50 +00:00
John McCall a464ff9d15 Switch some random local-decl cleanups over to using lazy cleanups. Turn on
the block-release unwind cleanup:  we're never going to test it if we don't turn
it on.

llvm-svn: 108992
2010-07-21 06:13:08 +00:00
John McCall 906da4bb52 Switch finally cleanups over to being lazy cleanups. We get basically nothing
from the laziness features here except better block ordering, but it removes yet
another CleanupBlock use.

llvm-svn: 108990
2010-07-21 05:47:49 +00:00
John McCall f99a631e4e Implement proper base/member destructor EH chaining.
llvm-svn: 108989
2010-07-21 05:30:47 +00:00
John McCall 53cad2ef04 Change PushDestructorCleanup to use lazy cleanups.
llvm-svn: 108979
2010-07-21 01:41:18 +00:00
John McCall 1d9875654f Convert the EH cleanups for base and member destructors in a constructor into
lazy cleanups.

llvm-svn: 108978
2010-07-21 01:23:41 +00:00
Douglas Gregor 05fc5be32f Implement zero-initialization for array new when there is an
initializer of (). Make sure to use a simple memset() when we can, or
fall back to generating a loop when a simple memset will not
suffice. Fixes <rdar://problem/8212208>, a regression due to my work
in r107857.

llvm-svn: 108977
2010-07-21 01:10:17 +00:00
John McCall 1e67040fb7 Convert the end-catch call for finally blocks to a lazy cleanup. This kills off
the last of the shared-code cleanups.

llvm-svn: 108975
2010-07-21 00:52:03 +00:00
John McCall c20acd31f7 Convert the ObjC @synchronized cleanups to laziness. This is not actually
a big deal, except that I want to eliminate the shared-code EH cleanups
in preparation for a significant algorithmic fix.

llvm-svn: 108973
2010-07-21 00:41:47 +00:00
John McCall 8f51041184 Add a little helper method which will be useful soon.
llvm-svn: 108972
2010-07-21 00:40:03 +00:00
Devang Patel 0043977f09 Remove unintended code that was checked in as part of r108916.
llvm-svn: 108951
2010-07-20 22:32:37 +00:00
Devang Patel 11a42a4655 Remove unused argument.
llvm-svn: 108946
2010-07-20 22:20:10 +00:00
John McCall 5add20cefa Fix the IR generation for catching pointers by references.
Fixes <rdar://problem/8212123>.

llvm-svn: 108944
2010-07-20 22:17:55 +00:00
Chris Lattner 32ac583d91 in 'new int[4]', constant fold the 4*4=16 instead of
doing an overflow check.

llvm-svn: 108943
2010-07-20 21:55:52 +00:00
Chris Lattner f2f3870189 Follow the implementation approach suggested by PR6687,
which generates more efficient and more obviously conformant
code.  We now test for overflow of the multiply then force
the result to -1 if so.  On X86, this generates nice code
like this:

__Z4testl:                              ## @_Z4testl
## BB#0:                                ## %entry
	subl	$12, %esp
	movl	$4, %eax
	mull	16(%esp)
	testl	%edx, %edx
	movl	$-1, %ecx
	cmovel	%eax, %ecx
	movl	%ecx, (%esp)
	call	__Znam
	addl	$12, %esp
	ret

llvm-svn: 108927
2010-07-20 21:07:09 +00:00
Fariborz Jahanian 217af240b5 Adopt objc_assign_threadlocal() for __thread variables of GC types.
Implements radar 8203301.

llvm-svn: 108917
2010-07-20 20:30:03 +00:00
Devang Patel 6c01820900 Print template argument names for template class.
llvm-svn: 108916
2010-07-20 20:24:18 +00:00
Chris Lattner 26008e07de implement rdar://5739832 - operator new should check for overflow in multiply,
causing clang to compile this code into something that correctly throws a
length error, fixing a potential integer overflow security attack:

void *test(long N) {
  return new int[N];
}

int main() {
  test(1L << 62);
}

We do this even when exceptions are disabled, because it is better for the
code to abort than for the attack to succeed.

This is heavily based on a patch that Fariborz wrote.

llvm-svn: 108915
2010-07-20 20:19:24 +00:00
Dan Gohman 481e40c681 Use getDebugLoc and setDebugLoc instead of getDbgMetadata and setDbgMetadata,
avoiding MDNode overhead.

llvm-svn: 108911
2010-07-20 20:13:52 +00:00
Chris Lattner b7a95cf165 delete a loop that just generates dead code. In an example
like this:

void *test(long N) {
  return new int[N][42][42];
}

the loop generates two dead mul instructions:

  %tmp = load i64* %N.addr                        ; <i64> [#uses=2]
  %0 = mul i64 %tmp, 7056                         ; <i64> [#uses=1]
  %1 = mul i64 %tmp, 42                           ; <i64> [#uses=1]
  %2 = mul i64 %1, 42                             ; <i64> [#uses=0]
  %call = call noalias i8* @_Znam(i64 %0)         ; <i8*> [#uses=1]

The scale of these multiplies is already handled by the typesize stuff.

llvm-svn: 108884
2010-07-20 18:49:33 +00:00
Chris Lattner cb46bdc34f remove the special case for constant array sizes from
EmitCXXNewAllocSize.  This code uses IRBuilder, which does
constant folding already.

llvm-svn: 108882
2010-07-20 18:45:57 +00:00
Jim Grosbach 71d963e954 Re-apply fixed version of 108749, correctly conditionalizing the new sections on
ObjC ABI version 2 this time.

llvm-svn: 108847
2010-07-20 16:20:26 +00:00
Sebastian Redl c57d34bc35 Update ImplicitCastExpr to be able to represent an XValue.
llvm-svn: 108807
2010-07-20 04:20:21 +00:00
Stuart Hastings 7d7bc561bf Correct line info for declarations/definitions. Radar 8063111.
llvm-svn: 108785
2010-07-19 23:56:31 +00:00
Jim Grosbach 50c63168ed Temporarily revert. Some odd internal breakage is likely related.
llvm-svn: 108764
2010-07-19 22:43:34 +00:00
Jim Grosbach f699594de8 Put ObjC method names, method types and class names in separate string literal
sections. rdar://8207705

llvm-svn: 108749
2010-07-19 20:54:43 +00:00
Eli Friedman f8340deacd Fix mangling for static member variables of classes inside an extern "C"
linkage specification.  Not sure if this is the ideal fix, but I'm reasonably
sure it's correct vs. gcc.

llvm-svn: 108656
2010-07-18 20:49:59 +00:00
Chandler Carruth bc8cab16c5 Improve the representation of the atomic builtins in a few ways. First, we make
their call expressions synthetically have the "deduced" types based on their
first argument. We only insert conversions in the AST for arguments whose
values require conversion to match the value type expected. This keeps PR7600
closed by maintaining the return type, but avoids assertions due to unexpected
implicit casts making the type unsigned (test case added from Daniel).

The magic is moved into the codegen for the atomic builtin which inserts the
casts as needed at the IR level to raise the type to an integer suitable for
the LLVM intrinsic. This shouldn't cause any real change in functionality, but
now we can make the builtin be more truly polymorphic.

llvm-svn: 108638
2010-07-18 07:23:17 +00:00
Chris Lattner ad4f38b1a9 BUILD_ARCHIVE is the default for libraries, no need to set it.
llvm-svn: 108633
2010-07-18 00:14:47 +00:00
Eli Friedman 3ee1022f37 Fix crash initializing a bit-field with a non-constant in a place where we
try to evaluate the initializer as a constant.

llvm-svn: 108632
2010-07-17 23:55:01 +00:00
John McCall 36ea3723c0 The GNU-runtime ObjC personality function doesn't let us rethrow with URR for
multiple reasons.  Rethrow with _objc_exception_throw instead.  Fixes PR7656.

llvm-svn: 108595
2010-07-17 00:43:08 +00:00
Eli Friedman eca55afea3 Fix for PR3800: make sure not to evaluate the expression for a read-write
asm operand twice.

llvm-svn: 108489
2010-07-16 00:55:21 +00:00
Daniel Dunbar 3348e2d175 IRgen: Support user defined attributes on block runtime functions.
- This issue here is that /usr/include/Blocks.h wants to define some of the
   block runtime globals as weak, depending on the target. This doesn't work in
   Clang because we aren't using the AST decl for these globals.

 - The fix is a pretty gross hack which just watches all the decls for the
   specific blocks globals we need to know about; if we see one we use it,
   otherwise we use the hand coded type.

   In time, I would like to clean this up by changing IRgen to ask Sema/AST for
   the decl, which would then be lazily loaded from the builtin table if
   necessary. This could be used in a whole host of places in IRgen and would
   get rid of a lot of grotty hand coding of LLVM IR; however, we need some
   extra Sema support for this as well as support for builtin global variables.

llvm-svn: 108482
2010-07-16 00:00:19 +00:00
Daniel Dunbar 900546d2e3 IRgen: Move blocks runtime interfaces to CodeGenModule.
llvm-svn: 108481
2010-07-16 00:00:15 +00:00
John McCall 70013b640f When deferring the emission of declarations with initializers in C++, remember
the order they appeared in the translation unit.  If they get emitted, put them
in their proper order.  Fixes rdar://problem/7458115

llvm-svn: 108477
2010-07-15 23:40:35 +00:00
Devang Patel 8fd6499a97 Set "optimization is ON" and supply other optional parameters. This helps codegenerator preserve info in case the symbol is deleted.
llvm-svn: 108471
2010-07-15 23:09:46 +00:00
Douglas Gregor 8997690ff1 Don't suppress the emission of available_externally functions marked
with always_inline attribute. Thanks to Howard for the tip.

llvm-svn: 108469
2010-07-15 22:58:18 +00:00
Devang Patel b3026df9fa Mark implementation generated methods as artificial.
Tested by namespace.exp and virtfunc.exp from gdb testsuite.

llvm-svn: 108468
2010-07-15 22:57:00 +00:00
John McCall ec624b2d19 After some discussion, the ABI list settled on a much more sensible mangling
for string literals.

llvm-svn: 108464
2010-07-15 21:53:03 +00:00
Douglas Gregor cdb466e58f Reinstate the scalar-cast-to-const-reference improvements, this time
with the proper spelling of "non-class prvalue". Silly me, I think
class rvalues were xvalues rather than prvalues!

Hah hah hah.

llvm-svn: 108443
2010-07-15 18:58:16 +00:00
Douglas Gregor 31e225cc90 Revert r108431 and r108433 (the cast-to-const-reference fixes), which
broke nightlytest.

llvm-svn: 108439
2010-07-15 18:41:54 +00:00
Devang Patel 99c372134d Revert 108220 and subsequent patch.
This is not required (I am not 100% sure why) but method.exp from gdb testsuite flagged regression due to this patch.

llvm-svn: 108434
2010-07-15 18:16:09 +00:00
Douglas Gregor 6744cbda03 Spell isPRValue() properly.
llvm-svn: 108433
2010-07-15 18:12:28 +00:00
Douglas Gregor 1bae6a1be9 Teach CodeGenFunction::EmitCastLValue() to handle casts to an lvalue
that involve binding a reference to a pure rvalue temporary (e.g., not
a class temporary), by creating a new temporary and copying the result
there. Fixes PR6024.

llvm-svn: 108431
2010-07-15 18:04:13 +00:00
Douglas Gregor cee039093a CK_BitCast is not an lvalue bitcast any longer
llvm-svn: 108428
2010-07-15 16:39:55 +00:00
Daniel Dunbar 1d14dd1dc6 CodeGen: Tweak ABI handling for Minix, patch by Kees van Reeuwijk!
llvm-svn: 108423
2010-07-15 15:02:28 +00:00
Daniel Dunbar 6f2e839693 CodeGen/ObjC/NeXT: Fix Obj-C message send to match llvm-gcc when choosing
whether to use objc_msgSend_fpret; the choice is target dependent, not Obj-C ABI
dependent.
 - <rdar://problem/8139758> arm objc _objc_msgSend_fpret bug

llvm-svn: 108379
2010-07-14 23:39:36 +00:00
Douglas Gregor c357f4121e Add lvalue-bitcast support for complex numbers.
llvm-svn: 108363
2010-07-14 21:35:45 +00:00
John McCall 4f3b5f302c Fix the mangling of template template arguments, which do not always
follow <name>;  instead they follow <type>, which has <name> as a subset.

Fixes PR7446.

llvm-svn: 108326
2010-07-14 06:43:17 +00:00
John McCall afe20780ee Remove a few mangling FIXMEs:
- TSTs whose template is a template template parameter already work
 - we don't provide an imaginary type, so we can't mangle one
 - we don't need a generic FIXME for vendor type qualifiers

llvm-svn: 108317
2010-07-14 04:38:21 +00:00
John McCall 05ddbb80d2 Implement the standard mangling for array-subscript expressions, and implement
the current proposals from David Vandervoorde for new, delete, throw, typeid,
imaginary literals, string literals, and null literals.

llvm-svn: 108315
2010-07-14 04:20:34 +00:00
John McCall 11e577b99a Work around an obnoxious GCC warning by changing semantics in a hopefully-
harmless way.

llvm-svn: 108295
2010-07-13 23:19:49 +00:00
Douglas Gregor 51954276cc Introduce a new cast kind for an "lvalue bitcast", which handles
reinterpret_casts (possibly indirectly via C-style/functional casts)
on values, e.g., 

  int i;
  reinterpret_cast<short&>(i);

The IR generated for this is essentially the same as for

  *reinterpret_cast<short*>(&i).

Fixes PR6437, PR7593, and PR7344. 

llvm-svn: 108294
2010-07-13 23:17:26 +00:00
John McCall 5c0e69ef0e Switch the __cxa_rethrow cleanup to be lazy.
llvm-svn: 108288
2010-07-13 22:24:23 +00:00
John McCall 5c08ab956b Allow for the possibility that __cxa_end_catch might throw for a catch-all block
or a catch of a record type by value or reference.  Also convert this to a
lazy cleanup.

llvm-svn: 108287
2010-07-13 22:12:14 +00:00
John McCall bb0260139a Switch the __cxa_free_exception cleanup to be lazy.
llvm-svn: 108276
2010-07-13 21:17:51 +00:00
John McCall 2b7fc3828e Teach IR generation how to lazily emit cleanups. This has a lot of advantages,
mostly in avoiding unnecessary work at compile time but also in producing more
sensible block orderings.

Move the destructor cleanups for local variables over to use lazy cleanups.
Eventually all cleanups will do this;  for now we have some awkward code
duplication.

Tell IR generation just to never produce landing pads in -fno-exceptions.
This is a much more comprehensive solution to a problem which previously was
half-solved by checks in most cleanup-generation spots.

llvm-svn: 108270
2010-07-13 20:32:21 +00:00
Douglas Gregor a8a089bfd5 Whenever we're creating an expression that is typically an rvalue
(e.g., a call, cast, etc.), immediately adjust the expression's type
to strip cv-qualifiers off of all non-class types (in C++) or all
types (in C). This effectively extends my previous fix for PR7463,
which was restricted to calls, to other kinds of expressions within
similar characteristics. I've audited every use of
getNonReferenceType() in the code base, switching to the newly-renamed
getNonLValueExprType() where necessary. 

Big thanks to Eli for pointing out just how incomplete my original fix
for PR7463 actually was. We've been handling cv-qualifiers on rvalues
wrong for a very, very long time. Fixes PR7463.

llvm-svn: 108253
2010-07-13 18:40:04 +00:00
Devang Patel 01c8c100c2 Add volatile qualifiers for "this".
llvm-svn: 108245
2010-07-13 16:23:13 +00:00
Douglas Gregor a700f68828 Reinstate the optimization suppressing available_externally functions
at -O0. The only change from the previous patch is that we don't try
to generate virtual method thunks for an available_externally
function.

llvm-svn: 108230
2010-07-13 06:02:28 +00:00
Devang Patel 0a34e31d81 const qualify debug info for "this" for const methods.
llvm-svn: 108220
2010-07-13 00:24:30 +00:00
Devang Patel 0aabb1200f While collecting members for a class, always create delcaration entry for methods. Debug info for method definition will be generated while generating code for method body.
Tested by classes.exp in gdb testsuite.

llvm-svn: 108205
2010-07-12 22:54:41 +00:00
Douglas Gregor 553f3a9b30 Speculatively revert r108156; it appears to be breaking self-host.
llvm-svn: 108194
2010-07-12 21:08:32 +00:00
Douglas Gregor dbb2806a7b Do not generate LLVM IR for available_externally function bodies at
-O0, since we won't be using the definitions for anything anyway. For
lib/System/Path.o when built in Debug+Asserts mode, this leads to a 4%
improvement in compile time (and suppresses 440 function bodies).

<rdar://problem/7987644>

llvm-svn: 108156
2010-07-12 17:24:55 +00:00
Devang Patel 8f3f76f991 Handle forward declarations properly in debug info.
Patch by Alexander Kabaev.
PR 7595.

llvm-svn: 107900
2010-07-08 19:56:29 +00:00
John McCall be349def4b Mark calls to 'throw()' functions as nounwind, and mark the functions nounwind
as well.

llvm-svn: 107858
2010-07-08 06:48:12 +00:00
Douglas Gregor 747eb7840a Reinstate the fix for PR7556. A silly use of isTrivial() was
suppressing copies of objects with trivial copy constructors.

llvm-svn: 107857
2010-07-08 06:14:04 +00:00
Chris Lattner cb7696cf35 fix the clang side of PR7437: EmitAggregateCopy
was not producing a memcpy with the right address
spaces because of two places in it doing casts of
the arguments to i8, one of which that didn't
preserve the address space.

There is also an optimizer bug here.

llvm-svn: 107842
2010-07-08 00:07:45 +00:00
Douglas Gregor e182370eda Revert r107828 and r107827, the fix for PR7556, which seems to be
breaking bootstrap on Linux.

llvm-svn: 107837
2010-07-07 23:37:33 +00:00
Douglas Gregor 6df2b8c3ac Rename CXXZeroInitValueExpr to CXXScalarValueInitExpr, to reflect its
newly-narrowed scope. No functionality change.

llvm-svn: 107828
2010-07-07 22:43:56 +00:00
Douglas Gregor 442612c285 Do not use CXXZeroValueInitExpr for class types. Instead, use
CXXConstructExpr/CXXTemporaryObjectExpr/CXXNewExpr as
appropriate. Fixes PR7556, and provides a slide codegen improvement
when copy-initializing a POD class type from a value-initialized
temporary. Previously, we weren't eliding the copy.

llvm-svn: 107827
2010-07-07 22:35:13 +00:00
Chris Lattner 3e2ee147d0 add driver support for minix, patch by Kees van Reeuwijk
from PR7583

llvm-svn: 107788
2010-07-07 16:01:42 +00:00
Argyrios Kyrtzidis 54fcbc7345 getBody() -> hasBody()
llvm-svn: 107773
2010-07-07 12:24:18 +00:00
Argyrios Kyrtzidis 36ea322579 Introduce Decl::hasBody() and FunctionDecl::hasBody() and use them instead of getBody() when we are just checking the existence of a body, to avoid de-serialization of the body from PCH.
Makes de-serialization of the function body even more "lazier".

llvm-svn: 107768
2010-07-07 11:31:19 +00:00
John McCall b609d3f5f9 Teach function-try-blocks on constructors and destructors to implicitly
rethrow.  Fixes rdar://problem/7696603

llvm-svn: 107757
2010-07-07 06:56:46 +00:00
John McCall 09ae03299a Provide a hook for the benefit of clients using clang IR gen as a subroutine:
emit metadata associating allocas and global values with a Decl*.  This feature
is controlled by an option that (intentionally) cannot be enabled on the command
line.

To use this feature, simply set
  CodeGenOptions.EmitDeclMetadata = true;
and then interpret the completely underspecified metadata. :)

llvm-svn: 107739
2010-07-06 23:57:41 +00:00
John McCall 189223e222 Make CGBuilderTy a typedef again; its functionality has been rolled back
into IRBuilder.

llvm-svn: 107687
2010-07-06 18:43:48 +00:00
John McCall 2d605ac1f5 When destroying a cleanup, kill any references to instructions in the entry
block before deleting it.  Fixes PR7575.

This really just a short-term fix before implementing lazy cleanups.

llvm-svn: 107676
2010-07-06 17:35:03 +00:00
John McCall 466e221037 When creating functions to run global initializers and destructors, mark them
as nounwind in -fno-exceptions.  Fixes rdar://problem/8090834.

llvm-svn: 107639
2010-07-06 04:38:10 +00:00
John McCall bd30929e4d Validated by nightly-test runs on x86 and x86-64 darwin, including after
self-host.  Hopefully these results hold up on different platforms.  

I tried to keep the GNU ObjC runtime happy, but it's hard for me to test.
Reimplement how clang generates IR for exceptions.  Instead of creating new
invoke destinations which sequentially chain to the previous destination,
push a more semantic representation of *why* we need the cleanup/catch/filter
behavior, then collect that information into a single landing pad upon request.

Also reorganizes how normal cleanups (i.e. cleanups triggered by non-exceptional
control flow) are generated, since it's actually fairly closely tied in with
the former.  Remove the need to track which cleanup scope a block is associated
with.

Document a lot of previously poorly-understood (by me, at least) behavior.

The new framework implements the Horrible Hack (tm), which requires every
landing pad to have a catch-all so that inlining will work.  Clang no longer
requires the Horrible Hack just to make exceptions flow correctly within
a function, however.  The HH is an unfortunate requirement of LLVM's EH IR.

llvm-svn: 107631
2010-07-06 01:34:17 +00:00
Chris Lattner ceddafb846 Generate fewer first class aggregate values for other
coerce cases (e.g. {double,int}) which avoids fastisel
bailing out at -O0.

llvm-svn: 107628
2010-07-05 20:41:41 +00:00
Chris Lattner c401de9998 in the "coerce" case, the ABI handling code ends up making the
alloca for an argument.  Make sure the argument gets the proper
decl alignment, which may be different than the type alignment.

This fixes PR7567

llvm-svn: 107627
2010-07-05 20:21:00 +00:00
Chris Lattner 53b479ff6a fix PR7564 a cast where the bitfield struct init code
wasn't handling array padding elements right.

llvm-svn: 107621
2010-07-05 18:03:30 +00:00
Chris Lattner 9a3459f1a6 AppendBitField really can never fail, so return its return value.
Everyone knows that no bugs are ever possible with bitfields.

llvm-svn: 107620
2010-07-05 17:04:23 +00:00
Charles Davis 3babfba597 Mangle Objective-C pointers and block pointers in the Microsoft C++ Mangler.
ObjC pointers were easy enough (as far as the ABI is concerned, they're
just pointers to structs), but I had to invent a new mangling for block
pointers. This is particularly worrying with the Microsoft ABI, because
it is a vendor-specific ABI; extending it could come back to bite us
later when MS extends it on their own (and you know they will).

llvm-svn: 107572
2010-07-03 16:56:59 +00:00
John McCall 1180f8e90f Provide convenience routines to save and restore the current insertion
point.

llvm-svn: 107570
2010-07-03 09:25:20 +00:00
Charles Davis 3b10dd1bec Fix mangling of array dimensions in the Microsoft C++ Mangler.
llvm-svn: 107568
2010-07-03 08:15:16 +00:00
Charles Davis d49950a317 Mangle member pointer types in the Microsoft C++ Mangler.
llvm-svn: 107567
2010-07-03 08:01:32 +00:00
Charles Davis 0029a2a957 Fix mangling of function pointers in the Microsoft C++ Mangler.
llvm-svn: 107564
2010-07-03 05:53:41 +00:00
Charles Davis 77552766d9 Fix mangling of array parameters for functions in the Microsoft C++ Mangler.
Only actual functions get mangled correctly; I don't know how to fix it for
function pointers yet. Thanks to John McCall for the hint.

Also, mangle anonymous tag types. I don't have a suitable testcase yet; I have
a feeling that that's going to need support for static locals, and I haven't
figured out exactly how MSVC's scheme for mangling those works.

llvm-svn: 107561
2010-07-03 02:41:45 +00:00
Douglas Gregor bac7490ffc Remove unnecessary ASTContext parameter from
CXXRecordDecl::getDestructor(); no functionality change.

llvm-svn: 107394
2010-07-01 14:13:13 +00:00
Chris Lattner 0e7929f30c fix rdar://8147692 - yet another crash due to my abi work.
llvm-svn: 107387
2010-07-01 06:20:47 +00:00
Daniel Dunbar bb7ac52e02 Driver/IRgen: Add support for -momit-leaf-frame-pointer.
llvm-svn: 107367
2010-07-01 01:31:45 +00:00
Daniel Dunbar 3de064dfdf Revert "IRgen: Make sure any prolog instructions get debug info.", the lexical
scope hasn't been set up yet so this isn't valid. It was just a cleanup to the
IR, so I'm going to ignore it for now.

llvm-svn: 107356
2010-07-01 00:16:31 +00:00
Daniel Dunbar 6696e22cc9 IRgen: Fix debug info regression in r106970; when we eliminate the return value
store make sure to move the debug metadata from the store (which is actual
'return' statement location) to the return instruction (which otherwise would
have the function end location as its debug info).
 - Tested by gdb test suite.

llvm-svn: 107322
2010-06-30 21:27:58 +00:00
Daniel Dunbar d7ac9a375a IRgen: Make sure any prolog instructions get debug info.
llvm-svn: 107320
2010-06-30 21:27:56 +00:00
Chris Lattner 5c740f1523 Reapply:
r107173, "fix PR7519: after thrashing around and remembering how all this stuff"
r107216, "fix PR7523, which was caused by the ABI code calling ConvertType instead"

This includes a fix to make ConvertTypeForMem handle the "recursive" case, and call
it as such when lowering function types which have an indirect result.

llvm-svn: 107310
2010-06-30 19:14:05 +00:00
Fariborz Jahanian 02995320e9 Use isFunctionOrMethod for vars declared locallly
in method/blocks to decide not to mangle them.

llvm-svn: 107309
2010-06-30 18:57:21 +00:00
Fariborz Jahanian 0f19afb9d4 extern variable declared locally to objective-c++ method
should not be mangled either. Fixes radar 8016412.

llvm-svn: 107303
2010-06-30 18:27:47 +00:00
Chris Lattner 749b8ed5af reduce nesting.
llvm-svn: 107292
2010-06-30 16:58:07 +00:00
Charles Davis 2a47730767 Mangle arrays in the Microsoft C++ Mangler. It's not quite finished (it
doesn't mangle array parameters right), but I think that should be fixed
in Sema (Doug, John, what do you think?).

Also, stub out the remaining mangleType() routines.

llvm-svn: 107264
2010-06-30 08:09:57 +00:00
Daniel Dunbar e422266926 Revert r107173, "fix PR7519: after thrashing around and remembering how all this stuff", it broke bootstrap.
llvm-svn: 107232
2010-06-30 00:22:35 +00:00
Daniel Dunbar 8386469d7d Revert r107216, "fix PR7523, which was caused by the ABI code calling ConvertType instead", it is part of a boostrap breaking sequence.
llvm-svn: 107231
2010-06-30 00:22:30 +00:00
Daniel Dunbar 8c94ffe776 IRgen: Assignment to Objective-C properties shouldn't reload the value, for
complex values either. Previously we did this properly for regular assignment,
but not for compound assignment.
 - Also, tidy up assignment code a bit to look more like the scalar path.

llvm-svn: 107217
2010-06-29 22:44:21 +00:00
Chris Lattner 466b1419c6 fix PR7523, which was caused by the ABI code calling ConvertType instead
of ConvertTypeRecursive when it needed to in a few cases, causing pointer
types to get resolved at the wrong time.

llvm-svn: 107216
2010-06-29 22:39:04 +00:00
Daniel Dunbar c85ea8e175 IRgen: Assignment to Objective-C properties shouldn't reload the value (which
would trigger an extra method call).
 - While in the area, I also changed Clang to not emit an unnecessary load from
   'x' in cases like 'y = (x = 1)'.

llvm-svn: 107210
2010-06-29 22:00:45 +00:00
Chris Lattner cccaad9584 change ABIArgInfo to hold its llvm type with PATypeHolder so that
it doesn't dangle as types get refined.  This fixes Shootout-C++/lists1
and probably also PR7522.

llvm-svn: 107196
2010-06-29 19:21:36 +00:00
Chris Lattner 34d6281ae5 relax the CGFunctionInfo::CGFunctionInfo ctor to allow any sequence
of CanQualTypes to be passed in.

llvm-svn: 107176
2010-06-29 18:13:52 +00:00
Chris Lattner ab1e65e2ea fix PR7519: after thrashing around and remembering how all this stuff
works, the fix is quite simple: just make sure to call ConvertTypeRecursive
when the function type being lowered is in the midst of ConvertType.

llvm-svn: 107173
2010-06-29 17:56:33 +00:00
Chris Lattner e70a007b36 minor cleanups.
llvm-svn: 107150
2010-06-29 16:40:28 +00:00
Chris Lattner 22a931e3bb Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.

When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the 
preferred type.  If so, use that pointer type instead of i64.  This
allows us to compile A function taking a stringref into something
like this:

define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
  %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=4]
  %0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  store i64 %D.coerce0, i64* %0
  %1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
  store i8* %D.coerce1, i8** %1
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
  %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
  %tmp3 = load i8** %tmp2                         ; <i8*> [#uses=1]
  %add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
  ret i8* %add.ptr
}

instead of this:

define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
  %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=3]
  %0 = insertvalue %0 undef, i64 %D.coerce0, 0    ; <%0> [#uses=1]
  %1 = insertvalue %0 %0, i64 %D.coerce1, 1       ; <%0> [#uses=1]
  %2 = bitcast %struct.DeclGroup* %D to %0*       ; <%0*> [#uses=1]
  store %0 %1, %0* %2, align 1
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
  %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
  %tmp3 = load i8** %tmp2                         ; <i8*> [#uses=1]
  %add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
  ret i8* %add.ptr
}

This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef

llvm-svn: 107123
2010-06-29 06:01:59 +00:00
Chris Lattner 399d22ac1b plumb preferred types down into X86_64ABIInfo::classifyArgumentType,
no functionality change.

llvm-svn: 107115
2010-06-29 01:14:09 +00:00
Chris Lattner 1d7c9f7f4b Pass the LLVM IR version of argument types down into computeInfo.
This is somewhat annoying to do this at this level, but it avoids
having ABIInfo know depend on CodeGenTypes for a hint.

Nothing is using this yet, so no functionality change.

llvm-svn: 107111
2010-06-29 01:08:48 +00:00
Chris Lattner 9e748e9d6e add IR names to coerced arguments.
llvm-svn: 107105
2010-06-29 00:14:52 +00:00
Chris Lattner 15ec361bd6 make the argument passing stuff in the FCA case smarter still, by
avoiding making the FCA at all when the types exactly line up.  For
example, before we made:

%struct.DeclGroup = type { i64, i64 }

define i64 @_Z3foo9DeclGroup(i64, i64) nounwind {
entry:
  %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=3]
  %2 = insertvalue %struct.DeclGroup undef, i64 %0, 0 ; <%struct.DeclGroup> [#uses=1]
  %3 = insertvalue %struct.DeclGroup %2, i64 %1, 1 ; <%struct.DeclGroup> [#uses=1]
  store %struct.DeclGroup %3, %struct.DeclGroup* %D
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
  %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i64*> [#uses=1]
  %tmp3 = load i64* %tmp2                         ; <i64> [#uses=1]
  %add = add nsw i64 %tmp1, %tmp3                 ; <i64> [#uses=1]
  ret i64 %add
}

... which has the pointless insertvalue, which fastisel hates, now we
make:

%struct.DeclGroup = type { i64, i64 }

define i64 @_Z3foo9DeclGroup(i64, i64) nounwind {
entry:
  %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=4]
  %2 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  store i64 %0, i64* %2
  %3 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i64*> [#uses=1]
  store i64 %1, i64* %3
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
  %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i64*> [#uses=1]
  %tmp3 = load i64* %tmp2                         ; <i64> [#uses=1]
  %add = add nsw i64 %tmp1, %tmp3                 ; <i64> [#uses=1]
  ret i64 %add
}

This only kicks in when x86-64 abi lowering decides it likes us.

llvm-svn: 107104
2010-06-29 00:06:42 +00:00
Chris Lattner 3dd716c3c3 Change CGCall to handle the "coerce" case where the coerce-to type
is a FCA to pass each of the elements as individual scalars.  This
produces code fast isel is less likely to reject and is easier on
the optimizers.

For example, before we would compile:
struct DeclGroup { long NumDecls; char * Y; };
char * foo(DeclGroup D) {
  return D.NumDecls+D.Y;
}

to:
%struct.DeclGroup = type { i64, i64 }

define i64 @_Z3foo9DeclGroup(%struct.DeclGroup) nounwind {
entry:
  %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=3]
  store %struct.DeclGroup %0, %struct.DeclGroup* %D, align 1
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
  %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i64*> [#uses=1]
  %tmp3 = load i64* %tmp2                         ; <i64> [#uses=1]
  %add = add nsw i64 %tmp1, %tmp3                 ; <i64> [#uses=1]
  ret i64 %add
}

Now we get:

%0 = type { i64, i64 }
%struct.DeclGroup = type { i64, i8* }

define i8* @_Z3foo9DeclGroup(i64, i64) nounwind {
entry:
  %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=3]
  %2 = insertvalue %0 undef, i64 %0, 0            ; <%0> [#uses=1]
  %3 = insertvalue %0 %2, i64 %1, 1               ; <%0> [#uses=1]
  %4 = bitcast %struct.DeclGroup* %D to %0*       ; <%0*> [#uses=1]
  store %0 %3, %0* %4, align 1
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
  %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
  %tmp3 = load i8** %tmp2                         ; <i8*> [#uses=1]
  %add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
  ret i8* %add.ptr
}

Elimination of the FCA inside the function is still-to-come.

llvm-svn: 107099
2010-06-28 23:44:11 +00:00
Chris Lattner d200eda487 make the trivial forms of CreateCoerced{Load|Store} trivial.
llvm-svn: 107091
2010-06-28 22:51:39 +00:00
Chris Lattner 93af332819 pass/return structs of char and short as i8/i16 to avoid
aweful through-memory coersion, just like we do for i32 now.

llvm-svn: 107078
2010-06-28 21:59:07 +00:00
Chris Lattner d776fb150e more tidying up.
llvm-svn: 107076
2010-06-28 21:43:59 +00:00
Chris Lattner 0cf2419cd7 random acts of tidying.
llvm-svn: 107050
2010-06-28 20:05:43 +00:00
Chris Lattner a7d81ab7f3 X86-64:
pass/return structs of float/int as float/i32 instead of double/i64
to make the code generated for ABI cleaner.  Passing in the low part
of a double is the same as passing in a float.

For example, we now compile:

struct DeclGroup { float NumDecls; };
float foo(DeclGroup D);
void bar(DeclGroup *D) {
 foo(*D);
}

into:

%struct.DeclGroup = type { float }

define void @_Z3barP9DeclGroup(%struct.DeclGroup* %D) nounwind {
entry:
  %D.addr = alloca %struct.DeclGroup*, align 8    ; <%struct.DeclGroup**> [#uses=2]
  %agg.tmp = alloca %struct.DeclGroup, align 4    ; <%struct.DeclGroup*> [#uses=2]
  store %struct.DeclGroup* %D, %struct.DeclGroup** %D.addr
  %tmp = load %struct.DeclGroup** %D.addr         ; <%struct.DeclGroup*> [#uses=1]
  %tmp1 = bitcast %struct.DeclGroup* %agg.tmp to i8* ; <i8*> [#uses=1]
  %tmp2 = bitcast %struct.DeclGroup* %tmp to i8*  ; <i8*> [#uses=1]
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 4, i32 4, i1 false)
  %coerce.dive = getelementptr %struct.DeclGroup* %agg.tmp, i32 0, i32 0 ; <float*> [#uses=1]
  %0 = load float* %coerce.dive, align 1          ; <float> [#uses=1]
  %call = call float @_Z3foo9DeclGroup(float %0)  ; <float> [#uses=0]
  ret void
}

instead of:

%struct.DeclGroup = type { float }

define void @_Z3barP9DeclGroup(%struct.DeclGroup* %D) nounwind {
entry:
  %D.addr = alloca %struct.DeclGroup*, align 8    ; <%struct.DeclGroup**> [#uses=2]
  %agg.tmp = alloca %struct.DeclGroup, align 4    ; <%struct.DeclGroup*> [#uses=2]
  %tmp3 = alloca double                           ; <double*> [#uses=2]
  store %struct.DeclGroup* %D, %struct.DeclGroup** %D.addr
  %tmp = load %struct.DeclGroup** %D.addr         ; <%struct.DeclGroup*> [#uses=1]
  %tmp1 = bitcast %struct.DeclGroup* %agg.tmp to i8* ; <i8*> [#uses=1]
  %tmp2 = bitcast %struct.DeclGroup* %tmp to i8*  ; <i8*> [#uses=1]
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 4, i32 4, i1 false)
  %coerce.dive = getelementptr %struct.DeclGroup* %agg.tmp, i32 0, i32 0 ; <float*> [#uses=1]
  %0 = bitcast double* %tmp3 to float*            ; <float*> [#uses=1]
  %1 = load float* %coerce.dive                   ; <float> [#uses=1]
  store float %1, float* %0, align 1
  %2 = load double* %tmp3                         ; <double> [#uses=1]
  %call = call float @_Z3foo9DeclGroup(double %2) ; <float> [#uses=0]
  ret void
}

which is this machine code (at -O0):

__Z3barP9DeclGroup:
	subq	$24, %rsp
	movq	%rdi, 16(%rsp)
	movq	16(%rsp), %rdi
	leaq	8(%rsp), %rax
	movl	(%rdi), %ecx
	movl	%ecx, (%rax)
	movss	8(%rsp), %xmm0
	callq	__Z3foo9DeclGroup
	addq	$24, %rsp
	ret

vs this:

__Z3barP9DeclGroup:
	subq	$24, %rsp
	movq	%rdi, 16(%rsp)
	movq	16(%rsp), %rdi
	leaq	8(%rsp), %rax
	movl	(%rdi), %ecx
	movl	%ecx, (%rax)
	movss	8(%rsp), %xmm0
	movss	%xmm0, (%rsp)
	movsd	(%rsp), %xmm0
	callq	__Z3foo9DeclGroup
	addq	$24, %rsp
	ret

At -O3, it is the difference between this now:

__Z3barP9DeclGroup:
	movss	(%rdi), %xmm0
	jmp	__Z3foo9DeclGroup  # TAILCALL

vs this before:

__Z3barP9DeclGroup:
	movl	(%rdi), %eax
	movd	%rax, %xmm0
	jmp	__Z3foo9DeclGroup  # TAILCALL

llvm-svn: 107048
2010-06-28 19:56:59 +00:00
Fariborz Jahanian c42461e145 Minor refactorin of my last patch (radar 7860965 related).
llvm-svn: 107047
2010-06-28 19:42:10 +00:00
Fariborz Jahanian 36ad0e99d5 Have __func__ and siblings point to block's implementation function
name. Fixes radar 7860965.

llvm-svn: 107044
2010-06-28 18:58:34 +00:00
Chris Lattner c1028f689e Fix UnitTests/2004-02-02-NegativeZero.c, which regressed when
I broke negate of FP values.

llvm-svn: 107019
2010-06-28 17:12:37 +00:00
Anders Carlsson 3f48c603fb Correctly destroy reference temporaries with global storage. Remove ErrorUnsupported call when binding a global reference to a non-lvalue. Fixes PR7326.
llvm-svn: 106983
2010-06-27 17:52:15 +00:00
Anders Carlsson 18c205ecdf Add a CreateReferenceTemporary that will do the right thing for variables with global storage.
llvm-svn: 106982
2010-06-27 17:23:46 +00:00
Anders Carlsson 2969c8c69d Simplify CodeGenFunction::EmitReferenceBindingToExpr as a first step towards fixing PR7326.
llvm-svn: 106981
2010-06-27 16:56:04 +00:00
Anders Carlsson ca68d357d4 Reduce indentation.
llvm-svn: 106980
2010-06-27 15:24:55 +00:00
Chris Lattner 818efb64a3 misc tidying
llvm-svn: 106978
2010-06-27 07:40:06 +00:00
Chris Lattner 5e016ae983 finally get around to doing a significant cleanup to irgen:
have CGF create and make accessible standard int32,int64 and 
intptr types.  This fixes a ton of 80 column violations 
introduced by LLVMContextification and cleans up stuff a lot.

llvm-svn: 106977
2010-06-27 07:15:29 +00:00
Chris Lattner e000907e13 tidy up OrderGlobalInits
llvm-svn: 106976
2010-06-27 06:32:58 +00:00
Chris Lattner 055097f024 If coercing something from int or pointer type to int or pointer type
(potentially after unwrapping it from a struct) do it without going through
memory.  We now compile:

struct DeclGroup {
  unsigned NumDecls;
};

int foo(DeclGroup D) {
  return D.NumDecls;
}

into:

%struct.DeclGroup = type { i32 }

define i32 @_Z3foo9DeclGroup(i64) nounwind ssp noredzone {
entry:
  %D = alloca %struct.DeclGroup, align 4          ; <%struct.DeclGroup*> [#uses=2]
  %coerce.dive = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  %coerce.val.ii = trunc i64 %0 to i32            ; <i32> [#uses=1]
  store i32 %coerce.val.ii, i32* %coerce.dive
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  %tmp1 = load i32* %tmp                          ; <i32> [#uses=1]
  ret i32 %tmp1
}

instead of:

%struct.DeclGroup = type { i32 }

define i32 @_Z3foo9DeclGroup(i64) nounwind ssp noredzone {
entry:
  %D = alloca %struct.DeclGroup, align 4          ; <%struct.DeclGroup*> [#uses=2]
  %tmp = alloca i64                               ; <i64*> [#uses=2]
  %coerce.dive = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  store i64 %0, i64* %tmp
  %1 = bitcast i64* %tmp to i32*                  ; <i32*> [#uses=1]
  %2 = load i32* %1, align 1                      ; <i32> [#uses=1]
  store i32 %2, i32* %coerce.dive
  %tmp1 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  %tmp2 = load i32* %tmp1                         ; <i32> [#uses=1]
  ret i32 %tmp2
}

... which is quite a bit less terrifying.

llvm-svn: 106975
2010-06-27 06:26:04 +00:00
Chris Lattner 895c52ba8b Same patch as the previous on the store side. Before we compiled this:
struct DeclGroup {
  unsigned NumDecls;
};

int foo(DeclGroup D) {
  return D.NumDecls;
}

to:

%struct.DeclGroup = type { i32 }

define i32 @_Z3foo9DeclGroup(i64) nounwind ssp noredzone {
entry:
  %D = alloca %struct.DeclGroup, align 4          ; <%struct.DeclGroup*> [#uses=2]
  %tmp = alloca i64                               ; <i64*> [#uses=2]
  store i64 %0, i64* %tmp
  %1 = bitcast i64* %tmp to %struct.DeclGroup*    ; <%struct.DeclGroup*> [#uses=1]
  %2 = load %struct.DeclGroup* %1, align 1        ; <%struct.DeclGroup> [#uses=1]
  store %struct.DeclGroup %2, %struct.DeclGroup* %D
  %tmp1 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  %tmp2 = load i32* %tmp1                         ; <i32> [#uses=1]
  ret i32 %tmp2
}

which caused fast isel bailouts due to the FCA load/store of %2.  Now
we generate this just blissful code:

%struct.DeclGroup = type { i32 }

define i32 @_Z3foo9DeclGroup(i64) nounwind ssp noredzone {
entry:
  %D = alloca %struct.DeclGroup, align 4          ; <%struct.DeclGroup*> [#uses=2]
  %tmp = alloca i64                               ; <i64*> [#uses=2]
  %coerce.dive = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  store i64 %0, i64* %tmp
  %1 = bitcast i64* %tmp to i32*                  ; <i32*> [#uses=1]
  %2 = load i32* %1, align 1                      ; <i32> [#uses=1]
  store i32 %2, i32* %coerce.dive
  %tmp1 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  %tmp2 = load i32* %tmp1                         ; <i32> [#uses=1]
  ret i32 %tmp2
}

This avoids fastisel bailing out and is groundwork for future patch.
This reduces bailouts on CGStmt.ll to 911 from 935.

llvm-svn: 106974
2010-06-27 06:04:18 +00:00
Chris Lattner 1cd6698a7c improve CreateCoercedLoad a bit to generate slightly less awful
IR when handling X86-64 by-value struct stuff.  For example, we
use to compile this:

struct DeclGroup {
  unsigned NumDecls;
};

int foo(DeclGroup D);
void bar(DeclGroup *D) {
  foo(*D);
}

into:

define void @_Z3barP9DeclGroup(%struct.DeclGroup* %D) ssp nounwind {
entry:
  %D.addr = alloca %struct.DeclGroup*, align 8    ; <%struct.DeclGroup**> [#uses=2]
  %agg.tmp = alloca %struct.DeclGroup, align 4    ; <%struct.DeclGroup*> [#uses=2]
  %tmp3 = alloca i64                              ; <i64*> [#uses=2]
  store %struct.DeclGroup* %D, %struct.DeclGroup** %D.addr
  %tmp = load %struct.DeclGroup** %D.addr         ; <%struct.DeclGroup*> [#uses=1]
  %tmp1 = bitcast %struct.DeclGroup* %agg.tmp to i8* ; <i8*> [#uses=1]
  %tmp2 = bitcast %struct.DeclGroup* %tmp to i8*  ; <i8*> [#uses=1]
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 4, i32 4, i1 false)
  %0 = bitcast i64* %tmp3 to %struct.DeclGroup*   ; <%struct.DeclGroup*> [#uses=1]
  %1 = load %struct.DeclGroup* %agg.tmp           ; <%struct.DeclGroup> [#uses=1]
  store %struct.DeclGroup %1, %struct.DeclGroup* %0, align 1
  %2 = load i64* %tmp3                            ; <i64> [#uses=1]
  call void @_Z3foo9DeclGroup(i64 %2)
  ret void
}

which would cause fastisel to bail out due to the first class aggregate load %1.  With
this patch we now compile it into the (still awful):

define void @_Z3barP9DeclGroup(%struct.DeclGroup* %D) nounwind ssp noredzone {
entry:
  %D.addr = alloca %struct.DeclGroup*, align 8    ; <%struct.DeclGroup**> [#uses=2]
  %agg.tmp = alloca %struct.DeclGroup, align 4    ; <%struct.DeclGroup*> [#uses=2]
  %tmp3 = alloca i64                              ; <i64*> [#uses=2]
  store %struct.DeclGroup* %D, %struct.DeclGroup** %D.addr
  %tmp = load %struct.DeclGroup** %D.addr         ; <%struct.DeclGroup*> [#uses=1]
  %tmp1 = bitcast %struct.DeclGroup* %agg.tmp to i8* ; <i8*> [#uses=1]
  %tmp2 = bitcast %struct.DeclGroup* %tmp to i8*  ; <i8*> [#uses=1]
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 4, i32 4, i1 false)
  %coerce.dive = getelementptr %struct.DeclGroup* %agg.tmp, i32 0, i32 0 ; <i32*> [#uses=1]
  %0 = bitcast i64* %tmp3 to i32*                 ; <i32*> [#uses=1]
  %1 = load i32* %coerce.dive                     ; <i32> [#uses=1]
  store i32 %1, i32* %0, align 1
  %2 = load i64* %tmp3                            ; <i64> [#uses=1]
  %call = call i32 @_Z3foo9DeclGroup(i64 %2) noredzone ; <i32> [#uses=0]
  ret void
}

which doesn't bail out.  On CGStmt.ll, this reduces fastisel bail outs from 958 to 935,
and is the precursor of better things to come.

llvm-svn: 106973
2010-06-27 05:56:15 +00:00
Chris Lattner 3fcc790cd8 Change IR generation for return (in the simple case) to avoid doing silly
load/store nonsense in the epilog.  For example, for:

int foo(int X) {
  int A[100];
  return A[X];
}

we used to generate:

  %arrayidx = getelementptr inbounds [100 x i32]* %A, i32 0, i64 %idxprom ; <i32*> [#uses=1]
  %tmp1 = load i32* %arrayidx                     ; <i32> [#uses=1]
  store i32 %tmp1, i32* %retval
  %0 = load i32* %retval                          ; <i32> [#uses=1]
  ret i32 %0
}

which codegen'd to this code:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	subq	$408, %rsp              ## imm = 0x198
	movl	%edi, 400(%rsp)
	movl	400(%rsp), %edi
	movslq	%edi, %rax
	movl	(%rsp,%rax,4), %edi
	movl	%edi, 404(%rsp)
	movl	404(%rsp), %eax
	addq	$408, %rsp              ## imm = 0x198
	ret

Now we generate:

  %arrayidx = getelementptr inbounds [100 x i32]* %A, i32 0, i64 %idxprom ; <i32*> [#uses=1]
  %tmp1 = load i32* %arrayidx                     ; <i32> [#uses=1]
  ret i32 %tmp1
}

and:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	subq	$408, %rsp              ## imm = 0x198
	movl	%edi, 404(%rsp)
	movl	404(%rsp), %edi
	movslq	%edi, %rax
	movl	(%rsp,%rax,4), %eax
	addq	$408, %rsp              ## imm = 0x198
	ret

This actually does matter, cutting out 2000 lines of IR from CGStmt.ll 
for example.

Another interesting effect is that altivec.h functions which are dead
now get dce'd by the inliner.  Hence all the changes to 
builtins-ppc-altivec.c to ensure the calls aren't dead.

llvm-svn: 106970
2010-06-27 01:06:27 +00:00
Chris Lattner 726b3d09cd reduce indentation
llvm-svn: 106967
2010-06-26 23:13:19 +00:00
Chris Lattner 6c5abe88bf Implement rdar://7530813 - collapse multiple GEP instructions in IRgen
This avoids generating two gep's for common array operations.  Before
we would generate something like:

  %tmp = load i32* %X.addr                        ; <i32> [#uses=1]
  %arraydecay = getelementptr inbounds [100 x i32]* %A, i32 0, i32 0 ; <i32*> [#uses=1]
  %arrayidx = getelementptr inbounds i32* %arraydecay, i32 %tmp ; <i32*> [#uses=1]
  %tmp1 = load i32* %arrayidx                     ; <i32> [#uses=1]

Now we generate:

  %tmp = load i32* %X.addr                        ; <i32> [#uses=1]
  %arrayidx = getelementptr inbounds [100 x i32]* %A, i32 0, i32 %tmp ; <i32*> [#uses=1]
  %tmp1 = load i32* %arrayidx                     ; <i32> [#uses=1]

Less IR is better at -O0.

llvm-svn: 106966
2010-06-26 23:03:20 +00:00
Chris Lattner 57ce97151f minor cleanup: don't emit the base of an array subscript until after
we're done diddling around with the index stuff.  Use a cheaper type
comparison.

llvm-svn: 106963
2010-06-26 22:40:46 +00:00
Chris Lattner 431bef4409 fix inc/dec to honor -fwrapv and -ftrapv, implementing PR7426.
llvm-svn: 106962
2010-06-26 22:18:28 +00:00
Chris Lattner 05dc78c096 move scalar inc/dec codegen into ScalarExprEmitter instead
of being in CGF.  No functionality change.

llvm-svn: 106961
2010-06-26 22:09:34 +00:00
Chris Lattner fa20e95043 use more efficient type comparison predicates.
llvm-svn: 106958
2010-06-26 21:52:32 +00:00
Chris Lattner 0bf27620f0 Fix unary minus to trap on overflow with -ftrapv, refactoring binop
code so we can use it from VisitUnaryMinus.

llvm-svn: 106957
2010-06-26 21:48:21 +00:00
Chris Lattner 51924e517b Implement support for -fwrapv, rdar://7221421
As part of this, pull together trapv handling into the same enum.

This also add support for NSW multiplies.

This also makes PCH disagreement on overflow behavior silent, since it
really doesn't matter except for warnings and codegen (no macros get 
defined etc).

llvm-svn: 106956
2010-06-26 21:25:03 +00:00
Chris Lattner 217e056e40 implement rdar://7432000 - signed negate should codegen as NSW.
While I'm in there, adjust pointer to member adjustments as well.

llvm-svn: 106955
2010-06-26 20:27:24 +00:00
Anders Carlsson 04775f8413 Change EmitReferenceBindingToExpr to take a decl instead of a boolean.
llvm-svn: 106949
2010-06-26 16:35:32 +00:00
Anders Carlsson 709ef8e46c Add function for mangling reference temporaries.
llvm-svn: 106948
2010-06-26 16:09:40 +00:00
Charles Davis f4db33cbdf Mangle pointer and (lvalue) reference types in the Microsoft C++ Mangler.
Also, fix mangling of throw specs. Turns out MSVC totally ignores throw
specs when mangling names.

llvm-svn: 106937
2010-06-26 03:50:05 +00:00
Fariborz Jahanian b66b08ef01 Minor change to my last patch to fix PR7490.
llvm-svn: 106875
2010-06-25 20:01:13 +00:00
Fariborz Jahanian d5202e0926 IRGen for trivial initialization of dynamiccaly allocated
array of other done c++ objects. Fixes PR7490.

llvm-svn: 106869
2010-06-25 18:26:07 +00:00
Fariborz Jahanian 9b5528d278 Patch to correctly mangle block helper functions
when block literal is declared inside a ctor/dtor.
Fixes radr 8096995.

llvm-svn: 106700
2010-06-24 00:08:06 +00:00
Chris Lattner 37141f4fb4 improve altivec vector bool/pixel support, patch by Anton Yartsev
with several tweaks by me.

llvm-svn: 106619
2010-06-23 06:00:24 +00:00
Chris Lattner b48a2d5d2f polish the -finstrument-functions implementation, patch by Nelson Elhage!
llvm-svn: 106618
2010-06-23 05:21:28 +00:00
Douglas Gregor 49b4d73451 Type Type::isRealFloatingType() that vectors are not floating-point
types, updating callers of both isFloatingType() and
isRealFloatingType() accordingly. Caught at least one issue where we
allowed one to declare a vector of vectors (!), along with cleaning up
the standard-conversion logic for C++.

llvm-svn: 106595
2010-06-22 23:07:26 +00:00
Fariborz Jahanian 7966aff294 Fixes a problem in generation of meta-data for
category implementation whereby property list was missing.
NeXt ObjC runtime (radar 8093297).

llvm-svn: 106550
2010-06-22 16:33:55 +00:00
Anders Carlsson ea836bc41c Switch over to the new caching version of getMangledName.
llvm-svn: 106549
2010-06-22 16:16:50 +00:00
Anders Carlsson 2e2f4d2e6d Add a new variant of getMangledName that caches the mangling for decls.
llvm-svn: 106547
2010-06-22 16:05:32 +00:00
Anders Carlsson 16d9f1788e Add GlobalDecl::getCanonicalDecl.
llvm-svn: 106546
2010-06-22 16:00:14 +00:00
Fariborz Jahanian 469b200321 Per Chris's comment, remove another static (this one
is a static comparator operator).

llvm-svn: 106511
2010-06-22 00:23:08 +00:00
Chris Lattner 3c77a355e0 implement support for -finstrument-functions, patch by Nelson
Elhage!

llvm-svn: 106507
2010-06-22 00:03:40 +00:00
Fariborz Jahanian c9fec975e6 Avoid using a local static for providing lexical
order of priorotized global object initializations.

llvm-svn: 106503
2010-06-21 23:31:29 +00:00
Fariborz Jahanian 9adb2e646c In fragile-abi (32bit mode abi) generate global symbol
objc_category_name_xxx for each category implementation.
(fixes PR7431) patch by Nico Weber.

llvm-svn: 106492
2010-06-21 22:05:18 +00:00
Fariborz Jahanian 89bdd14f2f In supporting init-priority, globals with the same init_priority must be
emitted in the order in which they are seen (still radar 8076356).

llvm-svn: 106485
2010-06-21 21:27:42 +00:00
Anders Carlsson 280e61f148 Fix an Obj-C++ miscompile when calling an Obj-C method that returns a C++ reference.
llvm-svn: 106477
2010-06-21 20:59:55 +00:00
Fariborz Jahanian 090e4e5773 Use more efficient API of SmallVector/array_pod_sort
for sorting (radar 8076356).

llvm-svn: 106453
2010-06-21 19:49:38 +00:00
Fariborz Jahanian 9f2a4eed0d IRGen for implementation of init-priority attribute.
Test case will be checked in llvm test suite.
(finishes off radar 8076356).

llvm-svn: 106441
2010-06-21 18:45:05 +00:00
Douglas Gregor 5dd34744c5 Instantiations subject to an explicit template instantiation
declaration have default visibility even under
-fvisibility=hidden. Fixes <rdar://problem/8109763>.

llvm-svn: 106440
2010-06-21 18:41:26 +00:00
Nate Begeman ed48c857dc Implement remaining codegen for NEON, all operations should now work.
llvm-svn: 106407
2010-06-20 23:05:28 +00:00
Anton Korobeynikov cc50b7d7d5 More AltiVec support.
Patch by Anton Yartsev!

llvm-svn: 106387
2010-06-19 09:47:18 +00:00
Eli Friedman c96b2496fc Fix for PR7415: refactor CodeGenModule::MayDeferGeneration and make it less
conservative for static variables in templated classes.

llvm-svn: 106385
2010-06-19 06:24:06 +00:00
Chris Lattner 87233f785b Fix PR7097, a bad interaction between -fno-use-cxa-atexit and
-mconstructor-aliases by using a WeakVH instead of a raw pointer.

llvm-svn: 106384
2010-06-19 05:52:45 +00:00
Charles Davis 108f5a2748 Mangle tag types (unions, structs, classes, enums) in the Microsoft C++ Mangler.
Also, test that static members with default visibility in a struct have the
right mangling.

llvm-svn: 106276
2010-06-18 07:51:00 +00:00
Fariborz Jahanian 64cda8b5f3 objective-C++ IRGen: property reference as an
lvalue when performing a derived-to-base conversion.
Fixes radar 7501812. Added an executable test to
llvm-test suite.

llvm-svn: 106247
2010-06-17 23:00:29 +00:00
Fariborz Jahanian 9240f3dac7 Objective-c++ IRGen. Support for @selector expression as
an lvalue. Fixes PR7390.

llvm-svn: 106235
2010-06-17 19:56:20 +00:00
Charles Davis 8c02c13e19 Mangle operator names in the Microsoft C++ Mangler.
llvm-svn: 106211
2010-06-17 06:47:31 +00:00
Nate Begeman dbafec1f3e Remove last of the bool shifts for MS VC++, patch by dimitry andric
llvm-svn: 106206
2010-06-17 02:26:59 +00:00
Alexis Hunt c675ec09f0 Update CMake build for new attribute changes.
llvm-svn: 106188
2010-06-17 00:37:02 +00:00
Rafael Espindola 23a8a06554 Change the test for which ABI/CC to use on ARM to be base on the environment
(the last argument of the triple).

llvm-svn: 106131
2010-06-16 19:01:17 +00:00
Fariborz Jahanian 4a30307840 Fixed conflict between objc_memmove_collectable builtin
decl. and one ddefined in darwin header file.

llvm-svn: 106107
2010-06-16 16:22:04 +00:00
Rafael Espindola a92c442437 Don't set the calling convention for ARM if it is already the default.
llvm-svn: 106106
2010-06-16 16:13:39 +00:00
Charles Davis 89338af1ff Start mangling function types in the Microsoft C++ Mangler.
llvm-svn: 106081
2010-06-16 05:33:16 +00:00
Douglas Gregor 6972a62c8f Give Type::isIntegralType() an ASTContext parameter, so that it
provides C "integer type" semantics in C and C++ "integral type"
semantics in C++. 

Note that I still need to update isIntegerType (and possibly other
predicates) using the same approach I've taken for
isIntegralType(). The two should have the same meaning, but currently
don't (!).

llvm-svn: 106074
2010-06-16 00:35:25 +00:00
Douglas Gregor b90df60b3b Introduce Type::isIntegralOrEnumerationType(), to cover those places
in C++ that involve both integral and enumeration types. Convert all
of the callers to Type::isIntegralType() that are meant to work with
both integral and enumeration types over to
Type::isIntegralOrEnumerationType(), to prepare to eliminate
enumeration types as integral types.

llvm-svn: 106071
2010-06-16 00:17:44 +00:00
Chandler Carruth 8509824cdb Move CodeGenOptions.h *back* into Frontend. This should have been done when the
dependency edge was reversed such that CodeGen depends on Frontend.

llvm-svn: 106065
2010-06-15 23:19:56 +00:00
Fariborz Jahanian 021510e96f Patch adds support for copying of those
objective-c++ class objects which have GC'able objc object
pointers and need to use ObjC's objc_memmove_collectable
API (radar 8070772). 

llvm-svn: 106061
2010-06-15 22:44:06 +00:00