annotate gen/functions.cpp @ 1651:cb960b882ca3 default tip

bindings were moved to dsource.org/projects/bindings/
author Moritz Warning <moritzwarning@web.de>
date Thu, 20 May 2010 20:05:03 +0200
parents 40bd4a0d4870
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1 #include "gen/llvm.h"
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 258
diff changeset
2 #include "llvm/Support/CFG.h"
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
3 #include "llvm/Intrinsics.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
4
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
5 #include "mtype.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
6 #include "aggregate.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
7 #include "init.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
8 #include "declaration.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
9 #include "template.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
10 #include "module.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
11 #include "statement.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
12
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
13 #include "gen/irstate.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
14 #include "gen/tollvm.h"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
15 #include "gen/llvmhelpers.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
16 #include "gen/runtime.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
17 #include "gen/arrays.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
18 #include "gen/logger.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
19 #include "gen/functions.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
20 #include "gen/todebug.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
21 #include "gen/classes.h"
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
22 #include "gen/dvalue.h"
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 958
diff changeset
23 #include "gen/abi.h"
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents: 1162
diff changeset
24 #include "gen/nested.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
25
1117
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1072
diff changeset
26 using namespace llvm::Attribute;
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1072
diff changeset
27
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
28 const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
29 {
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
30 if (Logger::enabled())
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
31 Logger::println("DtoFunctionType(%s)", type->toChars());
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
32 LOG_SCOPE
1364
46f6365a50d7 Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1359
diff changeset
33
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
34 // sanity check
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: 428
diff changeset
35 assert(type->ty == Tfunction);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
36 TypeFunction* f = (TypeFunction*)type;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
37
1359
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
38 TargetABI* abi = (f->linkage == LINKintrinsic ? TargetABI::getIntrinsic() : gABI);
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
39 // Tell the ABI we're resolving a new function type
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
40 abi->newFunctionType(f);
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
41
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
42 // Do not modify f->fty yet; this function may be called recursively if any
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
43 // of the argument types refer to this type.
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
44 IrFuncTy fty;
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
45
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
46 // llvm idx counter
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
47 size_t lidx = 0;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
48
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
49 // main needs a little special handling
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
50 if (ismain)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
51 {
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
52 fty.ret = new IrFuncTyArg(Type::tint32, false);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
53 }
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
54 // sane return value
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
55 else
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
56 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
57 Type* rt = f->next;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
58 unsigned a = 0;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
59 // sret return
1359
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
60 if (abi->returnInArg(f))
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
61 {
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
62 fty.arg_sret = new IrFuncTyArg(rt, true, StructRet | NoAlias | NoCapture);
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
63 rt = Type::tvoid;
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
64 lidx++;
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
65 }
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
66 // sext/zext return
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
67 else if (unsigned se = DtoShouldExtend(rt))
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
68 {
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
69 a = se;
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
70 }
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
71 fty.ret = new IrFuncTyArg(rt, false, a);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
72 }
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
73 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
74
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
75 // member functions
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
76 if (thistype)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
77 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
78 bool toref = (thistype->toBasetype()->ty == Tstruct);
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
79 fty.arg_this = new IrFuncTyArg(thistype, toref);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
80 lidx++;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
81 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
82
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
83 // and nested functions
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
84 else if (nesttype)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
85 {
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
86 fty.arg_nest = new IrFuncTyArg(nesttype, false);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
87 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
88 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
89
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
90 // vararg functions are special too
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
91 if (f->varargs)
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
92 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
93 if (f->linkage == LINKd)
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
94 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
95 // d style with hidden args
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
96 // 2 (array) is handled by the frontend
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
97 if (f->varargs == 1)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
98 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
99 // _arguments
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
100 fty.arg_arguments = new IrFuncTyArg(Type::typeinfo->type->arrayOf(), false);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
101 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
102 // _argptr
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
103 fty.arg_argptr = new IrFuncTyArg(Type::tvoid->pointerTo(), false, NoAlias | NoCapture);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
104 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
105 }
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
106 }
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
107 else if (f->linkage == LINKc)
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 958
diff changeset
108 {
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
109 fty.c_vararg = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
110 }
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 958
diff changeset
111 else
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 958
diff changeset
112 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
113 type->error(0, "invalid linkage for variadic function");
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
114 fatal();
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
115 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
116 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
117
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
118 // if this _Dmain() doesn't have an argument, we force it to have one
1607
207a8a438dea Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents: 1571
diff changeset
119 int nargs = Parameter::dim(f->parameters);
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: 920
diff changeset
120
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
121 if (ismain && nargs == 0)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
122 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
123 Type* mainargs = Type::tchar->arrayOf()->arrayOf();
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
124 fty.args.push_back(new IrFuncTyArg(mainargs, false));
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
125 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
126 }
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
127 // add explicit parameters
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
128 else for (int i = 0; i < nargs; 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
129 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
130 // get argument
1607
207a8a438dea Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents: 1571
diff changeset
131 Parameter* arg = Parameter::getNth(f->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
132
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
133 // reference semantics? ref, out and static arrays are
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
134 bool byref = (arg->storageClass & (STCref|STCout)) || (arg->type->toBasetype()->ty == Tsarray);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
135
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
136 Type* argtype = arg->type;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
137 unsigned a = 0;
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 546
diff changeset
138
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
139 // handle lazy args
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
140 if (arg->storageClass & STClazy)
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
141 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
142 Logger::println("lazy param");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
143 TypeFunction *ltf = new TypeFunction(NULL, arg->type, 0, LINKd);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
144 TypeDelegate *ltd = new TypeDelegate(ltf);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
145 argtype = ltd;
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
146 }
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
147 // byval
1407
9a049fd1a014 Let TargetABI::passByValue() know when a parameter is byref (either explicitly
Frits van Bommel <fvbommel wxs.nl>
parents: 1364
diff changeset
148 else if (abi->passByVal(byref ? argtype->pointerTo() : argtype))
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
149 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
150 if (!byref) a |= llvm::Attribute::ByVal;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
151 byref = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
152 }
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
153 // sext/zext
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
154 else if (!byref)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
155 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
156 a |= DtoShouldExtend(argtype);
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
157 }
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
158
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
159 fty.args.push_back(new IrFuncTyArg(argtype, byref, a));
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
160 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
161 }
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
162
1226
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
163 // Now we can modify f->fty safely.
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
164 f->fty = fty;
00f377e03423 Fix a problem which occurred when a function type was forward-referenced by
Frits van Bommel <fvbommel wxs.nl>
parents: 1217
diff changeset
165
1359
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
166 // let the abi rewrite the types as necesary
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
167 abi->rewriteFunctionType(f);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
168
1359
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
169 // Tell the ABI we're done with this function type
34f2fd925de3 Intrinsics shouldn't see struct padding, so use a special TargetABI for them
Frits van Bommel <fvbommel wxs.nl>
parents: 1350
diff changeset
170 abi->doneWithFunctionType();
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
171
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
172 // build the function type
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
173 std::vector<const LLType*> argtypes;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
174 argtypes.reserve(lidx);
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
175
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
176 if (f->fty.arg_sret) argtypes.push_back(f->fty.arg_sret->ltype);
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
177 if (f->fty.arg_this) argtypes.push_back(f->fty.arg_this->ltype);
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
178 if (f->fty.arg_nest) argtypes.push_back(f->fty.arg_nest->ltype);
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
179 if (f->fty.arg_arguments) argtypes.push_back(f->fty.arg_arguments->ltype);
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
180 if (f->fty.arg_argptr) argtypes.push_back(f->fty.arg_argptr->ltype);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
181
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
182 size_t beg = argtypes.size();
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
183 size_t nargs2 = f->fty.args.size();
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
184 for (size_t i = 0; i < nargs2; i++)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
185 {
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
186 argtypes.push_back(f->fty.args[i]->ltype);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
187 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
188
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
189 // reverse params?
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
190 if (f->fty.reverseParams && nargs2 > 1)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
191 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
192 std::reverse(argtypes.begin() + beg, argtypes.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
193 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
194
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
195 llvm::FunctionType* functype = llvm::FunctionType::get(f->fty.ret->ltype, argtypes, f->fty.c_vararg);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
196
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
197 Logger::cout() << "Final function type: " << *functype << "\n";
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
198
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
199 return functype;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
200 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
201
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
202 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
203
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
204 static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
205 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
206 TypeFunction* f = (TypeFunction*)fdecl->type;
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
207 const llvm::FunctionType* fty = 0;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
208
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
209 // create new ir funcTy
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
210 f->fty.reset();
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
211 f->fty.ret = new IrFuncTyArg(Type::tvoid, false);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
212
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
213 f->fty.args.push_back(new IrFuncTyArg(Type::tvoid->pointerTo(), false));
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
214
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
215 if (fdecl->llvmInternal == LLVMva_start)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
216 fty = GET_INTRINSIC_DECL(vastart)->getFunctionType();
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
217 else if (fdecl->llvmInternal == LLVMva_copy) {
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
218 fty = GET_INTRINSIC_DECL(vacopy)->getFunctionType();
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
219 f->fty.args.push_back(new IrFuncTyArg(Type::tvoid->pointerTo(), false));
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
220 }
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
221 else if (fdecl->llvmInternal == LLVMva_end)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
222 fty = GET_INTRINSIC_DECL(vaend)->getFunctionType();
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
223 assert(fty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
224
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
225 return fty;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
226 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
227
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
228 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
229
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
230 const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
231 {
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
232 // handle for C vararg intrinsics
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
233 if (fdecl->isVaIntrinsic())
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
234 return DtoVaFunctionType(fdecl);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
235
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
236 Type *dthis=0, *dnest=0;
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
237
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
238 if (fdecl->needThis()) {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
239 if (AggregateDeclaration* ad = fdecl->isMember2()) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
240 Logger::println("isMember = this is: %s", ad->type->toChars());
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
241 dthis = ad->type;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
242 const LLType* thisty = DtoType(dthis);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
243 //Logger::cout() << "this llvm type: " << *thisty << '\n';
1364
46f6365a50d7 Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1359
diff changeset
244 if (ad->isStructDeclaration())
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
245 thisty = getPtrToType(thisty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
246 }
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
247 else {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
248 Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind());
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
249 assert(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
250 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
251 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
252 else if (fdecl->isNested()) {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
253 dnest = Type::tvoid->pointerTo();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
254 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
255
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
256 const llvm::FunctionType* functype = DtoFunctionType(fdecl->type, dthis, dnest, fdecl->isMain());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
257
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
258 return functype;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
259 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
260
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
261 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
262
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
263 static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
264 {
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
265 TypeFunction* f = (TypeFunction*)fdecl->type->toBasetype();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
266 const llvm::FunctionType* fty = DtoVaFunctionType(fdecl);
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
267 llvm::Function* func = 0;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
268
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
269 if (fdecl->llvmInternal == LLVMva_start)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
270 func = GET_INTRINSIC_DECL(vastart);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
271 else if (fdecl->llvmInternal == LLVMva_copy)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
272 func = GET_INTRINSIC_DECL(vacopy);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
273 else if (fdecl->llvmInternal == LLVMva_end)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
274 func = GET_INTRINSIC_DECL(vaend);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
275 assert(func);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
276
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
277 fdecl->ir.irFunc->func = func;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
278 return func;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
279 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
280
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
281 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
282
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
283 void DtoResolveFunction(FuncDeclaration* fdecl)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
284 {
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
285 if (!global.params.useUnitTests && fdecl->isUnitTestDeclaration()) {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
286 Logger::println("Ignoring unittest %s", fdecl->toPrettyChars());
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
287 return; // ignore declaration completely
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
288 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
289
1364
46f6365a50d7 Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1359
diff changeset
290 if (fdecl->ir.resolved) return;
46f6365a50d7 Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1359
diff changeset
291 fdecl->ir.resolved = true;
46f6365a50d7 Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1359
diff changeset
292
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
293 //printf("resolve function: %s\n", fdecl->toPrettyChars());
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
294
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
295 if (fdecl->parent)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
296 if (TemplateInstance* tinst = fdecl->parent->isTemplateInstance())
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
297 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
298 TemplateDeclaration* tempdecl = tinst->tempdecl;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
299 if (tempdecl->llvmInternal == LLVMva_arg)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
300 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
301 Logger::println("magic va_arg found");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
302 fdecl->llvmInternal = LLVMva_arg;
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
303 fdecl->ir.resolved = true;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
304 fdecl->ir.declared = true;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
305 fdecl->ir.initialized = true;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
306 fdecl->ir.defined = true;
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
307 return; // this gets mapped to an instruction so a declaration makes no sence
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
308 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
309 else if (tempdecl->llvmInternal == LLVMva_start)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
310 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
311 Logger::println("magic va_start found");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
312 fdecl->llvmInternal = LLVMva_start;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
313 }
527
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
314 else if (tempdecl->llvmInternal == LLVMintrinsic)
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
315 {
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
316 Logger::println("overloaded intrinsic found");
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
317 fdecl->llvmInternal = LLVMintrinsic;
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
318 DtoOverloadedIntrinsicName(tinst, tempdecl, fdecl->intrinsicName);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
319 fdecl->linkage = LINKintrinsic;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
320 ((TypeFunction*)fdecl->type)->linkage = LINKintrinsic;
527
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
321 }
1152
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
322 else if (tempdecl->llvmInternal == LLVMinline_asm)
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
323 {
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
324 Logger::println("magic inline asm found");
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
325 TypeFunction* tf = (TypeFunction*)fdecl->type;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
326 if (tf->varargs != 1 || (fdecl->parameters && fdecl->parameters->dim != 0))
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
327 {
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
328 error("invalid __asm declaration, must be a D style variadic with no explicit parameters");
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
329 fatal();
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
330 }
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
331 fdecl->llvmInternal = LLVMinline_asm;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
332 fdecl->ir.resolved = true;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
333 fdecl->ir.declared = true;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
334 fdecl->ir.initialized = true;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
335 fdecl->ir.defined = true;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
336 return; // this gets mapped to a special inline asm call, no point in going on.
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
337 }
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
338 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
339
1364
46f6365a50d7 Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1359
diff changeset
340 DtoType(fdecl->type);
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
341
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
342 Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
343 LOG_SCOPE;
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
344
1261
854e86eaa022 Revert change to treat bodyless functions in abstract classes as abstract.
Christian Kamm <kamm incasoftware de>
parents: 1251
diff changeset
345 // queue declaration unless the function is abstract without body
854e86eaa022 Revert change to treat bodyless functions in abstract classes as abstract.
Christian Kamm <kamm incasoftware de>
parents: 1251
diff changeset
346 if (!fdecl->isAbstract() || fdecl->fbody)
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
347 {
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
348 DtoDeclareFunction(fdecl);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
349 }
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
350 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
351
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
352 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
353
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
354 static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl)
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
355 {
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
356 int funcNumArgs = func->getArgumentList().size();
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
357
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
358 LLSmallVector<llvm::AttributeWithIndex, 9> attrs;
632
df196c8dea26 Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 622
diff changeset
359 llvm::AttributeWithIndex PAWI;
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
360
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
361 int idx = 0;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
362
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
363 // handle implicit args
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
364 #define ADD_PA(X) \
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
365 if (f->fty.X) { \
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
366 if (f->fty.X->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
367 PAWI.Index = idx; \
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
368 PAWI.Attrs = f->fty.X->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
369 attrs.push_back(PAWI); \
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
370 } \
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
371 idx++; \
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
372 }
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
373
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
374 ADD_PA(ret)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
375 ADD_PA(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
376 ADD_PA(arg_this)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
377 ADD_PA(arg_nest)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
378 ADD_PA(arg_arguments)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
379 ADD_PA(arg_argptr)
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
380
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
381 #undef ADD_PA
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
382
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
383 // set attrs on the rest of the arguments
1607
207a8a438dea Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents: 1571
diff changeset
384 size_t n = Parameter::dim(f->parameters);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
385 LLSmallVector<unsigned,8> 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
386
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
387 for (size_t k = 0; k < n; ++k)
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
388 {
1607
207a8a438dea Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents: 1571
diff changeset
389 Parameter* fnarg = Parameter::getNth(f->parameters, k);
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
390 assert(fnarg);
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
391
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
392 attrptr[k] = f->fty.args[k]->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
393 }
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
394
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
395 // reverse params?
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
396 if (f->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
397 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
398 std::reverse(attrptr.begin(), attrptr.end());
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
399 }
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
400
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
401 // build rest of attrs list
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
402 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
403 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
404 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
405 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
406 PAWI.Index = idx+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
407 PAWI.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
408 attrs.push_back(PAWI);
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 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
411
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
412 llvm::AttrListPtr attrlist = llvm::AttrListPtr::get(attrs.begin(), attrs.end());
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
413 func->setAttributes(attrlist);
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
414 }
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
415
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
416 //////////////////////////////////////////////////////////////////////////////////////////
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
417
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
418 void DtoDeclareFunction(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
419 {
1155
ba9d6292572a Fixed forward reference problem in struct methods on x86-64.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1152
diff changeset
420 DtoResolveFunction(fdecl);
ba9d6292572a Fixed forward reference problem in struct methods on x86-64.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1152
diff changeset
421
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
422 if (fdecl->ir.declared) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
423 fdecl->ir.declared = true;
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
424
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
425 Logger::println("DtoDeclareFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
426 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
427
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
428 //printf("declare function: %s\n", fdecl->toPrettyChars());
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
429
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
430 // intrinsic sanity check
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
431 if (fdecl->llvmInternal == LLVMintrinsic && fdecl->fbody) {
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
432 error(fdecl->loc, "intrinsics cannot have function bodies");
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
433 fatal();
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
434 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
435
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
436 // get TypeFunction*
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
437 Type* t = fdecl->type->toBasetype();
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
438 TypeFunction* f = (TypeFunction*)t;
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
439
940
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
440 bool declareOnly = !mustDefineSymbol(fdecl);
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
441
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
442 if (fdecl->llvmInternal == LLVMva_start)
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
443 declareOnly = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
444
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
445 if (!fdecl->ir.irFunc) {
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
446 fdecl->ir.irFunc = new IrFunction(fdecl);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
447 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
448
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
449 // mangled name
443
44f08170f4ef Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
450 const char* mangled_name;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
451 if (fdecl->llvmInternal == LLVMintrinsic)
443
44f08170f4ef Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
452 mangled_name = fdecl->intrinsicName.c_str();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
453 else
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
454 mangled_name = fdecl->mangle();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
455
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
456 llvm::Function* vafunc = 0;
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
457 if (fdecl->isVaIntrinsic())
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
458 vafunc = DtoDeclareVaFunction(fdecl);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
459
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
460 // construct function
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
461 const llvm::FunctionType* functype = DtoFunctionType(fdecl);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
462 llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
463 if (!func)
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 173
diff changeset
464 func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
465
1155
ba9d6292572a Fixed forward reference problem in struct methods on x86-64.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1152
diff changeset
466 if (Logger::enabled())
ba9d6292572a Fixed forward reference problem in struct methods on x86-64.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1152
diff changeset
467 Logger::cout() << "func = " << *func << std::endl;
ba9d6292572a Fixed forward reference problem in struct methods on x86-64.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1152
diff changeset
468
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
469 // add func to IRFunc
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
470 fdecl->ir.irFunc->func = func;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
471
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
472 // calling convention
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
473 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic)
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
474 func->setCallingConv(DtoCallingConv(fdecl->loc, f->linkage));
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
475 else // fall back to C, it should be the right thing to do
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
476 func->setCallingConv(llvm::CallingConv::C);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
477
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
478 fdecl->ir.irFunc->func = func;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
479
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
480 // parameter attributes
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
481 if (!fdecl->isIntrinsic()) {
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
482 set_param_attrs(f, func, fdecl);
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
483 }
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
484
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
485 // main
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
486 if (fdecl->isMain()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
487 gIR->mainFunc = func;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
488 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
489
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
490 // static ctor
934
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
491 if (fdecl->isStaticCtorDeclaration()) {
958
89729c76b8ff Static ctors/dtors added via template mixins should not be added to modules
Christian Kamm <kamm incasoftware de>
parents: 947
diff changeset
492 if (mustDefineSymbol(fdecl)) {
934
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
493 gIR->ctors.push_back(fdecl);
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
494 }
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
495 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
496 // static dtor
934
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
497 else if (fdecl->isStaticDtorDeclaration()) {
958
89729c76b8ff Static ctors/dtors added via template mixins should not be added to modules
Christian Kamm <kamm incasoftware de>
parents: 947
diff changeset
498 if (mustDefineSymbol(fdecl)) {
934
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
499 gIR->dtors.push_back(fdecl);
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
500 }
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
501 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
502
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
503 // we never reference parameters of function prototypes
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
504 std::string str;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
505 if (!declareOnly)
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
506 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
507 // name parameters
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
508 llvm::Function::arg_iterator iarg = func->arg_begin();
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
509
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
510 if (f->fty.arg_sret) {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
511 iarg->setName(".sret_arg");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
512 fdecl->ir.irFunc->retArg = iarg;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
513 ++iarg;
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
514 }
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
515
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
516 if (f->fty.arg_this) {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
517 iarg->setName(".this_arg");
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
518 fdecl->ir.irFunc->thisArg = iarg;
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
519 assert(fdecl->ir.irFunc->thisArg);
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
520 ++iarg;
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
521 }
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
522 else if (f->fty.arg_nest) {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
523 iarg->setName(".nest_arg");
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
524 fdecl->ir.irFunc->nestArg = iarg;
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
525 assert(fdecl->ir.irFunc->nestArg);
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
526 ++iarg;
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
527 }
119
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 117
diff changeset
528
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
529 if (f->fty.arg_argptr) {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
530 iarg->setName("._arguments");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
531 fdecl->ir.irFunc->_arguments = iarg;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
532 ++iarg;
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
533 iarg->setName("._argptr");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
534 fdecl->ir.irFunc->_argptr = iarg;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
535 ++iarg;
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
536 }
119
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 117
diff changeset
537
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
538 int k = 0;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
539
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
540 for (; iarg != func->arg_end(); ++iarg)
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
541 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
542 if (fdecl->parameters && fdecl->parameters->dim > k)
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
543 {
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
544 Dsymbol* argsym;
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
545 if (f->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
546 argsym = (Dsymbol*)fdecl->parameters->data[fdecl->parameters->dim-k-1];
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
547 else
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
548 argsym = (Dsymbol*)fdecl->parameters->data[k];
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
549
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
550 VarDeclaration* argvd = argsym->isVarDeclaration();
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
551 assert(argvd);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
552 assert(!argvd->ir.irLocal);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
553 argvd->ir.irLocal = new IrLocal(argvd);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
554 argvd->ir.irLocal->value = iarg;
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
555
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
556 str = argvd->ident->toChars();
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
557 str.append("_arg");
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
558 iarg->setName(str);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
559
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
560 k++;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
561 }
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
562 else
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
563 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
564 iarg->setName("unnamed");
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
565 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
566 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
567 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
568
830
504a21e81a46 Only run unittests contained directly in the module.
Christian Kamm <kamm incasoftware de>
parents: 797
diff changeset
569 if (fdecl->isUnitTestDeclaration() && !declareOnly)
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
570 gIR->unitTests.push_back(fdecl);
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
571
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
572 if (!declareOnly)
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
573 Type::sir->addFunctionBody(fdecl->ir.irFunc);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
574 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
575 assert(func->getLinkage() != llvm::GlobalValue::InternalLinkage);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
576 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
577
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
578 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
579
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
580 // FIXME: this isn't too pretty!
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
581
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
582 void DtoDefineFunction(FuncDeclaration* fd)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
583 {
1155
ba9d6292572a Fixed forward reference problem in struct methods on x86-64.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1152
diff changeset
584 DtoDeclareFunction(fd);
ba9d6292572a Fixed forward reference problem in struct methods on x86-64.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1152
diff changeset
585
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
586 if (fd->ir.defined) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
587 fd->ir.defined = true;
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
588
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
589 assert(fd->ir.declared);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
590
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
591 if (Logger::enabled())
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
592 Logger::println("DtoDefineFunc(%s): %s", fd->toPrettyChars(), fd->loc.toChars());
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
593 LOG_SCOPE;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
594
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
595 // if this function is naked, we take over right away! no standard processing!
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
596 if (fd->naked)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
597 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
598 DtoDefineNakedFunction(fd);
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
599 return;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
600 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
601
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
602 #ifndef DISABLE_DEBUG_INFO
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
603 // debug info
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
604 if (global.params.symdebug)
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
605 fd->ir.irFunc->diSubprogram = DtoDwarfSubProgram(fd);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
606 #endif
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
607
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
608 Type* t = fd->type->toBasetype();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
609 TypeFunction* f = (TypeFunction*)t;
1364
46f6365a50d7 Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1359
diff changeset
610 assert(f->irtype);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
611
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
612 llvm::Function* func = fd->ir.irFunc->func;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
613 const llvm::FunctionType* functype = func->getFunctionType();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
614
940
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
615 // sanity check
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
616 assert(mustDefineSymbol(fd));
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
617
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
618 // set module owner
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
619 fd->ir.DModule = gIR->dmodule;
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 173
diff changeset
620
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
621 // is there a body?
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
622 if (fd->fbody == NULL)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
623 return;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
624
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
625 Logger::println("Doing function body for: %s", fd->toChars());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
626 assert(fd->ir.irFunc);
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
627 IrFunction* irfunction = fd->ir.irFunc;
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
628 gIR->functions.push_back(irfunction);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
629
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
630 if (fd->isMain())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
631 gIR->emitMain = true;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
632
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
633 std::string entryname("entry");
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
634
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
635 llvm::BasicBlock* beginbb = llvm::BasicBlock::Create(gIR->context(), entryname,func);
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
636 llvm::BasicBlock* endbb = llvm::BasicBlock::Create(gIR->context(), "endentry",func);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
637
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
638 //assert(gIR->scopes.empty());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
639 gIR->scopes.push_back(IRScope(beginbb, endbb));
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
640
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
641 // create alloca point
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1261
diff changeset
642 // this gets erased when the function is complete, so alignment etc does not matter at all
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
643 llvm::Instruction* allocaPoint = new llvm::AllocaInst(LLType::getInt32Ty(gIR->context()), "alloca point", beginbb);
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
644 irfunction->allocapoint = allocaPoint;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
645
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
646 #ifndef DISABLE_DEBUG_INFO
452
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 449
diff changeset
647 // debug info - after all allocas, but before any llvm.dbg.declare etc
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 449
diff changeset
648 if (global.params.symdebug) DtoDwarfFuncStart(fd);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
649 #endif
452
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 449
diff changeset
650
526
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
651 // this hack makes sure the frame pointer elimination optimization is disabled.
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
652 // this this eliminates a bunch of inline asm related issues.
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
653 if (fd->inlineAsm)
526
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
654 {
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
655 // emit a call to llvm_eh_unwind_init
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
656 LLFunction* hack = GET_INTRINSIC_DECL(eh_unwind_init);
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
657 gIR->ir->CreateCall(hack, "");
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
658 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
659
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
660 // give the 'this' argument storage and debug info
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
661 if (f->fty.arg_this)
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
662 {
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
663 LLValue* thisvar = irfunction->thisArg;
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
664 assert(thisvar);
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
665
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1261
diff changeset
666 LLValue* thismem = DtoRawAlloca(thisvar->getType(), 0, "this"); // FIXME: align?
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
667 DtoStore(thisvar, thismem);
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
668 irfunction->thisArg = thismem;
1464
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
669
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
670 assert(!fd->vthis->ir.irLocal);
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
671 fd->vthis->ir.irLocal = new IrLocal(fd->vthis);
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
672 fd->vthis->ir.irLocal->value = thismem;
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
673
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
674 #ifndef DISABLE_DEBUG_INFO
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
675 if (global.params.symdebug)
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
676 DtoDwarfLocalVariable(thismem, fd->vthis);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
677 #endif
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: 752
diff changeset
678
1464
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
679 #if DMDV1
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
680 if (fd->vthis->nestedref)
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: 752
diff changeset
681 {
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
682 fd->nestedVars.insert(fd->vthis);
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: 752
diff changeset
683 }
1464
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
684 #endif
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
685 }
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
686
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
687 // give arguments storage
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
688 // and debug info
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
689 if (fd->parameters)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
690 {
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
691 size_t n = f->fty.args.size();
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
692 assert(n == fd->parameters->dim);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
693 for (int i=0; i < n; ++i)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
694 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
695 Dsymbol* argsym = (Dsymbol*)fd->parameters->data[i];
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
696 VarDeclaration* vd = argsym->isVarDeclaration();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
697 assert(vd);
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: 752
diff changeset
698
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: 920
diff changeset
699 IrLocal* irloc = vd->ir.irLocal;
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: 920
diff changeset
700 assert(irloc);
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: 920
diff changeset
701
1464
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
702 #if DMDV1
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
703 if (vd->nestedref)
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: 752
diff changeset
704 {
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
705 fd->nestedVars.insert(vd);
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: 752
diff changeset
706 }
1464
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
707 #endif
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
708
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
709 bool refout = vd->storage_class & (STCref | STCout);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
710 bool lazy = vd->storage_class & STClazy;
457
d82ebdba4191 Fixed debug info and lazy arguments.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 455
diff changeset
711
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
712 if (!refout && (!f->fty.args[i]->byref || lazy))
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
713 {
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
714 // alloca a stack slot for this first class value arg
1045
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
715 const LLType* argt;
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
716 if (lazy)
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
717 argt = irloc->value->getType();
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
718 else
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
719 argt = DtoType(vd->type);
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1261
diff changeset
720 LLValue* mem = DtoRawAlloca(argt, 0, vd->ident->toChars());
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
721
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
722 // let the abi transform the argument back first
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
723 DImValue arg_dval(vd->type, irloc->value);
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
724 f->fty.getParam(vd->type, i, &arg_dval, mem);
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
725
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
726 // set the arg var value to the alloca
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
727 irloc->value = mem;
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
728 }
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
729
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
730 #ifndef DISABLE_DEBUG_INFO
752
2d7bcfa68128 Enable function parameter debug info for a wider range of args.
Christian Kamm <kamm incasoftware de>
parents: 739
diff changeset
731 if (global.params.symdebug && !(isaArgument(irloc->value) && !isaArgument(irloc->value)->hasByValAttr()) && !refout)
2d7bcfa68128 Enable function parameter debug info for a wider range of args.
Christian Kamm <kamm incasoftware de>
parents: 739
diff changeset
732 DtoDwarfLocalVariable(irloc->value, vd);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
733 #endif
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
734 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
735 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
736
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: 752
diff changeset
737 // need result variable? (nested)
1464
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
738 #if DMDV1
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
739 if (fd->vresult && fd->vresult->nestedref) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
740 Logger::println("nested vresult value: %s", fd->vresult->toChars());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
741 fd->nestedVars.insert(fd->vresult);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
742 }
1464
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
743 #endif
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
744
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
745 #if DMDV2
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
746 // fill nestedVars
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
747 size_t nnest = fd->closureVars.dim;
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
748 for (size_t i = 0; i < nnest; ++i)
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
749 {
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
750 VarDeclaration* vd = (VarDeclaration*)fd->closureVars.data[i];
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
751 fd->nestedVars.insert(vd);
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
752 }
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
753 #endif
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
754
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents: 1162
diff changeset
755 DtoCreateNestedContext(fd);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
756
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
757 #if DMDV2
1464
93644700a0b3 Some minor changes to handling of variables referenced from nested functions in D2 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1407
diff changeset
758 if (fd->vresult && fd->vresult->nestedrefs.dim) // FIXME: not sure here :/
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
759 #else
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
760 if (fd->vresult && fd->vresult->nestedref)
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
761 #endif
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
762 {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
763 DtoNestedInit(fd->vresult);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
764 } else if (fd->vresult) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
765 fd->vresult->ir.irLocal = new IrLocal(fd->vresult);
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1261
diff changeset
766 fd->vresult->ir.irLocal->value = DtoAlloca(fd->vresult->type, fd->vresult->toChars());
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
767 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
768
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
769 // copy _argptr and _arguments to a memory location
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
770 if (f->linkage == LINKd && f->varargs == 1)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
771 {
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
772 // _argptr
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1261
diff changeset
773 LLValue* argptrmem = DtoRawAlloca(fd->ir.irFunc->_argptr->getType(), 0, "_argptr_mem");
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
774 new llvm::StoreInst(fd->ir.irFunc->_argptr, argptrmem, gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
775 fd->ir.irFunc->_argptr = argptrmem;
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
776
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
777 // _arguments
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1261
diff changeset
778 LLValue* argumentsmem = DtoRawAlloca(fd->ir.irFunc->_arguments->getType(), 0, "_arguments_mem");
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
779 new llvm::StoreInst(fd->ir.irFunc->_arguments, argumentsmem, gIR->scopebb());
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
780 fd->ir.irFunc->_arguments = argumentsmem;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
781 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
782
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
783 // output function body
1510
b6b6afc2dfc7 Put scope-limited data on the stack instead of using 'new' and 'delete'.
Frits van Bommel <fvbommel wxs.nl>
parents: 1508
diff changeset
784 {
b6b6afc2dfc7 Put scope-limited data on the stack instead of using 'new' and 'delete'.
Frits van Bommel <fvbommel wxs.nl>
parents: 1508
diff changeset
785 FuncGen fg;
b6b6afc2dfc7 Put scope-limited data on the stack instead of using 'new' and 'delete'.
Frits van Bommel <fvbommel wxs.nl>
parents: 1508
diff changeset
786 irfunction->gen = &fg;
b6b6afc2dfc7 Put scope-limited data on the stack instead of using 'new' and 'delete'.
Frits van Bommel <fvbommel wxs.nl>
parents: 1508
diff changeset
787 fd->fbody->toIR(gIR);
b6b6afc2dfc7 Put scope-limited data on the stack instead of using 'new' and 'delete'.
Frits van Bommel <fvbommel wxs.nl>
parents: 1508
diff changeset
788 irfunction->gen = 0;
b6b6afc2dfc7 Put scope-limited data on the stack instead of using 'new' and 'delete'.
Frits van Bommel <fvbommel wxs.nl>
parents: 1508
diff changeset
789 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
790
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
791 // TODO: clean up this mess
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
792
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
793 // std::cout << *func << std::endl;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
794
1494
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
795 llvm::BasicBlock* bb = gIR->scopebb();
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
796 if (pred_begin(bb) == pred_end(bb) && bb != &bb->getParent()->getEntryBlock()) {
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
797 // This block is trivially unreachable, so just delete it.
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
798 // (This is a common case because it happens when 'return'
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
799 // is the last statement in a function)
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
800 bb->eraseFromParent();
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
801 } else if (!gIR->scopereturned()) {
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
802 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
803 // in automatically, so we do it here.
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
804
428
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
805 // pass the previous block into this block
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
806 #ifndef DISABLE_DEBUG_INFO
428
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
807 if (global.params.symdebug) DtoDwarfFuncEnd(fd);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1607
diff changeset
808 #endif
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
809 if (func->getReturnType() == LLType::getVoidTy(gIR->context())) {
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
810 llvm::ReturnInst::Create(gIR->context(), gIR->scopebb());
428
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
811 }
1494
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
812 else if (!fd->isMain()) {
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
813 AsmBlockStatement* asmb = fd->fbody->endsWithAsm();
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
814 if (asmb) {
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
815 assert(asmb->abiret);
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
816 llvm::ReturnInst::Create(gIR->context(), asmb->abiret, bb);
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
817 }
1494
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
818 else {
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
819 llvm::ReturnInst::Create(gIR->context(), llvm::UndefValue::get(func->getReturnType()), bb);
1494
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
820 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
821 }
1494
b243e28f63d4 Generate less dead code by deleting unreachable blocks at the end of functions
Frits van Bommel <fvbommel wxs.nl>
parents: 1464
diff changeset
822 else
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
823 llvm::ReturnInst::Create(gIR->context(), LLConstant::getNullValue(func->getReturnType()), bb);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
824 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
825
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
826 // std::cout << *func << std::endl;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
827
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
828 // erase alloca point
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
829 allocaPoint->eraseFromParent();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
830 allocaPoint = 0;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
831 gIR->func()->allocapoint = 0;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
832
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
833 gIR->scopes.pop_back();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
834
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
835 // get rid of the endentry block, it's never used
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
836 assert(!func->getBasicBlockList().empty());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
837 func->getBasicBlockList().pop_back();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
838
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
839 gIR->functions.pop_back();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
840
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
841 // std::cout << *func << std::endl;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
842 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
843
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
844 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
845
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
846 const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl)
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
847 {
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
848 Dsymbol* parent = fdecl->toParent();
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
849 ClassDeclaration* cd = parent->isClassDeclaration();
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
850 assert(cd);
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
851
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
852 FuncDeclaration* f = fdecl;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
853
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
854 while (cd)
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
855 {
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
856 ClassDeclaration* base = cd->baseClass;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
857 if (!base)
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
858 break;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
859 FuncDeclaration* f2 = base->findFunc(fdecl->ident, (TypeFunction*)fdecl->type);
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
860 if (f2) {
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
861 f = f2;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
862 cd = base;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
863 }
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
864 else
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
865 break;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
866 }
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
867
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
868 DtoResolveDsymbol(f);
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
869 return llvm::cast<llvm::FunctionType>(DtoType(f->type));
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
870 }
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
871
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
872 //////////////////////////////////////////////////////////////////////////////////////////
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
873
1607
207a8a438dea Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents: 1571
diff changeset
874 DValue* DtoArgument(Parameter* fnarg, Expression* argexp)
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
875 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
876 Logger::println("DtoArgument");
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
877 LOG_SCOPE;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
878
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
879 DValue* arg = argexp->toElem(gIR);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
880
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
881 // ref/out arg
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
882 if (fnarg && (fnarg->storageClass & (STCref | STCout)))
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
883 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
884 if (arg->isVar())
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
885 arg = new DImValue(argexp->type, arg->getLVal());
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
886 else
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
887 arg = new DImValue(argexp->type, arg->getRVal());
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
888 }
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
889 // lazy arg
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
890 else if (fnarg && (fnarg->storageClass & STClazy))
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
891 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
892 assert(argexp->type->toBasetype()->ty == Tdelegate);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
893 assert(!arg->isLVal());
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
894 return arg;
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
895 }
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
896 // byval arg, but expr has no storage yet
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 546
diff changeset
897 else if (DtoIsPassedByRef(argexp->type) && (arg->isSlice() || arg->isNull()))
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
898 {
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1261
diff changeset
899 LLValue* alloc = DtoAlloca(argexp->type, ".tmp_arg");
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 546
diff changeset
900 DVarValue* vv = new DVarValue(argexp->type, alloc);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 379
diff changeset
901 DtoAssign(argexp->loc, vv, arg);
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
902 arg = vv;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
903 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
904
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
905 return arg;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
906 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
907
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
908 //////////////////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
909
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
910 void DtoVariadicArgument(Expression* argexp, LLValue* dst)
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
911 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
912 Logger::println("DtoVariadicArgument");
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
913 LOG_SCOPE;
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 546
diff changeset
914 DVarValue vv(argexp->type, dst);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 379
diff changeset
915 DtoAssign(argexp->loc, &vv, argexp->toElem(gIR));
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
916 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
917
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
918 //////////////////////////////////////////////////////////////////////////////////////////
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
919
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
920 bool FuncDeclaration::isIntrinsic()
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
921 {
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
922 return (llvmInternal == LLVMintrinsic || isVaIntrinsic());
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
923 }
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
924
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
925 bool FuncDeclaration::isVaIntrinsic()
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
926 {
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
927 return (llvmInternal == LLVMva_start ||
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
928 llvmInternal == LLVMva_copy ||
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
929 llvmInternal == LLVMva_end);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
930 }