Commit Graph

16 Commits

Author SHA1 Message Date
Chris Lattner f99b3f5ec2 Emit codegen of enum literals.
llvm-svn: 39646
2007-06-11 03:52:52 +00:00
Chris Lattner d9d2fb1420 Implement array subscripts for non-vla types.
llvm-svn: 39622
2007-06-08 23:31:14 +00:00
Chris Lattner 4347e369b4 implement codegen of string literals.
llvm-svn: 39597
2007-06-06 04:54:52 +00:00
Chris Lattner 83b484b3be implement the real int/fp conversions
llvm-svn: 39596
2007-06-06 04:39:08 +00:00
Chris Lattner cf106ab42a implement support for casts to/from pointers.
llvm-svn: 39595
2007-06-06 04:05:39 +00:00
Chris Lattner 8394d795c3 implement codegen of a bunch more loop constructs and most expressions
llvm-svn: 39593
2007-06-05 20:53:16 +00:00
Chris Lattner 946aa31f02 implement codegen of while stmts and lvalue evaluation of paren exprs :)
llvm-svn: 39582
2007-06-05 03:59:43 +00:00
Chris Lattner b16f455e8c Type::isSignedInteger() and isUnsignedInteger() did not properly account for
'char', which varies based on the target.

Instead of spreading target knowledge throughout the compiler, bifurcate char
into Char_S and Char_U, and have ASTContext create the right one based on the
target, when it starts up.

llvm-svn: 39577
2007-06-03 07:25:34 +00:00
Chris Lattner cf25024828 Implement EmitUsualArithmeticConversions, so we can add shorts to floats and
ints to long long etc.  For int to longlong, we now get:

        %tmp = load i64* %F             ; <i64> [#uses=1]
        %tmp1 = load i32* %D            ; <i32> [#uses=1]
        %promote = sext i32 %tmp1 to i64                ; <i64> [#uses=1]
        %tmp2 = add i64 %tmp, %promote          ; <i64> [#uses=0]

llvm-svn: 39576
2007-06-03 02:02:44 +00:00
Chris Lattner c18f9d1aed Change EmitUsualArithmeticConversions to use EmitExprWithUsualUnaryConversions.
This allows us to compile:

  register short X;
  {
    int Y;
    return 1+X+Y;

into:

        %tmp = load i16* %X             ; <i16> [#uses=1]
        %promote = sext i16 %tmp to i32         ; <i32> [#uses=1]
        %tmp1 = add i32 1, %promote             ; <i32> [#uses=1]
        %tmp2 = load i32* %Y            ; <i32> [#uses=1]
        %tmp3 = add i32 %tmp1, %tmp2            ; <i32> [#uses=1]
        ret i32 %tmp3

Look at the amazing sign extension, so much happier than an assertion failure. :)

llvm-svn: 39565
2007-06-02 22:51:30 +00:00
Chris Lattner 6db1fb845a implement a first hack at codegen'ing the usual unary conversions.
This allows us to compile:

int func() {
  int A[10];
  if (!A) {

to:

define i32 @func() {
entry:
        %A = alloca [10 x i32]          ; <[10 x i32]*> [#uses=1]
        %arraydecay = getelementptr [10 x i32]* %A, i32 0, i32 0                ; <i32*> [#uses=1]
        %tobool = icmp ne i32* %arraydecay, null                ; <i1> [#uses=1]
        %lnot = xor i1 %tobool, true            ; <i1> [#uses=1]
        br i1 %lnot, label %ifthen, label %ifend

-Chris

llvm-svn: 39564
2007-06-02 22:49:07 +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 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
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 e47e440c42 split stmt/expr codegen into their own files.
llvm-svn: 39540
2007-06-01 18:02:12 +00:00