Commit Graph

288 Commits

Author SHA1 Message Date
Douglas Gregor dcf1962405 Explicitly store the condition variable within switch statements, and
make sure that this variable is destroyed when we exit the switch
statement.

llvm-svn: 89776
2009-11-24 17:07:59 +00:00
Douglas Gregor 965f450d42 Introduce cleanup scopes for "if" statements in two places:
- Outside the "if", to ensure that we destroy the condition variable
    at the end of the "if" statement rather than at the end of the
    block containing the "if" statement.
  - Inside the "then" and "else" branches, so that we emit then- or
    else-local cleanups at the end of the corresponding block when the
    block is not a compound statement.

To make adding these new cleanup scopes easier (and since
switch/do/while will all need the same treatment), added the
CleanupScope RAII object to introduce a new cleanup scope and make
sure it gets cleaned up.

llvm-svn: 89773
2009-11-24 16:43:22 +00:00
Douglas Gregor 633caca353 Explicitly track the condition variable within an "if" statement,
rather than burying it in a CXXConditionDeclExpr (that occassionally
hides behind implicit conversions). Similar changes for
switch, while, and do-while will follow, then the removal of
CXXConditionDeclExpr. This commit is the canary.

llvm-svn: 89717
2009-11-23 23:44:04 +00:00
Daniel Dunbar 1b4441915a Wherein the TargetInfo argument to Preprocessor is made 'const' and propogated.
llvm-svn: 87087
2009-11-13 05:51:54 +00:00
Devang Patel 94f798c079 "Attach debug info with llvm instructions" mode was enabled a month ago. Now make it permanent and remove old way of inserting intrinsics to encode debug info for locations and types.
llvm-svn: 87007
2009-11-12 18:21:39 +00:00
Chris Lattner 353fc1e447 update comment, pointed out by Gabor
llvm-svn: 86263
2009-11-06 18:10:47 +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
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 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
Devang Patel 5d90d62701 Add support to attach debug info to an instruction.
This is not yet enabled.

llvm-svn: 83399
2009-10-06 18:36:08 +00:00
Anders Carlsson 52d78a518a CodeGen for try statements. (We just emit the body for now).
llvm-svn: 82910
2009-09-27 18:58:34 +00:00
Mike Stump 11289f4280 Remove tabs, and whitespace cleanups.
llvm-svn: 81346
2009-09-09 15:08:12 +00:00
Owen Anderson 41a750271b Update for LLVM API change.
llvm-svn: 78946
2009-08-13 21:57:51 +00:00
Owen Anderson 758428f4e3 Update for LLVM API change.
llvm-svn: 78259
2009-08-05 23:18:46 +00:00
Anders Carlsson 5638895b2a Revert the fix for PR3800, it broke things.
llvm-svn: 78084
2009-08-04 18:18:36 +00:00
Anders Carlsson 44616ce317 Remove old code that was causing the new test to fail.
llvm-svn: 77862
2009-08-02 04:17:43 +00:00
Anders Carlsson 7df966e040 Don't evaluate inout constraints twice. Fixes PR3800.
llvm-svn: 77854
2009-08-02 03:40:19 +00:00
Mike Stump 658fe02d17 Canonicalize else spacing.
llvm-svn: 77629
2009-07-30 22:28:39 +00:00
Owen Anderson b7a2fe6f81 Update for LLVM API change.
llvm-svn: 77012
2009-07-24 23:12:58 +00:00
Daniel Dunbar c3ab4c6c98 Detect when the current generation point is unreachable after emitting
expressions.
 - This generally catches the important case of noreturn functions.

 - With the last two changes, we are down to 152 unreachable blocks emitted on
   403.gcc, vs the 1805 we started with.

llvm-svn: 76364
2009-07-19 08:23:12 +00:00
Daniel Dunbar 669521c97c Fix thinko.
llvm-svn: 76362
2009-07-19 07:03:11 +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
Owen Anderson a296c03430 Update for LLVM API change.
llvm-svn: 76090
2009-07-16 18:09:38 +00:00
Eli Friedman b909bf4937 Add IRGen support for return statements in functions with reference
type.

llvm-svn: 72459
2009-05-27 04:56:12 +00:00
Mike Stump ec3cbfe8c6 Fixup codegen for volatile structs in the trivial cases (a a=a and a=a=a).
llvm-svn: 72439
2009-05-26 22:03:21 +00:00
Jay Foad 7d0479f2c2 Use v.data() instead of &v[0] when SmallVector v might be empty.
llvm-svn: 72210
2009-05-21 09:52:38 +00:00
Chris Lattner 23d5a39195 "Fix" a problem with debug info in the presence of always_inline
function calls.  For a program like this:

