Mercurial > projects > ldc
annotate gen/abi.cpp @ 1541:1e7a09548e67
Target.addPassesToEmitFile takes a formatted_raw_ostream now
Build fix for LLVM r75670
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Tue, 14 Jul 2009 23:06:31 +0200 |
parents | 2292878925f4 |
children | 7fcb72d518f6 |
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); |
1438
c363d131c1ef
Add some missing returns.
Frits van Bommel <fvbommel wxs.nl>
parents:
1359
diff
changeset
|
135 return 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 } |
1446
fe151804995a
Improve ABI conformance on x86 by passing the `sret` parameter in EAX if there's
Frits van Bommel <fvbommel wxs.nl>
parents:
1438
diff
changeset
|
199 else if (IrFuncTyArg* sret = fty.arg_sret) |
fe151804995a
Improve ABI conformance on x86 by passing the `sret` parameter in EAX if there's
Frits van Bommel <fvbommel wxs.nl>
parents:
1438
diff
changeset
|
200 { |
fe151804995a
Improve ABI conformance on x86 by passing the `sret` parameter in EAX if there's
Frits van Bommel <fvbommel wxs.nl>
parents:
1438
diff
changeset
|
201 Logger::println("Putting sret ptr in register"); |
fe151804995a
Improve ABI conformance on x86 by passing the `sret` parameter in EAX if there's
Frits van Bommel <fvbommel wxs.nl>
parents:
1438
diff
changeset
|
202 // sret and inreg are incompatible, but the ABI requires the |
fe151804995a
Improve ABI conformance on x86 by passing the `sret` parameter in EAX if there's
Frits van Bommel <fvbommel wxs.nl>
parents:
1438
diff
changeset
|
203 // sret parameter to be in EAX in this situation... |
fe151804995a
Improve ABI conformance on x86 by passing the `sret` parameter in EAX if there's
Frits van Bommel <fvbommel wxs.nl>
parents:
1438
diff
changeset
|
204 sret->attrs = (sret->attrs | llvm::Attribute::InReg) |
fe151804995a
Improve ABI conformance on x86 by passing the `sret` parameter in EAX if there's
Frits van Bommel <fvbommel wxs.nl>
parents:
1438
diff
changeset
|
205 & ~llvm::Attribute::StructRet; |
fe151804995a
Improve ABI conformance on x86 by passing the `sret` parameter in EAX if there's
Frits van Bommel <fvbommel wxs.nl>
parents:
1438
diff
changeset
|
206 } |
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 // otherwise try to mark the last param inreg |
1446
fe151804995a
Improve ABI conformance on x86 by passing the `sret` parameter in EAX if there's
Frits van Bommel <fvbommel wxs.nl>
parents:
1438
diff
changeset
|
208 else if (!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
|
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 // 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
|
211 // * 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
|
212 // * 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
|
213 // * 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
|
214 |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
215 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
|
216 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
|
217 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
|
218 |
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 (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
|
220 { |
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
|
221 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
|
222 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
|
223 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
224 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
|
225 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
226 // 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
|
227 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
|
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 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
|
230 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
|
231 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
|
232 // 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
|
233 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
|
234 } |
1040
0477f98d357e
Fixed inreg attribute to no longer overwrite sign/zeroext.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
235 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
|
236 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
237 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
238 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
239 // 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
|
240 // "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
|
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 // 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
|
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 // 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
|
245 // 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
|
246 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
|
247 { |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
248 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
|
249 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
250 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
251 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
252 // 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
|
253 else |
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 // 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
|
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 // 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
|
258 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
|
259 { |
1051
dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents:
1050
diff
changeset
|
260 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
|
261 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
|
262 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
263 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
264 // 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
|
265 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
266 // 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
|
267 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
268 } |
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 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
272 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
273 /////////////////// 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
|
274 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
275 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
276 |
1047
6bb04dbee21f
Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents:
1043
diff
changeset
|
277 #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
|
278 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
279 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
280 ////////////////////////////////////////////////////////////////////////////// |
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 /////////////////// 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
|
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 ////////////////////////////////////////////////////////////////////////////// |
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 |
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 // 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
|
286 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
|
287 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
288 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
|
289 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
290 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
|
291 } |
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 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
293 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
|
294 { |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
295 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
|
296 } |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
297 |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
298 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
|
299 { |
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1018
diff
changeset
|
300 // 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
|
301 } |
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
|
302 }; |
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
|
303 |
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
|
304 ////////////////////////////////////////////////////////////////////////////// |
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
|
305 ////////////////////////////////////////////////////////////////////////////// |
989
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
306 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
307 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
308 ////////////////////////////////////////////////////////////////////////////// |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
309 |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
310 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
|
311 { |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
312 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
|
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 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
|
315 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
|
316 case ARCHx86_64: |
1047
6bb04dbee21f
Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents:
1043
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 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
|
321 } |
420ef073448d
Forgot new files that were supposed to be in last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff
changeset
|
322 } |
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
|
323 |
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 ////////////////////////////////////////////////////////////////////////////// |
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 ////////////////////////////////////////////////////////////////////////////// |
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 |
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 // 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
|
331 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
|
332 { |
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 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
|
334 |
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 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
|
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 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
|
338 } |
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 |
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 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
|
341 { |
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 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
|
343 } |
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 |
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 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
|
346 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
|
347 // 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
|
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 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
|
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 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
|
352 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
|
353 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
|
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 } |
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 |
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 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
|
358 { |
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 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
|
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 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
|
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 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
|
364 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
|
365 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
|
366 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
|
367 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
|
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 } |
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 |
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 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
|
372 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
|
373 |
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 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
|
375 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
|
376 |
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 (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
|
378 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
|
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 // 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
|
381 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
|
382 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
|
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 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
|
385 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
|
386 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
|
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 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
|
389 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
|
390 } |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
391 } |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
392 }; |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
393 |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
394 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
|
395 { |
34f2fd925de3
Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
396 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
|
397 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
|
398 } |