blob: 0246ba2ee8ca61d50a7e204c1bbfb2690400f971 [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"
Daniel Dunbarde7fb842008-08-11 05:00:27 +000017#include "clang/AST/ASTContext.h"
18#include "clang/AST/StmtVisitor.h"
Anders Carlssonfb1aeb82008-02-05 16:35:33 +000019#include "clang/Basic/TargetInfo.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020#include "llvm/Constants.h"
21#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
Anders Carlssonfb1aeb82008-02-05 16:35:33 +000023#include "llvm/InlineAsm.h"
24#include "llvm/ADT/StringExtras.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000025using namespace clang;
26using namespace CodeGen;
27
28//===----------------------------------------------------------------------===//
29// Statement Emission
30//===----------------------------------------------------------------------===//
31
32void CodeGenFunction::EmitStmt(const Stmt *S) {
33 assert(S && "Null statement?");
34
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000035 // Generate stoppoints if we are emitting debug info.
36 // Beginning of a Compound Statement (e.g. an opening '{') does not produce
37 // executable code. So do not generate a stoppoint for that.
38 CGDebugInfo *DI = CGM.getDebugInfo();
39 if (DI && S->getStmtClass() != Stmt::CompoundStmtClass) {
40 if (S->getLocStart().isValid()) {
41 DI->setLocation(S->getLocStart());
42 }
43
44 DI->EmitStopPoint(CurFn, Builder);
45 }
46
Reid Spencer5f016e22007-07-11 17:01:13 +000047 switch (S->getStmtClass()) {
48 default:
Chris Lattner1e4d21e2007-08-26 22:58:05 +000049 // Must be an expression in a stmt context. Emit the value (to get
50 // side-effects) and ignore the result.
Reid Spencer5f016e22007-07-11 17:01:13 +000051 if (const Expr *E = dyn_cast<Expr>(S)) {
Chris Lattner1e4d21e2007-08-26 22:58:05 +000052 if (!hasAggregateLLVMType(E->getType()))
53 EmitScalarExpr(E);
Chris Lattner9b2dc282008-04-04 16:54:41 +000054 else if (E->getType()->isAnyComplexType())
Chris Lattner1e4d21e2007-08-26 22:58:05 +000055 EmitComplexExpr(E);
56 else
57 EmitAggExpr(E, 0, false);
Reid Spencer5f016e22007-07-11 17:01:13 +000058 } else {
Chris Lattnerdc4d2802007-12-02 01:49:16 +000059 WarnUnsupported(S, "statement");
Reid Spencer5f016e22007-07-11 17:01:13 +000060 }
61 break;
62 case Stmt::NullStmtClass: break;
63 case Stmt::CompoundStmtClass: EmitCompoundStmt(cast<CompoundStmt>(*S)); break;
64 case Stmt::LabelStmtClass: EmitLabelStmt(cast<LabelStmt>(*S)); break;
65 case Stmt::GotoStmtClass: EmitGotoStmt(cast<GotoStmt>(*S)); break;
Daniel Dunbar0ffb1252008-08-04 16:51:22 +000066 case Stmt::IndirectGotoStmtClass:
67 EmitIndirectGotoStmt(cast<IndirectGotoStmt>(*S)); break;
Reid Spencer5f016e22007-07-11 17:01:13 +000068
69 case Stmt::IfStmtClass: EmitIfStmt(cast<IfStmt>(*S)); break;
70 case Stmt::WhileStmtClass: EmitWhileStmt(cast<WhileStmt>(*S)); break;
71 case Stmt::DoStmtClass: EmitDoStmt(cast<DoStmt>(*S)); break;
72 case Stmt::ForStmtClass: EmitForStmt(cast<ForStmt>(*S)); break;
73
74 case Stmt::ReturnStmtClass: EmitReturnStmt(cast<ReturnStmt>(*S)); break;
75 case Stmt::DeclStmtClass: EmitDeclStmt(cast<DeclStmt>(*S)); break;
Chris Lattnerda138702007-07-16 21:28:45 +000076
77 case Stmt::BreakStmtClass: EmitBreakStmt(); break;
78 case Stmt::ContinueStmtClass: EmitContinueStmt(); break;
Devang Patel51b09f22007-10-04 23:45:31 +000079 case Stmt::SwitchStmtClass: EmitSwitchStmt(cast<SwitchStmt>(*S)); break;
80 case Stmt::DefaultStmtClass: EmitDefaultStmt(cast<DefaultStmt>(*S)); break;
81 case Stmt::CaseStmtClass: EmitCaseStmt(cast<CaseStmt>(*S)); break;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +000082 case Stmt::AsmStmtClass: EmitAsmStmt(cast<AsmStmt>(*S)); break;
Reid Spencer5f016e22007-07-11 17:01:13 +000083 }
84}
85
Chris Lattner33793202007-08-31 22:09:40 +000086/// EmitCompoundStmt - Emit a compound statement {..} node. If GetLast is true,
87/// this captures the expression result of the last sub-statement and returns it
88/// (for use by the statement expression extension).
Chris Lattner9b655512007-08-31 22:49:20 +000089RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
90 llvm::Value *AggLoc, bool isAggVol) {
Reid Spencer5f016e22007-07-11 17:01:13 +000091 // FIXME: handle vla's etc.
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000092 CGDebugInfo *DI = CGM.getDebugInfo();
93 if (DI) {
Chris Lattner345f7202008-07-26 20:15:14 +000094 if (S.getLBracLoc().isValid())
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000095 DI->setLocation(S.getLBracLoc());
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000096 DI->EmitRegionStart(CurFn, Builder);
97 }
98
Chris Lattner33793202007-08-31 22:09:40 +000099 for (CompoundStmt::const_body_iterator I = S.body_begin(),
100 E = S.body_end()-GetLast; I != E; ++I)
Reid Spencer5f016e22007-07-11 17:01:13 +0000101 EmitStmt(*I);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000102
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000103 if (DI) {
Chris Lattner345f7202008-07-26 20:15:14 +0000104 if (S.getRBracLoc().isValid())
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000105 DI->setLocation(S.getRBracLoc());
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000106 DI->EmitRegionEnd(CurFn, Builder);
107 }
108
Chris Lattner33793202007-08-31 22:09:40 +0000109 if (!GetLast)
110 return RValue::get(0);
Chris Lattner9b655512007-08-31 22:49:20 +0000111
Chris Lattner91d723d2008-07-26 20:23:23 +0000112 // We have to special case labels here. They are statements, but when put at
113 // the end of a statement expression, they yield the value of their
114 // subexpression. Handle this by walking through all labels we encounter,
115 // emitting them before we evaluate the subexpr.
116 const Stmt *LastStmt = S.body_back();
117 while (const LabelStmt *LS = dyn_cast<LabelStmt>(LastStmt)) {
118 EmitLabel(*LS);
119 LastStmt = LS->getSubStmt();
120 }
121
122 return EmitAnyExpr(cast<Expr>(LastStmt), AggLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +0000123}
124
125void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB) {
126 // Emit a branch from this block to the next one if this was a real block. If
127 // this was just a fall-through block after a terminator, don't emit it.
128 llvm::BasicBlock *LastBB = Builder.GetInsertBlock();
129
130 if (LastBB->getTerminator()) {
131 // If the previous block is already terminated, don't touch it.
Daniel Dunbar16f23572008-07-25 01:11:38 +0000132 } else if (LastBB->empty() && isDummyBlock(LastBB)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000133 // If the last block was an empty placeholder, remove it now.
134 // TODO: cache and reuse these.
Daniel Dunbar16f23572008-07-25 01:11:38 +0000135 LastBB->eraseFromParent();
Reid Spencer5f016e22007-07-11 17:01:13 +0000136 } else {
137 // Otherwise, create a fall-through branch.
138 Builder.CreateBr(BB);
139 }
140 CurFn->getBasicBlockList().push_back(BB);
141 Builder.SetInsertPoint(BB);
142}
143
Chris Lattner91d723d2008-07-26 20:23:23 +0000144void CodeGenFunction::EmitLabel(const LabelStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000145 llvm::BasicBlock *NextBB = getBasicBlockForLabel(&S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000146 EmitBlock(NextBB);
Chris Lattner91d723d2008-07-26 20:23:23 +0000147}
148
149
150void CodeGenFunction::EmitLabelStmt(const LabelStmt &S) {
151 EmitLabel(S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000152 EmitStmt(S.getSubStmt());
153}
154
155void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) {
156 Builder.CreateBr(getBasicBlockForLabel(S.getLabel()));
157
158 // Emit a block after the branch so that dead code after a goto has some place
159 // to go.
Gabor Greif984d0b42008-04-06 20:42:52 +0000160 Builder.SetInsertPoint(llvm::BasicBlock::Create("", CurFn));
Reid Spencer5f016e22007-07-11 17:01:13 +0000161}
162
Daniel Dunbar0ffb1252008-08-04 16:51:22 +0000163void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) {
164 // Emit initial switch which will be patched up later by
165 // EmitIndirectSwitches(). We need a default dest, so we use the
166 // current BB, but this is overwritten.
167 llvm::Value *V = Builder.CreatePtrToInt(EmitScalarExpr(S.getTarget()),
168 llvm::Type::Int32Ty,
169 "addr");
170 llvm::SwitchInst *I = Builder.CreateSwitch(V, Builder.GetInsertBlock());
171 IndirectSwitches.push_back(I);
172
173 // Emit a block after the branch so that dead code after a goto has some place
174 // to go.
175 Builder.SetInsertPoint(llvm::BasicBlock::Create("", CurFn));
176}
177
Reid Spencer5f016e22007-07-11 17:01:13 +0000178void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
Daniel Dunbar0ffb1252008-08-04 16:51:22 +0000179 // FIXME: It would probably be nice for us to skip emission of if
180 // (0) code here.
181
Reid Spencer5f016e22007-07-11 17:01:13 +0000182 // C99 6.8.4.1: The first substatement is executed if the expression compares
183 // unequal to 0. The condition must be a scalar type.
184 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
185
Gabor Greif984d0b42008-04-06 20:42:52 +0000186 llvm::BasicBlock *ContBlock = llvm::BasicBlock::Create("ifend");
187 llvm::BasicBlock *ThenBlock = llvm::BasicBlock::Create("ifthen");
Reid Spencer5f016e22007-07-11 17:01:13 +0000188 llvm::BasicBlock *ElseBlock = ContBlock;
189
190 if (S.getElse())
Gabor Greif984d0b42008-04-06 20:42:52 +0000191 ElseBlock = llvm::BasicBlock::Create("ifelse");
Reid Spencer5f016e22007-07-11 17:01:13 +0000192
193 // Insert the conditional branch.
194 Builder.CreateCondBr(BoolCondVal, ThenBlock, ElseBlock);
195
196 // Emit the 'then' code.
197 EmitBlock(ThenBlock);
198 EmitStmt(S.getThen());
Devang Pateld9363c32007-09-28 21:49:18 +0000199 llvm::BasicBlock *BB = Builder.GetInsertBlock();
200 if (isDummyBlock(BB)) {
201 BB->eraseFromParent();
202 Builder.SetInsertPoint(ThenBlock);
Chris Lattner345f7202008-07-26 20:15:14 +0000203 } else {
Devang Pateld9363c32007-09-28 21:49:18 +0000204 Builder.CreateBr(ContBlock);
Chris Lattner345f7202008-07-26 20:15:14 +0000205 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000206
207 // Emit the 'else' code if present.
208 if (const Stmt *Else = S.getElse()) {
209 EmitBlock(ElseBlock);
210 EmitStmt(Else);
Devang Pateld9363c32007-09-28 21:49:18 +0000211 llvm::BasicBlock *BB = Builder.GetInsertBlock();
212 if (isDummyBlock(BB)) {
213 BB->eraseFromParent();
214 Builder.SetInsertPoint(ElseBlock);
Chris Lattner345f7202008-07-26 20:15:14 +0000215 } else {
Devang Pateld9363c32007-09-28 21:49:18 +0000216 Builder.CreateBr(ContBlock);
Chris Lattner345f7202008-07-26 20:15:14 +0000217 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000218 }
219
220 // Emit the continuation block for code after the if.
221 EmitBlock(ContBlock);
222}
223
224void CodeGenFunction::EmitWhileStmt(const WhileStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000225 // Emit the header for the loop, insert it, which will create an uncond br to
226 // it.
Gabor Greif984d0b42008-04-06 20:42:52 +0000227 llvm::BasicBlock *LoopHeader = llvm::BasicBlock::Create("whilecond");
Reid Spencer5f016e22007-07-11 17:01:13 +0000228 EmitBlock(LoopHeader);
229
230 // Evaluate the conditional in the while header. C99 6.8.5.1: The evaluation
231 // of the controlling expression takes place before each execution of the loop
232 // body.
233 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
Devang Patel2c30d8f2007-10-09 20:51:27 +0000234
235 // while(1) is common, avoid extra exit blocks. Be sure
Reid Spencer5f016e22007-07-11 17:01:13 +0000236 // to correctly handle break/continue though.
Devang Patel2c30d8f2007-10-09 20:51:27 +0000237 bool EmitBoolCondBranch = true;
238 if (llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal))
239 if (C->isOne())
240 EmitBoolCondBranch = false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000241
242 // Create an exit block for when the condition fails, create a block for the
243 // body of the loop.
Gabor Greif984d0b42008-04-06 20:42:52 +0000244 llvm::BasicBlock *ExitBlock = llvm::BasicBlock::Create("whileexit");
245 llvm::BasicBlock *LoopBody = llvm::BasicBlock::Create("whilebody");
Reid Spencer5f016e22007-07-11 17:01:13 +0000246
247 // As long as the condition is true, go to the loop body.
Devang Patel2c30d8f2007-10-09 20:51:27 +0000248 if (EmitBoolCondBranch)
249 Builder.CreateCondBr(BoolCondVal, LoopBody, ExitBlock);
Chris Lattnerda138702007-07-16 21:28:45 +0000250
251 // Store the blocks to use for break and continue.
252 BreakContinueStack.push_back(BreakContinue(ExitBlock, LoopHeader));
Reid Spencer5f016e22007-07-11 17:01:13 +0000253
254 // Emit the loop body.
255 EmitBlock(LoopBody);
256 EmitStmt(S.getBody());
Chris Lattnerda138702007-07-16 21:28:45 +0000257
258 BreakContinueStack.pop_back();
Reid Spencer5f016e22007-07-11 17:01:13 +0000259
260 // Cycle to the condition.
261 Builder.CreateBr(LoopHeader);
262
263 // Emit the exit block.
264 EmitBlock(ExitBlock);
Devang Patel2c30d8f2007-10-09 20:51:27 +0000265
266 // If LoopHeader is a simple forwarding block then eliminate it.
267 if (!EmitBoolCondBranch
268 && &LoopHeader->front() == LoopHeader->getTerminator()) {
269 LoopHeader->replaceAllUsesWith(LoopBody);
270 LoopHeader->getTerminator()->eraseFromParent();
271 LoopHeader->eraseFromParent();
272 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000273}
274
275void CodeGenFunction::EmitDoStmt(const DoStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000276 // Emit the body for the loop, insert it, which will create an uncond br to
277 // it.
Gabor Greif984d0b42008-04-06 20:42:52 +0000278 llvm::BasicBlock *LoopBody = llvm::BasicBlock::Create("dobody");
279 llvm::BasicBlock *AfterDo = llvm::BasicBlock::Create("afterdo");
Reid Spencer5f016e22007-07-11 17:01:13 +0000280 EmitBlock(LoopBody);
Chris Lattnerda138702007-07-16 21:28:45 +0000281
Gabor Greif984d0b42008-04-06 20:42:52 +0000282 llvm::BasicBlock *DoCond = llvm::BasicBlock::Create("docond");
Chris Lattnerda138702007-07-16 21:28:45 +0000283
284 // Store the blocks to use for break and continue.
285 BreakContinueStack.push_back(BreakContinue(AfterDo, DoCond));
Reid Spencer5f016e22007-07-11 17:01:13 +0000286
287 // Emit the body of the loop into the block.
288 EmitStmt(S.getBody());
289
Chris Lattnerda138702007-07-16 21:28:45 +0000290 BreakContinueStack.pop_back();
291
292 EmitBlock(DoCond);
293
Reid Spencer5f016e22007-07-11 17:01:13 +0000294 // C99 6.8.5.2: "The evaluation of the controlling expression takes place
295 // after each execution of the loop body."
296
297 // Evaluate the conditional in the while header.
298 // C99 6.8.5p2/p4: The first substatement is executed if the expression
299 // compares unequal to 0. The condition must be a scalar type.
300 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
Devang Patel05f6e6b2007-10-09 20:33:39 +0000301
302 // "do {} while (0)" is common in macros, avoid extra blocks. Be sure
303 // to correctly handle break/continue though.
304 bool EmitBoolCondBranch = true;
305 if (llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal))
306 if (C->isZero())
307 EmitBoolCondBranch = false;
308
Reid Spencer5f016e22007-07-11 17:01:13 +0000309 // As long as the condition is true, iterate the loop.
Devang Patel05f6e6b2007-10-09 20:33:39 +0000310 if (EmitBoolCondBranch)
311 Builder.CreateCondBr(BoolCondVal, LoopBody, AfterDo);
Reid Spencer5f016e22007-07-11 17:01:13 +0000312
313 // Emit the exit block.
314 EmitBlock(AfterDo);
Devang Patel05f6e6b2007-10-09 20:33:39 +0000315
316 // If DoCond is a simple forwarding block then eliminate it.
317 if (!EmitBoolCondBranch && &DoCond->front() == DoCond->getTerminator()) {
318 DoCond->replaceAllUsesWith(AfterDo);
319 DoCond->getTerminator()->eraseFromParent();
320 DoCond->eraseFromParent();
321 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000322}
323
324void CodeGenFunction::EmitForStmt(const ForStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000325 // FIXME: What do we do if the increment (f.e.) contains a stmt expression,
326 // which contains a continue/break?
Chris Lattnerda138702007-07-16 21:28:45 +0000327 // TODO: We could keep track of whether the loop body contains any
328 // break/continue statements and not create unnecessary blocks (like
329 // "afterfor" for a condless loop) if it doesn't.
330
Reid Spencer5f016e22007-07-11 17:01:13 +0000331 // Evaluate the first part before the loop.
332 if (S.getInit())
333 EmitStmt(S.getInit());
334
335 // Start the loop with a block that tests the condition.
Gabor Greif984d0b42008-04-06 20:42:52 +0000336 llvm::BasicBlock *CondBlock = llvm::BasicBlock::Create("forcond");
337 llvm::BasicBlock *AfterFor = llvm::BasicBlock::Create("afterfor");
Chris Lattnerda138702007-07-16 21:28:45 +0000338
Reid Spencer5f016e22007-07-11 17:01:13 +0000339 EmitBlock(CondBlock);
340
341 // Evaluate the condition if present. If not, treat it as a non-zero-constant
342 // according to 6.8.5.3p2, aka, true.
343 if (S.getCond()) {
344 // C99 6.8.5p2/p4: The first substatement is executed if the expression
345 // compares unequal to 0. The condition must be a scalar type.
346 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
347
348 // As long as the condition is true, iterate the loop.
Gabor Greif984d0b42008-04-06 20:42:52 +0000349 llvm::BasicBlock *ForBody = llvm::BasicBlock::Create("forbody");
Reid Spencer5f016e22007-07-11 17:01:13 +0000350 Builder.CreateCondBr(BoolCondVal, ForBody, AfterFor);
351 EmitBlock(ForBody);
352 } else {
353 // Treat it as a non-zero constant. Don't even create a new block for the
354 // body, just fall into it.
355 }
356
Chris Lattnerda138702007-07-16 21:28:45 +0000357 // If the for loop doesn't have an increment we can just use the
358 // condition as the continue block.
359 llvm::BasicBlock *ContinueBlock;
360 if (S.getInc())
Gabor Greif984d0b42008-04-06 20:42:52 +0000361 ContinueBlock = llvm::BasicBlock::Create("forinc");
Chris Lattnerda138702007-07-16 21:28:45 +0000362 else
363 ContinueBlock = CondBlock;
364
365 // Store the blocks to use for break and continue.
366 BreakContinueStack.push_back(BreakContinue(AfterFor, ContinueBlock));
367
Reid Spencer5f016e22007-07-11 17:01:13 +0000368 // If the condition is true, execute the body of the for stmt.
369 EmitStmt(S.getBody());
Chris Lattnerda138702007-07-16 21:28:45 +0000370
371 BreakContinueStack.pop_back();
372
373 if (S.getInc())
374 EmitBlock(ContinueBlock);
Reid Spencer5f016e22007-07-11 17:01:13 +0000375
376 // If there is an increment, emit it next.
377 if (S.getInc())
Chris Lattner883f6a72007-08-11 00:04:45 +0000378 EmitStmt(S.getInc());
Reid Spencer5f016e22007-07-11 17:01:13 +0000379
380 // Finally, branch back up to the condition for the next iteration.
381 Builder.CreateBr(CondBlock);
382
Chris Lattnerda138702007-07-16 21:28:45 +0000383 // Emit the fall-through block.
384 EmitBlock(AfterFor);
Reid Spencer5f016e22007-07-11 17:01:13 +0000385}
386
387/// EmitReturnStmt - Note that due to GCC extensions, this can have an operand
388/// if the function returns void, or may be missing one if the function returns
389/// non-void. Fun stuff :).
390void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000391 // Emit the result value, even if unused, to evalute the side effects.
392 const Expr *RV = S.getRetValue();
Chris Lattner4b0029d2007-08-26 07:14:44 +0000393
Eli Friedman144ac612008-05-22 01:22:33 +0000394 llvm::Value* RetValue = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000395 if (FnRetTy->isVoidType()) {
Eli Friedman144ac612008-05-22 01:22:33 +0000396 // Make sure not to return anything
397 if (RV) {
398 // Evaluate the expression for side effects
399 EmitAnyExpr(RV);
400 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000401 } else if (RV == 0) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000402 const llvm::Type *RetTy = CurFn->getFunctionType()->getReturnType();
Eli Friedman144ac612008-05-22 01:22:33 +0000403 if (RetTy != llvm::Type::VoidTy) {
404 // Handle "return;" in a function that returns a value.
405 RetValue = llvm::UndefValue::get(RetTy);
406 }
Chris Lattner4b0029d2007-08-26 07:14:44 +0000407 } else if (!hasAggregateLLVMType(RV->getType())) {
Eli Friedman144ac612008-05-22 01:22:33 +0000408 RetValue = EmitScalarExpr(RV);
Chris Lattner9b2dc282008-04-04 16:54:41 +0000409 } else if (RV->getType()->isAnyComplexType()) {
Chris Lattner345f7202008-07-26 20:15:14 +0000410 EmitComplexExprIntoAddr(RV, CurFn->arg_begin(), false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000411 } else {
Chris Lattner345f7202008-07-26 20:15:14 +0000412 EmitAggExpr(RV, CurFn->arg_begin(), false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000413 }
Eli Friedman144ac612008-05-22 01:22:33 +0000414
415 if (RetValue) {
416 Builder.CreateRet(RetValue);
417 } else {
418 Builder.CreateRetVoid();
419 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000420
421 // Emit a block after the branch so that dead code after a return has some
422 // place to go.
Gabor Greif984d0b42008-04-06 20:42:52 +0000423 EmitBlock(llvm::BasicBlock::Create());
Reid Spencer5f016e22007-07-11 17:01:13 +0000424}
425
426void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) {
Steve Naroff94745042007-09-13 23:52:58 +0000427 for (const ScopedDecl *Decl = S.getDecl(); Decl;
428 Decl = Decl->getNextDeclarator())
Reid Spencer5f016e22007-07-11 17:01:13 +0000429 EmitDecl(*Decl);
Chris Lattner6fa5f092007-07-12 15:43:07 +0000430}
Chris Lattnerda138702007-07-16 21:28:45 +0000431
432void CodeGenFunction::EmitBreakStmt() {
433 assert(!BreakContinueStack.empty() && "break stmt not in a loop or switch!");
434
435 llvm::BasicBlock *Block = BreakContinueStack.back().BreakBlock;
436 Builder.CreateBr(Block);
Gabor Greif984d0b42008-04-06 20:42:52 +0000437 EmitBlock(llvm::BasicBlock::Create());
Chris Lattnerda138702007-07-16 21:28:45 +0000438}
439
440void CodeGenFunction::EmitContinueStmt() {
441 assert(!BreakContinueStack.empty() && "continue stmt not in a loop!");
442
443 llvm::BasicBlock *Block = BreakContinueStack.back().ContinueBlock;
444 Builder.CreateBr(Block);
Gabor Greif984d0b42008-04-06 20:42:52 +0000445 EmitBlock(llvm::BasicBlock::Create());
Chris Lattnerda138702007-07-16 21:28:45 +0000446}
Devang Patel51b09f22007-10-04 23:45:31 +0000447
Devang Patelc049e4f2007-10-08 20:57:48 +0000448/// EmitCaseStmtRange - If case statement range is not too big then
449/// add multiple cases to switch instruction, one for each value within
450/// the range. If range is too big then emit "if" condition check.
451void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S) {
Daniel Dunbar16f23572008-07-25 01:11:38 +0000452 // XXX kill me with param - ddunbar
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000453 assert(S.getRHS() && "Expected RHS value in CaseStmt");
Devang Patelc049e4f2007-10-08 20:57:48 +0000454
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000455 llvm::APSInt LHS = S.getLHS()->getIntegerConstantExprValue(getContext());
456 llvm::APSInt RHS = S.getRHS()->getIntegerConstantExprValue(getContext());
457
Daniel Dunbar16f23572008-07-25 01:11:38 +0000458 // Emit the code for this case. We do this first to make sure it is
459 // properly chained from our predecessor before generating the
460 // switch machinery to enter this block.
461 StartBlock("sw.bb");
462 llvm::BasicBlock *CaseDest = Builder.GetInsertBlock();
463 EmitStmt(S.getSubStmt());
464
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000465 // If range is empty, do nothing.
466 if (LHS.isSigned() ? RHS.slt(LHS) : RHS.ult(LHS))
467 return;
Devang Patelc049e4f2007-10-08 20:57:48 +0000468
469 llvm::APInt Range = RHS - LHS;
Daniel Dunbar16f23572008-07-25 01:11:38 +0000470 // FIXME: parameters such as this should not be hardcoded.
Devang Patelc049e4f2007-10-08 20:57:48 +0000471 if (Range.ult(llvm::APInt(Range.getBitWidth(), 64))) {
472 // Range is small enough to add multiple switch instruction cases.
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000473 for (unsigned i = 0, e = Range.getZExtValue() + 1; i != e; ++i) {
Devang Patel2d79d0f2007-10-05 20:54:07 +0000474 SwitchInsn->addCase(llvm::ConstantInt::get(LHS), CaseDest);
475 LHS++;
476 }
Devang Patelc049e4f2007-10-08 20:57:48 +0000477 return;
478 }
479
Daniel Dunbar16f23572008-07-25 01:11:38 +0000480 // The range is too big. Emit "if" condition into a new block,
481 // making sure to save and restore the current insertion point.
482 llvm::BasicBlock *RestoreBB = Builder.GetInsertBlock();
Devang Patel2d79d0f2007-10-05 20:54:07 +0000483
Daniel Dunbar16f23572008-07-25 01:11:38 +0000484 // Push this test onto the chain of range checks (which terminates
485 // in the default basic block). The switch's default will be changed
486 // to the top of this chain after switch emission is complete.
487 llvm::BasicBlock *FalseDest = CaseRangeBlock;
488 CaseRangeBlock = llvm::BasicBlock::Create("sw.caserange");
Devang Patelc049e4f2007-10-08 20:57:48 +0000489
Daniel Dunbar16f23572008-07-25 01:11:38 +0000490 CurFn->getBasicBlockList().push_back(CaseRangeBlock);
491 Builder.SetInsertPoint(CaseRangeBlock);
Devang Patelc049e4f2007-10-08 20:57:48 +0000492
493 // Emit range check.
494 llvm::Value *Diff =
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000495 Builder.CreateSub(SwitchInsn->getCondition(), llvm::ConstantInt::get(LHS),
496 "tmp");
Devang Patelc049e4f2007-10-08 20:57:48 +0000497 llvm::Value *Cond =
498 Builder.CreateICmpULE(Diff, llvm::ConstantInt::get(Range), "tmp");
499 Builder.CreateCondBr(Cond, CaseDest, FalseDest);
500
Daniel Dunbar16f23572008-07-25 01:11:38 +0000501 // Restore the appropriate insertion point.
502 Builder.SetInsertPoint(RestoreBB);
Devang Patelc049e4f2007-10-08 20:57:48 +0000503}
504
505void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) {
506 if (S.getRHS()) {
507 EmitCaseStmtRange(S);
508 return;
509 }
510
511 StartBlock("sw.bb");
512 llvm::BasicBlock *CaseDest = Builder.GetInsertBlock();
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000513 llvm::APSInt CaseVal = S.getLHS()->getIntegerConstantExprValue(getContext());
514 SwitchInsn->addCase(llvm::ConstantInt::get(CaseVal),
515 CaseDest);
Devang Patel51b09f22007-10-04 23:45:31 +0000516 EmitStmt(S.getSubStmt());
517}
518
519void CodeGenFunction::EmitDefaultStmt(const DefaultStmt &S) {
Daniel Dunbar16f23572008-07-25 01:11:38 +0000520 llvm::BasicBlock *DefaultBlock = SwitchInsn->getDefaultDest();
521 assert(DefaultBlock->empty() && "EmitDefaultStmt: Default block already defined?");
522 EmitBlock(DefaultBlock);
Devang Patel51b09f22007-10-04 23:45:31 +0000523 EmitStmt(S.getSubStmt());
524}
525
526void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
527 llvm::Value *CondV = EmitScalarExpr(S.getCond());
528
529 // Handle nested switch statements.
530 llvm::SwitchInst *SavedSwitchInsn = SwitchInsn;
Devang Patelc049e4f2007-10-08 20:57:48 +0000531 llvm::BasicBlock *SavedCRBlock = CaseRangeBlock;
Devang Patel51b09f22007-10-04 23:45:31 +0000532
Daniel Dunbar16f23572008-07-25 01:11:38 +0000533 // Create basic block to hold stuff that comes after switch
534 // statement. We also need to create a default block now so that
535 // explicit case ranges tests can have a place to jump to on
536 // failure.
537 llvm::BasicBlock *NextBlock = llvm::BasicBlock::Create("sw.epilog");
538 llvm::BasicBlock *DefaultBlock = llvm::BasicBlock::Create("sw.default");
539 SwitchInsn = Builder.CreateSwitch(CondV, DefaultBlock);
540 CaseRangeBlock = DefaultBlock;
Devang Patel51b09f22007-10-04 23:45:31 +0000541
Eli Friedmand28a80d2008-05-12 16:08:04 +0000542 // Create basic block for body of switch
Daniel Dunbar16f23572008-07-25 01:11:38 +0000543 StartBlock("sw.body");
Eli Friedmand28a80d2008-05-12 16:08:04 +0000544
Devang Patele9b8c0a2007-10-30 20:59:40 +0000545 // All break statements jump to NextBlock. If BreakContinueStack is non empty
546 // then reuse last ContinueBlock.
Devang Patel51b09f22007-10-04 23:45:31 +0000547 llvm::BasicBlock *ContinueBlock = NULL;
548 if (!BreakContinueStack.empty())
549 ContinueBlock = BreakContinueStack.back().ContinueBlock;
550 BreakContinueStack.push_back(BreakContinue(NextBlock, ContinueBlock));
551
552 // Emit switch body.
553 EmitStmt(S.getBody());
554 BreakContinueStack.pop_back();
555
Daniel Dunbar16f23572008-07-25 01:11:38 +0000556 // Update the default block in case explicit case range tests have
557 // been chained on top.
558 SwitchInsn->setSuccessor(0, CaseRangeBlock);
Devang Patelc049e4f2007-10-08 20:57:48 +0000559
Daniel Dunbar16f23572008-07-25 01:11:38 +0000560 // If a default was never emitted then reroute any jumps to it and
561 // discard.
562 if (!DefaultBlock->getParent()) {
563 DefaultBlock->replaceAllUsesWith(NextBlock);
564 delete DefaultBlock;
565 }
Devang Patel51b09f22007-10-04 23:45:31 +0000566
Daniel Dunbar16f23572008-07-25 01:11:38 +0000567 // Emit continuation.
568 EmitBlock(NextBlock);
569
Devang Patel51b09f22007-10-04 23:45:31 +0000570 SwitchInsn = SavedSwitchInsn;
Devang Patelc049e4f2007-10-08 20:57:48 +0000571 CaseRangeBlock = SavedCRBlock;
Devang Patel51b09f22007-10-04 23:45:31 +0000572}
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000573
Chris Lattner345f7202008-07-26 20:15:14 +0000574static std::string ConvertAsmString(const char *Start, unsigned NumOperands,
575 bool IsSimple) {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000576 static unsigned AsmCounter = 0;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000577 AsmCounter++;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000578 std::string Result;
Anders Carlsson2abd25f2008-02-05 23:18:57 +0000579 if (IsSimple) {
580 while (*Start) {
581 switch (*Start) {
582 default:
583 Result += *Start;
584 break;
585 case '$':
586 Result += "$$";
587 break;
588 }
Anders Carlsson2abd25f2008-02-05 23:18:57 +0000589 Start++;
590 }
591
592 return Result;
593 }
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000594
595 while (*Start) {
596 switch (*Start) {
597 default:
598 Result += *Start;
599 break;
600 case '$':
601 Result += "$$";
602 break;
603 case '%':
604 // Escaped character
605 Start++;
606 if (!*Start) {
607 // FIXME: This should be caught during Sema.
608 assert(0 && "Trailing '%' in asm string.");
609 }
610
611 char EscapedChar = *Start;
612 if (EscapedChar == '%') {
613 // Escaped percentage sign.
614 Result += '%';
Chris Lattner345f7202008-07-26 20:15:14 +0000615 } else if (EscapedChar == '=') {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000616 // Generate an unique ID.
617 Result += llvm::utostr(AsmCounter);
618 } else if (isdigit(EscapedChar)) {
619 // %n - Assembler operand n
620 char *End;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000621 unsigned long n = strtoul(Start, &End, 10);
622 if (Start == End) {
623 // FIXME: This should be caught during Sema.
624 assert(0 && "Missing operand!");
625 } else if (n >= NumOperands) {
626 // FIXME: This should be caught during Sema.
627 assert(0 && "Operand number out of range!");
628 }
629
630 Result += '$' + llvm::utostr(n);
Lauro Ramos Venancio7695f702008-02-26 19:19:58 +0000631 Start = End - 1;
Anders Carlsson2abd25f2008-02-05 23:18:57 +0000632 } else if (isalpha(EscapedChar)) {
633 char *End;
634
635 unsigned long n = strtoul(Start + 1, &End, 10);
636 if (Start == End) {
637 // FIXME: This should be caught during Sema.
638 assert(0 && "Missing operand!");
639 } else if (n >= NumOperands) {
640 // FIXME: This should be caught during Sema.
641 assert(0 && "Operand number out of range!");
642 }
643
644 Result += "${" + llvm::utostr(n) + ':' + EscapedChar + '}';
Lauro Ramos Venancio7695f702008-02-26 19:19:58 +0000645 Start = End - 1;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000646 } else {
647 assert(0 && "Unhandled asm escaped character!");
648 }
649 }
650 Start++;
651 }
652
653 return Result;
654}
655
Lauro Ramos Venancioa5694b82008-02-26 18:33:46 +0000656static std::string SimplifyConstraint(const char* Constraint,
657 TargetInfo &Target) {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000658 std::string Result;
659
660 while (*Constraint) {
661 switch (*Constraint) {
662 default:
Lauro Ramos Venancioa5694b82008-02-26 18:33:46 +0000663 Result += Target.convertConstraint(*Constraint);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000664 break;
665 // Ignore these
666 case '*':
667 case '?':
668 case '!':
669 break;
670 case 'g':
671 Result += "imr";
672 break;
673 }
674
675 Constraint++;
676 }
677
678 return Result;
679}
680
681void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
682 std::string AsmString =
683 ConvertAsmString(std::string(S.getAsmString()->getStrData(),
684 S.getAsmString()->getByteLength()).c_str(),
Anders Carlsson2abd25f2008-02-05 23:18:57 +0000685 S.getNumOutputs() + S.getNumInputs(), S.isSimple());
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000686
687 std::string Constraints;
688
689 llvm::Value *ResultAddr = 0;
690 const llvm::Type *ResultType = llvm::Type::VoidTy;
691
692 std::vector<const llvm::Type*> ArgTypes;
693 std::vector<llvm::Value*> Args;
Anders Carlssonf39a4212008-02-05 20:01:53 +0000694
695 // Keep track of inout constraints.
696 std::string InOutConstraints;
697 std::vector<llvm::Value*> InOutArgs;
698 std::vector<const llvm::Type*> InOutArgTypes;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000699
700 for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) {
701 std::string OutputConstraint(S.getOutputConstraint(i)->getStrData(),
702 S.getOutputConstraint(i)->getByteLength());
703
704 TargetInfo::ConstraintInfo Info;
705 bool result = Target.validateOutputConstraint(OutputConstraint.c_str(),
706 Info);
707 assert(result && "Failed to parse output constraint");
708
709 // Simplify the output constraint.
Lauro Ramos Venancioa5694b82008-02-26 18:33:46 +0000710 OutputConstraint = SimplifyConstraint(OutputConstraint.c_str() + 1, Target);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000711
712 LValue Dest = EmitLValue(S.getOutputExpr(i));
713 const llvm::Type *DestValueType =
714 cast<llvm::PointerType>(Dest.getAddress()->getType())->getElementType();
715
716 // If the first output operand is not a memory dest, we'll
717 // make it the return value.
718 if (i == 0 && !(Info & TargetInfo::CI_AllowsMemory) &&
Dan Gohmand79a7262008-05-22 22:12:56 +0000719 DestValueType->isSingleValueType()) {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000720 ResultAddr = Dest.getAddress();
721 ResultType = DestValueType;
722 Constraints += "=" + OutputConstraint;
723 } else {
724 ArgTypes.push_back(Dest.getAddress()->getType());
Anders Carlssoncad3ab62008-02-05 16:57:38 +0000725 Args.push_back(Dest.getAddress());
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000726 if (i != 0)
727 Constraints += ',';
Anders Carlssonf39a4212008-02-05 20:01:53 +0000728 Constraints += "=*";
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000729 Constraints += OutputConstraint;
Anders Carlssonf39a4212008-02-05 20:01:53 +0000730 }
731
732 if (Info & TargetInfo::CI_ReadWrite) {
733 // FIXME: This code should be shared with the code that handles inputs.
734 InOutConstraints += ',';
735
736 const Expr *InputExpr = S.getOutputExpr(i);
737 llvm::Value *Arg;
738 if ((Info & TargetInfo::CI_AllowsRegister) ||
739 !(Info & TargetInfo::CI_AllowsMemory)) {
Dan Gohmand79a7262008-05-22 22:12:56 +0000740 if (ConvertType(InputExpr->getType())->isSingleValueType()) {
Anders Carlssonf39a4212008-02-05 20:01:53 +0000741 Arg = EmitScalarExpr(InputExpr);
742 } else {
Dan Gohmand79a7262008-05-22 22:12:56 +0000743 assert(0 && "FIXME: Implement passing multiple-value types as inputs");
Anders Carlssonf39a4212008-02-05 20:01:53 +0000744 }
745 } else {
746 LValue Dest = EmitLValue(InputExpr);
747 Arg = Dest.getAddress();
748 InOutConstraints += '*';
749 }
750
751 InOutArgTypes.push_back(Arg->getType());
752 InOutArgs.push_back(Arg);
753 InOutConstraints += OutputConstraint;
754 }
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000755 }
756
757 unsigned NumConstraints = S.getNumOutputs() + S.getNumInputs();
758
759 for (unsigned i = 0, e = S.getNumInputs(); i != e; i++) {
760 const Expr *InputExpr = S.getInputExpr(i);
761
762 std::string InputConstraint(S.getInputConstraint(i)->getStrData(),
763 S.getInputConstraint(i)->getByteLength());
764
765 TargetInfo::ConstraintInfo Info;
766 bool result = Target.validateInputConstraint(InputConstraint.c_str(),
767 NumConstraints,
768 Info);
769 assert(result && "Failed to parse input constraint");
770
771 if (i != 0 || S.getNumOutputs() > 0)
772 Constraints += ',';
773
774 // Simplify the input constraint.
Lauro Ramos Venancioa5694b82008-02-26 18:33:46 +0000775 InputConstraint = SimplifyConstraint(InputConstraint.c_str(), Target);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000776
777 llvm::Value *Arg;
778
779 if ((Info & TargetInfo::CI_AllowsRegister) ||
780 !(Info & TargetInfo::CI_AllowsMemory)) {
Dan Gohmand79a7262008-05-22 22:12:56 +0000781 if (ConvertType(InputExpr->getType())->isSingleValueType()) {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000782 Arg = EmitScalarExpr(InputExpr);
783 } else {
Dan Gohmand79a7262008-05-22 22:12:56 +0000784 assert(0 && "FIXME: Implement passing multiple-value types as inputs");
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000785 }
786 } else {
787 LValue Dest = EmitLValue(InputExpr);
788 Arg = Dest.getAddress();
789 Constraints += '*';
790 }
791
792 ArgTypes.push_back(Arg->getType());
793 Args.push_back(Arg);
794 Constraints += InputConstraint;
795 }
796
Anders Carlssonf39a4212008-02-05 20:01:53 +0000797 // Append the "input" part of inout constraints last.
798 for (unsigned i = 0, e = InOutArgs.size(); i != e; i++) {
799 ArgTypes.push_back(InOutArgTypes[i]);
800 Args.push_back(InOutArgs[i]);
801 }
802 Constraints += InOutConstraints;
803
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000804 // Clobbers
805 for (unsigned i = 0, e = S.getNumClobbers(); i != e; i++) {
806 std::string Clobber(S.getClobber(i)->getStrData(),
807 S.getClobber(i)->getByteLength());
808
809 Clobber = Target.getNormalizedGCCRegisterName(Clobber.c_str());
810
Anders Carlssonea041752008-02-06 00:11:32 +0000811 if (i != 0 || NumConstraints != 0)
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000812 Constraints += ',';
Anders Carlssonea041752008-02-06 00:11:32 +0000813
814 Constraints += "~{";
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000815 Constraints += Clobber;
Anders Carlssonea041752008-02-06 00:11:32 +0000816 Constraints += '}';
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000817 }
818
819 // Add machine specific clobbers
820 if (const char *C = Target.getClobbers()) {
821 if (!Constraints.empty())
822 Constraints += ',';
823 Constraints += C;
824 }
Anders Carlssonf39a4212008-02-05 20:01:53 +0000825
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000826 const llvm::FunctionType *FTy =
827 llvm::FunctionType::get(ResultType, ArgTypes, false);
828
829 llvm::InlineAsm *IA =
830 llvm::InlineAsm::get(FTy, AsmString, Constraints,
831 S.isVolatile() || S.getNumOutputs() == 0);
832 llvm::Value *Result = Builder.CreateCall(IA, Args.begin(), Args.end(), "");
Eli Friedman1e692ac2008-06-13 23:01:12 +0000833 if (ResultAddr) // FIXME: volatility
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000834 Builder.CreateStore(Result, ResultAddr);
835}