Mercurial > projects > ldc
annotate gen/irstate.cpp @ 1117:4c20fcc4252b
Fun with parameter attributes: For several of the "synthetic" parameters added
to D functions, we can apply noalias and nocapture. They are sret parameters,
'nest' pointers passed to nested functions, and _argptr:
Nocapture:
- Sret and nest are nocapture because they don't represent D-level variables,
and thus the callee can't (validly) obtain a pointer to them, let alone keep
it around after it returns.
- _argptr is nocapture because although the callee has access to it as a
pointer, that pointer is invalidated when it returns.
All three are noalias because they're function-local variables
- Sret and _argptr are noalias because they're freshly alloca'd memory only
used for a single function call that's not allowed to keep an aliasing
pointer to it around (since the parameter is nocapture).
- 'Nest' is noalias because the callee only ever has access to one such pointer
per parent function, and every parent function has a different one.
This commit also ensures attributes set on sret, _arguments and _argptr are
propagated to calls to such functions.
It also adds one exception to the general rule that attributes on function types
should propagate to calls: the type of a delegate's function pointer has a
'nest' parameter, but this can either be a true 'nest' (for delegates to nested
functions) or a 'this' (for delegates to member functions). Since 'this' is
neither noalias nor nocapture, and there's generally no way to tell which one it
is, we remove these attributes at the call site if the callee is a delegate.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sat, 14 Mar 2009 22:15:31 +0100 |
parents | 8c73ff5f69e0 |
children | f99a3b393c03 |
rev | line source |
---|---|
1 | 1 /* DMDFE backend stubs |
2 * This file contains the implementations of the backend routines. | |
3 * For dmdfe these do nothing but print a message saying the module | |
4 * has been parsed. Substitute your own behaviors for these routimes. | |
5 */ | |
6 | |
40 | 7 #include <cstdarg> |
8 | |
9 #include "gen/llvm.h" | |
10 | |
1 | 11 #include "mtype.h" |
40 | 12 #include "declaration.h" |
309 | 13 #include "statement.h" |
40 | 14 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
15 #include "gen/irstate.h" |
40 | 16 #include "tollvm.h" |
1 | 17 |
18 IRState* gIR = 0; | |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
946
diff
changeset
|
19 llvm::TargetMachine* gTargetMachine = 0; |
73 | 20 const llvm::TargetData* gTargetData = 0; |
988
2667e3a145be
- Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
946
diff
changeset
|
21 TargetABI* gABI = 0; |
1 | 22 |
23 ////////////////////////////////////////////////////////////////////////////////////////// | |
24 IRScope::IRScope() | |
25 { | |
40 | 26 begin = end = NULL; |
1 | 27 } |
28 | |
29 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) | |
30 { | |
31 begin = b; | |
32 end = e; | |
40 | 33 builder.SetInsertPoint(b); |
1 | 34 } |
35 | |
36 ////////////////////////////////////////////////////////////////////////////////////////// | |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
37 IRLoopScope::IRLoopScope() |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
38 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
39 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
40 |
311
9967a3270837
[svn r332] Fix codegen for continue within switch.
ChristianK
parents:
309
diff
changeset
|
41 IRLoopScope::IRLoopScope(Statement* s, EnclosingHandler* enclosinghandler, llvm::BasicBlock* b, llvm::BasicBlock* e, bool isSwitch) |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
42 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
43 begin = b; |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
44 end = e; |
262
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
252
diff
changeset
|
45 //builder.SetInsertPoint(b); |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
46 this->s = s; |
309 | 47 this->enclosinghandler = enclosinghandler; |
311
9967a3270837
[svn r332] Fix codegen for continue within switch.
ChristianK
parents:
309
diff
changeset
|
48 this->isSwitch = isSwitch; |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
49 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
50 |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
51 ////////////////////////////////////////////////////////////////////////////////////////// |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
493
diff
changeset
|
52 IRState::IRState(llvm::Module* m) |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
493
diff
changeset
|
53 : module(m), difactory(*m) |
1 | 54 { |
161
3a891cfcd249
[svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents:
148
diff
changeset
|
55 interfaceInfoType = NULL; |
309 | 56 mutexType = NULL; |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
315
diff
changeset
|
57 moduleRefType = NULL; |
309 | 58 |
1 | 59 dmodule = 0; |
60 emitMain = false; | |
61 mainFunc = 0; | |
40 | 62 ir.state = this; |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
63 asmBlock = NULL; |
252 | 64 |
65 dwarfCUs = NULL; | |
66 dwarfSPs = NULL; | |
67 dwarfGVs = NULL; | |
40 | 68 } |
69 | |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
113
diff
changeset
|
70 IrFunction* IRState::func() |
40 | 71 { |
72 assert(!functions.empty() && "Function stack is empty!"); | |
73 return functions.back(); | |
1 | 74 } |
75 | |
76 llvm::Function* IRState::topfunc() | |
77 { | |
40 | 78 assert(!functions.empty() && "Function stack is empty!"); |
100 | 79 return functions.back()->func; |
1 | 80 } |
81 | |
82 TypeFunction* IRState::topfunctype() | |
83 { | |
40 | 84 assert(!functions.empty() && "Function stack is empty!"); |
100 | 85 return functions.back()->type; |
1 | 86 } |
87 | |
88 llvm::Instruction* IRState::topallocapoint() | |
89 { | |
40 | 90 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
100 | 91 return functions.back()->allocapoint; |
1 | 92 } |
93 | |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
113
diff
changeset
|
94 IrStruct* IRState::topstruct() |
1 | 95 { |
96 assert(!structs.empty() && "Struct vector is empty!"); | |
97 return structs.back(); | |
98 } | |
99 | |
100 IRScope& IRState::scope() | |
101 { | |
102 assert(!scopes.empty()); | |
103 return scopes.back(); | |
104 } | |
105 | |
106 llvm::BasicBlock* IRState::scopebb() | |
107 { | |
108 IRScope& s = scope(); | |
109 assert(s.begin); | |
110 return s.begin; | |
111 } | |
112 llvm::BasicBlock* IRState::scopeend() | |
113 { | |
114 IRScope& s = scope(); | |
115 assert(s.end); | |
116 return s.end; | |
117 } | |
118 bool IRState::scopereturned() | |
119 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
120 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
121 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 122 } |
123 | |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
124 LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, const char* Name) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
125 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
126 LLSmallVector<LLValue*, 1> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
127 return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
128 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
129 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
130 LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
131 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
132 LLSmallVector<LLValue*, 1> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
133 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
134 return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
135 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
136 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
137 LLCallSite IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
138 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
139 LLSmallVector<LLValue*, 2> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
140 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
141 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
142 return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
143 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
144 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
145 LLCallSite IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
146 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
147 LLSmallVector<LLValue*, 3> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
148 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
149 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
150 args.push_back(Arg3); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
151 return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
152 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
153 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
988
diff
changeset
|
154 LLCallSite IRState::CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name) |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
155 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
156 LLSmallVector<LLValue*, 4> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
157 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
158 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
159 args.push_back(Arg3); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
160 args.push_back(Arg4); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
161 return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
162 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
163 |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
164 |
1 | 165 ////////////////////////////////////////////////////////////////////////////////////////// |
166 | |
493
017ca8645a1f
Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents:
334
diff
changeset
|
167 IRBuilder<>* IRBuilderHelper::operator->() |
40 | 168 { |
493
017ca8645a1f
Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents:
334
diff
changeset
|
169 IRBuilder<>& b = state->scope().builder; |
40 | 170 assert(b.GetInsertBlock() != NULL); |
171 return &b; | |
172 } |