Mercurial > projects > ldc
annotate gen/irstate.cpp @ 323:0d52412d5b1a trunk
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
Changed the way moduleinfo is registered to use the same approach as DMD, this eliminates the need for correct linking order and should make the way for using a natively compiled runtime library. This should speed up linking tremendously and should now be possible.
Fixed the llvm.used array to only be emitted if really necessary.
author | lindquist |
---|---|
date | Wed, 09 Jul 2008 23:43:51 +0200 |
parents | a9697749e898 |
children | 20446d22f832 |
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; | |
73 | 19 const llvm::TargetData* gTargetData = 0; |
1 | 20 |
21 ////////////////////////////////////////////////////////////////////////////////////////// | |
22 IRScope::IRScope() | |
23 { | |
40 | 24 begin = end = NULL; |
1 | 25 } |
26 | |
27 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e) | |
28 { | |
29 begin = b; | |
30 end = e; | |
40 | 31 builder.SetInsertPoint(b); |
1 | 32 } |
33 | |
34 ////////////////////////////////////////////////////////////////////////////////////////// | |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
35 IRLoopScope::IRLoopScope() |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
36 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
37 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
38 |
311
9967a3270837
[svn r332] Fix codegen for continue within switch.
ChristianK
parents:
309
diff
changeset
|
39 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
|
40 { |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
41 begin = b; |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
42 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
|
43 //builder.SetInsertPoint(b); |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
44 this->s = s; |
309 | 45 this->enclosinghandler = enclosinghandler; |
311
9967a3270837
[svn r332] Fix codegen for continue within switch.
ChristianK
parents:
309
diff
changeset
|
46 this->isSwitch = isSwitch; |
145
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
47 } |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
48 |
8f704cb9969b
[svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents:
136
diff
changeset
|
49 ////////////////////////////////////////////////////////////////////////////////////////// |
1 | 50 IRState::IRState() |
51 { | |
161
3a891cfcd249
[svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents:
148
diff
changeset
|
52 interfaceInfoType = NULL; |
309 | 53 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
|
54 moduleRefType = NULL; |
309 | 55 |
1 | 56 dmodule = 0; |
57 module = 0; | |
58 emitMain = false; | |
59 mainFunc = 0; | |
40 | 60 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
|
61 asmBlock = NULL; |
252 | 62 |
63 dwarfCUs = NULL; | |
64 dwarfSPs = NULL; | |
65 dwarfGVs = NULL; | |
40 | 66 } |
67 | |
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
|
68 IrFunction* IRState::func() |
40 | 69 { |
70 assert(!functions.empty() && "Function stack is empty!"); | |
71 return functions.back(); | |
1 | 72 } |
73 | |
74 llvm::Function* IRState::topfunc() | |
75 { | |
40 | 76 assert(!functions.empty() && "Function stack is empty!"); |
100 | 77 return functions.back()->func; |
1 | 78 } |
79 | |
80 TypeFunction* IRState::topfunctype() | |
81 { | |
40 | 82 assert(!functions.empty() && "Function stack is empty!"); |
100 | 83 return functions.back()->type; |
1 | 84 } |
85 | |
86 llvm::Instruction* IRState::topallocapoint() | |
87 { | |
40 | 88 assert(!functions.empty() && "AllocaPoint stack is empty!"); |
100 | 89 return functions.back()->allocapoint; |
1 | 90 } |
91 | |
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
|
92 IrStruct* IRState::topstruct() |
1 | 93 { |
94 assert(!structs.empty() && "Struct vector is empty!"); | |
95 return structs.back(); | |
96 } | |
97 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
98 IRExp* IRState::topexp() |
1 | 99 { |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
100 return exps.empty() ? NULL : &exps.back(); |
1 | 101 } |
102 | |
103 IRScope& IRState::scope() | |
104 { | |
105 assert(!scopes.empty()); | |
106 return scopes.back(); | |
107 } | |
108 | |
109 llvm::BasicBlock* IRState::scopebb() | |
110 { | |
111 IRScope& s = scope(); | |
112 assert(s.begin); | |
113 return s.begin; | |
114 } | |
115 llvm::BasicBlock* IRState::scopeend() | |
116 { | |
117 IRScope& s = scope(); | |
118 assert(s.end); | |
119 return s.end; | |
120 } | |
121 bool IRState::scopereturned() | |
122 { | |
14
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
123 //return scope().returned; |
0e86428ee567
[svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents:
6
diff
changeset
|
124 return !scopebb()->empty() && scopebb()->back().isTerminator(); |
1 | 125 } |
126 | |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
127 CallOrInvoke* IRState::CreateCallOrInvoke(LLValue* Callee, const char* 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 LLSmallVector<LLValue*, 1> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
130 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
|
131 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
132 |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
133 CallOrInvoke* IRState::CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name) |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
134 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
135 LLSmallVector<LLValue*, 1> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
136 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
137 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
|
138 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
139 |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
140 CallOrInvoke* IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name) |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
141 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
142 LLSmallVector<LLValue*, 2> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
143 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
144 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
145 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
|
146 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
147 |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
148 CallOrInvoke* IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name) |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
149 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
150 LLSmallVector<LLValue*, 3> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
151 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
152 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
153 args.push_back(Arg3); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
154 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
|
155 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
156 |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
157 CallOrInvoke* IRState::CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name) |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
158 { |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
159 LLSmallVector<LLValue*, 4> args; |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
160 args.push_back(Arg1); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
161 args.push_back(Arg2); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
162 args.push_back(Arg3); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
163 args.push_back(Arg4); |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
164 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
|
165 } |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
166 |
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
311
diff
changeset
|
167 |
1 | 168 ////////////////////////////////////////////////////////////////////////////////////////// |
169 | |
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:
189
diff
changeset
|
170 IRBuilder* IRBuilderHelper::operator->() |
40 | 171 { |
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:
189
diff
changeset
|
172 IRBuilder& b = state->scope().builder; |
40 | 173 assert(b.GetInsertBlock() != NULL); |
174 return &b; | |
175 } | |
176 | |
177 ////////////////////////////////////////////////////////////////////////////////////////// | |
178 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
179 IRExp::IRExp() |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
180 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
181 e1 = e2 = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
182 v = NULL; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
183 } |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
184 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
82
diff
changeset
|
185 IRExp::IRExp(Expression* l, Expression* r, DValue* val) |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
186 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
187 e1 = l; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
188 e2 = r; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
189 v = val; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
40
diff
changeset
|
190 } |