#include <stdio.h>
static __inline__ __attribute__((always_inline)) 
int bar(int x) { return 4; }
int main() { 
  int X = bar(4);
  printf("%d\n", X);
}

clang was not outputing any debug info for the body of main().  This is
because the backend is getting confused by the region_start/end that clang
is emitting for block scopes.  For now, just disable these (matching llvm-gcc),
this stuff is in progress of rework anyway.

llvm-svn: 70889
2009-05-04 18:27:04 +00:00
Daniel Dunbar d53e07b396 Remove unnecessary copy of constraint info.
llvm-svn: 70835
2009-05-04 06:56:16 +00:00
Eli Friedman 33955dd28f Remove unnecessary push_back (at least, I think it's unnecessary);
hopefully, this fixes PR4144 without any regressions.

llvm-svn: 70823
2009-05-04 04:12:48 +00:00
Chris Lattner 61af27860d look at the right operand when increasing the size of an asm output,
this fixes http://llvm.org/bugs/show_bug.cgi?id=3373#c20

llvm-svn: 70685
2009-05-03 09:05:53 +00:00
Chris Lattner 99837deeaf don't shadow 'i'
llvm-svn: 70680
2009-05-03 08:38:58 +00:00
Chris Lattner 59c3a9cd54 add support for tying asm operands where the result is smaller than
the input.  This is part of PR3373.

llvm-svn: 70677
2009-05-03 08:21:20 +00:00
Chris Lattner 10f221f321 implement support for asm outputs targetting non-simple lvalue destinations
like bitfields.  incidentally llvm-gcc crashes on this sort of thing also. :)

llvm-svn: 70675
2009-05-03 07:53:25 +00:00
Chris Lattner b65933eaa2 handle codegen of asms where a small input is tied to a large output.
llvm-svn: 70672
2009-05-03 07:27:51 +00:00
Chris Lattner 17769a34da refactor some code to get the input/output constraint info before
processing the outputs, no functionality change.

llvm-svn: 70671
2009-05-03 07:05:00 +00:00
Anders Carlsson b4e463287e Don't use indirect memory destinations for inline asm. Fixes 6841383.
llvm-svn: 70523
2009-05-01 00:16:04 +00:00
Chris Lattner c16d476b30 pull operands names "[foo]" into ConstraintInfo.
llvm-svn: 70136
2009-04-26 17:57:12 +00:00
Chris Lattner c3f4c7b1c5 pull the constraint string into the ConstraintInfo struct
instead of passing it around in addition to it.

llvm-svn: 70135
2009-04-26 17:19:08 +00:00
Chris Lattner d9725f7041 change TargetInfo::ConstraintInfo to be a struct that contains
the enum along with some other data.

llvm-svn: 70114
2009-04-26 07:16:29 +00:00
Eli Friedman c08711e840 Minor simplification.
llvm-svn: 68992
2009-04-13 21:41:57 +00:00
Daniel Dunbar f77e292a0f Fix a subtle bug where the cleanup scope entries had a dangling block reference
- <rdar://problem/6732143> Crash when generating @synchronize for
   zero-cost exception

 - Thanks to Anders for helping track down the problem.

llvm-svn: 68186
2009-04-01 04:37:47 +00:00
Chris Lattner cda4d7e196 introduce a new -fheinous-gnu-extensions flag that enables really
really horrible extensions that are disabled by default but that can
be accepted by -fheinous-gnu-extensions (but which always emit a 
warning when enabled).

As our first instance of this, implement PR3788/PR3794, which allows
non-lvalues in inline asms in contexts where lvalues are required. bleh.

llvm-svn: 66910
2009-03-13 17:38:01 +00:00
Chris Lattner d8c7ba278e add plumbing to report diagnostics back through sema for malformed asmstrings.
llvm-svn: 66598
2009-03-10 23:41:04 +00:00
Chris Lattner 35b5836147 move the asm string analysis code out of codegen into common
code where Sema can get to it.  No functionality change.

llvm-svn: 66596
2009-03-10 23:21:44 +00:00
Chris Lattner f85a938985 Fix PR3682 by just disabling a broken assertion. This check should be
done in sema, and is reflected by the existing PR3258.  In the meantime,
fix PR3682 by disabling a bogus assertion (which doesn't account for + 
operands).

