Commit Graph

218 Commits

Author SHA1 Message Date
Chris Lattner 6c4d255bf3 Implement clang support for indirect branch and address of label
using the new LLVM support for this.  This is temporarily hiding
behind horrible and ugly #ifdefs until the time when the optimizer
is stable (hopefully a week or so).  Until then, lets make it "opt in" :)

llvm-svn: 85446
2009-10-28 23:59:40 +00:00
Chris Lattner a0c0d88ba8 factor a creation of Int32Ty.
llvm-svn: 85422
2009-10-28 20:36:47 +00:00
Mike Stump ae2559a221 Fixup the return type of functions.
llvm-svn: 84922
2009-10-23 01:52:13 +00:00
Chris Lattner 2bb5cb490c reimplement codegen for indirect goto with the following advantages:
1. CGF now has fewer bytes of state (one pointer instead of a vector).
2. The generated code is determinstic, instead of getting labels in
   'map order' based on pointer addresses.
3. Clang now emits one 'indirect goto switch' for each function, instead
   of one for each indirect goto.  This fixes an M*N = N^2 IR size issue
   when there are lots of address-taken labels and lots of indirect gotos.
4. This also makes the default cause do something useful, reducing the
   size of the jump table needed (by one).

llvm-svn: 83952
2009-10-13 06:55:33 +00:00
Chris Lattner 92ae16b0ae number address-taken labels from 1. This allows 0 to be used as a sentinel
for a null pointer.  In other words, "&&foo != NULL" will always work out to
true.

llvm-svn: 83948
2009-10-13 06:04:29 +00:00
Chris Lattner dd7eaad7d4 Use the new Type::getInt8PtrTy method. This should probably be used in a lot
more places in clang codegen now.

llvm-svn: 83947
2009-10-13 06:02:42 +00:00
Anders Carlsson 6b7378bbe1 Emit the destructor epilogue in a cleanup block so a return from a destructor body still calls the epilogue.
llvm-svn: 83397
2009-10-06 18:09:57 +00:00
Douglas Gregor 369acf9304 CodeGen may see out-of-line declarations of the various special member
functions when they are explicitly declared, e.g., via a function
template specialization or explicit template instantiation
declaration. Don't try to synthesize bodies for the special member
functions in this case; rather, check whether we have an implicit
declaration and, if so, synthesize the appropriate function
body. Fixes PR5084.

llvm-svn: 83212
2009-10-01 20:44:19 +00:00
Anders Carlsson b05a3e551b Improve support for member function pointers.
llvm-svn: 83039
2009-09-29 02:09:01 +00:00
Anders Carlsson d30d820dc4 Make hasAggregateLLVMType use positive checks.
llvm-svn: 83037
2009-09-29 01:15:29 +00:00
Mike Stump 1dbb8f78a3 Fix 80-col violation.
llvm-svn: 82782
2009-09-25 18:11:00 +00:00
John McCall 9dd450bb78 Change all the Type::getAsFoo() methods to specializations of Type::getAs().
Several of the existing methods were identical to their respective
specializations, and so have been removed entirely.  Several more 'leaf'
optimizations were introduced.

The getAsFoo() methods which imposed extra conditions, like
getAsObjCInterfacePointerType(), have been left in place.

llvm-svn: 82501
2009-09-21 23:43:11 +00:00
Anders Carlsson ddf57d3df9 Remove an unnecessary FunctionDecl parameter to the synthesizing functions.
llvm-svn: 81759
2009-09-14 05:32:02 +00:00
Anders Carlsson fd384d8065 Pass the GlobalDecl to getMangledName, fixes PR4890.
llvm-svn: 81486
2009-09-11 00:11:35 +00:00
Anders Carlsson 73fcc95f0f Pass GlobalDecls to GenerateCode and StartFunction.
llvm-svn: 81485
2009-09-11 00:07:24 +00:00
Anders Carlsson e9766d559b If a cast expression needs either a conversion function or a constructor to be called, generate implicit child expressions that call them.
llvm-svn: 81383
2009-09-09 21:33:21 +00:00
Mike Stump 11289f4280 Remove tabs, and whitespace cleanups.
llvm-svn: 81346
2009-09-09 15:08:12 +00:00
Fariborz Jahanian 0a484d007b Patch to ir-gen user-defined conversions used in expressions
[12.3.2-p3]

