Commit Graph

218 Commits

Author SHA1 Message Date
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 b48a2d5d2f polish the -finstrument-functions implementation, patch by Nelson Elhage!
llvm-svn: 106618
2010-06-23 05:21:28 +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
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
Douglas Gregor 7e10f3699a Improve name mangling for blocks and support mangling of static local
variables within blocks. We loosely follow GCC's mangling, but since
these are always internal symbols the names don't really matter. I
intend to revisit block mangling later, because GCC's mangling is
rather verbose. <rdar://problem/8015719>.

llvm-svn: 104610
2010-05-25 17:04:15 +00:00
Anders Carlsson c0964b60e5 Re-land the fix for PR7139.
llvm-svn: 104446
2010-05-22 17:35:42 +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
Anders Carlsson 16e94af67c Don't copy or initialize empty classes. Fixes PR7012.
llvm-svn: 102891
2010-05-03 01:20:20 +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
Devang Patel 74c10507a6 Fix debug info for cleanup block.
llvm-svn: 101100
2010-04-13 00:08:43 +00:00
Mon P Wang cc2ab0cdc9 Reapply patch for adding support for address spaces and added a isVolatile field to memcpy, memmove, and memset.
llvm-svn: 100305
2010-04-04 03:10:52 +00:00
Mon P Wang f7f3bff646 Revert r100193 since it causes failures in objc in clang
llvm-svn: 100200
2010-04-02 18:43:42 +00:00
Mon P Wang 4b82a88764 Reapply patch for adding support for address spaces and added a isVolatile field to memcpy, memmove, and memset.
llvm-svn: 100193
2010-04-02 18:04:30 +00:00
Bob Wilson adb58e32cc Revert Mon Ping's 99930 due to broken llvm-gcc buildbots.
llvm-svn: 99949
2010-03-30 22:28:46 +00:00
Mon P Wang 231e99743a Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset
llvm-svn: 99930
2010-03-30 21:02:45 +00:00
Rafael Espindola c50c27cca8 the big refactoring bits of PR3782.
This introduces FunctionType::ExtInfo to hold the calling convention and the
noreturn attribute. The next patch will extend it to include the regparm
attribute and fix the bug.

llvm-svn: 99920
2010-03-30 20:24:48 +00:00
Anders Carlsson a864caff8c Rename CGVtableInfo to CodeGenVTables in preparation of adding another VTableInfo class.
llvm-svn: 99250
2010-03-23 04:11:45 +00:00
Douglas Gregor 36c569fb33 Eliminate the default arguments to ASTContext::getFunctionType(),
fixing up a few callers that thought they were propagating NoReturn
information but were in fact saying something about exception
specifications.

llvm-svn: 96766
2010-02-21 22:15:06 +00:00
John McCall b81884d347 More refactoring around constructor/destructor code generation.
Fix some bugs with function-try-blocks and simplify normal try-block
code generation.

This implementation excludes a deleting destructor's call to
operator delete() from the function-try-block, which I believe
is correct but which I can't find straightforward support for at
a moment's glance.

llvm-svn: 96670
2010-02-19 09:25:03 +00:00
John McCall 5c60a6f597 Make deleting and complete dtor variants defer to other dtor variants by
calling them as subroutines.  This triggers whenever the alias optimization
doesn't, i.e. when the dtor has linkonce linkage or there are virtual bases
or it's the deleting dtor.

llvm-svn: 96605
2010-02-18 19:59:28 +00:00
John McCall 89b12b34f6 Extract out function-body code generation into its own method. No functionality
change.

llvm-svn: 96564
2010-02-18 03:17:58 +00:00
John McCall 347132b32f IRgen optimization: cache the value of 'this' and 'vtt' instead of
repeatedly reloading from an alloca.  We still need to create the alloca
for debug info purposes (although we currently create it in all cases
because of some abstraction boundaries that're hard to break down).

llvm-svn: 96403
2010-02-16 22:04:33 +00:00
Daniel Dunbar fd09df7839 IRgen: Switch 'retval' to use CreateIRTemp.
llvm-svn: 96376
2010-02-16 19:45:20 +00:00
Jakob Stoklund Olesen 819e54b65c Pass inline keyword to optimizer as the new InlineHint function attribute.
At the moment the inlinehint attribute is ignored by the Inliner unless you
pass a -respect-inlinehint option.  This will soon be the default.

The inlinehint attribute is set if the inline keyword is explicitly specified
on any declaration.

llvm-svn: 95623
2010-02-09 00:10:00 +00:00
Anders Carlsson ff8cce4395 Make sure to set vtable pointers in the destructors as well.
llvm-svn: 95525
2010-02-07 19:45:40 +00:00
John McCall ab26cfa58d Standardize the parsing of function type attributes in a way that
follows (as conservatively as possible) gcc's current behavior:  attributes
written on return types that don't apply there are applied to the function
instead, etc.  Only parse CC attributes as type attributes, not as decl attributes;
don't accepet noreturn as a decl attribute on ValueDecls, either (it still
needs to apply to other decls, like blocks).  Consistently consume CC/noreturn
information throughout codegen;  enforce this by removing their default values
in CodeGenTypes::getFunctionInfo().

