blob: a5cf946ea62d17e9cbd1a2935e6ac820eda6718b [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- CGStmt.cpp - Emit LLVM Code from Statements ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This contains code to emit Stmt nodes as LLVM code.
11//
12//===----------------------------------------------------------------------===//
13
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000014#include "CGDebugInfo.h"
15#include "CodeGenModule.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016#include "CodeGenFunction.h"
17#include "clang/AST/AST.h"
Anders Carlssonfb1aeb82008-02-05 16:35:33 +000018#include "clang/Basic/TargetInfo.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000019#include "llvm/Constants.h"
20#include "llvm/DerivedTypes.h"
21#include "llvm/Function.h"
Anders Carlssonfb1aeb82008-02-05 16:35:33 +000022#include "llvm/InlineAsm.h"
23#include "llvm/ADT/StringExtras.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000024using namespace clang;
25using namespace CodeGen;
26
27//===----------------------------------------------------------------------===//
28// Statement Emission
29//===----------------------------------------------------------------------===//
30
31void CodeGenFunction::EmitStmt(const Stmt *S) {
32 assert(S && "Null statement?");
33
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000034 // Generate stoppoints if we are emitting debug info.
35 // Beginning of a Compound Statement (e.g. an opening '{') does not produce
36 // executable code. So do not generate a stoppoint for that.
37 CGDebugInfo *DI = CGM.getDebugInfo();
38 if (DI && S->getStmtClass() != Stmt::CompoundStmtClass) {
39 if (S->getLocStart().isValid()) {
40 DI->setLocation(S->getLocStart());
41 }
42
43 DI->EmitStopPoint(CurFn, Builder);
44 }
45
Reid Spencer5f016e22007-07-11 17:01:13 +000046 switch (S->getStmtClass()) {
47 default:
Chris Lattner1e4d21e2007-08-26 22:58:05 +000048 // Must be an expression in a stmt context. Emit the value (to get
49 // side-effects) and ignore the result.
Reid Spencer5f016e22007-07-11 17:01:13 +000050 if (const Expr *E = dyn_cast<Expr>(S)) {
Chris Lattner1e4d21e2007-08-26 22:58:05 +000051 if (!hasAggregateLLVMType(E->getType()))
52 EmitScalarExpr(E);
Chris Lattner9b2dc282008-04-04 16:54:41 +000053 else if (E->getType()->isAnyComplexType())
Chris Lattner1e4d21e2007-08-26 22:58:05 +000054 EmitComplexExpr(E);
55 else
56 EmitAggExpr(E, 0, false);
Reid Spencer5f016e22007-07-11 17:01:13 +000057 } else {
Chris Lattnerdc4d2802007-12-02 01:49:16 +000058 WarnUnsupported(S, "statement");
Reid Spencer5f016e22007-07-11 17:01:13 +000059 }
60 break;
61 case Stmt::NullStmtClass: break;
62 case Stmt::CompoundStmtClass: EmitCompoundStmt(cast<CompoundStmt>(*S)); break;
63 case Stmt::LabelStmtClass: EmitLabelStmt(cast<LabelStmt>(*S)); break;
64 case Stmt::GotoStmtClass: EmitGotoStmt(cast<GotoStmt>(*S)); break;
Daniel Dunbar0ffb1252008-08-04 16:51:22 +000065 case Stmt::IndirectGotoStmtClass:
66 EmitIndirectGotoStmt(cast<IndirectGotoStmt>(*S)); break;
Reid Spencer5f016e22007-07-11 17:01:13 +000067
68 case Stmt::IfStmtClass: EmitIfStmt(cast<IfStmt>(*S)); break;
69 case Stmt::WhileStmtClass: EmitWhileStmt(cast<WhileStmt>(*S)); break;
70 case Stmt::DoStmtClass: EmitDoStmt(cast<DoStmt>(*S)); break;
71 case Stmt::ForStmtClass: EmitForStmt(cast<ForStmt>(*S)); break;
72
73 case Stmt::ReturnStmtClass: EmitReturnStmt(cast<ReturnStmt>(*S)); break;
74 case Stmt::DeclStmtClass: EmitDeclStmt(cast<DeclStmt>(*S)); break;
Chris Lattnerda138702007-07-16 21:28:45 +000075
76 case Stmt::BreakStmtClass: EmitBreakStmt(); break;
77 case Stmt::ContinueStmtClass: EmitContinueStmt(); break;
Devang Patel51b09f22007-10-04 23:45:31 +000078 case Stmt::SwitchStmtClass: EmitSwitchStmt(cast<SwitchStmt>(*S)); break;
79 case Stmt::DefaultStmtClass: EmitDefaultStmt(cast<DefaultStmt>(*S)); break;
80 case Stmt::CaseStmtClass: EmitCaseStmt(cast<CaseStmt>(*S)); break;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +000081 case Stmt::AsmStmtClass: EmitAsmStmt(cast<AsmStmt>(*S)); break;
Reid Spencer5f016e22007-07-11 17:01:13 +000082 }
83}
84
Chris Lattner33793202007-08-31 22:09:40 +000085/// EmitCompoundStmt - Emit a compound statement {..} node. If GetLast is true,
86/// this captures the expression result of the last sub-statement and returns it
87/// (for use by the statement expression extension).
Chris Lattner9b655512007-08-31 22:49:20 +000088RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
89 llvm::Value *AggLoc, bool isAggVol) {
Reid Spencer5f016e22007-07-11 17:01:13 +000090 // FIXME: handle vla's etc.
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000091 CGDebugInfo *DI = CGM.getDebugInfo();
92 if (DI) {
Chris Lattner345f7202008-07-26 20:15:14 +000093 if (S.getLBracLoc().isValid())
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000094 DI->setLocation(S.getLBracLoc());
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000095 DI->EmitRegionStart(CurFn, Builder);
96 }
97
Chris Lattner33793202007-08-31 22:09:40 +000098 for (CompoundStmt::const_body_iterator I = S.body_begin(),
99 E = S.body_end()-GetLast; I != E; ++I)
Reid Spencer5f016e22007-07-11 17:01:13 +0000100 EmitStmt(*I);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000101
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000102 if (DI) {
Chris Lattner345f7202008-07-26 20:15:14 +0000103 if (S.getRBracLoc().isValid())
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000104 DI->setLocation(S.getRBracLoc());
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000105 DI->EmitRegionEnd(CurFn, Builder);
106 }
107
Chris Lattner33793202007-08-31 22:09:40 +0000108 if (!GetLast)
109 return RValue::get(0);
Chris Lattner9b655512007-08-31 22:49:20 +0000110
Chris Lattner91d723d2008-07-26 20:23:23 +0000111 // We have to special case labels here. They are statements, but when put at
112 // the end of a statement expression, they yield the value of their
113 // subexpression. Handle this by walking through all labels we encounter,
114 // emitting them before we evaluate the subexpr.
115 const Stmt *LastStmt = S.body_back();
116 while (const LabelStmt *LS = dyn_cast<LabelStmt>(LastStmt)) {
117 EmitLabel(*LS);
118 LastStmt = LS->getSubStmt();
119 }
120
121 return EmitAnyExpr(cast<Expr>(LastStmt), AggLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +0000122}
123
124void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB) {
125 // Emit a branch from this block to the next one if this was a real block. If
126 // this was just a fall-through block after a terminator, don't emit it.
127 llvm::BasicBlock *LastBB = Builder.GetInsertBlock();
128
129 if (LastBB->getTerminator()) {
130 // If the previous block is already terminated, don't touch it.
Daniel Dunbar16f23572008-07-25 01:11:38 +0000131 } else if (LastBB->empty() && isDummyBlock(LastBB)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000132 // If the last block was an empty placeholder, remove it now.
133 // TODO: cache and reuse these.
Daniel Dunbar16f23572008-07-25 01:11:38 +0000134 LastBB->eraseFromParent();
Reid Spencer5f016e22007-07-11 17:01:13 +0000135 } else {
136 // Otherwise, create a fall-through branch.
137 Builder.CreateBr(BB);
138 }
139 CurFn->getBasicBlockList().push_back(BB);
140 Builder.SetInsertPoint(BB);
141}
142
Chris Lattner91d723d2008-07-26 20:23:23 +0000143void CodeGenFunction::EmitLabel(const LabelStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000144 llvm::BasicBlock *NextBB = getBasicBlockForLabel(&S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000145 EmitBlock(NextBB);
Chris Lattner91d723d2008-07-26 20:23:23 +0000146}
147
148
149void CodeGenFunction::EmitLabelStmt(const LabelStmt &S) {
150 EmitLabel(S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000151 EmitStmt(S.getSubStmt());
152}
153
154void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) {
155 Builder.CreateBr(getBasicBlockForLabel(S.getLabel()));
156
157 // Emit a block after the branch so that dead code after a goto has some place
158 // to go.
Gabor Greif984d0b42008-04-06 20:42:52 +0000159 Builder.SetInsertPoint(llvm::BasicBlock::Create("", CurFn));
Reid Spencer5f016e22007-07-11 17:01:13 +0000160}
161
Daniel Dunbar0ffb1252008-08-04 16:51:22 +0000162void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) {
163 // Emit initial switch which will be patched up later by
164 // EmitIndirectSwitches(). We need a default dest, so we use the
165 // current BB, but this is overwritten.
166 llvm::Value *V = Builder.CreatePtrToInt(EmitScalarExpr(S.getTarget()),
167 llvm::Type::Int32Ty,
168 "addr");
169 llvm::SwitchInst *I = Builder.CreateSwitch(V, Builder.GetInsertBlock());
170 IndirectSwitches.push_back(I);
171
172 // Emit a block after the branch so that dead code after a goto has some place
173 // to go.
174 Builder.SetInsertPoint(llvm::BasicBlock::Create("", CurFn));
175}
176
Reid Spencer5f016e22007-07-11 17:01:13 +0000177void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
Daniel Dunbar0ffb1252008-08-04 16:51:22 +0000178 // FIXME: It would probably be nice for us to skip emission of if
179 // (0) code here.
180
Reid Spencer5f016e22007-07-11 17:01:13 +0000181 // C99 6.8.4.1: The first substatement is executed if the expression compares
182 // unequal to 0. The condition must be a scalar type.
183 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
184
Gabor Greif984d0b42008-04-06 20:42:52 +0000185 llvm::BasicBlock *ContBlock = llvm::BasicBlock::Create("ifend");
186 llvm::BasicBlock *ThenBlock = llvm::BasicBlock::Create("ifthen");
Reid Spencer5f016e22007-07-11 17:01:13 +0000187 llvm::BasicBlock *ElseBlock = ContBlock;
188
189 if (S.getElse())
Gabor Greif984d0b42008-04-06 20:42:52 +0000190 ElseBlock = llvm::BasicBlock::Create("ifelse");
Reid Spencer5f016e22007-07-11 17:01:13 +0000191
192 // Insert the conditional branch.
193 Builder.CreateCondBr(BoolCondVal, ThenBlock, ElseBlock);
194
195 // Emit the 'then' code.
196 EmitBlock(ThenBlock);
197 EmitStmt(S.getThen());
Devang Pateld9363c32007-09-28 21:49:18 +0000198 llvm::BasicBlock *BB = Builder.GetInsertBlock();
199 if (isDummyBlock(BB)) {
200 BB->eraseFromParent();
201 Builder.SetInsertPoint(ThenBlock);
Chris Lattner345f7202008-07-26 20:15:14 +0000202 } else {
Devang Pateld9363c32007-09-28 21:49:18 +0000203 Builder.CreateBr(ContBlock);
Chris Lattner345f7202008-07-26 20:15:14 +0000204 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000205
206 // Emit the 'else' code if present.
207 if (const Stmt *Else = S.getElse()) {
208 EmitBlock(ElseBlock);
209 EmitStmt(Else);
Devang Pateld9363c32007-09-28 21:49:18 +0000210 llvm::BasicBlock *BB = Builder.GetInsertBlock();
211 if (isDummyBlock(BB)) {
212 BB->eraseFromParent();
213 Builder.SetInsertPoint(ElseBlock);
Chris Lattner345f7202008-07-26 20:15:14 +0000214 } else {
Devang Pateld9363c32007-09-28 21:49:18 +0000215 Builder.CreateBr(ContBlock);
Chris Lattner345f7202008-07-26 20:15:14 +0000216 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000217 }
218
219 // Emit the continuation block for code after the if.
220 EmitBlock(ContBlock);
221}
222
223void CodeGenFunction::EmitWhileStmt(const WhileStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000224 // Emit the header for the loop, insert it, which will create an uncond br to
225 // it.
Gabor Greif984d0b42008-04-06 20:42:52 +0000226 llvm::BasicBlock *LoopHeader = llvm::BasicBlock::Create("whilecond");
Reid Spencer5f016e22007-07-11 17:01:13 +0000227 EmitBlock(LoopHeader);
228
229 // Evaluate the conditional in the while header. C99 6.8.5.1: The evaluation
230 // of the controlling expression takes place before each execution of the loop
231 // body.
232 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
Devang Patel2c30d8f2007-10-09 20:51:27 +0000233
234 // while(1) is common, avoid extra exit blocks. Be sure
Reid Spencer5f016e22007-07-11 17:01:13 +0000235 // to correctly handle break/continue though.
Devang Patel2c30d8f2007-10-09 20:51:27 +0000236 bool EmitBoolCondBranch = true;
237 if (llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal))
238 if (C->isOne())
239 EmitBoolCondBranch = false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000240
241 // Create an exit block for when the condition fails, create a block for the
242 // body of the loop.
Gabor Greif984d0b42008-04-06 20:42:52 +0000243 llvm::BasicBlock *ExitBlock = llvm::BasicBlock::Create("whileexit");
244 llvm::BasicBlock *LoopBody = llvm::BasicBlock::Create("whilebody");
Reid Spencer5f016e22007-07-11 17:01:13 +0000245
246 // As long as the condition is true, go to the loop body.
Devang Patel2c30d8f2007-10-09 20:51:27 +0000247 if (EmitBoolCondBranch)
248 Builder.CreateCondBr(BoolCondVal, LoopBody, ExitBlock);
Chris Lattnerda138702007-07-16 21:28:45 +0000249
250 // Store the blocks to use for break and continue.
251 BreakContinueStack.push_back(BreakContinue(ExitBlock, LoopHeader));
Reid Spencer5f016e22007-07-11 17:01:13 +0000252
253 // Emit the loop body.
254 EmitBlock(LoopBody);
255 EmitStmt(S.getBody());
Chris Lattnerda138702007-07-16 21:28:45 +0000256
257 BreakContinueStack.pop_back();
Reid Spencer5f016e22007-07-11 17:01:13 +0000258
259 // Cycle to the condition.
260 Builder.CreateBr(LoopHeader);
261
262 // Emit the exit block.
263 EmitBlock(ExitBlock);
Devang Patel2c30d8f2007-10-09 20:51:27 +0000264
265 // If LoopHeader is a simple forwarding block then eliminate it.
266 if (!EmitBoolCondBranch
267 && &LoopHeader->front() == LoopHeader->getTerminator()) {
268 LoopHeader->replaceAllUsesWith(LoopBody);
269 LoopHeader->getTerminator()->eraseFromParent();
270 LoopHeader->eraseFromParent();
271 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000272}
273
274void CodeGenFunction::EmitDoStmt(const DoStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000275 // Emit the body for the loop, insert it, which will create an uncond br to
276 // it.
Gabor Greif984d0b42008-04-06 20:42:52 +0000277 llvm::BasicBlock *LoopBody = llvm::BasicBlock::Create("dobody");
278 llvm::BasicBlock *AfterDo = llvm::BasicBlock::Create("afterdo");
Reid Spencer5f016e22007-07-11 17:01:13 +0000279 EmitBlock(LoopBody);
Chris Lattnerda138702007-07-16 21:28:45 +0000280
Gabor Greif984d0b42008-04-06 20:42:52 +0000281 llvm::BasicBlock *DoCond = llvm::BasicBlock::Create("docond");
Chris Lattnerda138702007-07-16 21:28:45 +0000282
283 // Store the blocks to use for break and continue.
284 BreakContinueStack.push_back(BreakContinue(AfterDo, DoCond));
Reid Spencer5f016e22007-07-11 17:01:13 +0000285
286 // Emit the body of the loop into the block.
287 EmitStmt(S.getBody());
288
Chris Lattnerda138702007-07-16 21:28:45 +0000289 BreakContinueStack.pop_back();
290
291 EmitBlock(DoCond);
292
Reid Spencer5f016e22007-07-11 17:01:13 +0000293 // C99 6.8.5.2: "The evaluation of the controlling expression takes place
294 // after each execution of the loop body."
295
296 // Evaluate the conditional in the while header.
297 // C99 6.8.5p2/p4: The first substatement is executed if the expression
298 // compares unequal to 0. The condition must be a scalar type.
299 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
Devang Patel05f6e6b2007-10-09 20:33:39 +0000300
301 // "do {} while (0)" is common in macros, avoid extra blocks. Be sure
302 // to correctly handle break/continue though.
303 bool EmitBoolCondBranch = true;
304 if (llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal))
305 if (C->isZero())
306 EmitBoolCondBranch = false;
307
Reid Spencer5f016e22007-07-11 17:01:13 +0000308 // As long as the condition is true, iterate the loop.
Devang Patel05f6e6b2007-10-09 20:33:39 +0000309 if (EmitBoolCondBranch)
310 Builder.CreateCondBr(BoolCondVal, LoopBody, AfterDo);
Reid Spencer5f016e22007-07-11 17:01:13 +0000311
312 // Emit the exit block.
313 EmitBlock(AfterDo);
Devang Patel05f6e6b2007-10-09 20:33:39 +0000314
315 // If DoCond is a simple forwarding block then eliminate it.
316 if (!EmitBoolCondBranch && &DoCond->front() == DoCond->getTerminator()) {
317 DoCond->replaceAllUsesWith(AfterDo);
318 DoCond->getTerminator()->eraseFromParent();
319 DoCond->eraseFromParent();
320 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000321}
322
323void CodeGenFunction::EmitForStmt(const ForStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000324 // FIXME: What do we do if the increment (f.e.) contains a stmt expression,
325 // which contains a continue/break?
Chris Lattnerda138702007-07-16 21:28:45 +0000326 // TODO: We could keep track of whether the loop body contains any
327 // break/continue statements and not create unnecessary blocks (like
328 // "afterfor" for a condless loop) if it doesn't.
329
Reid Spencer5f016e22007-07-11 17:01:13 +0000330 // Evaluate the first part before the loop.
331 if (S.getInit())
332 EmitStmt(S.getInit());
333
334 // Start the loop with a block that tests the condition.
Gabor Greif984d0b42008-04-06 20:42:52 +0000335 llvm::BasicBlock *CondBlock = llvm::BasicBlock::Create("forcond");
336 llvm::BasicBlock *AfterFor = llvm::BasicBlock::Create("afterfor");
Chris Lattnerda138702007-07-16 21:28:45 +0000337
Reid Spencer5f016e22007-07-11 17:01:13 +0000338 EmitBlock(CondBlock);
339
340 // Evaluate the condition if present. If not, treat it as a non-zero-constant
341 // according to 6.8.5.3p2, aka, true.
342 if (S.getCond()) {
343 // C99 6.8.5p2/p4: The first substatement is executed if the expression
344 // compares unequal to 0. The condition must be a scalar type.
345 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
346
347 // As long as the condition is true, iterate the loop.
Gabor Greif984d0b42008-04-06 20:42:52 +0000348 llvm::BasicBlock *ForBody = llvm::BasicBlock::Create("forbody");
Reid Spencer5f016e22007-07-11 17:01:13 +0000349 Builder.CreateCondBr(BoolCondVal, ForBody, AfterFor);
350 EmitBlock(ForBody);
351 } else {
352 // Treat it as a non-zero constant. Don't even create a new block for the
353 // body, just fall into it.
354 }
355
Chris Lattnerda138702007-07-16 21:28:45 +0000356 // If the for loop doesn't have an increment we can just use the
357 // condition as the continue block.
358 llvm::BasicBlock *ContinueBlock;
359 if (S.getInc())
Gabor Greif984d0b42008-04-06 20:42:52 +0000360 ContinueBlock = llvm::BasicBlock::Create("forinc");
Chris Lattnerda138702007-07-16 21:28:45 +0000361 else
362 ContinueBlock = CondBlock;
363
364 // Store the blocks to use for break and continue.
365 BreakContinueStack.push_back(BreakContinue(AfterFor, ContinueBlock));
366
Reid Spencer5f016e22007-07-11 17:01:13 +0000367 // If the condition is true, execute the body of the for stmt.
368 EmitStmt(S.getBody());
Chris Lattnerda138702007-07-16 21:28:45 +0000369
370 BreakContinueStack.pop_back();
371
372 if (S.getInc())
373 EmitBlock(ContinueBlock);
Reid Spencer5f016e22007-07-11 17:01:13 +0000374
375 // If there is an increment, emit it next.
376 if (S.getInc())
Chris Lattner883f6a72007-08-11 00:04:45 +0000377 EmitStmt(S.getInc());
Reid Spencer5f016e22007-07-11 17:01:13 +0000378
379 // Finally, branch back up to the condition for the next iteration.
380 Builder.CreateBr(CondBlock);
381
Chris Lattnerda138702007-07-16 21:28:45 +0000382 // Emit the fall-through block.
383 EmitBlock(AfterFor);
Reid Spencer5f016e22007-07-11 17:01:13 +0000384}
385
386/// EmitReturnStmt - Note that due to GCC extensions, this can have an operand
387/// if the function returns void, or may be missing one if the function returns
388/// non-void. Fun stuff :).
389void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000390 // Emit the result value, even if unused, to evalute the side effects.
391 const Expr *RV = S.getRetValue();
Chris Lattner4b0029d2007-08-26 07:14:44 +0000392
Eli Friedman144ac612008-05-22 01:22:33 +0000393 llvm::Value* RetValue = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000394 if (FnRetTy->isVoidType()) {
Eli Friedman144ac612008-05-22 01:22:33 +0000395 // Make sure not to return anything
396 if (RV) {
397 // Evaluate the expression for side effects
398 EmitAnyExpr(RV);
399 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000400 } else if (RV == 0) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000401 const llvm::Type *RetTy = CurFn->getFunctionType()->getReturnType();
Eli Friedman144ac612008-05-22 01:22:33 +0000402 if (RetTy != llvm::Type::VoidTy) {
403 // Handle "return;" in a function that returns a value.
404 RetValue = llvm::UndefValue::get(RetTy);
405 }
Chris Lattner4b0029d2007-08-26 07:14:44 +0000406 } else if (!hasAggregateLLVMType(RV->getType())) {
Eli Friedman144ac612008-05-22 01:22:33 +0000407 RetValue = EmitScalarExpr(RV);
Chris Lattner9b2dc282008-04-04 16:54:41 +0000408 } else if (RV->getType()->isAnyComplexType()) {
Chris Lattner345f7202008-07-26 20:15:14 +0000409 EmitComplexExprIntoAddr(RV, CurFn->arg_begin(), false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000410 } else {
Chris Lattner345f7202008-07-26 20:15:14 +0000411 EmitAggExpr(RV, CurFn->arg_begin(), false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000412 }
Eli Friedman144ac612008-05-22 01:22:33 +0000413
414 if (RetValue) {
415 Builder.CreateRet(RetValue);
416 } else {
417 Builder.CreateRetVoid();
418 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000419
420 // Emit a block after the branch so that dead code after a return has some
421 // place to go.
Gabor Greif984d0b42008-04-06 20:42:52 +0000422 EmitBlock(llvm::BasicBlock::Create());
Reid Spencer5f016e22007-07-11 17:01:13 +0000423}
424
425void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) {
Steve Naroff94745042007-09-13 23:52:58 +0000426 for (const ScopedDecl *Decl = S.getDecl(); Decl;
427 Decl = Decl->getNextDeclarator())
Reid Spencer5f016e22007-07-11 17:01:13 +0000428 EmitDecl(*Decl);
Chris Lattner6fa5f092007-07-12 15:43:07 +0000429}
Chris Lattnerda138702007-07-16 21:28:45 +0000430
431void CodeGenFunction::EmitBreakStmt() {
432 assert(!BreakContinueStack.empty() && "break stmt not in a loop or switch!");
433
434 llvm::BasicBlock *Block = BreakContinueStack.back().BreakBlock;
435 Builder.CreateBr(Block);
Gabor Greif984d0b42008-04-06 20:42:52 +0000436 EmitBlock(llvm::BasicBlock::Create());
Chris Lattnerda138702007-07-16 21:28:45 +0000437}
438
439void CodeGenFunction::EmitContinueStmt() {
440 assert(!BreakContinueStack.empty() && "continue stmt not in a loop!");
441
442 llvm::BasicBlock *Block = BreakContinueStack.back().ContinueBlock;
443 Builder.CreateBr(Block);
Gabor Greif984d0b42008-04-06 20:42:52 +0000444 EmitBlock(llvm::BasicBlock::Create());
Chris Lattnerda138702007-07-16 21:28:45 +0000445}
Devang Patel51b09f22007-10-04 23:45:31 +0000446
Devang Patelc049e4f2007-10-08 20:57:48 +0000447/// EmitCaseStmtRange - If case statement range is not too big then
448/// add multiple cases to switch instruction, one for each value within
449/// the range. If range is too big then emit "if" condition check.
450void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S) {
Daniel Dunbar16f23572008-07-25 01:11:38 +0000451 // XXX kill me with param - ddunbar
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000452 assert(S.getRHS() && "Expected RHS value in CaseStmt");
Devang Patelc049e4f2007-10-08 20:57:48 +0000453
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000454 llvm::APSInt LHS = S.getLHS()->getIntegerConstantExprValue(getContext());
455 llvm::APSInt RHS = S.getRHS()->getIntegerConstantExprValue(getContext());
456
Daniel Dunbar16f23572008-07-25 01:11:38 +0000457 // Emit the code for this case. We do this first to make sure it is
458 // properly chained from our predecessor before generating the
459 // switch machinery to enter this block.
460 StartBlock("sw.bb");
461 llvm::BasicBlock *CaseDest = Builder.GetInsertBlock();
462 EmitStmt(S.getSubStmt());
463
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000464 // If range is empty, do nothing.
465 if (LHS.isSigned() ? RHS.slt(LHS) : RHS.ult(LHS))
466 return;
Devang Patelc049e4f2007-10-08 20:57:48 +0000467
468 llvm::APInt Range = RHS - LHS;
Daniel Dunbar16f23572008-07-25 01:11:38 +0000469 // FIXME: parameters such as this should not be hardcoded.
Devang Patelc049e4f2007-10-08 20:57:48 +0000470 if (Range.ult(llvm::APInt(Range.getBitWidth(), 64))) {
471 // Range is small enough to add multiple switch instruction cases.
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000472 for (unsigned i = 0, e = Range.getZExtValue() + 1; i != e; ++i) {
Devang Patel2d79d0f2007-10-05 20:54:07 +0000473 SwitchInsn->addCase(llvm::ConstantInt::get(LHS), CaseDest);
474 LHS++;
475 }
Devang Patelc049e4f2007-10-08 20:57:48 +0000476 return;
477 }
478
Daniel Dunbar16f23572008-07-25 01:11:38 +0000479 // The range is too big. Emit "if" condition into a new block,
480 // making sure to save and restore the current insertion point.
481 llvm::BasicBlock *RestoreBB = Builder.GetInsertBlock();
Devang Patel2d79d0f2007-10-05 20:54:07 +0000482
Daniel Dunbar16f23572008-07-25 01:11:38 +0000483 // Push this test onto the chain of range checks (which terminates
484 // in the default basic block). The switch's default will be changed
485 // to the top of this chain after switch emission is complete.
486 llvm::BasicBlock *FalseDest = CaseRangeBlock;
487 CaseRangeBlock = llvm::BasicBlock::Create("sw.caserange");
Devang Patelc049e4f2007-10-08 20:57:48 +0000488
Daniel Dunbar16f23572008-07-25 01:11:38 +0000489 CurFn->getBasicBlockList().push_back(CaseRangeBlock);
490 Builder.SetInsertPoint(CaseRangeBlock);
Devang Patelc049e4f2007-10-08 20:57:48 +0000491
492 // Emit range check.
493 llvm::Value *Diff =
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000494 Builder.CreateSub(SwitchInsn->getCondition(), llvm::ConstantInt::get(LHS),
495 "tmp");
Devang Patelc049e4f2007-10-08 20:57:48 +0000496 llvm::Value *Cond =
497 Builder.CreateICmpULE(Diff, llvm::ConstantInt::get(Range), "tmp");
498 Builder.CreateCondBr(Cond, CaseDest, FalseDest);
499
Daniel Dunbar16f23572008-07-25 01:11:38 +0000500 // Restore the appropriate insertion point.
501 Builder.SetInsertPoint(RestoreBB);
Devang Patelc049e4f2007-10-08 20:57:48 +0000502}
503
504void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) {
505 if (S.getRHS()) {
506 EmitCaseStmtRange(S);
507 return;
508 }
509
510 StartBlock("sw.bb");
511 llvm::BasicBlock *CaseDest = Builder.GetInsertBlock();
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000512 llvm::APSInt CaseVal = S.getLHS()->getIntegerConstantExprValue(getContext());
513 SwitchInsn->addCase(llvm::ConstantInt::get(CaseVal),
514 CaseDest);
Devang Patel51b09f22007-10-04 23:45:31 +0000515 EmitStmt(S.getSubStmt());
516}
517
518void CodeGenFunction::EmitDefaultStmt(const DefaultStmt &S) {
Daniel Dunbar16f23572008-07-25 01:11:38 +0000519 llvm::BasicBlock *DefaultBlock = SwitchInsn->getDefaultDest();
520 assert(DefaultBlock->empty() && "EmitDefaultStmt: Default block already defined?");
521 EmitBlock(DefaultBlock);
Devang Patel51b09f22007-10-04 23:45:31 +0000522 EmitStmt(S.getSubStmt());
523}
524
525void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
526 llvm::Value *CondV = EmitScalarExpr(S.getCond());
527
528 // Handle nested switch statements.
529 llvm::SwitchInst *SavedSwitchInsn = SwitchInsn;
Devang Patelc049e4f2007-10-08 20:57:48 +0000530 llvm::BasicBlock *SavedCRBlock = CaseRangeBlock;
Devang Patel51b09f22007-10-04 23:45:31 +0000531
Daniel Dunbar16f23572008-07-25 01:11:38 +0000532 // Create basic block to hold stuff that comes after switch
533 // statement. We also need to create a default block now so that
534 // explicit case ranges tests can have a place to jump to on
535 // failure.
536 llvm::BasicBlock *NextBlock = llvm::BasicBlock::Create("sw.epilog");
537 llvm::BasicBlock *DefaultBlock = llvm::BasicBlock::Create("sw.default");
538 SwitchInsn = Builder.CreateSwitch(CondV, DefaultBlock);
539 CaseRangeBlock = DefaultBlock;
Devang Patel51b09f22007-10-04 23:45:31 +0000540
Eli Friedmand28a80d2008-05-12 16:08:04 +0000541 // Create basic block for body of switch
Daniel Dunbar16f23572008-07-25 01:11:38 +0000542 StartBlock("sw.body");
Eli Friedmand28a80d2008-05-12 16:08:04 +0000543
Devang Patele9b8c0a2007-10-30 20:59:40 +0000544 // All break statements jump to NextBlock. If BreakContinueStack is non empty
545 // then reuse last ContinueBlock.
Devang Patel51b09f22007-10-04 23:45:31 +0000546 llvm::BasicBlock *ContinueBlock = NULL;
547 if (!BreakContinueStack.empty())
548 ContinueBlock = BreakContinueStack.back().ContinueBlock;
549 BreakContinueStack.push_back(BreakContinue(NextBlock, ContinueBlock));
550
551 // Emit switch body.
552 EmitStmt(S.getBody());
553 BreakContinueStack.pop_back();
554
Daniel Dunbar16f23572008-07-25 01:11:38 +0000555 // Update the default block in case explicit case range tests have
556 // been chained on top.
557 SwitchInsn->setSuccessor(0, CaseRangeBlock);
Devang Patelc049e4f2007-10-08 20:57:48 +0000558
Daniel Dunbar16f23572008-07-25 01:11:38 +0000559 // If a default was never emitted then reroute any jumps to it and
560 // discard.
561 if (!DefaultBlock->getParent()) {
562 DefaultBlock->replaceAllUsesWith(NextBlock);
563 delete DefaultBlock;
564 }
Devang Patel51b09f22007-10-04 23:45:31 +0000565
Daniel Dunbar16f23572008-07-25 01:11:38 +0000566 // Emit continuation.
567 EmitBlock(NextBlock);
568
Devang Patel51b09f22007-10-04 23:45:31 +0000569 SwitchInsn = SavedSwitchInsn;
Devang Patelc049e4f2007-10-08 20:57:48 +0000570 CaseRangeBlock = SavedCRBlock;
Devang Patel51b09f22007-10-04 23:45:31 +0000571}
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000572
Chris Lattner345f7202008-07-26 20:15:14 +0000573static std::string ConvertAsmString(const char *Start, unsigned NumOperands,
574 bool IsSimple) {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000575 static unsigned AsmCounter = 0;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000576 AsmCounter++;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000577 std::string Result;
Anders Carlsson2abd25f2008-02-05 23:18:57 +0000578 if (IsSimple) {
579 while (*Start) {
580 switch (*Start) {
581 default:
582 Result += *Start;
583 break;
584 case '$':
585 Result += "$$";
586 break;
587 }
Anders Carlsson2abd25f2008-02-05 23:18:57 +0000588 Start++;
589 }
590
591 return Result;
592 }
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000593
594 while (*Start) {
595 switch (*Start) {
596 default:
597 Result += *Start;
598 break;
599 case '$':
600 Result += "$$";
601 break;
602 case '%':
603 // Escaped character
604 Start++;
605 if (!*Start) {
606 // FIXME: This should be caught during Sema.
607 assert(0 && "Trailing '%' in asm string.");
608 }
609
610 char EscapedChar = *Start;
611 if (EscapedChar == '%') {
612 // Escaped percentage sign.
613 Result += '%';
Chris Lattner345f7202008-07-26 20:15:14 +0000614 } else if (EscapedChar == '=') {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000615 // Generate an unique ID.
616 Result += llvm::utostr(AsmCounter);
617 } else if (isdigit(EscapedChar)) {
618 // %n - Assembler operand n
619 char *End;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000620 unsigned long n = strtoul(Start, &End, 10);
621 if (Start == End) {
622 // FIXME: This should be caught during Sema.
623 assert(0 && "Missing operand!");
624 } else if (n >= NumOperands) {
625 // FIXME: This should be caught during Sema.
626 assert(0 && "Operand number out of range!");
627 }
628
629 Result += '$' + llvm::utostr(n);
Lauro Ramos Venancio7695f702008-02-26 19:19:58 +0000630 Start = End - 1;
Anders Carlsson2abd25f2008-02-05 23:18:57 +0000631 } else if (isalpha(EscapedChar)) {
632 char *End;
633
634 unsigned long n = strtoul(Start + 1, &End, 10);
635 if (Start == End) {
636 // FIXME: This should be caught during Sema.
637 assert(0 && "Missing operand!");
638 } else if (n >= NumOperands) {
639 // FIXME: This should be caught during Sema.
640 assert(0 && "Operand number out of range!");
641 }
642
643 Result += "${" + llvm::utostr(n) + ':' + EscapedChar + '}';
Lauro Ramos Venancio7695f702008-02-26 19:19:58 +0000644 Start = End - 1;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000645 } else {
646 assert(0 && "Unhandled asm escaped character!");
647 }
648 }
649 Start++;
650 }
651
652 return Result;
653}
654
Lauro Ramos Venancioa5694b82008-02-26 18:33:46 +0000655static std::string SimplifyConstraint(const char* Constraint,
656 TargetInfo &Target) {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000657 std::string Result;
658
659 while (*Constraint) {
660 switch (*Constraint) {
661 default:
Lauro Ramos Venancioa5694b82008-02-26 18:33:46 +0000662 Result += Target.convertConstraint(*Constraint);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000663 break;
664 // Ignore these
665 case '*':
666 case '?':
667 case '!':
668 break;
669 case 'g':
670 Result += "imr";
671 break;
672 }
673
674 Constraint++;
675 }
676
677 return Result;
678}
679
680void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
681 std::string AsmString =
682 ConvertAsmString(std::string(S.getAsmString()->getStrData(),
683 S.getAsmString()->getByteLength()).c_str(),
Anders Carlsson2abd25f2008-02-05 23:18:57 +0000684 S.getNumOutputs() + S.getNumInputs(), S.isSimple());
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000685
686 std::string Constraints;
687
688 llvm::Value *ResultAddr = 0;
689 const llvm::Type *ResultType = llvm::Type::VoidTy;
690
691 std::vector<const llvm::Type*> ArgTypes;
692 std::vector<llvm::Value*> Args;
Anders Carlssonf39a4212008-02-05 20:01:53 +0000693
694 // Keep track of inout constraints.
695 std::string InOutConstraints;
696 std::vector<llvm::Value*> InOutArgs;
697 std::vector<const llvm::Type*> InOutArgTypes;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000698
699 for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) {
700 std::string OutputConstraint(S.getOutputConstraint(i)->getStrData(),
701 S.getOutputConstraint(i)->getByteLength());
702
703 TargetInfo::ConstraintInfo Info;
704 bool result = Target.validateOutputConstraint(OutputConstraint.c_str(),
705 Info);
706 assert(result && "Failed to parse output constraint");
707
708 // Simplify the output constraint.
Lauro Ramos Venancioa5694b82008-02-26 18:33:46 +0000709 OutputConstraint = SimplifyConstraint(OutputConstraint.c_str() + 1, Target);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000710
711 LValue Dest = EmitLValue(S.getOutputExpr(i));
712 const llvm::Type *DestValueType =
713 cast<llvm::PointerType>(Dest.getAddress()->getType())->getElementType();
714
715 // If the first output operand is not a memory dest, we'll
716 // make it the return value.
717 if (i == 0 && !(Info & TargetInfo::CI_AllowsMemory) &&
Dan Gohmand79a7262008-05-22 22:12:56 +0000718 DestValueType->isSingleValueType()) {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000719 ResultAddr = Dest.getAddress();
720 ResultType = DestValueType;
721 Constraints += "=" + OutputConstraint;
722 } else {
723 ArgTypes.push_back(Dest.getAddress()->getType());
Anders Carlssoncad3ab62008-02-05 16:57:38 +0000724 Args.push_back(Dest.getAddress());
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000725 if (i != 0)
726 Constraints += ',';
Anders Carlssonf39a4212008-02-05 20:01:53 +0000727 Constraints += "=*";
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000728 Constraints += OutputConstraint;
Anders Carlssonf39a4212008-02-05 20:01:53 +0000729 }
730
731 if (Info & TargetInfo::CI_ReadWrite) {
732 // FIXME: This code should be shared with the code that handles inputs.
733 InOutConstraints += ',';
734
735 const Expr *InputExpr = S.getOutputExpr(i);
736 llvm::Value *Arg;
737 if ((Info & TargetInfo::CI_AllowsRegister) ||
738 !(Info & TargetInfo::CI_AllowsMemory)) {
Dan Gohmand79a7262008-05-22 22:12:56 +0000739 if (ConvertType(InputExpr->getType())->isSingleValueType()) {
Anders Carlssonf39a4212008-02-05 20:01:53 +0000740 Arg = EmitScalarExpr(InputExpr);
741 } else {
Dan Gohmand79a7262008-05-22 22:12:56 +0000742 assert(0 && "FIXME: Implement passing multiple-value types as inputs");
Anders Carlssonf39a4212008-02-05 20:01:53 +0000743 }
744 } else {
745 LValue Dest = EmitLValue(InputExpr);
746 Arg = Dest.getAddress();
747 InOutConstraints += '*';
748 }
749
750 InOutArgTypes.push_back(Arg->getType());
751 InOutArgs.push_back(Arg);
752 InOutConstraints += OutputConstraint;
753 }
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000754 }
755
756 unsigned NumConstraints = S.getNumOutputs() + S.getNumInputs();
757
758 for (unsigned i = 0, e = S.getNumInputs(); i != e; i++) {
759 const Expr *InputExpr = S.getInputExpr(i);
760
761 std::string InputConstraint(S.getInputConstraint(i)->getStrData(),
762 S.getInputConstraint(i)->getByteLength());
763
764 TargetInfo::ConstraintInfo Info;
765 bool result = Target.validateInputConstraint(InputConstraint.c_str(),
766 NumConstraints,
767 Info);
768 assert(result && "Failed to parse input constraint");
769
770 if (i != 0 || S.getNumOutputs() > 0)
771 Constraints += ',';
772
773 // Simplify the input constraint.
Lauro Ramos Venancioa5694b82008-02-26 18:33:46 +0000774 InputConstraint = SimplifyConstraint(InputConstraint.c_str(), Target);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000775
776 llvm::Value *Arg;
777
778 if ((Info & TargetInfo::CI_AllowsRegister) ||
779 !(Info & TargetInfo::CI_AllowsMemory)) {
Dan Gohmand79a7262008-05-22 22:12:56 +0000780 if (ConvertType(InputExpr->getType())->isSingleValueType()) {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000781 Arg = EmitScalarExpr(InputExpr);
782 } else {
Dan Gohmand79a7262008-05-22 22:12:56 +0000783 assert(0 && "FIXME: Implement passing multiple-value types as inputs");
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000784 }
785 } else {
786 LValue Dest = EmitLValue(InputExpr);
787 Arg = Dest.getAddress();
788 Constraints += '*';
789 }
790
791 ArgTypes.push_back(Arg->getType());
792 Args.push_back(Arg);
793 Constraints += InputConstraint;
794 }
795
Anders Carlssonf39a4212008-02-05 20:01:53 +0000796 // Append the "input" part of inout constraints last.
797 for (unsigned i = 0, e = InOutArgs.size(); i != e; i++) {
798 ArgTypes.push_back(InOutArgTypes[i]);
799 Args.push_back(InOutArgs[i]);
800 }
801 Constraints += InOutConstraints;
802
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000803 // Clobbers
804 for (unsigned i = 0, e = S.getNumClobbers(); i != e; i++) {
805 std::string Clobber(S.getClobber(i)->getStrData(),
806 S.getClobber(i)->getByteLength());
807
808 Clobber = Target.getNormalizedGCCRegisterName(Clobber.c_str());
809
Anders Carlssonea041752008-02-06 00:11:32 +0000810 if (i != 0 || NumConstraints != 0)
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000811 Constraints += ',';
Anders Carlssonea041752008-02-06 00:11:32 +0000812
813 Constraints += "~{";
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000814 Constraints += Clobber;
Anders Carlssonea041752008-02-06 00:11:32 +0000815 Constraints += '}';
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000816 }
817
818 // Add machine specific clobbers
819 if (const char *C = Target.getClobbers()) {
820 if (!Constraints.empty())
821 Constraints += ',';
822 Constraints += C;
823 }
Anders Carlssonf39a4212008-02-05 20:01:53 +0000824
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000825 const llvm::FunctionType *FTy =
826 llvm::FunctionType::get(ResultType, ArgTypes, false);
827
828 llvm::InlineAsm *IA =
829 llvm::InlineAsm::get(FTy, AsmString, Constraints,
830 S.isVolatile() || S.getNumOutputs() == 0);
831 llvm::Value *Result = Builder.CreateCall(IA, Args.begin(), Args.end(), "");
Eli Friedman1e692ac2008-06-13 23:01:12 +0000832 if (ResultAddr) // FIXME: volatility
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000833 Builder.CreateStore(Result, ResultAddr);
834}