llvm-svn: 80436
2009-08-29 20:33:32 +00:00
Mike Stump 3722f5896c Regularize the case and sort.
llvm-svn: 80163
2009-08-26 22:31:08 +00:00
Anders Carlsson 4557b2c0c2 Remove dead code
llvm-svn: 79921
2009-08-24 16:52:33 +00:00
Fariborz Jahanian d172e91f2a Patch to 1) synthesizing non-trivial default destructor when
one is not provided by user. 2) More complete
emission of ctor prologue when it has no initializer
list or when it is synthesized.

llvm-svn: 79269
2009-08-17 19:04:50 +00:00
Eli Friedman 04fddf0d1f Fix for PR4721: adjust CodeGen and ASTContext so that we have a
consistent model for handling size expressions for VLAs.

The model is essentially as follows: VLA types own their associated
expression.  In some cases, we need to create multiple VLA types to 
represent a given VLA (for canonical types, or qualifiers on array types,
or type merging).  If we need to create multiple types based off of 
the same VLA declaration, we use the new refcounting functionality so they can 
all own the expression. The VLASizeMap in CodeGenFunction then uses the size
expression to identify the group of VLA types based off of the same original
declaration.

I'm not particularly attached to the VLA types owning the expression, 
but we're stuck with at least until someone comes up with a way 
to walk the VLA expressions for a declaration.

I did the parallel fix in ASTContext for DependentSizedArrayType, but I 
haven't really looked closely at it, so there might still be issues 
there.

I'll clean up the code duplication in ASTContext in a followup commit.

llvm-svn: 79071
2009-08-15 02:50:32 +00:00
Chris Lattner 8dc7626f9c minor cleanups for VLA stuff.
llvm-svn: 79059
2009-08-15 00:03:43 +00:00
Owen Anderson 41a750271b Update for LLVM API change.
llvm-svn: 78946
2009-08-13 21:57:51 +00:00
Fariborz Jahanian de7d4c264a Patch for synthesizing copy assignment operator.
WIP.

llvm-svn: 78841
2009-08-12 21:14:35 +00:00
Fariborz Jahanian 9d3405ceab minor refactoring. No change otherwise.
llvm-svn: 78582
2009-08-10 18:46:38 +00:00
Anders Carlsson f48123b413 Improve handling of member pointers.
llvm-svn: 78536
2009-08-09 18:26:27 +00:00
Anders Carlsson b8be93fc92 Add support for global initializers.
llvm-svn: 78515
2009-08-08 23:24:23 +00:00
Fariborz Jahanian f6bda5d61e Refactoring of copy ctor ir-gen. No change in functionality.
llvm-svn: 78489
2009-08-08 19:31:03 +00:00
Fariborz Jahanian b68df0bc42 Synthesized copy constructor now generates code for
copying non-virtual base classes which have non-trivial
constructor. Work in progress.

llvm-svn: 78436
2009-08-07 23:51:33 +00:00
Fariborz Jahanian 40134e71be More synthesis of copy constructors. Work in progress.
llvm-svn: 78402
2009-08-07 20:22:40 +00:00
Fariborz Jahanian 9301b24c0a Patch toward synthesizing copy constructors.
Work in progress.

llvm-svn: 78355
2009-08-06 23:38:16 +00:00
Owen Anderson 0b75f23b94 Update for LLVM API change.
llvm-svn: 77722
2009-07-31 20:28:54 +00:00
Fariborz Jahanian 6f14c73087 Synthesize the default constructor which has not
been declared as needed.