llvm-svn: 95436
2010-02-05 21:31:56 +00:00
Anders Carlsson ae612d22ac Rename StartConditionalBranch/FinishConditionalBranch to BeginConditionalBranch/EndConditionalBranch.
llvm-svn: 95308
2010-02-04 17:18:07 +00:00
Anders Carlsson 60ddba67a8 Fix a nasty bug where temporaries weren't marked as being conditional in some cases.
llvm-svn: 94341
2010-01-24 00:20:05 +00:00
Devang Patel 934661ed73 Emit human readable names for c/c++ functions. Avoid emitting linkage name if it matches regular name.
llvm-svn: 93383
2010-01-14 00:36:21 +00:00
Ken Dyck 40775003e6 Roll out ASTContext::getTypeSizeInChars(), replacing instances of
"ASTContext::getTypeSize() / 8". Replace [u]int64_t variables with CharUnits
ones as appropriate. 

Also rename RawType, fromRaw(), and getRaw() in CharUnits to QuantityType, 
fromQuantity(), and getQuantity() for clarity.

llvm-svn: 93153
2010-01-11 17:06:35 +00:00
Anders Carlsson e36a6b3e44 Correctly pass VTT parameters to constructors and destructors. The VTTs aren't yet used in the ctors/dtors, but that will follow.
llvm-svn: 92409
2010-01-02 01:01:18 +00:00
Douglas Gregor 507eb87f05 Eliminate the ASTContext argument to CXXConstructorDecl::isCopyConstructor, since the context is available in the Decl
llvm-svn: 91862
2009-12-22 00:34:07 +00:00
Mike Stump e8c3b3eca4 Switch codegen for -fcatch-undefined-bahavior over to __builtin_trap
instead of abort to improve codesize and codegen.

llvm-svn: 91374
2009-12-15 00:35:12 +00:00
Mike Stump ba6a0c40c4 Add support for detecting undefined shift behavior. WIP.
llvm-svn: 91341
2009-12-14 21:58:14 +00:00
Mike Stump d954638f02 Implement runtime checks for undefined behavior. WIP.
This implements a new flag -fcatch-undefined-behavior.  The flag turns
on additional runtime checks for:

  T a[I];

  a[i]    abort when i < 0 or i >= I.

Future stuff includes shifts by >= bitwidth amounts.

llvm-svn: 91198
2009-12-12 01:27:46 +00:00
Eli Friedman d5bc94e2eb Get rid of static variable.
llvm-svn: 91041
2009-12-10 02:21:21 +00:00
Mike Stump f5cbb08c4b Ensure we only generate one terminate handler.
llvm-svn: 90998
2009-12-10 00:02:42 +00:00
Mike Stump aff69af918 Add cleanups for exceptional edges. WIP.
llvm-svn: 90940
2009-12-09 03:35:49 +00:00
Benjamin Kramer ba8451b243 Use StringRef in CGDebugInfo::EmitFunctionStart.
llvm-svn: 90856
2009-12-08 14:04:35 +00:00
Mike Stump 1d849219a5 Add codegen support for exception specifications. WIP.
llvm-svn: 90817
2009-12-07 23:38:24 +00:00
Mike Stump bee78dd31b Add support for function try blocks.
llvm-svn: 90622
2009-12-04 23:26:17 +00:00
Eli Friedman 4b1942cb8b Make functions returning a struct indirectly evaluate the returned struct
directly into the sret pointer. This is an optimization in C, but is required
for correctness in C++ for classes with a non-trivial copy constructor.

llvm-svn: 90526
2009-12-04 02:43:40 +00:00
Mike Stump 33270211a0 More exception handling improvements... WIP.
Highlights include:

  Add a helper to generate __cxa_free_exception and _ZSt9terminatev.
  Add a region to handle EH object deallocation for ctor failures for throw.
  Add a terminate handler for __cxa_end_catch.
  A framework for adding cleanup actions for the exceptional edges only.

llvm-svn: 90305
2009-12-02 07:41:41 +00:00
Anders Carlsson 82ba57c8f0 Add VTT parameter to base ctors/dtors with virtual bases. (They aren't used yet).
llvm-svn: 89835
2009-11-25 03:15:49 +00:00
Anders Carlsson 0a66c26191 Fix lifetime of conditional temporaries. Patch by Victor Zverovich!
llvm-svn: 89467
2009-11-20 17:27:56 +00:00
Chris Lattner 4f24225e8e indirectbr seems to work! Rip out the old code.
llvm-svn: 86256
2009-11-06 17:38:18 +00:00
Anders Carlsson 421a5c9651 If a member variable of reference type is bound to a temporary in its member initializer it needs to be destroyed at the end of the constructor.
llvm-svn: 86230
2009-11-06 04:19:02 +00:00
Anders Carlsson 438cf92533 Cleanup ctor/dtor emission.
llvm-svn: 86222
2009-11-06 02:55:43 +00:00
Fariborz Jahanian 09cc10f9f8 This patch extends CleanupScope to support destruction
of array objects on block exit. Patch is by Anders Calrsson.

llvm-svn: 86032
2009-11-04 17:57:40 +00:00