comparison gen/irstate.h @ 315:a9697749e898 trunk

[svn r336] Made sure calls within a landing pad area are invokes. Nested trys still need some consideration.
author ChristianK
date Thu, 03 Jul 2008 22:05:45 +0200
parents 8d98e42ece93
children e9c93739bc4c
comparison
equal deleted inserted replaced
314:8d98e42ece93 315:a9697749e898
87 87
88 // stores the labels within the asm block 88 // stores the labels within the asm block
89 std::vector<Identifier*> internalLabels; 89 std::vector<Identifier*> internalLabels;
90 }; 90 };
91 91
92 // llvm::CallInst and llvm::InvokeInst don't share a common base
93 // but share common functionality. to avoid duplicating code for
94 // adjusting these common properties these structs are made
95 struct CallOrInvoke
96 {
97 virtual void setParamAttrs(const llvm::PAListPtr& Attrs) = 0;
98 virtual void setCallingConv(unsigned CC) = 0;
99 virtual llvm::Instruction* get() = 0;
100 };
101
102 struct CallOrInvoke_Call : public CallOrInvoke
103 {
104 llvm::CallInst* inst;
105 CallOrInvoke_Call(llvm::CallInst* call) : inst(call) {}
106
107 virtual void setParamAttrs(const llvm::PAListPtr& Attrs)
108 { inst->setParamAttrs(Attrs); }
109 virtual void setCallingConv(unsigned CC)
110 { inst->setCallingConv(CC); }
111 virtual llvm::Instruction* get()
112 { return inst; }
113 };
114
115 struct CallOrInvoke_Invoke : public CallOrInvoke
116 {
117 llvm::InvokeInst* inst;
118 CallOrInvoke_Invoke(llvm::InvokeInst* invoke) : inst(invoke) {}
119
120 virtual void setParamAttrs(const llvm::PAListPtr& Attrs)
121 { inst->setParamAttrs(Attrs); }
122 virtual void setCallingConv(unsigned CC)
123 { inst->setCallingConv(CC); }
124 virtual llvm::Instruction* get()
125 { return inst; }
126 };
127
92 // represents the module 128 // represents the module
93 struct IRState 129 struct IRState
94 { 130 {
95 IRState(); 131 IRState();
96 132
137 bool scopereturned(); 173 bool scopereturned();
138 174
139 // landing pads for try statements 175 // landing pads for try statements
140 typedef std::vector<llvm::BasicBlock*> BBVec; 176 typedef std::vector<llvm::BasicBlock*> BBVec;
141 BBVec landingPads; 177 BBVec landingPads;
178
179 // create a call or invoke, depending on the landing pad info
180 // the template function is defined further down in this file
181 template <typename InputIterator>
182 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name="");
183 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, const char* Name="");
184 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name="");
185 CallOrInvoke* CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name="");
186 CallOrInvoke* CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name="");
187 CallOrInvoke* CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name="");
142 188
143 // loop blocks 189 // loop blocks
144 typedef std::vector<IRLoopScope> LoopScopeVec; 190 typedef std::vector<IRLoopScope> LoopScopeVec;
145 LoopScopeVec loopbbs; 191 LoopScopeVec loopbbs;
146 192
178 LLGlobalVariable* dwarfCUs; 224 LLGlobalVariable* dwarfCUs;
179 LLGlobalVariable* dwarfSPs; 225 LLGlobalVariable* dwarfSPs;
180 LLGlobalVariable* dwarfGVs; 226 LLGlobalVariable* dwarfGVs;
181 }; 227 };
182 228
229 template <typename InputIterator>
230 CallOrInvoke* IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name)
231 {
232 if(landingPads.empty())
233 return new CallOrInvoke_Call(ir->CreateCall(Callee, ArgBegin, ArgEnd, Name));
234 else
235 {
236 llvm::BasicBlock* postinvoke = llvm::BasicBlock::Create("postinvoke", topfunc(), scopeend());
237 llvm::InvokeInst* invoke = ir->CreateInvoke(Callee, postinvoke, *landingPads.rbegin(), ArgBegin, ArgEnd, Name);
238 scope() = IRScope(postinvoke, scopeend());
239 return new CallOrInvoke_Invoke(invoke);
240 }
241 }
242
183 #endif // LLVMDC_GEN_IRSTATE_H 243 #endif // LLVMDC_GEN_IRSTATE_H