Chris Lattner
d2b88ab313
Implement codegen for + and - with pointers. Patch contributed by
...
Keith Bauer.
llvm-svn: 39793
2007-07-13 03:05:23 +00:00
Chris Lattner
bd4de5df77
Fix "no newline at end of file" warnings. Patch contributed by
...
Benoit Boissinot!
llvm-svn: 39780
2007-07-12 15:43:07 +00:00
Chris Lattner
07eb733ef8
Evaluate the initializer for automatic variables.
...
llvm-svn: 39771
2007-07-12 00:39:48 +00:00
Chris Lattner
dcca487cfa
implement codegen support for pre/post inc/dec.
...
llvm-svn: 39765
2007-07-11 23:43:46 +00:00
Chris Lattner
c14236b8ae
implement codegen support for the "default argument promotions" (C99 6.5.2.2p6).
...
Not having this prevented promoting float arguments to double when passed
into printf, for example.
llvm-svn: 39727
2007-07-10 22:18:37 +00:00
Chris Lattner
a779b3df28
implement codegen support for rvalue-only vector subscripts, such as:
...
float4 test(void);
float test2() {
return test()[1];
}
llvm-svn: 39725
2007-07-10 21:58:36 +00:00
Chris Lattner
08c4b9ffec
Add support for codegen'ing vector subscripts, at least when they are lvalues.
...
llvm-svn: 39724
2007-07-10 21:17:59 +00:00
Chris Lattner
50d4abd24c
Add support for vector formal arguments.
...
llvm-svn: 39721
2007-07-10 00:28:12 +00:00
Chris Lattner
6eea886b9e
implement support for llvm codegen of vectors. That was much easier than
...
I expected :)
llvm-svn: 39720
2007-07-10 00:23:39 +00:00
Chris Lattner
2ada32ed7d
implement codegen support for FP literals
...
llvm-svn: 39718
2007-07-09 23:03:16 +00:00
Chris Lattner
47c247e7bf
add codegen support for <<= and >>=.
...
llvm-svn: 39713
2007-06-29 17:26:27 +00:00
Chris Lattner
b25a94383a
Implement the rest of the compound assignment operators, except shifts.
...
llvm-svn: 39712
2007-06-29 17:03:06 +00:00
Chris Lattner
cd215f00ee
refactor some code, implement -=
...
llvm-svn: 39711
2007-06-29 16:52:55 +00:00
Chris Lattner
9369a563b4
Rename ArithAssignBinaryOperator -> CompoundAssignOperator, implement
...
codegen support for +=.
llvm-svn: 39710
2007-06-29 16:31:29 +00:00
Chris Lattner
69e70e506a
fix codegen of void return functions
...
llvm-svn: 39694
2007-06-27 18:10:00 +00:00
Chris Lattner
c8c3dadaa0
fix codegen of void-returning functions
...
llvm-svn: 39693
2007-06-27 18:08:49 +00:00
Chris Lattner
54fb19efaa
implement support for struct and complex returns.
...
llvm-svn: 39674
2007-06-22 22:02:34 +00:00
Chris Lattner
e9a6453ded
add some infrastructure for codegen'ing complex numbers. implement addition
...
of complex. We now produce optimal code for:
void test(_Complex float *Y) {
*Y = *Y + *Y;
}
$ clang -emit-llvm cg.c | llvm-as | opt -std-compile-opts | llc -march=x86-64
...
_test:
movss (%rdi), %xmm0
addss %xmm0, %xmm0
movss 4(%rdi), %xmm1
movss %xmm0, (%rdi)
addss %xmm1, %xmm1
movss %xmm1, 4(%rdi)
ret
llvm-svn: 39673
2007-06-22 21:44:33 +00:00
Chris Lattner
c6395936ae
Split complex types out from being members of BuiltinType to being their own
...
types.
llvm-svn: 39672
2007-06-22 20:56:16 +00:00
Chris Lattner
f033c147c9
remove location tracking for target info
...
llvm-svn: 39671
2007-06-22 19:05:19 +00:00
Chris Lattner
0fb8465981
Don't forget to set this
...
llvm-svn: 39670
2007-06-22 18:57:44 +00:00
Chris Lattner
09153c0a8c
Build enough support for aggregates to be able to compile this:
...
void test(int A, _Complex float Y) {
_Complex float X;
X = X;
}
llvm-svn: 39669
2007-06-22 18:48:09 +00:00
Chris Lattner
3e3a1e9cda
implement lowering of complex types
...
llvm-svn: 39668
2007-06-22 18:15:26 +00:00
Chris Lattner
f39b03d98b
fix naming of aggregate arguments.
...
llvm-svn: 39667
2007-06-22 18:15:16 +00:00
Chris Lattner
1fde0b345b
implement codegen of the relational operations
...
One major FIXME though.
llvm-svn: 39666
2007-06-20 18:30:55 +00:00
Chris Lattner
273c63d450
Implement the equality operators for simple types
...
llvm-svn: 39665
2007-06-20 18:02:30 +00:00
Chris Lattner
e1e93a5e5d
assert, don't crash, on int[]
...
llvm-svn: 39664
2007-06-20 17:12:11 +00:00
Chris Lattner
b6984c4854
Hook up global function and variable handling. We can now compile:
...
int X, bar(int,int,int);
short Y;
double foo() {
return bar(X, Y, 3);
}
into:
@X = external global i32 ; <i32*> [#uses=1]
@Y = external global i16 ; <i16*> [#uses=1]
define double @foo() {
entry:
%tmp = load i32* @X ; <i32> [#uses=1]
%tmp1 = load i16* @Y ; <i16> [#uses=1]
%promote = sext i16 %tmp1 to i32 ; <i32> [#uses=1]
%call = tail call i32 @bar( i32 %tmp, i32 %promote, i32 3 ) ; <i32> [#uses=1]
%conv = sitofp i32 %call to double ; <double> [#uses=1]
ret double %conv
}
declare i32 @bar(i32, i32, i32)
llvm-svn: 39663
2007-06-20 04:44:43 +00:00
Chris Lattner
2ccb73bc8b
Refactor CodeGenTypes out to CodeGenModule so it can be used for functions
...
and globals.
llvm-svn: 39661
2007-06-16 00:16:26 +00:00
Chris Lattner
2052bc8107
Split type analysis out to its own file, now the integer constant expr evaluation
...
is ready.
llvm-svn: 39660
2007-06-16 00:12:05 +00:00
Chris Lattner
23b7eb677d
Finally bite the bullet and make the major change: split the clang namespace
...
out of the llvm namespace. This makes the clang namespace be a sibling of
llvm instead of being a child.
The good thing about this is that it makes many things unambiguous. The
bad things is that many things in the llvm namespace (notably data structures
like smallvector) now require an llvm:: qualifier. IMO, libsystem and libsupport
should be split out of llvm into their own namespace in the future, which will fix
this issue.
llvm-svn: 39659
2007-06-15 23:05:46 +00:00
Chris Lattner
2b228c95aa
implement codegen of calls. We can now compile:
...
double foo( int (*FP)(int, int, int)) {
return FP(1, 2, 3);
}
to:
define double @foo(i32 (i32, i32, i32)* %FP) {
entry:
%call = tail call i32 %FP( i32 1, i32 2, i32 3 )
%conv = sitofp i32 %call to double
ret double %conv
}
llvm-svn: 39658
2007-06-15 21:34:29 +00:00
Chris Lattner
d760e468aa
Don't generate code for prototypes
...
llvm-svn: 39656
2007-06-15 21:16:23 +00:00
Chris Lattner
b48238188e
Fix a nasty bug which caused infinite recursion
...
llvm-svn: 39655
2007-06-15 21:04:38 +00:00
Chris Lattner
cf98efa73b
Implement implicit conversions in return stmts.
...
llvm-svn: 39653
2007-06-13 20:50:31 +00:00
Chris Lattner
53621a535d
Implement support for formal arguments. We can now compile this:
...
int test(int X, short Y, float Z) {
return (int)(X*Y+Z);
}
to:
define i32 @test(i32 %X, i16 %Y, float %Z) {
entry:
%promote = sext i16 %Y to i32 ; <i32> [#uses=1]
%mul = mul i32 %promote, %X ; <i32> [#uses=1]
%promote3 = sitofp i32 %mul to float ; <float> [#uses=1]
%add = add float %promote3, %Z ; <float> [#uses=1]
%conv = fptosi float %add to i32 ; <i32> [#uses=1]
ret i32 %conv
}
with:
$ clang -emit-llvm t.c | llvm-as | opt -std-compile-opts | llvm-dis
llvm-svn: 39652
2007-06-13 20:44:40 +00:00
Chris Lattner
f99b3f5ec2
Emit codegen of enum literals.
...
llvm-svn: 39646
2007-06-11 03:52:52 +00:00
Chris Lattner
45bb914249
Convert argument types over, which works for trivial scalars.
...
llvm-svn: 39625
2007-06-09 02:28:57 +00:00
Chris Lattner
1ad38f8fee
codegen all declarators in a declstmt, allowing us to successfully codegen
...
stuff like:
void test() {
int *X, Y, *Z[14];
X[Y] = 4;
}
llvm-svn: 39624
2007-06-09 01:20:56 +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
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
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
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
84915fa79b
Start stubbing out decl codegen.
...
llvm-svn: 39550
2007-06-02 04:16:21 +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
e47e440c42
split stmt/expr codegen into their own files.
...
llvm-svn: 39540
2007-06-01 18:02:12 +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
208ae96a8c
implement codegen of integer literals.
...
llvm-svn: 39530
2007-05-30 17:57:17 +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
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
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
Chris Lattner
bed314465a
Reorganize codegen files.
...
llvm-svn: 39504
2007-05-28 01:07:47 +00:00
Chris Lattner
f97fe38cb5
Initial scaffolding for an -emit-llvm mode. This requires the LLVM VMCore
...
library to be built for the driver to link.
llvm-svn: 39495
2007-05-24 06:29:05 +00:00