Commit Graph

421 Commits

Author SHA1 Message Date
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 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
Anders Carlsson 04775f8413 Change EmitReferenceBindingToExpr to take a decl instead of a boolean.
llvm-svn: 106949
2010-06-26 16:35:32 +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 3c77a355e0 implement support for -finstrument-functions, patch by Nelson
Elhage!

llvm-svn: 106507
2010-06-22 00:03:40 +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
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
Nate Begeman 91e1feab7a Add some missing shifts
Fix multiplies by scalar
Add SemaChecking code for all immediates
Add SemaChecking-gen support to arm_neon.td

llvm-svn: 105930
2010-06-14 05:21:25 +00:00
Nate Begeman 8ed060b95a Most of remaining builtins, 2 generics, vld, and rounding shfits remain.
llvm-svn: 105848
2010-06-11 22:57:12 +00:00
Nate Begeman 4a04b467d9 support _lane ops, and multiplies by scalar.
llvm-svn: 105770
2010-06-10 00:17:56 +00:00
Anders Carlsson 9eb101c5d3 Rename __tcf_ to __cxx_global_array_dtor. Remove the UniqueAggreDestructorCount from CodeGenFunction and let LLVM handle uniquing the internal functions instead.
llvm-svn: 105648
2010-06-08 22:30:17 +00:00
Anders Carlsson 165ec0a04f Simplify GenerateCXXAggrDestructorHelper.
llvm-svn: 105646
2010-06-08 22:14:59 +00:00
Nate Begeman ae6b1d8010 Fix NEON intrinsic argument passing, support vext. Most now successfully make it through codegen to the .s file
llvm-svn: 105599
2010-06-08 06:03:01 +00:00
John McCall 23f6626262 Correctly pass aggregates by reference when emitting thunks.
llvm-svn: 104778
2010-05-26 22:34:26 +00:00
Anders Carlsson c0964b60e5 Re-land the fix for PR7139.
llvm-svn: 104446
2010-05-22 17:35:42 +00:00
John McCall 78a151138a Push a return-value slot throughout ObjC message-send codegen. Will be
critical for ObjC++ correctness;  hard to test independently of various
required Sema changes, though.

llvm-svn: 104422
2010-05-22 01:48:05 +00:00
Anders Carlsson c866eb5ba9 Unbreak self-host.
llvm-svn: 104390
2010-05-21 22:17:48 +00:00
Anders Carlsson da1641cd12 Rename CodeGenFunction::EmitMemSetToZero to EmitNullInitialization. Handle setting null data member pointers correctly. Fixes PR7139.
llvm-svn: 104387
2010-05-21 21:45:41 +00:00
John McCall 9d42f0f174 Allocate space in a block record for implicit references to the Objective C
'self' variable arising from uses of the 'super' keyword.  Also reorganize
some code so that BlockInfo (now CGBlockInfo) can be opaque outside of
CGBlocks.cpp.

Fixes rdar://problem/8010633.

llvm-svn: 104312
2010-05-21 04:11:14 +00:00
John McCall c4094935c0 When emitting an lvalue for an anonymous struct or union member during
class initialization, drill down through an arbitrary number of anonymous
records.

