Mercurial > projects > ldc
annotate gen/abi.cpp @ 1202:7c7072437a89
Introduce checks to fix #173.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 12 Apr 2009 14:58:18 +0200 |
parents | dc608dc33081 |
children | 15e9762bb620 |
rev | line source |
---|---|
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
1 #include "gen/llvm.h" |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
2 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
3 #include <algorithm> |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
4 |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
5 #include "mars.h" |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
6 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
7 #include "gen/irstate.h" |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
8 #include "gen/llvmhelpers.h" |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
9 #include "gen/tollvm.h" |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
10 #include "gen/abi.h" |
996
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
11 #include "gen/logger.h" |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
12 #include "gen/dvalue.h" |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
13 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
14 #include "ir/irfunction.h" |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
15 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
16 ////////////////////////////////////////////////////////////////////////////// |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
17 |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
18 void ABIRewrite::getL(Type* dty, DValue* v, llvm::Value* lval) |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
19 { |
1043
0485751a40ae
Fix bug in default implementation of ABIRewrite::getL.
Frits van Bommel <fvbommel wxs.nl>
parents:
1042
diff
changeset
|
20 LLValue* rval = get(dty, v); |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
21 assert(rval->getType() == lval->getType()->getContainedType(0)); |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
22 DtoStore(rval, lval); |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
23 } |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
24 |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
25 ////////////////////////////////////////////////////////////////////////////// |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
26 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
27 ///////////////////// X86 //////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
28 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
29 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
30 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
31 // simply swap of real/imag parts for proper x87 complex abi |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
32 struct X87_complex_swap : ABIRewrite |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
33 { |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
34 LLValue* get(Type*, DValue* v) |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
35 { |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
36 return DtoAggrPairSwap(v->getRVal()); |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
37 } |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
38 LLValue* put(Type*, DValue* v) |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
39 { |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
40 return DtoAggrPairSwap(v->getRVal()); |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
41 } |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
42 const LLType* type(Type*, const LLType* t) |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
43 { |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
44 return t; |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
45 } |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
46 }; |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
47 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
48 ////////////////////////////////////////////////////////////////////////////// |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
49 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
50 struct X86_cfloat_rewrite : ABIRewrite |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
51 { |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
52 // i64 -> {float,float} |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
53 LLValue* get(Type*, DValue* dv) |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
54 { |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
55 LLValue* in = dv->getRVal(); |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
56 |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
57 // extract real part |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
58 LLValue* rpart = gIR->ir->CreateTrunc(in, LLType::Int32Ty); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
59 rpart = gIR->ir->CreateBitCast(rpart, LLType::FloatTy, ".re"); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
60 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
61 // extract imag part |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
62 LLValue* ipart = gIR->ir->CreateLShr(in, LLConstantInt::get(LLType::Int64Ty, 32, false)); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
63 ipart = gIR->ir->CreateTrunc(ipart, LLType::Int32Ty); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
64 ipart = gIR->ir->CreateBitCast(ipart, LLType::FloatTy, ".im"); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
65 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
66 // return {float,float} aggr pair with same bits |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
67 return DtoAggrPair(rpart, ipart, ".final_cfloat"); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
68 } |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
69 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
70 // {float,float} -> i64 |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
71 LLValue* put(Type*, DValue* dv) |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
72 { |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
73 LLValue* v = dv->getRVal(); |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
74 |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
75 // extract real |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
76 LLValue* r = gIR->ir->CreateExtractValue(v, 0); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
77 // cast to i32 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
78 r = gIR->ir->CreateBitCast(r, LLType::Int32Ty); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
79 // zext to i64 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
80 r = gIR->ir->CreateZExt(r, LLType::Int64Ty); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
81 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
82 // extract imag |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
83 LLValue* i = gIR->ir->CreateExtractValue(v, 1); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
84 // cast to i32 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
85 i = gIR->ir->CreateBitCast(i, LLType::Int32Ty); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
86 // zext to i64 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
87 i = gIR->ir->CreateZExt(i, LLType::Int64Ty); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
88 // shift up |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
89 i = gIR->ir->CreateShl(i, LLConstantInt::get(LLType::Int64Ty, 32, false)); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
90 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
91 // combine and return |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
92 return v = gIR->ir->CreateOr(r, i); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
93 } |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
94 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
95 // {float,float} -> i64 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
96 const LLType* type(Type*, const LLType* t) |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
97 { |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
98 return LLType::Int64Ty; |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
99 } |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
100 }; |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
101 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
102 ////////////////////////////////////////////////////////////////////////////// |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
103 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
104 // FIXME: try into eliminating the alloca or if at least check |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
105 // if it gets optimized away |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
106 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
107 // convert byval struct |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
108 // when |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
109 struct X86_struct_to_register : ABIRewrite |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
110 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
111 // int -> struct |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
112 LLValue* get(Type* dty, DValue* dv) |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
113 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
114 Logger::println("rewriting int -> struct"); |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
115 LLValue* mem = DtoAlloca(DtoType(dty), ".int_to_struct"); |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
116 LLValue* v = dv->getRVal(); |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
117 DtoStore(v, DtoBitCast(mem, getPtrToType(v->getType()))); |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
118 return DtoLoad(mem); |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
119 } |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
120 // int -> struct (with dst lvalue given) |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
121 void getL(Type* dty, DValue* dv, llvm::Value* lval) |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
122 { |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
123 Logger::println("rewriting int -> struct"); |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
124 LLValue* v = dv->getRVal(); |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
125 DtoStore(v, DtoBitCast(lval, getPtrToType(v->getType()))); |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
126 } |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
127 // struct -> int |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
128 LLValue* put(Type* dty, DValue* dv) |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
129 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
130 Logger::println("rewriting struct -> int"); |
1042
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
131 assert(dv->isLVal()); |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
132 LLValue* mem = dv->getLVal(); |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
133 const LLType* t = LLIntegerType::get(dty->size()*8); |
45af482e3832
Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1040
diff
changeset
|
134 DtoLoad(DtoBitCast(mem, getPtrToType(t))); |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
135 } |
1050
32ead42679d1
Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents:
1047
diff
changeset
|
136 const LLType* type(Type* t, const LLType*) |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
137 { |
1050
32ead42679d1
Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents:
1047
diff
changeset
|
138 size_t sz = t->size()*8; |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
139 return LLIntegerType::get(sz); |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
140 } |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
141 }; |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
142 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
143 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
144 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
145 struct X86TargetABI : TargetABI |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
146 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
147 X87_complex_swap swapComplex; |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
148 X86_cfloat_rewrite cfloatToInt; |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
149 X86_struct_to_register structToReg; |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
150 |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
151 bool returnInArg(TypeFunction* tf) |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
152 { |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
153 Type* rt = tf->next->toBasetype(); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
154 // D only returns structs on the stack |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
155 if (tf->linkage == LINKd) |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
156 return (rt->ty == Tstruct); |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
157 // other ABI's follow C, which is cdouble and creal returned on the stack |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
158 // as well as structs |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
159 else |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
160 return (rt->ty == Tstruct || rt->ty == Tcomplex64 || rt->ty == Tcomplex80); |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
161 } |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
162 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
163 bool passByVal(Type* t) |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
164 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
165 return t->toBasetype()->ty == Tstruct; |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
166 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
167 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
168 void rewriteFunctionType(TypeFunction* tf) |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
169 { |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
170 IrFuncTy& fty = tf->fty; |
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
171 Type* rt = fty.ret->type->toBasetype(); |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
172 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
173 // extern(D) |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
174 if (tf->linkage == LINKd) |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
175 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
176 // RETURN VALUE |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
177 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
178 // complex {re,im} -> {im,re} |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
179 if (rt->iscomplex()) |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
180 { |
1050
32ead42679d1
Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents:
1047
diff
changeset
|
181 Logger::println("Rewriting complex return value"); |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
182 fty.ret->rewrite = &swapComplex; |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
183 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
184 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
185 // IMPLICIT PARAMETERS |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
186 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
187 // mark this/nested params inreg |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
188 if (fty.arg_this) |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
189 { |
1050
32ead42679d1
Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents:
1047
diff
changeset
|
190 Logger::println("Putting 'this' in register"); |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
191 fty.arg_this->attrs = llvm::Attribute::InReg; |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
192 } |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
193 else if (fty.arg_nest) |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
194 { |
1050
32ead42679d1
Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents:
1047
diff
changeset
|
195 Logger::println("Putting context ptr in register"); |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
196 fty.arg_nest->attrs = llvm::Attribute::InReg; |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
197 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
198 // otherwise try to mark the last param inreg |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
199 else if (!fty.arg_sret && !fty.args.empty()) |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
200 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
201 // The last parameter is passed in EAX rather than being pushed on the stack if the following conditions are met: |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
202 // * It fits in EAX. |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
203 // * It is not a 3 byte struct. |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
204 // * It is not a floating point type. |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
205 |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
206 IrFuncTyArg* last = fty.args.back(); |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
207 Type* lastTy = last->type->toBasetype(); |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
208 unsigned sz = lastTy->size(); |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
209 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
210 if (last->byref && !last->isByVal()) |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
211 { |
1050
32ead42679d1
Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents:
1047
diff
changeset
|
212 Logger::println("Putting last (byref) parameter in register"); |
1040
0477f98d357e
Fixed inreg attribute to no longer overwrite sign/zeroext.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
213 last->attrs |= llvm::Attribute::InReg; |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
214 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
215 else if (!lastTy->isfloating() && (sz == 1 || sz == 2 || sz == 4)) // right? |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
216 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
217 // rewrite the struct into an integer to make inreg work |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
218 if (lastTy->ty == Tstruct) |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
219 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
220 last->rewrite = &structToReg; |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
221 last->ltype = structToReg.type(last->type, last->ltype); |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
222 last->byref = false; |
1040
0477f98d357e
Fixed inreg attribute to no longer overwrite sign/zeroext.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
223 // erase previous attributes |
0477f98d357e
Fixed inreg attribute to no longer overwrite sign/zeroext.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
224 last->attrs = 0; |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
225 } |
1040
0477f98d357e
Fixed inreg attribute to no longer overwrite sign/zeroext.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
226 last->attrs |= llvm::Attribute::InReg; |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
227 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
228 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
229 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
230 // FIXME: tf->varargs == 1 need to use C calling convention and vararg mechanism to live up to the spec: |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
231 // "The caller is expected to clean the stack. _argptr is not passed, it is computed by the callee." |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
232 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
233 // EXPLICIT PARAMETERS |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
234 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
235 // reverse parameter order |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
236 // for non variadics |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
237 if (!fty.args.empty() && tf->varargs != 1) |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
238 { |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
239 fty.reverseParams = true; |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
240 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
241 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
242 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
243 // extern(C) and all others |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
244 else |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
245 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
246 // RETURN VALUE |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
247 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
248 // cfloat -> i64 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
249 if (tf->next->toBasetype() == Type::tcomplex32) |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
250 { |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
251 fty.ret->rewrite = &cfloatToInt; |
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
252 fty.ret->ltype = LLType::Int64Ty; |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
253 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
254 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
255 // IMPLICIT PARAMETERS |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
256 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
257 // EXPLICIT PARAMETERS |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
258 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
259 } |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
260 }; |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
261 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
262 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
263 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
264 /////////////////// X86-64 ////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
265 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
266 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
267 |
1047
6bb04dbee21f
Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents:
1043
diff
changeset
|
268 #include "gen/abi-x86-64.h" |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
269 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
270 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
271 ////////////////////////////////////////////////////////////////////////////// |
996
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
272 /////////////////// Unknown targets ////////////////////////// |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
273 ////////////////////////////////////////////////////////////////////////////// |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
274 ////////////////////////////////////////////////////////////////////////////// |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
275 |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
276 // Some reasonable defaults for when we don't know what ABI to use. |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
277 struct UnknownTargetABI : TargetABI |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
278 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
279 bool returnInArg(TypeFunction* tf) |
996
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
280 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
281 return (tf->next->toBasetype()->ty == Tstruct); |
996
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
282 } |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
283 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
284 bool passByVal(Type* t) |
996
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
285 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
286 return t->toBasetype()->ty == Tstruct; |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
287 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
288 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
289 void rewriteFunctionType(TypeFunction* t) |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
290 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
291 // why? |
996
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
292 } |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
293 }; |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
294 |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
295 ////////////////////////////////////////////////////////////////////////////// |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
296 ////////////////////////////////////////////////////////////////////////////// |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
297 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
298 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
299 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
300 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
301 TargetABI * TargetABI::getTarget() |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
302 { |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
303 switch(global.params.cpu) |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
304 { |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
305 case ARCHx86: |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
306 return new X86TargetABI; |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
307 case ARCHx86_64: |
1047
6bb04dbee21f
Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents:
1043
diff
changeset
|
308 return getX86_64TargetABI(); |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
309 default: |
996
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
310 Logger::cout() << "WARNING: Unknown ABI, guessing...\n"; |
6e7dc3caccdd
Don't crash if we don't know what ABI to use. Assume some defaults instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
991
diff
changeset
|
311 return new UnknownTargetABI; |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
312 } |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
313 } |