llvm-svn: 66533
2009-03-10 06:42:37 +00:00
Chris Lattner 6dd0f9263d reduce duplication of parsing code between %0 and %x0 and
add support for modifiers on named references, like %c[foo].

llvm-svn: 66532
2009-03-10 06:38:02 +00:00
Chris Lattner d7d5fdf090 move matching of named operands into AsmStmt class. At the same
time handle + operands in operand counting, fixing asm.c:t7 to
expand into $2 instead of $1.

llvm-svn: 66531
2009-03-10 06:33:24 +00:00
Chris Lattner 80337892f4 reduce nesting, use memchr instead of explicit loop, eliminate a
temporary std::string to fix a fixme.

llvm-svn: 66530
2009-03-10 06:11:34 +00:00
Chris Lattner 2d43eaefa2 Expand %= into ${:uid} so that the code generator emits a unique ID for the
asm.  This allows us to properly handle the case when an optimizer duplicates
the asm, such as here:

void bar() {
  int i;
  for (i = 0; i < 3; ++i)
    asm("foo %=" : : "r"(0));
}

we now produce:

_bar:
	xorl	%eax, %eax
	## InlineAsm Start
	foo 0
	## InlineAsm End
	## InlineAsm Start
	foo 1
	## InlineAsm End
	## InlineAsm Start
	foo 2
	## InlineAsm End
	ret

instead of:

_bar:
	xorl	%eax, %eax
	## InlineAsm Start
	foo 1
	## InlineAsm End
	## InlineAsm Start
	foo 1
	## InlineAsm End
	## InlineAsm Start
	foo 1
	## InlineAsm End
	ret

This also fixes a fixme by eliminating a static.

llvm-svn: 66528
2009-03-10 05:39:21 +00:00
Chris Lattner 72bbf17340 add some helper methods to AsmStmt and add some comments.
llvm-svn: 66521
2009-03-10 04:59:06 +00:00
Chris Lattner 57e673772e slightly simplify some code, pull the 'is simple asm' case up in
ConvertAsmString and shrink it a bit.  No functionality change.

llvm-svn: 66520
2009-03-10 04:38:46 +00:00
Chris Lattner ff9fbcaa8a if we die in IR generation of a compound statement, include
it in the stack trace, giving us stuff like:

Stack dump:
0.	Program arguments: clang t.c -emit-llvm 
1.	<eof> parser at end of file
2.	t.c:1:5: LLVM IR generation of declaration 'a'
3.	t.c:1:9: LLVM IR generation of compound statement ('{}')
4.	t.c:2:3: LLVM IR generation of compound statement ('{}')
Abort

