annotate gen/tocall.cpp @ 1030:3ead5c40b7d6

Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 03 Mar 2009 17:21:35 +0100
parents 9167d492cbc2
children 45af482e3832
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
1 #include "gen/llvm.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
2
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
3 #include "mtype.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
4 #include "declaration.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
5
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
6 #include "gen/tollvm.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
7 #include "gen/llvmhelpers.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
8 #include "gen/irstate.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
9 #include "gen/dvalue.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
10 #include "gen/functions.h"
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 950
diff changeset
11 #include "gen/abi.h"
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
12
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
13 #include "gen/logger.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
14
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
15 //////////////////////////////////////////////////////////////////////////////////////////
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
16
435
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
17 TypeFunction* DtoTypeFunction(DValue* fnval)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
18 {
435
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
19 Type* type = fnval->getType()->toBasetype();
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
20 if (type->ty == Tfunction)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
21 {
435
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
22 return (TypeFunction*)type;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
23 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
24 else if (type->ty == Tdelegate)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
25 {
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
26 Type* next = type->nextOf();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
27 assert(next->ty == Tfunction);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
28 return (TypeFunction*)next;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
29 }
435
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
30
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
31 assert(0 && "cant get TypeFunction* from non lazy/function/delegate");
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
32 return 0;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
33 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
34
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
35 //////////////////////////////////////////////////////////////////////////////////////////
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
36
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
37 unsigned DtoCallingConv(Loc loc, LINK l)
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
38 {
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
39 if (l == LINKc || l == LINKcpp || l == LINKintrinsic)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
40 return llvm::CallingConv::C;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
41 else if (l == LINKd || l == LINKdefault)
526
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
42 {
782
29f0e5847123 Don't use StdCall on Windows.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
43 //TODO: StdCall is not a good base on Windows due to extra name mangling
29f0e5847123 Don't use StdCall on Windows.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
44 // applied there
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 787
diff changeset
45 if (global.params.cpu == ARCHx86)
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 787
diff changeset
46 return (global.params.os != OSWindows) ? llvm::CallingConv::X86_StdCall : llvm::CallingConv::C;
526
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
47 else
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
48 return llvm::CallingConv::Fast;
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
49 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 787
diff changeset
50 // on the other hand, here, it's exactly what we want!!! TODO: right?
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
51 else if (l == LINKwindows)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
52 return llvm::CallingConv::X86_StdCall;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
53 else
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
54 {
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
55 error(loc, "unsupported calling convention");
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
56 fatal();
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
57 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
58 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
59
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
60 //////////////////////////////////////////////////////////////////////////////////////////
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
61
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
62 DValue* DtoVaArg(Loc& loc, Type* type, Expression* valistArg)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
63 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
64 DValue* expelem = valistArg->toElem(gIR);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
65 const LLType* llt = DtoType(type);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
66 if (DtoIsPassedByRef(type))
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
67 llt = getPtrToType(llt);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
68 // issue a warning for broken va_arg instruction.
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
69 if (global.params.cpu != ARCHx86)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
70 warning("%s: va_arg for C variadic functions is probably broken for anything but x86", loc.toChars());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
71 // done
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
72 return new DImValue(type, gIR->ir->CreateVAArg(expelem->getLVal(), llt, "tmp"));
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
73 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
74
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
75 //////////////////////////////////////////////////////////////////////////////////////////
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
76
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
77 LLValue* DtoCallableValue(DValue* fn)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
78 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
79 Type* type = fn->getType()->toBasetype();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
80 if (type->ty == Tfunction)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
81 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
82 return fn->getRVal();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
83 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
84 else if (type->ty == Tdelegate)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
85 {
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
86 if (fn->isLVal())
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
87 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
88 LLValue* dg = fn->getLVal();
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
89 LLValue* funcptr = DtoGEPi(dg, 0, 1);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
90 return DtoLoad(funcptr);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
91 }
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
92 else
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
93 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
94 LLValue* dg = fn->getRVal();
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
95 assert(isaStruct(dg));
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
96 return gIR->ir->CreateExtractValue(dg, 1, ".funcptr");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
97 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
98 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
99 else
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
100 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
101 assert(0 && "not a callable type");
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
102 return NULL;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
103 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
104 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
105
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
106 //////////////////////////////////////////////////////////////////////////////////////////
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
107
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
108 const LLFunctionType* DtoExtractFunctionType(const LLType* type)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
109 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
110 if (const LLFunctionType* fty = isaFunction(type))
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
111 return fty;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
112 else if (const LLPointerType* pty = isaPointer(type))
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
113 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
114 if (const LLFunctionType* fty = isaFunction(pty->getElementType()))
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
115 return fty;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
116 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
117 return NULL;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
118 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
119
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
120 //////////////////////////////////////////////////////////////////////////////////////////
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
121
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
122 void DtoBuildDVarArgList(std::vector<LLValue*>& args, std::vector<llvm::AttributeWithIndex>& attrs, TypeFunction* tf, Expressions* arguments, size_t argidx)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
123 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
124 Logger::println("doing d-style variadic arguments");
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
125
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
126 std::vector<const LLType*> vtypes;
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
127
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
128 // number of non variadic args
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
129 int begin = tf->parameters->dim;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
130 Logger::println("num non vararg params = %d", begin);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
131
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
132 // get n args in arguments list
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
133 size_t n_arguments = arguments ? arguments->dim : 0;
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
134
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
135 // build struct with argument types (non variadic args)
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
136 for (int i=begin; i<n_arguments; i++)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
137 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
138 Expression* argexp = (Expression*)arguments->data[i];
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
139 vtypes.push_back(DtoType(argexp->type));
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
140 size_t sz = getTypePaddedSize(vtypes.back());
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
141 if (sz < PTRSIZE)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
142 vtypes.back() = DtoSize_t();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
143 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
144 const LLStructType* vtype = LLStructType::get(vtypes);
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
145
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
146 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
147 Logger::cout() << "d-variadic argument struct type:\n" << *vtype << '\n';
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
148
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 456
diff changeset
149 LLValue* mem = DtoAlloca(vtype,"_argptr_storage");
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
150
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
151 // store arguments in the struct
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
152 for (int i=begin,k=0; i<n_arguments; i++,k++)
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
153 {
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
154 Expression* argexp = (Expression*)arguments->data[i];
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
155 if (global.params.llvmAnnotate)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
156 DtoAnnotation(argexp->toChars());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
157 LLValue* argdst = DtoGEPi(mem,0,k);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
158 argdst = DtoBitCast(argdst, getPtrToType(DtoType(argexp->type)));
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
159 DtoVariadicArgument(argexp, argdst);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
160 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
161
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
162 // build type info array
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
163 const LLType* typeinfotype = DtoType(Type::typeinfo->type);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
164 const LLArrayType* typeinfoarraytype = LLArrayType::get(typeinfotype,vtype->getNumElements());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
165
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
166 llvm::GlobalVariable* typeinfomem =
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
167 new llvm::GlobalVariable(typeinfoarraytype, true, llvm::GlobalValue::InternalLinkage, NULL, "._arguments.storage", gIR->module);
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
168 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
169 Logger::cout() << "_arguments storage: " << *typeinfomem << '\n';
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
170
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
171 std::vector<LLConstant*> vtypeinfos;
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
172 for (int i=begin,k=0; i<n_arguments; i++,k++)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
173 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
174 Expression* argexp = (Expression*)arguments->data[i];
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
175 vtypeinfos.push_back(DtoTypeInfoOf(argexp->type));
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
176 }
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
177
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
178 // apply initializer
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
179 LLConstant* tiinits = llvm::ConstantArray::get(typeinfoarraytype, vtypeinfos);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
180 typeinfomem->setInitializer(tiinits);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
181
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
182 // put data in d-array
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
183 std::vector<LLConstant*> pinits;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
184 pinits.push_back(DtoConstSize_t(vtype->getNumElements()));
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
185 pinits.push_back(llvm::ConstantExpr::getBitCast(typeinfomem, getPtrToType(typeinfotype)));
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
186 const LLType* tiarrty = DtoType(Type::typeinfo->type->arrayOf());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
187 tiinits = llvm::ConstantStruct::get(pinits);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
188 LLValue* typeinfoarrayparam = new llvm::GlobalVariable(tiarrty,
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
189 true, llvm::GlobalValue::InternalLinkage, tiinits, "._arguments.array", gIR->module);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
190
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
191 // specify arguments
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
192 args.push_back(DtoLoad(typeinfoarrayparam));
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
193 ++argidx;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
194 args.push_back(gIR->ir->CreateBitCast(mem, getPtrToType(LLType::Int8Ty), "tmp"));
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
195 ++argidx;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
196
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
197 // pass non variadic args
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
198 for (int i=0; i<begin; i++)
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
199 {
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
200 Argument* fnarg = Argument::getNth(tf->parameters, i);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
201 DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
202 args.push_back(argval->getRVal());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
203
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
204 if (tf->fty->args[i]->attrs)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
205 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
206 llvm::AttributeWithIndex Attr;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
207 Attr.Index = argidx;
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 Attr.Attrs = tf->fty->args[i]->attrs;
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
209 attrs.push_back(Attr);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
210 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
211
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
212 ++argidx;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
213 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
214 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
215
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 // FIXME: this function is a mess !
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
217
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
218 DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* arguments)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
219 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
220 // the callee D type
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
221 Type* calleeType = fnval->getType();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
222
456
b975f29b7256 Make sure DtoType has been run on the DType before assembling a call.
Christian Kamm <kamm incasoftware de>
parents: 454
diff changeset
223 // if the type has not yet been processed, do so now
b975f29b7256 Make sure DtoType has been run on the DType before assembling a call.
Christian Kamm <kamm incasoftware de>
parents: 454
diff changeset
224 if (calleeType->ir.type == NULL)
b975f29b7256 Make sure DtoType has been run on the DType before assembling a call.
Christian Kamm <kamm incasoftware de>
parents: 454
diff changeset
225 DtoType(calleeType);
b975f29b7256 Make sure DtoType has been run on the DType before assembling a call.
Christian Kamm <kamm incasoftware de>
parents: 454
diff changeset
226
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
227 // get func value if any
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
228 DFuncValue* dfnval = fnval->isFunc();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
229
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
230 // handle special vararg intrinsics
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
231 bool va_intrinsic = (dfnval && dfnval->func && dfnval->func->isVaIntrinsic());
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
232
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
233 // get function type info
435
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
234 TypeFunction* tf = DtoTypeFunction(fnval);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
235
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
236 // misc
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
237 bool retinptr = tf->fty->arg_sret;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
238 bool thiscall = tf->fty->arg_this;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
239 bool delegatecall = (calleeType->toBasetype()->ty == Tdelegate);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
240 bool nestedcall = tf->fty->arg_nest;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
241 bool dvarargs = (tf->linkage == LINKd && tf->varargs == 1);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
242
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
243 unsigned callconv = DtoCallingConv(loc, tf->linkage);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
244
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
245 // get callee llvm value
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
246 LLValue* callable = DtoCallableValue(fnval);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
247 const LLFunctionType* callableTy = DtoExtractFunctionType(callable->getType());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
248 assert(callableTy);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
249
839
162a0502a6b9 Fixed another moreatatime (as opposed to oneatatime) issue with indexing unresolved class.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 805
diff changeset
250 // if (Logger::enabled())
162a0502a6b9 Fixed another moreatatime (as opposed to oneatatime) issue with indexing unresolved class.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 805
diff changeset
251 // Logger::cout() << "callable: " << *callable << '\n';
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
252
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
253 // get n arguments
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
254 size_t n_arguments = arguments ? arguments->dim : 0;
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
255
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
256 // get llvm argument iterator, for types
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
257 LLFunctionType::param_iterator argbegin = callableTy->param_begin();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
258 LLFunctionType::param_iterator argiter = argbegin;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
259
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
260 // parameter attributes
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
261 std::vector<llvm::AttributeWithIndex> attrs;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
262 llvm::AttributeWithIndex Attr;
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
263
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
264 // return attrs
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
265 if (tf->fty->ret->attrs)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
266 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
267 Attr.Index = 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
268 Attr.Attrs = tf->fty->ret->attrs;
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
269 attrs.push_back(Attr);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
270 }
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
271
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
272 // handle implicit arguments
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
273 std::vector<LLValue*> args;
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
274 args.reserve(tf->fty->args.size());
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
275
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
276 // return in hidden ptr is first
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
277 if (retinptr)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
278 {
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 456
diff changeset
279 LLValue* retvar = DtoAlloca(argiter->get()->getContainedType(0), ".rettmp");
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
280 ++argiter;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
281 args.push_back(retvar);
720
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
282
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
283 // add attrs for hidden ptr
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
284 Attr.Index = 1;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
285 Attr.Attrs = llvm::Attribute::StructRet;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
286 attrs.push_back(Attr);
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
287 }
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
288
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
289 // then comes a context argument...
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
290 if(thiscall || delegatecall || nestedcall)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
291 {
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
292 // ... which can be a 'this' argument
488
993b217af574 Error if there is no this in a call requiring this.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
293 if (thiscall && dfnval && dfnval->vthis)
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
294 {
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
295 LLValue* thisarg = DtoBitCast(dfnval->vthis, argiter->get());
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
296 ++argiter;
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
297 args.push_back(thisarg);
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
298 }
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
299 // ... or a delegate context arg
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
300 else if (delegatecall)
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
301 {
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
302 LLValue* ctxarg;
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
303 if (fnval->isLVal())
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
304 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
305 ctxarg = DtoLoad(DtoGEPi(fnval->getLVal(), 0,0));
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
306 }
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
307 else
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
308 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
309 ctxarg = gIR->ir->CreateExtractValue(fnval->getRVal(), 0, ".ptr");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
310 }
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
311 assert(ctxarg->getType() == argiter->get());
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
312 ++argiter;
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
313 args.push_back(ctxarg);
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
314 }
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
315 // ... or a nested function context arg
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
316 else if (nestedcall)
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
317 {
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
318 LLValue* contextptr = DtoNestedContext(loc, dfnval->func);
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
319 contextptr = DtoBitCast(contextptr, getVoidPtrType());
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
320 ++argiter;
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
321 args.push_back(contextptr);
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
322 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
323 else
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
324 {
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
325 error(loc, "Context argument required but none given");
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
326 fatal();
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
327 }
720
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
328
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
329 // add attributes for context argument
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
330 if (tf->fty->arg_this && tf->fty->arg_this->attrs)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
331 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
332 Attr.Index = retinptr ? 2 : 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
333 Attr.Attrs = tf->fty->arg_this->attrs;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
334 attrs.push_back(Attr);
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
335 }
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
336 else if (tf->fty->arg_nest && tf->fty->arg_nest->attrs)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
337 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
338 Attr.Index = retinptr ? 2 : 1;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
339 Attr.Attrs = tf->fty->arg_nest->attrs;
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
340 attrs.push_back(Attr);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
341 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
342 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
343
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
344 // handle the rest of the arguments based on param passing style
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
345
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
346 // variadic instrinsics need some custom casts
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
347 if (va_intrinsic)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
348 {
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
349 for (int i=0; i<n_arguments; i++)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
350 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
351 Expression* exp = (Expression*)arguments->data[i];
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
352 DValue* expelem = exp->toElem(gIR);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
353 // cast to va_list*
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
354 LLValue* val = DtoBitCast(expelem->getLVal(), getVoidPtrType());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
355 ++argiter;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
356 args.push_back(val);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
357 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
358 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
359
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
360 // d style varargs needs a few more hidden arguments as well as special passing
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
361 else if (dvarargs)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
362 {
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
363 DtoBuildDVarArgList(args, attrs, tf, arguments, argiter-argbegin+1);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
364 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
365
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
366 // otherwise we're looking at a normal function call
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
367 // or a C style vararg call
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
368 else
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
369 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
370 Logger::println("doing normal arguments");
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
371
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
372 size_t n = Argument::dim(tf->parameters);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
373
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
374 LLSmallVector<unsigned, 10> attrptr(n, 0);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
375
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
376 // do formal params
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
377 int beg = argiter-argbegin;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
378 for (int i=0; i<n; i++)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
379 {
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
380 Argument* fnarg = Argument::getNth(tf->parameters, i);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
381 assert(fnarg);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
382 DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
383 LLValue* arg = argval->getRVal();
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
384
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
385 int j = tf->fty->reverseParams ? beg + n - i - 1 : beg + i;
938
a904cc9bc064 Convert struct arg to integer when passing inreg to make sure LLVM doesn't
Christian Kamm <kamm incasoftware de>
parents: 930
diff changeset
386
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
387 // give the ABI a say
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
388 arg = tf->fty->putParam(argval->getType(), i, arg);
930
7985bb036db4 Follow the D ABI and pass the last arg in a register if it is a struct that fits.
Christian Kamm <kamm incasoftware de>
parents: 839
diff changeset
389
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
390 // parameter type mismatch, this is hard to get rid of
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
391 if (arg->getType() != callableTy->getParamType(j))
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
392 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
393 #if 1
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
394 if (Logger::enabled())
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
395 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
396 Logger::cout() << "arg: " << *arg << '\n';
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
397 Logger::cout() << "expects: " << *callableTy->getParamType(j) << '\n';
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
398 }
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
399 #endif
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
400 arg = DtoBitCast(arg, callableTy->getParamType(j));
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
401 }
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
402
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
403 // param attrs
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
404 attrptr[i] = tf->fty->args[i]->attrs;
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
405
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
406 ++argiter;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
407 args.push_back(arg);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
408 }
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
409
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
410 // reverse the relevant params as well as the param attrs
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
411 if (tf->fty->reverseParams)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
412 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
413 std::reverse(args.begin() + beg, args.end());
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
414 std::reverse(attrptr.begin(), attrptr.end());
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
415 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
416
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
417 // add attributes
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
418 for (int i = 0; i < n; i++)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
419 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
420 if (attrptr[i])
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
421 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
422 Attr.Index = beg + i + 1;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
423 Attr.Attrs = attrptr[i];
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
424 attrs.push_back(Attr);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
425 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
426 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
427
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
428 // do C varargs
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
429 if (n_arguments > n)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
430 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
431 for (int i=n; i<n_arguments; i++)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
432 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
433 Argument* fnarg = Argument::getNth(tf->parameters, i);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
434 DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
435 LLValue* arg = argval->getRVal();
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
436
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
437 // FIXME: do we need any param attrs here ?
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
438
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
439 ++argiter;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
440 args.push_back(arg);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
441 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
442 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
443 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
444
1030
3ead5c40b7d6 Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
445 #if 0
805
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
446 if (Logger::enabled())
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
447 {
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
448 Logger::println("%lu params passed", args.size());
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
449 for (int i=0; i<args.size(); ++i) {
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
450 assert(args[i]);
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
451 Logger::cout() << "arg["<<i<<"] = " << *args[i] << '\n';
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
452 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
453 }
1030
3ead5c40b7d6 Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
454 #endif
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
455
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
456 // void returns cannot not be named
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
457 const char* varname = "";
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
458 if (callableTy->getReturnType() != LLType::VoidTy)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
459 varname = "tmp";
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
460
1030
3ead5c40b7d6 Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
461 #if 0
805
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
462 if (Logger::enabled())
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
463 Logger::cout() << "Calling: " << *callable << '\n';
1030
3ead5c40b7d6 Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
464 #endif
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
465
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
466 // call the function
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1001
diff changeset
467 LLCallSite call = gIR->CreateCallOrInvoke(callable, args.begin(), args.end(), varname);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
468
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
469 // get return value
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1001
diff changeset
470 LLValue* retllval = (retinptr) ? args[0] : call.getInstruction();
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
471
1001
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
472 if (tf->linkage == LINKintrinsic)
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
473 {
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
474 // Ignore ABI for intrinsics
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
475 Type* rettype = tf->next;
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
476 if (rettype->ty == Tstruct) {
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
477 // LDC assumes structs are in memory, so put it there.
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
478 LLValue* mem = DtoAlloca(retllval->getType());
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
479 DtoStore(retllval, mem);
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
480 retllval = mem;
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
481 }
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
482 }
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
483 else if (!retinptr)
1001
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
484 {
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
485 // do abi specific return value fixups
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
486 retllval = tf->fty->getRet(tf->next, retllval);
1001
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
487 }
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
488
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
489 // repaint the type if necessary
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
490 if (resulttype)
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
491 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
492 Type* rbase = resulttype->toBasetype();
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
493 Type* nextbase = tf->nextOf()->toBasetype();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
494 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
495 rbase = rbase->mutableOf();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
496 nextbase = nextbase->mutableOf();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
497 #endif
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
498 if (!rbase->equals(nextbase))
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
499 {
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
500 Logger::println("repainting return value from '%s' to '%s'", tf->nextOf()->toChars(), rbase->toChars());
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
501 switch(rbase->ty)
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
502 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
503 case Tarray:
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
504 retllval = DtoAggrPaint(retllval, DtoType(rbase));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
505 break;
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
506
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
507 case Tclass:
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
508 case Taarray:
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
509 case Tpointer:
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
510 retllval = DtoBitCast(retllval, DtoType(rbase));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
511 break;
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
512
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
513 default:
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
514 assert(0 && "unhandled repainting of return value");
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
515 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
516 if (Logger::enabled())
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
517 Logger::cout() << "final return value: " << *retllval << '\n';
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
518 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
519 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
520
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
521 // set calling convention and parameter attributes
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
522 llvm::AttrListPtr attrlist = llvm::AttrListPtr::get(attrs.begin(), attrs.end());
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
523 if (dfnval && dfnval->func)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
524 {
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
525 LLFunction* llfunc = llvm::dyn_cast<LLFunction>(dfnval->val);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
526 if (llfunc && llfunc->isIntrinsic()) // override intrinsic attrs
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
527 attrlist = llvm::Intrinsic::getAttributes((llvm::Intrinsic::ID)llfunc->getIntrinsicID());
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
528 else
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1001
diff changeset
529 call.setCallingConv(callconv);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
530 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
531 else
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1001
diff changeset
532 call.setCallingConv(callconv);
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1001
diff changeset
533 call.setAttributes(attrlist);
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
534
1018
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
535 // if we are returning through a pointer arg
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
536 // make sure we provide a lvalue back!
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
537 if (retinptr)
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
538 return new DVarValue(resulttype, retllval);
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
539
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
540 return new DImValue(resulttype, retllval);
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
541 }