Mercurial > projects > ldc
annotate gen/abi.cpp @ 1359:34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
that removes it.
This unbreaks the `llvm_*_with_overflow` intrinsics.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sat, 16 May 2009 13:06:49 +0200 |
parents | 15e9762bb620 |
children | c363d131c1ef |
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" |
1359
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
13 #include "gen/abi-generic.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
|
14 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
15 #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
|
16 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
17 ////////////////////////////////////////////////////////////////////////////// |
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
|
18 |
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 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
|
20 { |
1043
0485751a40ae
Fix bug in default implementation of ABIRewrite::getL.
Frits van Bommel <fvbommel wxs.nl>
parents:
1042
diff
changeset
|
21 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
|
22 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
|
23 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
|
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 |
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
|
26 ////////////////////////////////////////////////////////////////////////////// |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
27 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
28 ///////////////////// X86 //////////////////////////// |
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 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
32 // 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
|
33 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
|
34 { |
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
|
35 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
|
36 { |
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
|
37 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
|
38 } |
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
|
39 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
|
40 { |
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
|
41 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
|
42 } |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
43 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
|
44 { |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
45 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
|
46 } |
1018
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 ////////////////////////////////////////////////////////////////////////////// |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
50 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
51 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
|
52 { |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
53 // 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
|
54 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
|
55 { |
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
|
56 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
|
57 |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
58 // 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
|
59 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
|
60 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
|
61 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
62 // 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
|
63 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
|
64 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
|
65 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
|
66 |
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 {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
|
68 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
|
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 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
71 // {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
|
72 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
|
73 { |
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
|
74 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
|
75 |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
76 // 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
|
77 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
|
78 // 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
|
79 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
|
80 // 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
|
81 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
|
82 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
83 // 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
|
84 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
|
85 // 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
|
86 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
|
87 // 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
|
88 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
|
89 // 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
|
90 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
|
91 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
92 // 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
|
93 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
|
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 |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
96 // {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
|
97 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
|
98 { |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
99 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
|
100 } |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
101 }; |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
102 |
1024
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 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
105 // 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
|
106 // 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
|
107 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
108 // 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
|
109 // when |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
110 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
|
111 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
112 // 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
|
113 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
|
114 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
115 Logger::println("rewriting int -> struct"); |
1350
15e9762bb620
Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1051
diff
changeset
|
116 LLValue* mem = DtoAlloca(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
|
117 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
|
118 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
|
119 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
|
120 } |
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
|
121 // 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
|
122 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
|
123 { |
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 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
|
125 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
|
126 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
|
127 } |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
128 // 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
|
129 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
|
130 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 } |
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
|
137 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
|
138 { |
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
|
139 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
|
140 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
|
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 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
146 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
|
147 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
152 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
|
153 { |
1018
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
154 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
|
155 // 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
|
156 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
|
157 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
|
158 // 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
|
159 // 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
|
160 else |
e8c6dbcd33d1
- Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1002
diff
changeset
|
161 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
|
162 } |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
163 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
164 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
|
165 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
166 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
|
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 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
169 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
|
170 { |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
171 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
|
172 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
|
173 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
174 // 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
|
175 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
|
176 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
177 // 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
|
178 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
179 // 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
|
180 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
|
181 { |
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
|
182 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
|
183 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
|
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 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
186 // 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
|
187 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
188 // 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
|
189 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
|
190 { |
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
|
191 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
|
192 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
|
193 } |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
194 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
|
195 { |
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
|
196 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
|
197 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
|
198 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
199 // 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
|
200 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
|
201 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
202 // 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
|
203 // * 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
|
204 // * 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
|
205 // * 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
|
206 |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
211 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
|
212 { |
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
|
213 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
|
214 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
|
215 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
216 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
|
217 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
218 // 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
|
219 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
|
220 { |
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->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
|
222 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
|
223 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
|
224 // 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
|
225 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
|
226 } |
1040
0477f98d357e
Fixed inreg attribute to no longer overwrite sign/zeroext.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
227 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
|
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 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
231 // 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
|
232 // "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
|
233 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
234 // 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
|
235 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
236 // 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
|
237 // 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
|
238 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
|
239 { |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
240 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
|
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 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
244 // 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
|
245 else |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
246 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
247 // 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
|
248 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
249 // 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
|
250 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
|
251 { |
1051
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->rewrite = &cfloatToInt; |
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
253 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
|
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 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
256 // 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
|
257 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
258 // 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
|
259 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
260 } |
989
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 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
265 /////////////////// 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
|
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 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
268 |
1047
6bb04dbee21f
Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents:
1043
diff
changeset
|
269 #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
|
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 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
272 ////////////////////////////////////////////////////////////////////////////// |
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
|
273 /////////////////// 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
|
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 |
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 // 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
|
278 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
|
279 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
280 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
|
281 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
282 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
|
283 } |
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
|
284 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
285 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
|
286 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
287 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
|
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 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
290 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
|
291 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
292 // 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
|
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 ////////////////////////////////////////////////////////////////////////////// |
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
|
297 ////////////////////////////////////////////////////////////////////////////// |
989
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 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
302 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
|
303 { |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
304 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
|
305 { |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
306 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
|
307 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
|
308 case ARCHx86_64: |
1047
6bb04dbee21f
Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents:
1043
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 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
|
313 } |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
314 } |
1359
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
315 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
316 ////////////////////////////////////////////////////////////////////////////// |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
317 ////////////////////////////////////////////////////////////////////////////// |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
318 ////////////////////////////////////////////////////////////////////////////// |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
319 ////////////////////////////////////////////////////////////////////////////// |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
320 ////////////////////////////////////////////////////////////////////////////// |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
321 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
322 // A simple ABI for LLVM intrinsics. |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
323 struct IntrinsicABI : TargetABI |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
324 { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
325 RemoveStructPadding remove_padding; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
326 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
327 bool returnInArg(TypeFunction* tf) |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
328 { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
329 return false; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
330 } |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
331 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
332 bool passByVal(Type* t) |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
333 { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
334 return false; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
335 } |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
336 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
337 void fixup(IrFuncTyArg& arg) { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
338 assert(arg.type->ty == Tstruct); |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
339 // TODO: Check that no unions are passed in or returned. |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
340 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
341 LLType* abiTy = DtoUnpaddedStructType(arg.type); |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
342 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
343 if (abiTy && abiTy != arg.ltype) { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
344 arg.ltype = abiTy; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
345 arg.rewrite = &remove_padding; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
346 } |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
347 } |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
348 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
349 void rewriteFunctionType(TypeFunction* tf) |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
350 { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
351 assert(tf->linkage == LINKintrinsic); |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
352 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
353 IrFuncTy& fty = tf->fty; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
354 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
355 if (!fty.arg_sret) { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
356 Type* rt = fty.ret->type->toBasetype(); |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
357 if (rt->ty == Tstruct) { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
358 Logger::println("Intrinsic ABI: Transforming return type"); |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
359 fixup(*fty.ret); |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
360 } |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
361 } |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
362 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
363 Logger::println("Intrinsic ABI: Transforming arguments"); |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
364 LOG_SCOPE; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
365 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
366 for (IrFuncTy::ArgIter I = fty.args.begin(), E = fty.args.end(); I != E; ++I) { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
367 IrFuncTyArg& arg = **I; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
368 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
369 if (Logger::enabled()) |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
370 Logger::cout() << "Arg: " << arg.type->toChars() << '\n'; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
371 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
372 // Arguments that are in memory are of no interest to us. |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
373 if (arg.byref) |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
374 continue; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
375 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
376 Type* ty = arg.type->toBasetype(); |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
377 if (ty->ty == Tstruct) |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
378 fixup(arg); |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
379 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
380 if (Logger::enabled()) |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
381 Logger::cout() << "New arg type: " << *arg.ltype << '\n'; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
382 } |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
383 } |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
384 }; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
385 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
386 TargetABI * TargetABI::getIntrinsic() |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
387 { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
388 static IntrinsicABI iabi; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
389 return &iabi; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
390 } |