llvm-svn: 66154
2009-03-05 08:04:57 +00:00
Chris Lattner 4192bce91b add a special case for codegen that improves the case where we have
multiple sequential cases to a) not create tons of fall-through basic blocks
and b) not recurse deeply.  This fixes codegen on 100K deep cases, and improves
codegen on moderate cases from this:

        switch i32 %tmp, label %sw.epilog [
                i32 1000, label %sw.bb
                i32 1001, label %sw.bb1
                i32 1002, label %sw.bb2
                i32 1003, label %sw.bb3
                i32 1004, label %sw.bb4
...
sw.bb:          ; preds = %entry
        br label %sw.bb1

sw.bb1:         ; preds = %entry, %sw.bb
        br label %sw.bb2

sw.bb2:         ; preds = %entry, %sw.bb1
        br label %sw.bb3

sw.bb3:         ; preds = %entry, %sw.bb2
        br label %sw.bb4

to:

        switch i32 %tmp, label %sw.epilog [
                i32 1000, label %sw.bb
                i32 1001, label %sw.bb
                i32 1002, label %sw.bb
                i32 1003, label %sw.bb
                i32 1004, label %sw.bb
sw.bb:  ;; many preds

llvm-svn: 66015
2009-03-04 04:46:18 +00:00
Anders Carlsson b3b675c35e inline asm calls should be nounwind. Chris, please review.
llvm-svn: 65866
2009-03-02 19:58:15 +00:00
Anders Carlsson e14282e274 Make sure to reset the DidCallStackSave variable before emitting a compound statement. Fixes PR3649.
llvm-svn: 65291
2009-02-22 18:44:21 +00:00
Anders Carlsson 63784f4e5e Add CodeGen support for the nodebug attribute.
llvm-svn: 64445
2009-02-13 08:11:52 +00:00
Anders Carlsson 7ccf3e4e28 Handle the case where EmitBlock might be called multiple times for the same block. Fixes PR3536.
llvm-svn: 64252
2009-02-10 22:50:24 +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 33747b6c41 Start removing the old Obj-C EH stack now that the cleanup stack is used instead.
llvm-svn: 64203
2009-02-10 05:52:02 +00:00
Anders Carlsson 1ac6282c5b Replace a bunch of EmitBranch calls with EmitBranchThroughCleanup. No functionality change (yet).
llvm-svn: 64159
2009-02-09 20:31:03 +00:00
Anders Carlsson ff0bb6ce62 Save and restore the DidCallStackSave variable
llvm-svn: 64157
2009-02-09 20:23:40 +00:00
Mike Stump a6dbd7b25a When we're at the stack depth we want, there isn't anything to do.
llvm-svn: 64095
2009-02-08 22:00:53 +00:00
Mike Stump 284d177c7f Wire up break and continue processing to the new stack depth adjuster.
If people could beat on it and let me know if there are any new
semantics required by newer language standards or DRs or any little
details I goofed on, I'd be happy to fix any issues found.

llvm-svn: 64079
2009-02-08 09:22:19 +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
Mike Stump 0509d9635b Ensure we track all the stack depths for all break and continue points
correctly.  This should lay the ground work to throw the big switch
and start code gening break and continue in the presense of vlas.

llvm-svn: 64046
2009-02-07 23:02:10 +00:00
Mike Stump 56d2a15829 Format for 80-cols.
llvm-svn: 64030
2009-02-07 20:14:12 +00:00
Mike Stump dc0d6be7b9 Arrange to have the correct StackDepth for while statements.
llvm-svn: 64021
2009-02-07 18:08:12 +00:00
Mike Stump 1f8be1b9ac Fit into 80-col.
llvm-svn: 64020
2009-02-07 17:18:33 +00:00
Mike Stump 1d91dd98ad Fixup goto codegen in and around VLAs.
llvm-svn: 64014
2009-02-07 12:52:26 +00:00
Anders Carlsson 570c357ded If an input constraint refers to an output constraint, it should have the same constraint info as the output constraint. Fixes PR3417
llvm-svn: 63127
2009-01-27 20:38:24 +00:00
Chris Lattner 66c6562e24 silence a couple unused variable 'result' warnings.
llvm-svn: 62674
2009-01-21 07:35:26 +00:00
Anders Carlsson a92271d067 CG support for inline asm constraints with symbolic names. Fixes PR3345
llvm-svn: 62444
2009-01-18 02:06:20 +00:00
Anders Carlsson a79203be85 Add sema support for symbolic names in inline asm statements.
llvm-svn: 62441
2009-01-18 01:56:57 +00:00
Anders Carlsson 19aa04d270 Change TargetInfo::validateInputConstraint to take begin/end name iterators instead of the number of outputs. No functionality change.
llvm-svn: 62433
2009-01-17 23:36:15 +00:00
Anders Carlsson 00057e4e09 Handle multi-value inputs
llvm-svn: 62069
2009-01-12 02:22:13 +00:00
Anders Carlsson 431acd1129 More inline asm fixes
llvm-svn: 62049
2009-01-11 21:23:27 +00:00
Anders Carlsson a948c34b0b Handle readwrite constraints correctly
llvm-svn: 62043
2009-01-11 19:46:50 +00:00
Anders Carlsson da5f56939b Use a common function for emitting asm inputs and remove a FIXME
llvm-svn: 62041
2009-01-11 19:32:54 +00:00
Eli Friedman dea4193e8a Fix for PR3246: an empty clobber list is the empty string, not a null
string.

That said, we should probably try and track down the correct clobber 
lists for the targets that don't have them (PPC, ARM, and Sparc), 
so that we can generate correct code.

llvm-svn: 61298
2008-12-21 01:15:32 +00:00
Eli Friedman 5ad3c91b27 Extend the unsupported error to include break and continue, and fix a
warning by using an unsigned index.

llvm-svn: 61292
2008-12-20 23:18:29 +00:00
Anders Carlsson fbef9c208f Check the entire StackSaveValues stack for VLAs when dealing with goto and return statements. Noticed by Eli Friedman.
llvm-svn: 61289
2008-12-20 21:33:38 +00:00
Anders Carlsson 6200f0c533 Add some ErrorUnsupported calls and turn on VLA codegen again.
llvm-svn: 61283
2008-12-20 19:33:21 +00:00
Anders Carlsson 6b958f9634 Store the size of the EH stack inside each BreakContinue struct so we know when a break/continue won't cross a try block.
llvm-svn: 60998
2008-12-13 22:52:24 +00:00
Anders Carlsson 8a472c3151 Work in preparation for VLAs. Make sure to restore the stack if necessary (Saving the stack isn't implemented right now :)
llvm-svn: 60925
2008-12-12 05:52:00 +00:00
Anders Carlsson 59689ed764 Use Expr::Evaluate for case statements. Fixes PR2525
llvm-svn: 59881
2008-11-22 21:04:56 +00:00
Chris Lattner e132e2432a Start implementing support for @synchonized with the darwin ObjC API.
Patch by Fariborz!

llvm-svn: 59377
2008-11-15 21:26:17 +00:00
Daniel Dunbar df21c6e203 Supply finished flag to EmitBlock for common statements which use
landing pads.
 - Primarily a cleanliness issue instead of a performance issue (this
   eliminates all blocks w/o predecessors on 176.gcc/expr.c), but this
   also allows subsequent code to recognize it is unreachable and
   potentially avoid IRgen.

llvm-svn: 59211
2008-11-13 01:54:24 +00:00
Daniel Dunbar a612e79be4 Normalize many BasicBlock names.
- Use dotted notation for blocks related to a particular statement
   type.
 - Use .end for landing pads.

No functionality change in NDEBUG mode. :)

llvm-svn: 59210
2008-11-13 01:38:36 +00:00
Daniel Dunbar fcac22eac1 Add IsFinished arg to EmitBlock.
- Indicates that caller is done with the block and it can be dropped
   if it has no predecessors. Useful for callers who need to make
   landing pads but which may not be reached.

No functionality change.

llvm-svn: 59207
2008-11-13 01:24:05 +00:00
Daniel Dunbar f75c823e5c For if blocks with no else, name the join block ifend instead of the
more confusing ifelse.

Use dotted names for if blocks (if.then vs ifthen).

llvm-svn: 59201
2008-11-13 00:47:57 +00:00
Daniel Dunbar 5fc2871820 IRgen improvements on unreachable code:
- Split out "simple" statements which can easily handle IR generation
   when there is no insert point. These are generally statements which
   start by emitting a new block or are only containers for other
   statements.

 - This fixes a regression in emitting dummy blocks, notably for case
   statements.

 - This also fixes spurious emission of a number of debug stoppoint
   intrinsic instructions.

Remove unneeded sw.body block, just clear the insertion point.

Lift out CodeGenFunction::EmitStopPoint which calls into the
CGDebugInfo class when generating debug info.

Normalize definitions of Emit{Break,Continue}Stmt and usage of
ErrorUnsupported.

llvm-svn: 59118
2008-11-12 08:21:33 +00:00
Chris Lattner cd439299b0 Move EmitBranchOnBoolExpr and ConstantFoldsToSimpleInteger to
CodeGenFunction.cpp.  Change VisitConditionalOperator to use
constant fold instead of codegen'ing a constant conditional.

Change ForStmt to use EmitBranchOnBoolExpr, this shrinks
expr.c very slightly to 40239 lines.

llvm-svn: 59113
2008-11-12 08:04:58 +00:00
Chris Lattner b7a9e16486 Make emission of 'if' conditions much more sophisticated when we
have a condition that is an &&/||.  Before we used to compile things like this:

int test() {
  if (x && y) foo(); else bar();
}

into:

	%0 = load i32* @x		; <i32> [#uses=1]
	%1 = icmp ne i32 %0, 0		; <i1> [#uses=1]
	br i1 %1, label %land_rhs, label %land_cont

land_rhs:		; preds = %entry
	%2 = load i32* @y		; <i32> [#uses=1]
	%3 = icmp ne i32 %2, 0		; <i1> [#uses=1]
	br label %land_cont

land_cont:		; preds = %land_rhs, %entry
	%4 = phi i1 [ false, %entry ], [ %3, %land_rhs ]		; <i1> [#uses=1]
	br i1 %4, label %ifthen, label %ifelse

ifthen:		; preds = %land_cont
	%call = call i32 (...)* @foo()		; <i32> [#uses=0]
	br label %ifend

ifelse:		; preds = %land_cont
	%call1 = call i32 (...)* @bar()		; <i32> [#uses=0]
	br label %ifend

ifend:		; preds = %ifelse, %ifthen


Now we turn it into the much more svelte code:

        %0 = load i32* @x               ; <i32> [#uses=1]
        %1 = icmp ne i32 %0, 0          ; <i1> [#uses=1]
        br i1 %1, label %land_lhs_true, label %ifelse

land_lhs_true:          ; preds = %entry
        %2 = load i32* @y               ; <i32> [#uses=1]
        %3 = icmp ne i32 %2, 0          ; <i1> [#uses=1]
        br i1 %3, label %ifthen, label %ifelse

ifthen:         ; preds = %land_lhs_true
        %call = call i32 (...)* @foo()          ; <i32> [#uses=0]
        br label %ifend

ifelse:         ; preds = %land_lhs_true, %entry
        %call1 = call i32 (...)* @bar()         ; <i32> [#uses=0]
        br label %ifend

ifend:          ; preds = %ifelse, %ifthen

Note the lack of a phi node.

This shrinks the -O0 .ll file for 176.gcc/expr.c from 43176 to 40267 lines.

llvm-svn: 59111
2008-11-12 07:46:33 +00:00
Chris Lattner 4ad31fcc43 Clean up some code to use isZero instead of calling getZExtValue.
llvm-svn: 59103
2008-11-12 04:54:14 +00:00
Daniel Dunbar 5c7e3935f1 Rework IRgen invariant w.r.t. current insert point.
- EmitStmt is no longer required to finish with a current insertion
   point defined (i.e. it does not need to make dummy
   blocks). Instead, it can clear the insertion point in the builder
   which indicates that the current insertion point is unreachable.
 - CodeGenFunction provides HaveInsertPoint and EnsureInsertPoint
   which respectively test if there is an insert point and ensure an
   insertion point exists (by making a dummy block).
 - Clearly mark functions in CodeGenFunction which can be called with
   no insertion point defined. Currently this is a limited set, and
   EmitStmt simply EnsureInsertPoint()s before emitting subsequent IR.

Remove EmitDummyBlock, which is no longer needed. Clients who haven't
already cleared the insertion point (typically via EmitBranch) can do
so by hand.

Remove isDummyBlock, which has effectively been renamed to
HaveInsertPoint.

The main thrust of this change is that we no longer have create dummy
blocks just to destroy them a short time later in EmitBlock in the
common case that there is no unreachable code following something like
a goto. 

Additionally, this means that we are not using the hokey condition in
isDummyBlock that a block without a name is a dummy block. Guess how
well that works when we never emit block names!

llvm-svn: 59089
2008-11-11 23:11:34 +00:00
Daniel Dunbar ab197ebb1a Change EmitBranch to always clear the insert point to clarify irgen
invariants.

llvm-svn: 59085
2008-11-11 22:06:59 +00:00
Daniel Dunbar c56e67644f Add CodeGenFunction::EmitBranch.
- Emits an unconditional branch, with extra logic to avoid generating
   spurious branches out of dummy blocks.

llvm-svn: 59037
2008-11-11 09:41:28 +00:00
Chris Lattner 5b1964b5f9 short circuit && and || when possible. This substantially reduces
the size of the -O0 output on some cases.  For example, on expr.c from
176.gcc, it shrinks the .ll file from 43164 to 42835 lines, and removed
references to two external symbols.

llvm-svn: 59034
2008-11-11 07:41:27 +00:00
Chris Lattner aaaa199ad1 Make codegen smart enough to not emit the dead side of an if whose
condition is a constant.  This shrinks -O0 codegen by quite a bit
on some cases.

llvm-svn: 59033
2008-11-11 07:24:28 +00:00
Daniel Dunbar 29ac59f25c Add CodeGenFunction::EmitDummyBlock for marking places where we make
"dummy" blocks (blocks just used to make sure we have a place to dump
code to).

llvm-svn: 59022
2008-11-11 04:34:23 +00:00
Daniel Dunbar 05e629aec6 Remove CodeGenFunction::StartBlock.
- Was confusing and only used in one small part of the code.

llvm-svn: 59020
2008-11-11 04:12:31 +00:00
Daniel Dunbar 75283ff38a Centralize basic block creation in CodeGenFunction::createBasicBlock.
- No functionality change.

llvm-svn: 59017
2008-11-11 02:29:29 +00:00
Anders Carlsson 3442f82c2f Support named operands in inline asm statements.
llvm-svn: 58940
2008-11-09 18:54:14 +00:00
Daniel Dunbar 1e75408d89 Emit error unsupported when asm string conversion fails instead of
assert.

llvm-svn: 57721
2008-10-17 20:58:01 +00:00
Daniel Dunbar b9fd902fdc Change CGDebugInfo::setLocation to just ignore invalid locations. This
simplifies clients.

Also, add assert that RegionStack is empty when the CGDebugInfo is
destroyed.

llvm-svn: 57684
2008-10-17 16:15:48 +00:00
Chris Lattner 5d3e26a4f6 silence release-assert warnings.
llvm-svn: 57392
2008-10-12 00:31:50 +00:00
Ted Kremenek 704a2505db In EmitDeclStmt: use DeclStmt::const_decl_iterator instead of walking the scoped decl chain.
llvm-svn: 57192
2008-10-06 18:42:27 +00:00
Daniel Dunbar e23f28f8a5 Emit error unsupported for break/continue/goto inside Obj-C exception
handling blocks.
 - This has false positives, but at least prevents miscompiles.

llvm-svn: 56958
2008-10-02 18:02:06 +00:00
Daniel Dunbar 2efd538f61 Add infrastructure for proper @finally support.
- Provides a basic primitive to jump to an arbitrary basic block,
   through the finally code.

 - Only used for return statements and rethrow currently. Still need
   to handle break, continue and goto.

 - Code still needs to be shuffled around to live elsewhere.

llvm-svn: 56827
2008-09-30 01:06:03 +00:00
Daniel Dunbar a2d3570fc9 Skip redundant if.
llvm-svn: 56762
2008-09-28 00:19:22 +00:00
Daniel Dunbar 1c64e5d12f Refactor some CodeGen functionality:
- Add CodeGenFunction::{EmitReturnOfRValue, EmitIvarOffset}
 - Factor EmitLValueForIvar out of EmitObjCIvarRefLValue.

No non-error functionality change (some unsupported errors are
degraded to asserts for the time being).

llvm-svn: 56543
2008-09-24 04:00:38 +00:00
Anders Carlsson 9396a89899 Make sure to store the exception in the catch parameter.
llvm-svn: 56102
2008-09-11 09:15:33 +00:00
Anders Carlsson b5130d8588 Make sure to emit the catch parameter as well as the catch body.
llvm-svn: 56101
2008-09-11 08:21:54 +00:00
Daniel Dunbar 54bb1933b1 Use a unified return block.
- For the time being this means our emitted code is somewhat worse,
   especially for aggregates. This will be fixed.

llvm-svn: 56013
2008-09-09 21:00:17 +00:00
Anders Carlsson 1963b0c38f Move handling of @try and @throw to the runtime class.
llvm-svn: 55983
2008-09-09 10:04:29 +00:00
Anders Carlsson 2e744e8aa6 Stub out CodeGenFunction::EmitObjCForCollectionStmt.
Add CodeGenFunction::EmitMemSetToZero and make AggExprEmitter::EmitAggregateClear use it.

llvm-svn: 55573
2008-08-30 19:51:14 +00:00
Daniel Dunbar a799807dea Downgrade a number of FIXME asserts to ErrorUnsupported.
- Notably VLAs

llvm-svn: 55544
2008-08-29 17:28:43 +00:00
Daniel Dunbar c8317a44cf Implement Obj-C ivar references to aggregates.
Implement Obj-C lvalue message sends (aggregate returns).

Update several places to emit more precise ErrorUnsupported warnings
  for currently unimplemented Obj-C features (main missing chunks are
  property references, Obj-C exception handling, and the for ... in
  syntax).

llvm-svn: 55234
2008-08-23 10:51:21 +00:00
Daniel Dunbar a7c8cf6200 Change WarnUnsupported to ErrorUnsupported (in name and in practice).
- We are beyond the point where this shows up often and when it does
   generating miscompiled files is bad.

llvm-svn: 54836
2008-08-16 00:56:44 +00:00
Daniel Dunbar 56fdb6ae69 More #include cleaning
- Kill unnecessary #includes in .cpp files. This is an automatic
   sweep so some things removed are actually used, but happen to be
   included by a previous header. I tried to get rid of the obvious
   examples and this was the easiest way to trim the #includes in one
   fell swoop.
 - We now return to regularly scheduled development.

llvm-svn: 54632
2008-08-11 06:23:49 +00:00
Daniel Dunbar ad319a73f2 More #include cleaning
- Remove internal uses of AST.h

llvm-svn: 54628
2008-08-11 05:00:27 +00:00
Daniel Dunbar 88402ce8d0 Add CodeGen support for indirect goto.
- Follows emission scheme used by llvm-gcc, i.e. invent an id for
   each label whose address is taken and replace each indirect goto by
   a switch to each possible target.
 - Currently we emit a switch for each indirect goto instead of
   merging them as llvm-gcc does.

llvm-svn: 54318
2008-08-04 16:51:22 +00:00
Chris Lattner 7e80097f6e implement codegen support for labels at the end of stmtexprs.
llvm-svn: 54100
2008-07-26 20:23:23 +00:00
Chris Lattner 6284378fcd minor tidying, no functionality change.
llvm-svn: 54099
2008-07-26 20:15:14 +00:00
Daniel Dunbar 0e5845c13a Rework codegen of case ranges
- Fix multiple issues with the way case ranges were emitted, see test
   cases details about the specific issues.

 - The root issue was not being careful about how basic blocks were
   emitted which led to them being chained together incorrectly,
   resulting in improper control flow.

 - Fixes <rdar://problem/6098585>

llvm-svn: 54006
2008-07-25 01:11:38 +00:00
Daniel Dunbar 2e0f1cd00c Fix EmitCaseStmtRange to ignore empty ranges
- Also cleaned up emission slightly 
 - Inspection of the code revealed several other bugs, however. Case
   ranges are not properly wired and can result in switch cases being
   dropped or even infinite loops. See: <rdar://problem/6098585>

Completes: <rdar://problem/6094119>
llvm-svn: 53975
2008-07-24 01:18:41 +00:00
Eli Friedman 327944b343 Basic support for volatile loads and stores. Stores the volatile
qualifier in the lvalue, and changes lvalue loads/stores to honor 
the volatile flag.  Places which need some further attention are marked 
with FIXMEs.

Patch by Cédric Venet.

llvm-svn: 52264
2008-06-13 23:01:12 +00:00
Sanjiv Gupta 98070578bf Generate subprogram debug info with -g.
Also take care of freeing memory at the right places.

llvm-svn: 51553
2008-05-25 05:15:42 +00:00
Dan Gohman 5d30975e5e Change uses of llvm::Type::isFirstClassType to use the new
llvm::Type::isSingleValueType. Currently these two functions have
the same behavior, but soon isFirstClassType will return true for
struct and array types.

Clang may some day want to use of isFirstClassType for some of
these some day as an optimization, but it'll require some
consideration.

llvm-svn: 51446
2008-05-22 22:12:56 +00:00
Eli Friedman 1763075b9c Make debugging information usable. This is barebones, but it makes -g
actually work (instead of crashing llc), and there's enough info emitted 
to get line number information in gdb. This should hopefully be helpful 
for debugging non-working programs.

I got rid of the begin/endregion calls because the implementation wasn't 
working; someone who knows the debugging info a bit better might try to 
add it. I really have no clue how a compiler is supposed to emit them.

This commit shouldn't have any effect without -g.

llvm-svn: 51404
2008-05-22 01:40:10 +00:00
Eli Friedman c7460b1011 Minor refactoring: compute the return value separately from emitting the
ret.

llvm-svn: 51403
2008-05-22 01:22:33 +00:00
Eli Friedman 6a7087e455 Emit basic block for switch body; fixes PR2307.
llvm-svn: 50968
2008-05-12 16:08:04 +00:00
Sanjiv Gupta 15cb669039 Added -g command line options to clang for generating source level debug information. This patch currently enables generation of line number debug information (stoppoints) and region begin/end debug information. The new files CGDebugInfo.h and CGDebugInfo.cpp implements the debug info manager class CGDebugInfo.
llvm-svn: 50848
2008-05-08 08:54:20 +00:00
Gabor Greif d36afd7d65 tracking API changes arising from r49277
llvm-svn: 49279
2008-04-06 20:42:52 +00:00
Chris Lattner f3bc75afcf Since isComplexType() no longer returns true for _Complex integers, the code
generator needs to call isAnyComplexType().  This fixes PR1960.

llvm-svn: 49220
2008-04-04 16:54:41 +00:00
Chris Lattner 4bd5596d08 Add initial support for objc codegen for methods, ivars, and the
etoile runtime, patch by David Chisnall!

llvm-svn: 48969
2008-03-30 23:03:07 +00:00
Chris Lattner 7a51313d8a Make a major restructuring of the clang tree: introduce a top-level
lib dir and move all the libraries into it.  This follows the main
llvm tree, and allows the libraries to be built in parallel.  The
top level now enforces that all the libs are built before Driver,
but we don't care what order the libs are built in.  This speeds
up parallel builds, particularly incremental ones.

llvm-svn: 48402
2008-03-15 23:59:48 +00:00