llvm-svn: 77641
2009-07-30 23:22:00 +00:00
Owen Anderson 7ec07a573c Update for LLVM API changes.
llvm-svn: 77638
2009-07-30 23:11:26 +00:00
Fariborz Jahanian aa01d2a532 Patch for future ir-gen for destructor calls.
llvm-svn: 77608
2009-07-30 17:49:11 +00:00
Owen Anderson 9793f0e4d7 Update for LLVM API change.
llvm-svn: 77514
2009-07-29 22:16:19 +00:00
Ted Kremenek c23c7e6a51 Change uses of:
Type::getAsReferenceType() -> Type::getAs<ReferenceType>()
  Type::getAsRecordType() -> Type::getAs<RecordType>()
  Type::getAsPointerType() -> Type::getAs<PointerType>()
  Type::getAsBlockPointerType() -> Type::getAs<BlockPointerType>()
  Type::getAsLValueReferenceType() -> Type::getAs<LValueReferenceType>()
  Type::getAsRValueReferenceType() -> Type::getAs<RValueReferenceType>()
  Type::getAsMemberPointerType() -> Type::getAs<MemberPointerType>()
  Type::getAsReferenceType() -> Type::getAs<ReferenceType>()
  Type::getAsTagType() -> Type::getAs<TagType>()
  
And remove Type::getAsReferenceType(), etc.

This change is similar to one I made a couple weeks ago, but that was partly
reverted pending some additional design discussion. With Doug's pending smart
pointer changes for Types, it seemed natural to take this approach.

llvm-svn: 77510
2009-07-29 21:53:49 +00:00
Owen Anderson b7a2fe6f81 Update for LLVM API change.
llvm-svn: 77012
2009-07-24 23:12:58 +00:00
Daniel Dunbar 7c02cf609d Shield clang from LLVM API changes, until the dust settles.
llvm-svn: 76862
2009-07-23 05:30:36 +00:00
Fariborz Jahanian 83381cc9a6 Move EmitCtorPrologue to CGCXX. Add an assert and FIXMEs.
llvm-svn: 76498
2009-07-20 23:18:55 +00:00
Fariborz Jahanian 127059c7ec Early ir-gen for constructor prologue. This is on going.
llvm-svn: 76493
2009-07-20 22:35:22 +00:00
Mike Stump 94e12450aa Remove an apparently unused header.
llvm-svn: 76473
2009-07-20 21:17:53 +00:00
Daniel Dunbar ea3060a9e5 Catch another trivial case where we can avoid emitting a separate return blcok.
llvm-svn: 76365
2009-07-19 08:24:34 +00:00
Daniel Dunbar b6adc43f6e Avoid generation of dead code in a few more situations.
- Emit variable declarations as "simple", we want to avoid forcing the creation
   of a dummy basic block, but still need to make the variable available for
   later use.

 - With that, we can now skip IRgen for other unreachable statements (which
   don't define a label).

 - Anders, I added two fixmes on calls to EmitVLASize, can you check them?

llvm-svn: 76361
2009-07-19 06:58:07 +00:00
Ted Kremenek 8a286fbdb9 Per offline discussion with Steve Naroff, add back Type::getAsXXXType() methods
until Doug Gregor's Type smart pointer code lands (or more discussion occurs).
These methods just call the new Type::getAs<XXX> methods, so we still have
reduced implementation redundancy. Having explicit getAsXXXType() methods makes
it easier to set breakpoints in the debugger.

llvm-svn: 76193
2009-07-17 17:50:17 +00:00
Ted Kremenek b825c0ddc5 Replaced Type::getAsLValueReferenceType(), Type::getAsRValueReferenceType(), Type::getAsMemberPointerType(), Type::getAsTagType(), and Type::getAsRecordType() with their Type::getAs<XXX> equivalents.
llvm-svn: 76139
2009-07-17 01:20:38 +00:00
Ted Kremenek e3fb4b6524 Add member template 'Type::getAs<T>', which converts a Type* to a respective T*.
This method is intended to eventually replace the individual
Type::getAsXXXType<> methods.

The motivation behind this change is twofold:

1) Reduce redundant implementations of Type::getAsXXXType() methods. Most of
them are basically copy-and-paste.

2) By centralizing the implementation of the getAs<Type> logic we can more
smoothly move over to Doug Gregor's proposed canonical type smart pointer
scheme.

