Commit Graph

34428 Commits

Author SHA1 Message Date
Chris Lattner 226d419e21 trivial simplification
llvm-svn: 39563
2007-06-02 22:47:37 +00:00
Chris Lattner ea3c20b9eb When a function decays into its address, ensure the result type keeps any
typedef information associated with the input.

llvm-svn: 39562
2007-06-02 22:47:04 +00:00
Chris Lattner 2b4e21ac3f Implement translation of pointer, reference and simple array types. We now
compile:

void foo() {
  int A[10];
  int *P;

into:

entry:
        %A = alloca [10 x i32]          ; <[10 x i32]*> [#uses=0]
        %P = alloca i32*                ; <i32**> [#uses=0]

llvm-svn: 39561
2007-06-02 19:52:24 +00:00
Chris Lattner a45c5af87b Implement a trivial optimization to reduce the number of compares emitted.
For:

  register short X;
  if (!X) {

We now produce:

        %tmp = load i16* %X             ; <i16> [#uses=1]
        %tobool = icmp ne i16 %tmp, 0           ; <i1> [#uses=1]
        %lnot = xor i1 %tobool, true            ; <i1> [#uses=1]
        br i1 %lnot, label %ifthen, label %ifend

instead of:

        %tmp = load i16* %X             ; <i16> [#uses=1]
        %tobool = icmp ne i16 %tmp, 0           ; <i1> [#uses=1]
        %lnot = xor i1 %tobool, true            ; <i1> [#uses=1]
        %lnot.ext = zext i1 %lnot to i32                ; <i32> [#uses=1]
        %tobool1 = icmp ne i32 %lnot.ext, 0             ; <i1> [#uses=1]
        br i1 %tobool1, label %ifthen, label %ifend

llvm-svn: 39560
2007-06-02 19:47:04 +00:00
Chris Lattner f0106d2578 Refactor EvaluateScalarValueToBool out of if statement emission, so it can
be shared.

Implement infrastructure for unary operator emission.

Implement basic logical not support.  We now compile:

  register short X;

  if (!X) {

into:

        %tmp = load i16* %X             ; <i16> [#uses=1]
        %tobool = icmp ne i16 %tmp, 0           ; <i1> [#uses=1]
        %lnot = xor i1 %tobool, true            ; <i1> [#uses=1]
        zext i1 %lnot to i32            ; <i32>:0 [#uses=1]
        %tobool1 = icmp ne i32 %0, 0            ; <i1> [#uses=1]
        br i1 %tobool1, label %ifthen, label %ifend

llvm-svn: 39559
2007-06-02 19:33:17 +00:00
Chris Lattner be31ed8e88 Correct the type of logical not.
llvm-svn: 39558
2007-06-02 19:11:33 +00:00
Bill Wendling d6de65740d Submitted by: Bill Wendling
- Added C99 reference to why "auto" and "register" cannot be used as a
  storage class specifier for file scoped variable declarations.

llvm-svn: 39557
2007-06-02 09:40:07 +00:00
Chris Lattner b4522b4dec Pretty print storage classes for vardecls.
llvm-svn: 39556
2007-06-02 05:27:01 +00:00
Chris Lattner d7f58867e5 Implement scaffolding for lvalues. Implement block vardecl lvalues.
This allows us to translate:

int func() {
  register int X;
  {
    int Y;
    return 1+X+Y;
  }
}

into:

define i32 @func() {
entry:
        %X = alloca i32         ; <i32*> [#uses=1]
        %Y = alloca i32         ; <i32*> [#uses=1]
        %allocapt = bitcast i32 undef to i32            ; <i32> [#uses=0]
        %tmp = load i32* %X             ; <i32> [#uses=1]
        %tmp1 = add i32 1, %tmp         ; <i32> [#uses=1]
        %tmp2 = load i32* %Y            ; <i32> [#uses=1]
        %tmp3 = add i32 %tmp1, %tmp2            ; <i32> [#uses=1]
        ret i32 %tmp3
                ; No predecessors!
        ret i32 undef
}

llvm-svn: 39555
2007-06-02 05:24:33 +00:00
Bill Wendling 44ebec5310 Submitted by: Bill Wendling
Removed #include <iostream>.

llvm-svn: 39554
2007-06-02 05:06:35 +00:00
Chris Lattner 03df12294b Add initial support for fixed-size local vardecls. This allows us to compile:
int func() {
  register int X;
  {
    int Y;

into:

define i32 @func() {
entry:
        %X = alloca i32         ; <i32*> [#uses=0]
        %Y = alloca i32         ; <i32*> [#uses=0]
        %allocapt = bitcast i32 undef to i32            ; <i32> [#uses=0]
...

llvm-svn: 39553
2007-06-02 04:53:11 +00:00
Chris Lattner 238cbc58c3 Modify Expr::isConstantExpr and friends take a pointer to a SourceLoc instead
of one by reference, making it optional.

llvm-svn: 39552
2007-06-02 04:48:48 +00:00
Chris Lattner 5e1f32a16f reorder files alphabetically
llvm-svn: 39551
2007-06-02 04:47:52 +00:00
Chris Lattner 84915fa79b Start stubbing out decl codegen.
llvm-svn: 39550
2007-06-02 04:16:21 +00:00
Chris Lattner e0c4ae1f24 Generalize this to support printing any valuedecl, e.g. function definitions.
We now print:
  extern void blah();
as:
  void (blah)();

Strange, but ok :)

llvm-svn: 39549
2007-06-02 03:38:08 +00:00
Chris Lattner d1c1c94663 DeclStmt can be just about any type of decl.
llvm-svn: 39548
2007-06-02 03:35:40 +00:00
Chris Lattner 3f3dbeedd3 implement codegen support for return of void and simple scalars.
llvm-svn: 39547
2007-06-02 03:19:07 +00:00
Chris Lattner adb6372aa5 Add support for functions that return non-void.
llvm-svn: 39546
2007-06-02 03:02:07 +00:00
Chris Lattner db91b16755 stub out codegen of binary plus. We now compile:
if (11 + 42) {

to:

        %tmp = add i32 11, 42           ; <i32> [#uses=1]
        %tobool = icmp ne i32 %tmp, 0           ; <i1> [#uses=1]
        br i1 %tobool, label %ifthen, label %ifend


but this doesn't handle any of the interesting/hard stuff yet.

llvm-svn: 39545
2007-06-02 00:16:28 +00:00
Chris Lattner 3e450f947b add new files.
llvm-svn: 39544
2007-06-02 00:01:41 +00:00
Steve Naroff 4555292b1e Bug #:
Submitted by:
Reviewed by:
After speaking with Chris, decided not to have GCC "attributes" inherit
from Decl. This will enable us to grow the attribute hierarchy over time
without effecting Decls.

llvm-svn: 39543
2007-06-01 21:56:17 +00:00
Steve Naroff 6a0675f8a4 Bug #:
Submitted by:
Reviewed by:
Add implemention file for GCC attributes

llvm-svn: 39542
2007-06-01 21:54:34 +00:00
Steve Naroff ff12778709 Bug #:
Submitted by:
Reviewed by:
Interface file for GCC attributes.

llvm-svn: 39541
2007-06-01 21:53:25 +00:00
Chris Lattner e47e440c42 split stmt/expr codegen into their own files.
llvm-svn: 39540
2007-06-01 18:02:12 +00:00
Steve Naroff 0f2fe17ff1 Bug #:
Submitted by:
Reviewed by:
Implement support for GCC __attribute__.

- Implement "TODO" in Parser::ParseAttributes. Changed the return type from
void to Parser::DeclTy. Changed all call sites to accept the return value.
- Added Action::ParseAttribute and Sema::ParseAttribute to return an
appropriate AST node. Added new node AttributeDecl to Decl.h.

Still to do...hook up to the Decl...

llvm-svn: 39539
2007-06-01 17:11:19 +00:00
Chris Lattner a076fde1e3 more minor improvements to pretty printer.
llvm-svn: 39538
2007-05-31 18:21:33 +00:00
Chris Lattner b4619481e6 add some ;'s
llvm-svn: 39537
2007-05-31 06:00:14 +00:00
Chris Lattner 1c31050d21 add fixme
llvm-svn: 39536
2007-05-31 06:00:00 +00:00
Chris Lattner df3cafb796 fix a small printer bug, to emit:
a = b;
  {
    int c;
    c = a + b;
    int d;
    d++;
  }
  int e;

instead of:

  a = b;
  {
    int c;
    c = a + b;
    int d;
    d++;
  }  int e;

llvm-svn: 39535
2007-05-31 05:08:56 +00:00
Chris Lattner dc6e3feade emit a return at the end of the function. Run the llvm verifier.
llvm-svn: 39534
2007-05-30 22:55:31 +00:00
Chris Lattner 5269c0377c Add support for codegen'ing paren exprs and if stmts. We can now codegen:
void test() {
  goto l;

l:
  if (11) {
    j: ;
  }
}

into:

define void @test() {
entry:
        br label %l

l:              ; preds = %entry
        icmp ne i32 11, 0               ; <i1>:0 [#uses=1]
        br i1 %0, label %ifthen, label %ifend

ifthen:         ; preds = %l
        br label %j

j:              ; preds = %ifthen
        br label %ifend

ifend:          ; preds = %j, %l
}

whoa... :)

llvm-svn: 39533
2007-05-30 21:03:58 +00:00
Chris Lattner b2e723bed4 add accessor
llvm-svn: 39532
2007-05-30 20:59:30 +00:00
Chris Lattner fc068c15d9 pretty print exprs in stmt contexts with a trailing semicolon.
llvm-svn: 39531
2007-05-30 17:57:36 +00:00
Chris Lattner 208ae96a8c implement codegen of integer literals.
llvm-svn: 39530
2007-05-30 17:57:17 +00:00
Chris Lattner b5217858ee Update
llvm-svn: 39529
2007-05-30 17:01:31 +00:00
Steve Naroff 9992bbab14 Bug #:
Submitted by:
Reviewed by:
- ParseForStatement(): Put back a test/assignment. My removal of
ParseExprStmt() was a bit over zealous:-(thanks to Chris for pointing it out)
- Add assert to VisitDeclStmt().
- Removed an out-of-date FIXME
- Added some curlies for a couple multi-line calls to Diag().

llvm-svn: 39528
2007-05-30 16:27:15 +00:00
Bill Wendling 216423bbd7 Submitted by: Bill Wendling
Comment format changes.

llvm-svn: 39527
2007-05-30 06:30:29 +00:00
Steve Naroff 56faab2d4f Bug #:
Submitted by:
Reviewed by:
- Many tweaks to various diagnostics.
- Fixed some location/range issues.
- Bug fix to Sema::ParseDeclStmt() - error return code is "true", not 0.

llvm-svn: 39526
2007-05-30 04:20:12 +00:00
Bill Wendling 4447083418 Submitted by: Bill Wendling
- Conjugate "diagnostic" correctly for 1 diagnostic.

llvm-svn: 39525
2007-05-30 02:38:09 +00:00
Chris Lattner ac24820fa5 Implement codegen support for labels and gotos. We now compile:
void test1() {
  foo:
    goto foo;
    goto foo;
    goto foo;
}

void test() {
  goto l;

l:
  ;
}
into:

define void @test1() {
entry:
        br label %foo

foo:            ; preds = %0, %foo, %entry
        br label %foo
                ; No predecessors!
        br label %foo
                ; No predecessors!
}

define void @test() {
entry:
        br label %l

l:              ; preds = %entry
}

llvm-svn: 39524
2007-05-30 00:13:02 +00:00
Steve Naroff eb9da94d37 Bug #:
Submitted by:
Reviewed by:
Unified the diagnostics for function calls. Since we have range support,
there is no need for including the argument number. Instead, I've made
the diags more expressive by including more type info.

Also improved the indentation of many calls to Diag (which can be 2-3
lines now).

llvm-svn: 39523
2007-05-30 00:06:37 +00:00
Chris Lattner 308f431017 Add codegen support for NullStmt and CompoundStmt. {;;{};;} is now ours!
llvm-svn: 39522
2007-05-29 23:50:05 +00:00
Chris Lattner d5322cd27e Don't print billions of spaces for a label with no indent.
llvm-svn: 39521
2007-05-29 23:49:07 +00:00
Chris Lattner da8a4f467b add accessors.
llvm-svn: 39520
2007-05-29 23:48:32 +00:00
Chris Lattner d1af2d2956 Implement conversion of clang ast types to LLVM types, at least for some trivial
cases.

llvm-svn: 39519
2007-05-29 23:17:50 +00:00
Steve Naroff 2a8ad18e71 Bug #:
Submitted by:
Reviewed by:
Implement some FIXME's that stand in the way of fully typechecking "for"
statements. This involved:

- Adding a DeclStmt AST node (with statement visitor). The DeclStmt
printer is preliminary.
- Added a ParseDeclStmt action, called from Parser::ParseForStatement()
and Parser::ParseStatementOrDeclaration(). DID NOT add to
Parser::ParseIdentifierStatement()...probably could have, however didn't
really understand the context of this rule (will speak with Chris).
- Removed ParseExprStmt (and it's clients)...it was vestigial.

llvm-svn: 39518
2007-05-29 22:59:26 +00:00
Steve Naroff 6f49f5df03 Bug #:
Submitted by:
Reviewed by:
- Finished Sema::ParseReturnStmt(). Still need to tweak ranges.
- Tweaked location for function arguments (they now point at the expression directly, no parens or commas).
- Added InvalidOperands helper...was sick of looking at the same 3 lines in ~9 Check functions.
- Added a few diags and moved a group of statement diags to the proper comment/category.

llvm-svn: 39517
2007-05-29 14:23:36 +00:00
Chris Lattner e64a1b5275 Fix two bugs that fell out from a testcase steve noticed. for this testcase:
extern int pintFunc(int *, int *);

int test() {
  pintFunc(0,
           3);
}

We now print:

t3.c:4:13: warning: passing argument 2 makes pointer from integer without a cast
  pintFunc(0,
  ~~~~~~~~  ^

instead of:

t3.c:4:13: warning: passing argument 2 makes pointer from integer without a cast
  pintFunc(0,
  ~~~~~~~~

llvm-svn: 39516
2007-05-29 05:53:15 +00:00
Steve Naroff 86272ea1fe Bug #:
Submitted by:
Reviewed by:
Implement type checking for ParseDoStmt, ParseWhileStmt, ParseIfStmt, and
ParseForStmt. ParseForStmt still under construction (contains a FIXME).

llvm-svn: 39515
2007-05-29 02:14:17 +00:00
Steve Naroff 3c87a57a2c Bug #:
Submitted by:
Reviewed by:
Add range support to Sema::CheckConditionalOperands().

llvm-svn: 39514
2007-05-28 19:40:22 +00:00