comparison gen/irstate.h @ 1013:8c73ff5f69e0

Use llvm::CallSite instead of custom CallOrInvoke class.
author Frits van Bommel <fvbommel wxs.nl>
date Sat, 28 Feb 2009 22:16:52 +0100
parents 2667e3a145be
children f99a3b393c03
comparison
equal deleted inserted replaced
1012:39cf8fa483fd 1013:8c73ff5f69e0
10 #include "aggregate.h" 10 #include "aggregate.h"
11 11
12 #include "ir/irfunction.h" 12 #include "ir/irfunction.h"
13 #include "ir/irstruct.h" 13 #include "ir/irstruct.h"
14 #include "ir/irvar.h" 14 #include "ir/irvar.h"
15
16 #include "llvm/Support/CallSite.h"
15 17
16 namespace llvm { 18 namespace llvm {
17 class TargetMachine; 19 class TargetMachine;
18 } 20 }
19 21
104 : asmBlock(b), retty(NULL), retn(0), retemu(false), retfixup(NULL), 106 : asmBlock(b), retty(NULL), retn(0), retemu(false), retfixup(NULL),
105 outputcount(0) 107 outputcount(0)
106 {} 108 {}
107 }; 109 };
108 110
109 // llvm::CallInst and llvm::InvokeInst don't share a common base
110 // but share common functionality. to avoid duplicating code for
111 // adjusting these common properties these structs are made
112 struct CallOrInvoke
113 {
114 virtual void setAttributes(const llvm::AttrListPtr& Attrs) = 0;
115 virtual void setCallingConv(unsigned CC) = 0;
116 virtual llvm::Instruction* get() = 0;
117 };
118
119 struct CallOrInvoke_Call : public CallOrInvoke
120 {
121 llvm::CallInst* inst;
122 CallOrInvoke_Call(llvm::CallInst* call) : inst(call) {}
123
124 virtual void setAttributes(const llvm::AttrListPtr& Attrs)
125 { inst->setAttributes(Attrs); }
126 virtual void setCallingConv(unsigned CC)
127 { inst->setCallingConv(CC); }
128 virtual llvm::Instruction* get()
129 { return inst; }
130 };
131
132 struct CallOrInvoke_Invoke : public CallOrInvoke
133 {
134 llvm::InvokeInst* inst;
135 CallOrInvoke_Invoke(llvm::InvokeInst* invoke) : inst(invoke) {}
136
137 virtual void setAttributes(const llvm::AttrListPtr& Attrs)
138 { inst->setAttributes(Attrs); }
139 virtual void setCallingConv(unsigned CC)
140 { inst->setCallingConv(CC); }
141 virtual llvm::Instruction* get()
142 { return inst; }
143 };
144
145 // represents the module 111 // represents the module
146 struct IRState 112 struct IRState
147 { 113 {
148 IRState(llvm::Module* m); 114 IRState(llvm::Module* m);
149 115
182 bool scopereturned(); 148 bool scopereturned();
183 149
184 // create a call or invoke, depending on the landing pad info 150 // create a call or invoke, depending on the landing pad info
185 // the template function is defined further down in this file 151 // the template function is defined further down in this file
186 template <typename InputIterator> 152 template <typename InputIterator>
187 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name=""); 153 llvm::CallSite CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name="");
188 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, const char* Name=""); 154 llvm::CallSite CreateCallOrInvoke(LLValue* Callee, const char* Name="");
189 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name=""); 155 llvm::CallSite CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name="");
190 CallOrInvoke* CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name=""); 156 llvm::CallSite CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name="");
191 CallOrInvoke* CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name=""); 157 llvm::CallSite CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name="");
192 CallOrInvoke* CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name=""); 158 llvm::CallSite CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name="");
193 159
194 // loop blocks 160 // loop blocks
195 typedef std::vector<IRLoopScope> LoopScopeVec; 161 typedef std::vector<IRLoopScope> LoopScopeVec;
196 LoopScopeVec loopbbs; 162 LoopScopeVec loopbbs;
197 163
235 LLGlobalVariable* dwarfSPs; 201 LLGlobalVariable* dwarfSPs;
236 LLGlobalVariable* dwarfGVs; 202 LLGlobalVariable* dwarfGVs;
237 }; 203 };
238 204
239 template <typename InputIterator> 205 template <typename InputIterator>
240 CallOrInvoke* IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name) 206 llvm::CallSite IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name)
241 { 207 {
242 llvm::BasicBlock* pad; 208 llvm::BasicBlock* pad;
243 if(pad = func()->landingPad.get()) 209 if(pad = func()->landingPad.get())
244 { 210 {
245 // intrinsics don't support invoking 211 // intrinsics don't support invoking
246 LLFunction* funcval = llvm::dyn_cast<LLFunction>(Callee); 212 LLFunction* funcval = llvm::dyn_cast<LLFunction>(Callee);
247 if (funcval && funcval->isIntrinsic()) 213 if (funcval && funcval->isIntrinsic())
248 { 214 {
249 return new CallOrInvoke_Call(ir->CreateCall(Callee, ArgBegin, ArgEnd, Name)); 215 return ir->CreateCall(Callee, ArgBegin, ArgEnd, Name);
250 } 216 }
251 217
252 llvm::BasicBlock* postinvoke = llvm::BasicBlock::Create("postinvoke", topfunc(), scopeend()); 218 llvm::BasicBlock* postinvoke = llvm::BasicBlock::Create("postinvoke", topfunc(), scopeend());
253 llvm::InvokeInst* invoke = ir->CreateInvoke(Callee, postinvoke, pad, ArgBegin, ArgEnd, Name); 219 llvm::InvokeInst* invoke = ir->CreateInvoke(Callee, postinvoke, pad, ArgBegin, ArgEnd, Name);
254 scope() = IRScope(postinvoke, scopeend()); 220 scope() = IRScope(postinvoke, scopeend());
255 return new CallOrInvoke_Invoke(invoke); 221 return invoke;
256 } 222 }
257 else 223 else
258 return new CallOrInvoke_Call(ir->CreateCall(Callee, ArgBegin, ArgEnd, Name)); 224 return ir->CreateCall(Callee, ArgBegin, ArgEnd, Name);
259 } 225 }
260 226
261 #endif // LDC_GEN_IRSTATE_H 227 #endif // LDC_GEN_IRSTATE_H