Along with this patch:

a) Removed 'Type::getAsPointerType()'; now clients use getAs<PointerType>.
b) Removed 'Type::getAsBlockPointerTypE()'; now clients use getAs<BlockPointerType>.

llvm-svn: 76098
2009-07-16 19:58:26 +00:00
Owen Anderson 170229f68d Update for LLVM API change, and contextify a bunch of related stuff.
llvm-svn: 75705
2009-07-14 23:10:40 +00:00
Owen Anderson ae86c19e68 Update for LLVM API change.
llvm-svn: 75446
2009-07-13 04:10:07 +00:00
Owen Anderson c9673d5bae Update for IRBuilder API change.
llvm-svn: 75041
2009-07-08 20:52:20 +00:00
Argyrios Kyrtzidis ddcd132a5b Remove the ASTContext parameter from the getBody() methods of Decl and subclasses.
Timings showed no significant difference before and after the commit.

llvm-svn: 74504
2009-06-30 02:35:26 +00:00
Argyrios Kyrtzidis b4b64ca752 Remove the ASTContext parameter from the attribute-related methods of Decl.
The implementations of these methods can Use Decl::getASTContext() to get the ASTContext.

This commit touches a lot of files since call sites for these methods are everywhere.
I used pre-tokenized "carbon.h" and "cocoa.h" headers to do some timings, and there was no real time difference between before the commit and after it.

llvm-svn: 74501
2009-06-30 02:34:44 +00:00
Douglas Gregor 78bd61f661 Move the static DeclAttrs map into ASTContext. Fixes <rdar://problem/6983177>.
llvm-svn: 73702
2009-06-18 16:11:24 +00:00
Anders Carlsson f3f91cee43 When possible, don't emit the cleanup block. Instead, just move the instructions to the current block.
llvm-svn: 72654
2009-05-31 00:33:20 +00:00
Eli Friedman 9444638e4e Re-add a slightly more general version of the check from r72578; it is
actually necessary in some obscure cases.

llvm-svn: 72585
2009-05-29 19:23:46 +00:00
Mike Stump a678874975 Oops, the testcase I was thinking of is supposed to error out. I
tried other things that might trip, but they all worked.

llvm-svn: 72584
2009-05-29 19:14:13 +00:00
Mike Stump 7f12d51a48 Fixup codegen for composition of vla types using a normal array type.
llvm-svn: 72578
2009-05-29 17:06:45 +00:00
Mike Stump 18bb9284ff Reflow some comments.
llvm-svn: 71937
2009-05-16 07:57:57 +00:00
Sebastian Redl a7b98a772c Implement function-try-blocks. However, there's a very subtle bug that I can't track down.
llvm-svn: 70155
2009-04-26 20:35:05 +00:00
Chris Lattner 28ec0cf86c the logic for computing __func__ and friends is really broken:
the type assigned by sema (and is visible with sizeof(__func__) for
example) has nothing to do with what codegen ends up producing.
We should eventually add a method on PredefinedExpr to handle this.
In the meantime, just set up some framework and add some fixme's.

llvm-svn: 69872
2009-04-23 05:30:27 +00:00
Chris Lattner b534f6a601 don't bother emitting a zero byte memset at all. We used to get them
in cases like this:

typedef struct {
  short instance;
  char name[0];
} ATTR_LIST_ENTRY2;

void test() {
  ATTR_LIST_ENTRY2 X = (ATTR_LIST_ENTRY2) { .instance = 7, };
}  

While it is safe to emit them, it is pretty silly.

llvm-svn: 69687
2009-04-21 17:59:23 +00:00
Douglas Gregor e3dcb2ddd1 FunctionDecl::getBody() is getting an ASTContext argument for use in
lazy PCH deserialization. Propagate that argument wherever it needs to
be. No functionality change, except that I've tightened up a few PCH
tests in preparation.