llvm-svn: 104310
2010-05-21 01:18:57 +00:00
John McCall 87fe5d5618 Support implicitly closing on 'this' in a block. Fixed PR7165.
(the codegen works here, too, but that's annoying to test without execution)

llvm-svn: 104202
2010-05-20 01:18:31 +00:00
Douglas Gregor 9154b5dffe Ensure that destructors are called for NRVO'd objects when the
function does not return. Thanks to Eli for pointing out this corner
case.

llvm-svn: 103941
2010-05-17 15:52:46 +00:00
Douglas Gregor 51150ab1f1 When initializing thread-safe statics, put the call to
__cxa_guard_abort along the exceptional edge into (in effect) a nested
"try" that rethrows after aborting. Fixes PR7144 and the remaining
Boost.ProgramOptions failures, along with the regressions that r103880
caused.

The crucial difference between this and r103880 is that we now follow
LLVM's little dance with the llvm.eh.exception and llvm.eh.selector
calls, then use _Unwind_Resume_or_Rethrow to rethrow.

llvm-svn: 103892
2010-05-16 01:24:12 +00:00
Douglas Gregor c278d1b3b9 Revert r103880 (thread-safe static initialization w/ exceptions),
because it's causing strange linker errors. Unfixes PR7144.

llvm-svn: 103890
2010-05-16 00:44:00 +00:00
Douglas Gregor 58142dd8a1 When initializing thread-safe statics, put the call to
__cxa_guard_abort along the exceptional edge into (in effect) a nested
"try" that rethrows after aborting. Fixes PR7144 and the remaining
Boost.ProgramOptions failures.

llvm-svn: 103880
2010-05-15 17:55:51 +00:00
Anders Carlsson a1bc38d53e Remove an unused function.
llvm-svn: 103793
2010-05-14 19:48:27 +00:00
Douglas Gregor 94f9a4820a Reimplement code generation for copying fields in the
implicitly-generated copy constructor. Previously, Sema would perform
some checking and instantiation to determine which copy constructors,
etc., would be called, then CodeGen would attempt to figure out which
copy constructor to call... but would get it wrong, or poke at an
uninstantiated default argument, or fail in other ways.

The new scheme is similar to what we now do for the implicit
copy-assignment operator, where Sema performs all of the semantic
analysis and builds specific ASTs that look similar to the ASTs we'd
get from explicitly writing the copy constructor, so that CodeGen need
only do a direct translation.

However, it's not quite that simple because one cannot explicit write
elementwise copy-construction of an array. So, I've extended
CXXBaseOrMemberInitializer to contain a list of indexing variables
used to copy-construct the elements. For example, if we have:

  struct A { A(const A&); };
  
  struct B {
    A array[2][3];
  };

then we generate an implicit copy assignment operator for B that looks
something like this:

  B::B(const B &other) : array[i0][i1](other.array[i0][i1]) { }

CodeGen will loop over the invented variables i0 and i1 to visit all
elements in the array, so that each element in the destination array
will be copy-constructed from the corresponding element in the source
array. Of course, if we're dealing with arrays of scalars or class
types with trivial copy-assignment operators, we just generate a
memcpy rather than a loop.

Fixes PR6928, PR5989, and PR6887. Boost.Regex now compiles and passes
all of its regression tests.

Conspicuously missing from this patch is handling for the exceptional
case, where we need to destruct those objects that we have
constructed. I'll address that case separately.

llvm-svn: 103079
2010-05-05 05:51:00 +00:00
Anders Carlsson f4da2cf20a Remove OldGetAddressOfBaseClass - bye bye ambiguities.
llvm-svn: 102889
2010-05-03 00:32:27 +00:00
Anders Carlsson c4d0d0fed1 More work towards getting rid of OldGetAddressOfBaseClass.
llvm-svn: 102887
2010-05-03 00:07:07 +00:00
Anders Carlsson f8a71f08d1 Add the same 'ForVirtualBase' parameter to EmitCXXDestructorCall.
llvm-svn: 102882
2010-05-02 23:29:11 +00:00
Anders Carlsson e11f9ce9dc Revert my last change and add a 'ForVirtualBase' parameter to EmitCXXConstructorCall instead.
llvm-svn: 102881
2010-05-02 23:20:53 +00:00
Anders Carlsson 4c638f1217 Pass the construction kind down to EmitCXXConstructorCall.
llvm-svn: 102880
2010-05-02 23:01:10 +00:00
Anders Carlsson 245820b9d9 Remove another unused function.
llvm-svn: 102871
2010-05-02 18:13:35 +00:00
Anders Carlsson 54eb4843b1 Remove an unused function.
llvm-svn: 102870
2010-05-02 18:12:22 +00:00
David Chisnall ff5f88c38e As per Chris' request, return the Instruction from EmitCall and add the metadata in the caller.
llvm-svn: 102862
2010-05-02 13:41:58 +00:00
Douglas Gregor b139cd5843 Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators. 

Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.

This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:

  - For a class subobject, call the appropriate copy-assignment
    operator, after overload resolution has determined what that is.
  - For an array of scalar types or an array of class types that have
    trivial copy assignment operators, construct a call to
    __builtin_memcpy.
  - For an array of class types with non-trivial copy assignment
    operators, synthesize a (possibly nested!) for loop whose inner
    statement calls the copy constructor.
  - For a scalar type, use built-in assignment.

This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.

Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.

llvm-svn: 102853
2010-05-01 20:49:11 +00:00
Anders Carlsson aab3b57359 Simplify EmitClassAggrMemberwiseCopy.
llvm-svn: 102848
2010-05-01 17:02:18 +00:00
Anders Carlsson ab826ad169 Clean up EmitClassMemberwiseCopy further.
llvm-svn: 102846
2010-05-01 16:54:05 +00:00
Anders Carlsson 820022c55c Get rid of a parameter from EmitClassMemberwiseCopy.
llvm-svn: 102845
2010-05-01 16:49:43 +00:00
David Chisnall 9eecafa480 Tweaked EmitCall() to permit the caller to provide some metadata to attach to the call site.
Used this in CGObjCGNU to attach metadata about message sends to permit speculative inlining.

llvm-svn: 102833
2010-05-01 11:15:56 +00:00
Anders Carlsson d6c5391cd9 Remove an unnecessary parameter from EmitClassCopyAssignment.
llvm-svn: 102747
2010-04-30 19:45:28 +00:00
Anders Carlsson 2b4ec8d003 Remove an unnecessary argument to EmitClassCopyAssignment.
llvm-svn: 102674
2010-04-29 23:51:42 +00:00
Fariborz Jahanian 0dec1e0d56 IRGen for initialization/destruction of
ivar class objects (NeXt runtime).
(radar 7900343).

llvm-svn: 102533
2010-04-28 21:28:56 +00:00
Anders Carlsson 53e1ba948d Revert enough of my patches to fix self-host again :(
llvm-svn: 102289
2010-04-25 00:52:09 +00:00
Anders Carlsson c4ba0cd2ea RenameGetAddressOfBaseOfCompleteClass to GetAddressOfDirectBaseInCompleteClass to reflect that it only handles direct bases.
llvm-svn: 102284
2010-04-24 23:01:49 +00:00
Anders Carlsson 26b6e23d57 More cleanup.
llvm-svn: 102282
2010-04-24 22:43:39 +00:00
Anders Carlsson 9523ad4fd3 Simplify EmitClassMemberwiseCopy now that it's only used for fields.
llvm-svn: 102281
2010-04-24 22:36:50 +00:00
Anders Carlsson bea9e74e82 Rename GetAddressOfBaseClass to OldGetAddressOfBaseClass.
llvm-svn: 102275
2010-04-24 21:51:08 +00:00
Anders Carlsson 8a64c1c94c Change CodeGenFunction::GetAddressOfDerivedClass to take a BasePath.
llvm-svn: 102273
2010-04-24 21:23:59 +00:00