llvm-svn: 69406
2009-04-18 00:02:19 +00:00
Anders Carlsson c483bd0724 Simplify CodeGenFunction::GenerateCode.
llvm-svn: 69134
2009-04-15 04:10:19 +00:00
Daniel Dunbar 4184ac847f Update to use hasAttr() instead of getAttr().
- No functionality change.

llvm-svn: 68987
2009-04-13 21:08:27 +00:00
Chris Lattner 5286e774ee reject codegen of __thread variables as unimplemented, rdar://6775265
llvm-svn: 68755
2009-04-10 00:35:59 +00:00
Anders Carlsson 468fa6366b Add some basic support for generating C++ member functions.
llvm-svn: 68425
2009-04-04 20:47:02 +00:00
Chris Lattner 2739d2bbe6 remove some obsolete comments, use an AssertingVH.
llvm-svn: 68151
2009-03-31 22:17:44 +00:00
Eli Friedman 09a9b6e335 Move where block-related variables are initialized so that block
types don't get generated when blocks aren't used.

llvm-svn: 67898
2009-03-28 03:24:54 +00:00
Chris Lattner 47640221da fix CreateTempAlloca to not set a name on the alloca for temporaries
in release-assert builds.  For automatic variables, explicitly set
a name with setName that does not make a temporary std::string.

This speeds up -emit-llvm-only -disable-free on PR3810 by 4.6%

llvm-svn: 67459
2009-03-22 00:24:14 +00:00
Anders Carlsson e73e3ecc04 Initialize the cleanup.dst variable if necessary. Fixes PR3789.
llvm-svn: 67075
2009-03-17 05:53:35 +00:00
Mike Stump aeb0ffd56c Codegen support for copy helpers for block literals.
llvm-svn: 66319
2009-03-07 02:35:30 +00:00
Mike Stump 0c74327715 Framework for codegen for copy/dispose helpers.
llvm-svn: 66231
2009-03-06 01:33:24 +00:00
Mike Stump 626aecc4be Add codegen support for __block variables to call _Block_object_dispose as necessary.
llvm-svn: 66117
2009-03-05 01:23:13 +00:00
Mike Stump 06acea8a69 Move some of the CodeGenFunction blocks code up and out. No
functionality change.

llvm-svn: 66048
2009-03-04 18:57:26 +00:00
Douglas Gregor deaad8cc34 Create a new TypeNodes.def file that enumerates all of the types,
giving them rough classifications (normal types, never-canonical
types, always-dependent types, abstract type representations) and
making it far easier to make sure that we've hit all of the cases when
decoding types. 

Switched some switch() statements on the type class over to using this
mechanism, and filtering out those things we don't care about. For
example, CodeGen should never see always-dependent or non-canonical
types, while debug info generation should never see always-dependent
types. More switch() statements on the type class need to be moved 
over to using this approach, so that we'll get warnings when we add a
new type then fail to account for it somewhere in the compiler.

As part of this, some types have been renamed:

  TypeOfExpr -> TypeOfExprType
  FunctionTypeProto -> FunctionProtoType
  FunctionTypeNoProto -> FunctionNoProtoType

There shouldn't be any functionality change...

llvm-svn: 65591
2009-02-26 23:50:07 +00:00
Daniel Dunbar 76ba41ce4f Add Type::hasPointerRepresentation predicate.
- For types whose native representation is a pointer.

 - Use to replace ExprConstant.cpp:HasPointerEvalType,
   CodeGenFunction::isObjCPointerType.

llvm-svn: 65569
2009-02-26 20:52:22 +00:00
Daniel Dunbar e2617d97a5 Drop uses of isPointerLikeType.
- No functionality change.

llvm-svn: 65560
2009-02-26 19:03:24 +00:00
Mike Stump b750d928ce CodeGen support for copied BlockDeclRefExprs.
llvm-svn: 65487
2009-02-25 23:33:13 +00:00
Daniel Dunbar 22a87f94a9 Pull COdeGenFunction::CreateStaticBlockVarDecl (just for creating the
global variable) out of GenerateStaticBlockVarDecl. 
 - No intended functionality change.
 - Prep for some mild cleanups and PR3662.

llvm-svn: 65466
2009-02-25 19:24:29 +00:00
Daniel Dunbar 1234749853 Add low level support for generating invoke instead of calls.
- No functionality change.

llvm-svn: 65325
2009-02-23 17:26:39 +00:00
Mike Stump cb2fbcb0c9 Add CodeGen support for the helper for BlockDeclRefExprs. The easier
stuff is mostly done.  Move BlockHasCopyDispose up.

llvm-svn: 65242
2009-02-21 20:00:35 +00:00
Douglas Gregor 5f361c9f1e Address Chris's comments regarding C++ name mangling.
llvm-svn: 64984
2009-02-18 23:53:56 +00:00
Anders Carlsson 63784f4e5e Add CodeGen support for the nodebug attribute.
llvm-svn: 64445
2009-02-13 08:11:52 +00:00
Douglas Gregor 5fec5b0495 Add basic support for C++ name mangling according to the Itanium C++
ABI to the CodeGen library. Since C++ code-generation is so
incomplete, we can't exercise much of this mangling code. However, a
few smoke tests show that it's doing the same thing as GCC. When C++
codegen matures, we'll extend the ABI tester to verify name-mangling
as well, and complete the implementation here.

At this point, the major client of name mangling is in the uses of the
new "overloadable" attribute in C, which allows overloading. Any
"overloadable" function in C (or in an extern "C" block in C++) will
be mangled the same way that the corresponding C++ function would be
mangled.

llvm-svn: 64413
2009-02-13 00:10:09 +00:00
Daniel Dunbar 2d0746fb97 Pull CodeGenFunction::EmitVAArg into target specific ABIInfo classes.
llvm-svn: 64235
2009-02-10 20:44:09 +00:00
Anders Carlsson 33c1b6528f Remove the last remnants of the Obj-C EH stack code.
llvm-svn: 64205
2009-02-10 06:07:49 +00:00
Anders Carlsson f4478e94b8 Add DidCallStackSave variable to CodeGenFunction.
llvm-svn: 64156
2009-02-09 20:20:56 +00:00
Anders Carlsson 9c964ac272 Reuse case destinations.
llvm-svn: 64100
2009-02-08 22:46:50 +00:00
Anders Carlsson f57b9eef62 Always check if we can remove branch fixups, even if the cleanup stack is empty.
llvm-svn: 64099
2009-02-08 22:45:15 +00:00
Anders Carlsson 76180ea456 Misc fixes to the cleanup stack code.
llvm-svn: 64096
2009-02-08 22:13:37 +00:00
Anders Carlsson 66c384ac2e More cleanup stack work, PopCleanupBlock now returns a struct with the switch block and end block.
llvm-svn: 64072
2009-02-08 07:46:24 +00:00
Anders Carlsson ae91d9b140 Split some functions up
llvm-svn: 64069
2009-02-08 03:55:35 +00:00
Anders Carlsson a586ad7f85 CleanupScope needs to push the cleanup block in its destructor
llvm-svn: 64068
2009-02-08 03:22:36 +00:00
Anders Carlsson 3c21dd5a80 Implement support for branch fixups.
llvm-svn: 64064
2009-02-08 01:23:05 +00:00
Anders Carlsson 7d70fd27a4 More cleanup stack work.
llvm-svn: 64059
2009-02-08 00:50:42 +00:00
Anders Carlsson fbfb5e6530 When emitting blocks, keep track of which cleanup scope they have. Minor fixes and cleanup.
llvm-svn: 64053
2009-02-08 00:16:35 +00:00
Anders Carlsson be0f76a712 Add support for emitting cleanup blocks. Make EmitCompoundStatement emit cleanup blocks if necessary
llvm-svn: 64051
2009-02-07 23:50:39 +00:00
Anders Carlsson 15cb75a20c Add plumbing for the cleanup stack.
llvm-svn: 64043
2009-02-07 22:53:43 +00:00
Mike Stump 1d91dd98ad Fixup goto codegen in and around VLAs.
llvm-svn: 64014
2009-02-07 12:52:26 +00:00