blob: 60aa7541cfb5619d938ce3621b4ed875f227157c [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/StmtVisitor.h"
Chris Lattner7d22bf02009-03-05 08:04:57 +000018#include "clang/Basic/PrettyStackTrace.h"
Anders Carlssonfb1aeb82008-02-05 16:35:33 +000019#include "clang/Basic/TargetInfo.h"
Anders Carlssonfb1aeb82008-02-05 16:35:33 +000020#include "llvm/ADT/StringExtras.h"
Anders Carlsson17d28a32008-12-12 05:52:00 +000021#include "llvm/InlineAsm.h"
22#include "llvm/Intrinsics.h"
Anders Carlssonebaae2a2009-01-12 02:22:13 +000023#include "llvm/Target/TargetData.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000024using namespace clang;
25using namespace CodeGen;
26
27//===----------------------------------------------------------------------===//
28// Statement Emission
29//===----------------------------------------------------------------------===//
30
Daniel Dunbar09124252008-11-12 08:21:33 +000031void CodeGenFunction::EmitStopPoint(const Stmt *S) {
Anders Carlssone896d982009-02-13 08:11:52 +000032 if (CGDebugInfo *DI = getDebugInfo()) {
Devang Patel60e4fd92010-05-12 00:39:34 +000033 if (isa<DeclStmt>(S))
34 DI->setLocation(S->getLocEnd());
35 else
36 DI->setLocation(S->getLocStart());
Devang Patel5a6fbcf2010-07-22 22:29:16 +000037 DI->UpdateLineDirectiveRegion(Builder);
Devang Patel4d939e62010-07-20 22:20:10 +000038 DI->EmitStopPoint(Builder);
Daniel Dunbar09124252008-11-12 08:21:33 +000039 }
40}
41
Reid Spencer5f016e22007-07-11 17:01:13 +000042void CodeGenFunction::EmitStmt(const Stmt *S) {
43 assert(S && "Null statement?");
Daniel Dunbara448fb22008-11-11 23:11:34 +000044
Daniel Dunbar09124252008-11-12 08:21:33 +000045 // Check if we can handle this without bothering to generate an
46 // insert point or debug info.
47 if (EmitSimpleStmt(S))
48 return;
49
Daniel Dunbard286f052009-07-19 06:58:07 +000050 // Check if we are generating unreachable code.
51 if (!HaveInsertPoint()) {
52 // If so, and the statement doesn't contain a label, then we do not need to
53 // generate actual code. This is safe because (1) the current point is
54 // unreachable, so we don't need to execute the code, and (2) we've already
55 // handled the statements which update internal data structures (like the
56 // local variable map) which could be used by subsequent statements.
57 if (!ContainsLabel(S)) {
58 // Verify that any decl statements were handled as simple, they may be in
59 // scope of subsequent reachable statements.
60 assert(!isa<DeclStmt>(*S) && "Unexpected DeclStmt!");
61 return;
62 }
63
64 // Otherwise, make a new block to hold the code.
65 EnsureInsertPoint();
66 }
67
Daniel Dunbar09124252008-11-12 08:21:33 +000068 // Generate a stoppoint if we are emitting debug info.
69 EmitStopPoint(S);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000070
Reid Spencer5f016e22007-07-11 17:01:13 +000071 switch (S->getStmtClass()) {
John McCall2a416372010-12-05 02:00:02 +000072 case Stmt::NoStmtClass:
73 case Stmt::CXXCatchStmtClass:
74 case Stmt::SwitchCaseClass:
75 llvm_unreachable("invalid statement class to emit generically");
76 case Stmt::NullStmtClass:
77 case Stmt::CompoundStmtClass:
78 case Stmt::DeclStmtClass:
79 case Stmt::LabelStmtClass:
80 case Stmt::GotoStmtClass:
81 case Stmt::BreakStmtClass:
82 case Stmt::ContinueStmtClass:
83 case Stmt::DefaultStmtClass:
84 case Stmt::CaseStmtClass:
85 llvm_unreachable("should have emitted these statements as simple");
Daniel Dunbarcd5e60e2009-07-19 08:23:12 +000086
John McCall2a416372010-12-05 02:00:02 +000087#define STMT(Type, Base)
88#define ABSTRACT_STMT(Op)
89#define EXPR(Type, Base) \
90 case Stmt::Type##Class:
91#include "clang/AST/StmtNodes.inc"
John McCallcd5b22e2011-01-12 03:41:02 +000092 {
93 // Remember the block we came in on.
94 llvm::BasicBlock *incoming = Builder.GetInsertBlock();
95 assert(incoming && "expression emission must have an insertion point");
96
John McCall2a416372010-12-05 02:00:02 +000097 EmitIgnoredExpr(cast<Expr>(S));
Mike Stump1eb44332009-09-09 15:08:12 +000098
John McCallcd5b22e2011-01-12 03:41:02 +000099 llvm::BasicBlock *outgoing = Builder.GetInsertBlock();
100 assert(outgoing && "expression emission cleared block!");
101
102 // The expression emitters assume (reasonably!) that the insertion
103 // point is always set. To maintain that, the call-emission code
104 // for noreturn functions has to enter a new block with no
105 // predecessors. We want to kill that block and mark the current
106 // insertion point unreachable in the common case of a call like
107 // "exit();". Since expression emission doesn't otherwise create
108 // blocks with no predecessors, we can just test for that.
109 // However, we must be careful not to do this to our incoming
110 // block, because *statement* emission does sometimes create
111 // reachable blocks which will have no predecessors until later in
112 // the function. This occurs with, e.g., labels that are not
113 // reachable by fallthrough.
114 if (incoming != outgoing && outgoing->use_empty()) {
115 outgoing->eraseFromParent();
116 Builder.ClearInsertionPoint();
Reid Spencer5f016e22007-07-11 17:01:13 +0000117 }
118 break;
John McCallcd5b22e2011-01-12 03:41:02 +0000119 }
John McCall2a416372010-12-05 02:00:02 +0000120
Mike Stump1eb44332009-09-09 15:08:12 +0000121 case Stmt::IndirectGotoStmtClass:
Daniel Dunbar0ffb1252008-08-04 16:51:22 +0000122 EmitIndirectGotoStmt(cast<IndirectGotoStmt>(*S)); break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000123
124 case Stmt::IfStmtClass: EmitIfStmt(cast<IfStmt>(*S)); break;
125 case Stmt::WhileStmtClass: EmitWhileStmt(cast<WhileStmt>(*S)); break;
126 case Stmt::DoStmtClass: EmitDoStmt(cast<DoStmt>(*S)); break;
127 case Stmt::ForStmtClass: EmitForStmt(cast<ForStmt>(*S)); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000128
Reid Spencer5f016e22007-07-11 17:01:13 +0000129 case Stmt::ReturnStmtClass: EmitReturnStmt(cast<ReturnStmt>(*S)); break;
Daniel Dunbara4275d12008-10-02 18:02:06 +0000130
Devang Patel51b09f22007-10-04 23:45:31 +0000131 case Stmt::SwitchStmtClass: EmitSwitchStmt(cast<SwitchStmt>(*S)); break;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000132 case Stmt::AsmStmtClass: EmitAsmStmt(cast<AsmStmt>(*S)); break;
Daniel Dunbar0a04d772008-08-23 10:51:21 +0000133
134 case Stmt::ObjCAtTryStmtClass:
Anders Carlsson64d5d6c2008-09-09 10:04:29 +0000135 EmitObjCAtTryStmt(cast<ObjCAtTryStmt>(*S));
Mike Stump1eb44332009-09-09 15:08:12 +0000136 break;
Daniel Dunbar0a04d772008-08-23 10:51:21 +0000137 case Stmt::ObjCAtCatchStmtClass:
Anders Carlssondde0a942008-09-11 09:15:33 +0000138 assert(0 && "@catch statements should be handled by EmitObjCAtTryStmt");
139 break;
Daniel Dunbar0a04d772008-08-23 10:51:21 +0000140 case Stmt::ObjCAtFinallyStmtClass:
Anders Carlsson64d5d6c2008-09-09 10:04:29 +0000141 assert(0 && "@finally statements should be handled by EmitObjCAtTryStmt");
Daniel Dunbar0a04d772008-08-23 10:51:21 +0000142 break;
143 case Stmt::ObjCAtThrowStmtClass:
Anders Carlsson64d5d6c2008-09-09 10:04:29 +0000144 EmitObjCAtThrowStmt(cast<ObjCAtThrowStmt>(*S));
Daniel Dunbar0a04d772008-08-23 10:51:21 +0000145 break;
146 case Stmt::ObjCAtSynchronizedStmtClass:
Chris Lattner10cac6f2008-11-15 21:26:17 +0000147 EmitObjCAtSynchronizedStmt(cast<ObjCAtSynchronizedStmt>(*S));
Daniel Dunbar0a04d772008-08-23 10:51:21 +0000148 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000149 case Stmt::ObjCForCollectionStmtClass:
Anders Carlsson3d8400d2008-08-30 19:51:14 +0000150 EmitObjCForCollectionStmt(cast<ObjCForCollectionStmt>(*S));
Daniel Dunbar0a04d772008-08-23 10:51:21 +0000151 break;
Anders Carlsson6815e942009-09-27 18:58:34 +0000152
153 case Stmt::CXXTryStmtClass:
154 EmitCXXTryStmt(cast<CXXTryStmt>(*S));
155 break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000156 }
157}
158
Daniel Dunbar09124252008-11-12 08:21:33 +0000159bool CodeGenFunction::EmitSimpleStmt(const Stmt *S) {
160 switch (S->getStmtClass()) {
161 default: return false;
162 case Stmt::NullStmtClass: break;
163 case Stmt::CompoundStmtClass: EmitCompoundStmt(cast<CompoundStmt>(*S)); break;
Daniel Dunbard286f052009-07-19 06:58:07 +0000164 case Stmt::DeclStmtClass: EmitDeclStmt(cast<DeclStmt>(*S)); break;
Daniel Dunbar09124252008-11-12 08:21:33 +0000165 case Stmt::LabelStmtClass: EmitLabelStmt(cast<LabelStmt>(*S)); break;
166 case Stmt::GotoStmtClass: EmitGotoStmt(cast<GotoStmt>(*S)); break;
167 case Stmt::BreakStmtClass: EmitBreakStmt(cast<BreakStmt>(*S)); break;
168 case Stmt::ContinueStmtClass: EmitContinueStmt(cast<ContinueStmt>(*S)); break;
169 case Stmt::DefaultStmtClass: EmitDefaultStmt(cast<DefaultStmt>(*S)); break;
170 case Stmt::CaseStmtClass: EmitCaseStmt(cast<CaseStmt>(*S)); break;
171 }
172
173 return true;
174}
175
Chris Lattner33793202007-08-31 22:09:40 +0000176/// EmitCompoundStmt - Emit a compound statement {..} node. If GetLast is true,
177/// this captures the expression result of the last sub-statement and returns it
178/// (for use by the statement expression extension).
Chris Lattner9b655512007-08-31 22:49:20 +0000179RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
John McCall558d2ab2010-09-15 10:14:12 +0000180 AggValueSlot AggSlot) {
Chris Lattner7d22bf02009-03-05 08:04:57 +0000181 PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),S.getLBracLoc(),
182 "LLVM IR generation of compound statement ('{}')");
Mike Stump1eb44332009-09-09 15:08:12 +0000183
Anders Carlssone896d982009-02-13 08:11:52 +0000184 CGDebugInfo *DI = getDebugInfo();
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000185 if (DI) {
Devang Patelbbd9fa42009-10-06 18:36:08 +0000186 DI->setLocation(S.getLBracLoc());
Devang Patel4d939e62010-07-20 22:20:10 +0000187 DI->EmitRegionStart(Builder);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000188 }
189
Anders Carlssonc71c8452009-02-07 23:50:39 +0000190 // Keep track of the current cleanup stack depth.
John McCallf1549f62010-07-06 01:34:17 +0000191 RunCleanupsScope Scope(*this);
Mike Stump1eb44332009-09-09 15:08:12 +0000192
Chris Lattner33793202007-08-31 22:09:40 +0000193 for (CompoundStmt::const_body_iterator I = S.body_begin(),
194 E = S.body_end()-GetLast; I != E; ++I)
Reid Spencer5f016e22007-07-11 17:01:13 +0000195 EmitStmt(*I);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000196
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000197 if (DI) {
Devang Patelcd9199e2010-04-13 00:08:43 +0000198 DI->setLocation(S.getRBracLoc());
Devang Patel4d939e62010-07-20 22:20:10 +0000199 DI->EmitRegionEnd(Builder);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000200 }
201
Anders Carlsson17d28a32008-12-12 05:52:00 +0000202 RValue RV;
Mike Stump1eb44332009-09-09 15:08:12 +0000203 if (!GetLast)
Anders Carlsson17d28a32008-12-12 05:52:00 +0000204 RV = RValue::get(0);
205 else {
Mike Stump1eb44332009-09-09 15:08:12 +0000206 // We have to special case labels here. They are statements, but when put
Anders Carlsson17d28a32008-12-12 05:52:00 +0000207 // at the end of a statement expression, they yield the value of their
208 // subexpression. Handle this by walking through all labels we encounter,
209 // emitting them before we evaluate the subexpr.
210 const Stmt *LastStmt = S.body_back();
211 while (const LabelStmt *LS = dyn_cast<LabelStmt>(LastStmt)) {
212 EmitLabel(*LS);
213 LastStmt = LS->getSubStmt();
214 }
Mike Stump1eb44332009-09-09 15:08:12 +0000215
Anders Carlsson17d28a32008-12-12 05:52:00 +0000216 EnsureInsertPoint();
Mike Stump1eb44332009-09-09 15:08:12 +0000217
John McCall558d2ab2010-09-15 10:14:12 +0000218 RV = EmitAnyExpr(cast<Expr>(LastStmt), AggSlot);
Anders Carlsson17d28a32008-12-12 05:52:00 +0000219 }
220
Anders Carlsson17d28a32008-12-12 05:52:00 +0000221 return RV;
Reid Spencer5f016e22007-07-11 17:01:13 +0000222}
223
Daniel Dunbaraa5bd872009-04-01 04:37:47 +0000224void CodeGenFunction::SimplifyForwardingBlocks(llvm::BasicBlock *BB) {
225 llvm::BranchInst *BI = dyn_cast<llvm::BranchInst>(BB->getTerminator());
Mike Stump1eb44332009-09-09 15:08:12 +0000226
Daniel Dunbaraa5bd872009-04-01 04:37:47 +0000227 // If there is a cleanup stack, then we it isn't worth trying to
228 // simplify this block (we would need to remove it from the scope map
229 // and cleanup entry).
John McCallf1549f62010-07-06 01:34:17 +0000230 if (!EHStack.empty())
Daniel Dunbaraa5bd872009-04-01 04:37:47 +0000231 return;
232
233 // Can only simplify direct branches.
234 if (!BI || !BI->isUnconditional())
235 return;
236
237 BB->replaceAllUsesWith(BI->getSuccessor(0));
238 BI->eraseFromParent();
239 BB->eraseFromParent();
240}
241
Daniel Dunbara0c21a82008-11-13 01:24:05 +0000242void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB, bool IsFinished) {
John McCall548ce5e2010-04-21 11:18:06 +0000243 llvm::BasicBlock *CurBB = Builder.GetInsertBlock();
244
Daniel Dunbard57a8712008-11-11 09:41:28 +0000245 // Fall out of the current block (if necessary).
246 EmitBranch(BB);
Daniel Dunbara0c21a82008-11-13 01:24:05 +0000247
248 if (IsFinished && BB->use_empty()) {
249 delete BB;
250 return;
251 }
252
John McCall839cbaa2010-04-21 10:29:06 +0000253 // Place the block after the current block, if possible, or else at
254 // the end of the function.
John McCall548ce5e2010-04-21 11:18:06 +0000255 if (CurBB && CurBB->getParent())
256 CurFn->getBasicBlockList().insertAfter(CurBB, BB);
John McCall839cbaa2010-04-21 10:29:06 +0000257 else
258 CurFn->getBasicBlockList().push_back(BB);
Reid Spencer5f016e22007-07-11 17:01:13 +0000259 Builder.SetInsertPoint(BB);
260}
261
Daniel Dunbard57a8712008-11-11 09:41:28 +0000262void CodeGenFunction::EmitBranch(llvm::BasicBlock *Target) {
263 // Emit a branch from the current block to the target one if this
264 // was a real block. If this was just a fall-through block after a
265 // terminator, don't emit it.
266 llvm::BasicBlock *CurBB = Builder.GetInsertBlock();
267
268 if (!CurBB || CurBB->getTerminator()) {
269 // If there is no insert point or the previous block is already
270 // terminated, don't touch it.
Daniel Dunbard57a8712008-11-11 09:41:28 +0000271 } else {
272 // Otherwise, create a fall-through branch.
273 Builder.CreateBr(Target);
274 }
Daniel Dunbar5e08ad32008-11-11 22:06:59 +0000275
276 Builder.ClearInsertionPoint();
Daniel Dunbard57a8712008-11-11 09:41:28 +0000277}
278
John McCallf1549f62010-07-06 01:34:17 +0000279CodeGenFunction::JumpDest
280CodeGenFunction::getJumpDestForLabel(const LabelStmt *S) {
281 JumpDest &Dest = LabelMap[S];
John McCallff8e1152010-07-23 21:56:41 +0000282 if (Dest.isValid()) return Dest;
John McCallf1549f62010-07-06 01:34:17 +0000283
284 // Create, but don't insert, the new block.
John McCallff8e1152010-07-23 21:56:41 +0000285 Dest = JumpDest(createBasicBlock(S->getName()),
286 EHScopeStack::stable_iterator::invalid(),
287 NextCleanupDestIndex++);
John McCallf1549f62010-07-06 01:34:17 +0000288 return Dest;
289}
290
Mike Stumpec9771d2009-02-08 09:22:19 +0000291void CodeGenFunction::EmitLabel(const LabelStmt &S) {
John McCallf1549f62010-07-06 01:34:17 +0000292 JumpDest &Dest = LabelMap[&S];
293
John McCallff8e1152010-07-23 21:56:41 +0000294 // If we didn't need a forward reference to this label, just go
John McCallf1549f62010-07-06 01:34:17 +0000295 // ahead and create a destination at the current scope.
John McCallff8e1152010-07-23 21:56:41 +0000296 if (!Dest.isValid()) {
John McCallf1549f62010-07-06 01:34:17 +0000297 Dest = getJumpDestInCurrentScope(S.getName());
298
299 // Otherwise, we need to give this label a target depth and remove
300 // it from the branch-fixups list.
301 } else {
John McCallff8e1152010-07-23 21:56:41 +0000302 assert(!Dest.getScopeDepth().isValid() && "already emitted label!");
303 Dest = JumpDest(Dest.getBlock(),
304 EHStack.stable_begin(),
305 Dest.getDestIndex());
John McCallf1549f62010-07-06 01:34:17 +0000306
John McCallff8e1152010-07-23 21:56:41 +0000307 ResolveBranchFixups(Dest.getBlock());
John McCallf1549f62010-07-06 01:34:17 +0000308 }
309
John McCallff8e1152010-07-23 21:56:41 +0000310 EmitBlock(Dest.getBlock());
Chris Lattner91d723d2008-07-26 20:23:23 +0000311}
312
313
314void CodeGenFunction::EmitLabelStmt(const LabelStmt &S) {
315 EmitLabel(S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000316 EmitStmt(S.getSubStmt());
317}
318
319void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) {
Daniel Dunbar09124252008-11-12 08:21:33 +0000320 // If this code is reachable then emit a stop point (if generating
321 // debug info). We have to do this ourselves because we are on the
322 // "simple" statement path.
323 if (HaveInsertPoint())
324 EmitStopPoint(&S);
Mike Stump36a2ada2009-02-07 12:52:26 +0000325
John McCallf1549f62010-07-06 01:34:17 +0000326 EmitBranchThroughCleanup(getJumpDestForLabel(S.getLabel()));
Reid Spencer5f016e22007-07-11 17:01:13 +0000327}
328
Chris Lattner3d00fdc2009-10-13 06:55:33 +0000329
Daniel Dunbar0ffb1252008-08-04 16:51:22 +0000330void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) {
John McCall95c225d2010-10-28 08:53:48 +0000331 if (const LabelStmt *Target = S.getConstantTarget()) {
332 EmitBranchThroughCleanup(getJumpDestForLabel(Target));
333 return;
334 }
335
Chris Lattner49c952f2009-11-06 18:10:47 +0000336 // Ensure that we have an i8* for our PHI node.
Chris Lattnerd9becd12009-10-28 23:59:40 +0000337 llvm::Value *V = Builder.CreateBitCast(EmitScalarExpr(S.getTarget()),
John McCalld16c2cf2011-02-08 08:22:06 +0000338 Int8PtrTy, "addr");
Chris Lattner3d00fdc2009-10-13 06:55:33 +0000339 llvm::BasicBlock *CurBB = Builder.GetInsertBlock();
340
Daniel Dunbar0ffb1252008-08-04 16:51:22 +0000341
Chris Lattner3d00fdc2009-10-13 06:55:33 +0000342 // Get the basic block for the indirect goto.
343 llvm::BasicBlock *IndGotoBB = GetIndirectGotoBlock();
344
345 // The first instruction in the block has to be the PHI for the switch dest,
346 // add an entry for this branch.
347 cast<llvm::PHINode>(IndGotoBB->begin())->addIncoming(V, CurBB);
348
349 EmitBranch(IndGotoBB);
Daniel Dunbar0ffb1252008-08-04 16:51:22 +0000350}
351
Chris Lattner62b72f62008-11-11 07:24:28 +0000352void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000353 // C99 6.8.4.1: The first substatement is executed if the expression compares
354 // unequal to 0. The condition must be a scalar type.
John McCallf1549f62010-07-06 01:34:17 +0000355 RunCleanupsScope ConditionScope(*this);
Douglas Gregor01234bb2009-11-24 16:43:22 +0000356
Douglas Gregor8cfe5a72009-11-23 23:44:04 +0000357 if (S.getConditionVariable())
John McCallb6bbcc92010-10-15 04:57:14 +0000358 EmitAutoVarDecl(*S.getConditionVariable());
Mike Stump1eb44332009-09-09 15:08:12 +0000359
Chris Lattner9bc47e22008-11-12 07:46:33 +0000360 // If the condition constant folds and can be elided, try to avoid emitting
361 // the condition and the dead arm of the if/else.
Chris Lattner31a09842008-11-12 08:04:58 +0000362 if (int Cond = ConstantFoldsToSimpleInteger(S.getCond())) {
Chris Lattner62b72f62008-11-11 07:24:28 +0000363 // Figure out which block (then or else) is executed.
364 const Stmt *Executed = S.getThen(), *Skipped = S.getElse();
Chris Lattner9bc47e22008-11-12 07:46:33 +0000365 if (Cond == -1) // Condition false?
Chris Lattner62b72f62008-11-11 07:24:28 +0000366 std::swap(Executed, Skipped);
Mike Stump1eb44332009-09-09 15:08:12 +0000367
Chris Lattner62b72f62008-11-11 07:24:28 +0000368 // If the skipped block has no labels in it, just emit the executed block.
369 // This avoids emitting dead code and simplifies the CFG substantially.
Chris Lattner9bc47e22008-11-12 07:46:33 +0000370 if (!ContainsLabel(Skipped)) {
Douglas Gregor01234bb2009-11-24 16:43:22 +0000371 if (Executed) {
John McCallf1549f62010-07-06 01:34:17 +0000372 RunCleanupsScope ExecutedScope(*this);
Chris Lattner62b72f62008-11-11 07:24:28 +0000373 EmitStmt(Executed);
Douglas Gregor01234bb2009-11-24 16:43:22 +0000374 }
Chris Lattner62b72f62008-11-11 07:24:28 +0000375 return;
376 }
377 }
Chris Lattner9bc47e22008-11-12 07:46:33 +0000378
379 // Otherwise, the condition did not fold, or we couldn't elide it. Just emit
380 // the conditional branch.
Daniel Dunbar781d7ca2008-11-13 00:47:57 +0000381 llvm::BasicBlock *ThenBlock = createBasicBlock("if.then");
382 llvm::BasicBlock *ContBlock = createBasicBlock("if.end");
383 llvm::BasicBlock *ElseBlock = ContBlock;
Reid Spencer5f016e22007-07-11 17:01:13 +0000384 if (S.getElse())
Daniel Dunbar781d7ca2008-11-13 00:47:57 +0000385 ElseBlock = createBasicBlock("if.else");
386 EmitBranchOnBoolExpr(S.getCond(), ThenBlock, ElseBlock);
Mike Stump1eb44332009-09-09 15:08:12 +0000387
Reid Spencer5f016e22007-07-11 17:01:13 +0000388 // Emit the 'then' code.
Douglas Gregor01234bb2009-11-24 16:43:22 +0000389 EmitBlock(ThenBlock);
390 {
John McCallf1549f62010-07-06 01:34:17 +0000391 RunCleanupsScope ThenScope(*this);
Douglas Gregor01234bb2009-11-24 16:43:22 +0000392 EmitStmt(S.getThen());
393 }
Daniel Dunbard57a8712008-11-11 09:41:28 +0000394 EmitBranch(ContBlock);
Mike Stump1eb44332009-09-09 15:08:12 +0000395
Reid Spencer5f016e22007-07-11 17:01:13 +0000396 // Emit the 'else' code if present.
397 if (const Stmt *Else = S.getElse()) {
398 EmitBlock(ElseBlock);
Douglas Gregor01234bb2009-11-24 16:43:22 +0000399 {
John McCallf1549f62010-07-06 01:34:17 +0000400 RunCleanupsScope ElseScope(*this);
Douglas Gregor01234bb2009-11-24 16:43:22 +0000401 EmitStmt(Else);
402 }
Daniel Dunbard57a8712008-11-11 09:41:28 +0000403 EmitBranch(ContBlock);
Reid Spencer5f016e22007-07-11 17:01:13 +0000404 }
Mike Stump1eb44332009-09-09 15:08:12 +0000405
Reid Spencer5f016e22007-07-11 17:01:13 +0000406 // Emit the continuation block for code after the if.
Daniel Dunbarc22d6652008-11-13 01:54:24 +0000407 EmitBlock(ContBlock, true);
Reid Spencer5f016e22007-07-11 17:01:13 +0000408}
409
410void CodeGenFunction::EmitWhileStmt(const WhileStmt &S) {
John McCallf1549f62010-07-06 01:34:17 +0000411 // Emit the header for the loop, which will also become
412 // the continue target.
413 JumpDest LoopHeader = getJumpDestInCurrentScope("while.cond");
John McCallff8e1152010-07-23 21:56:41 +0000414 EmitBlock(LoopHeader.getBlock());
Mike Stump72cac2c2009-02-07 18:08:12 +0000415
John McCallf1549f62010-07-06 01:34:17 +0000416 // Create an exit block for when the condition fails, which will
417 // also become the break target.
418 JumpDest LoopExit = getJumpDestInCurrentScope("while.end");
Mike Stump72cac2c2009-02-07 18:08:12 +0000419
420 // Store the blocks to use for break and continue.
John McCallf1549f62010-07-06 01:34:17 +0000421 BreakContinueStack.push_back(BreakContinue(LoopExit, LoopHeader));
Mike Stump1eb44332009-09-09 15:08:12 +0000422
Douglas Gregor5656e142009-11-24 21:15:44 +0000423 // C++ [stmt.while]p2:
424 // When the condition of a while statement is a declaration, the
425 // scope of the variable that is declared extends from its point
426 // of declaration (3.3.2) to the end of the while statement.
427 // [...]
428 // The object created in a condition is destroyed and created
429 // with each iteration of the loop.
John McCallf1549f62010-07-06 01:34:17 +0000430 RunCleanupsScope ConditionScope(*this);
Douglas Gregor5656e142009-11-24 21:15:44 +0000431
John McCallf1549f62010-07-06 01:34:17 +0000432 if (S.getConditionVariable())
John McCallb6bbcc92010-10-15 04:57:14 +0000433 EmitAutoVarDecl(*S.getConditionVariable());
Douglas Gregor5656e142009-11-24 21:15:44 +0000434
Mike Stump16b16202009-02-07 17:18:33 +0000435 // Evaluate the conditional in the while header. C99 6.8.5.1: The
436 // evaluation of the controlling expression takes place before each
437 // execution of the loop body.
Reid Spencer5f016e22007-07-11 17:01:13 +0000438 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
Douglas Gregor5656e142009-11-24 21:15:44 +0000439
Devang Patel2c30d8f2007-10-09 20:51:27 +0000440 // while(1) is common, avoid extra exit blocks. Be sure
Reid Spencer5f016e22007-07-11 17:01:13 +0000441 // to correctly handle break/continue though.
Devang Patel2c30d8f2007-10-09 20:51:27 +0000442 bool EmitBoolCondBranch = true;
Mike Stump1eb44332009-09-09 15:08:12 +0000443 if (llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal))
Devang Patel2c30d8f2007-10-09 20:51:27 +0000444 if (C->isOne())
445 EmitBoolCondBranch = false;
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Reid Spencer5f016e22007-07-11 17:01:13 +0000447 // As long as the condition is true, go to the loop body.
John McCallf1549f62010-07-06 01:34:17 +0000448 llvm::BasicBlock *LoopBody = createBasicBlock("while.body");
449 if (EmitBoolCondBranch) {
John McCallff8e1152010-07-23 21:56:41 +0000450 llvm::BasicBlock *ExitBlock = LoopExit.getBlock();
John McCallf1549f62010-07-06 01:34:17 +0000451 if (ConditionScope.requiresCleanups())
452 ExitBlock = createBasicBlock("while.exit");
453
454 Builder.CreateCondBr(BoolCondVal, LoopBody, ExitBlock);
455
John McCallff8e1152010-07-23 21:56:41 +0000456 if (ExitBlock != LoopExit.getBlock()) {
John McCallf1549f62010-07-06 01:34:17 +0000457 EmitBlock(ExitBlock);
458 EmitBranchThroughCleanup(LoopExit);
459 }
460 }
Douglas Gregor5656e142009-11-24 21:15:44 +0000461
John McCallf1549f62010-07-06 01:34:17 +0000462 // Emit the loop body. We have to emit this in a cleanup scope
463 // because it might be a singleton DeclStmt.
Douglas Gregor5656e142009-11-24 21:15:44 +0000464 {
John McCallf1549f62010-07-06 01:34:17 +0000465 RunCleanupsScope BodyScope(*this);
Douglas Gregor5656e142009-11-24 21:15:44 +0000466 EmitBlock(LoopBody);
467 EmitStmt(S.getBody());
468 }
Chris Lattnerda138702007-07-16 21:28:45 +0000469
Mike Stump1eb44332009-09-09 15:08:12 +0000470 BreakContinueStack.pop_back();
471
John McCallf1549f62010-07-06 01:34:17 +0000472 // Immediately force cleanup.
473 ConditionScope.ForceCleanup();
Douglas Gregor5656e142009-11-24 21:15:44 +0000474
John McCallf1549f62010-07-06 01:34:17 +0000475 // Branch to the loop header again.
John McCallff8e1152010-07-23 21:56:41 +0000476 EmitBranch(LoopHeader.getBlock());
Mike Stump1eb44332009-09-09 15:08:12 +0000477
Reid Spencer5f016e22007-07-11 17:01:13 +0000478 // Emit the exit block.
John McCallff8e1152010-07-23 21:56:41 +0000479 EmitBlock(LoopExit.getBlock(), true);
Douglas Gregor5656e142009-11-24 21:15:44 +0000480
Daniel Dunbaraa5bd872009-04-01 04:37:47 +0000481 // The LoopHeader typically is just a branch if we skipped emitting
482 // a branch, try to erase it.
John McCallf1549f62010-07-06 01:34:17 +0000483 if (!EmitBoolCondBranch)
John McCallff8e1152010-07-23 21:56:41 +0000484 SimplifyForwardingBlocks(LoopHeader.getBlock());
Reid Spencer5f016e22007-07-11 17:01:13 +0000485}
486
487void CodeGenFunction::EmitDoStmt(const DoStmt &S) {
John McCallf1549f62010-07-06 01:34:17 +0000488 JumpDest LoopExit = getJumpDestInCurrentScope("do.end");
489 JumpDest LoopCond = getJumpDestInCurrentScope("do.cond");
Mike Stump1eb44332009-09-09 15:08:12 +0000490
Chris Lattnerda138702007-07-16 21:28:45 +0000491 // Store the blocks to use for break and continue.
John McCallf1549f62010-07-06 01:34:17 +0000492 BreakContinueStack.push_back(BreakContinue(LoopExit, LoopCond));
Mike Stump1eb44332009-09-09 15:08:12 +0000493
John McCallf1549f62010-07-06 01:34:17 +0000494 // Emit the body of the loop.
495 llvm::BasicBlock *LoopBody = createBasicBlock("do.body");
496 EmitBlock(LoopBody);
497 {
498 RunCleanupsScope BodyScope(*this);
499 EmitStmt(S.getBody());
500 }
Mike Stump1eb44332009-09-09 15:08:12 +0000501
Anders Carlssone4b6d342009-02-10 05:52:02 +0000502 BreakContinueStack.pop_back();
Mike Stump1eb44332009-09-09 15:08:12 +0000503
John McCallff8e1152010-07-23 21:56:41 +0000504 EmitBlock(LoopCond.getBlock());
Mike Stump1eb44332009-09-09 15:08:12 +0000505
Reid Spencer5f016e22007-07-11 17:01:13 +0000506 // C99 6.8.5.2: "The evaluation of the controlling expression takes place
507 // after each execution of the loop body."
Mike Stump1eb44332009-09-09 15:08:12 +0000508
Reid Spencer5f016e22007-07-11 17:01:13 +0000509 // Evaluate the conditional in the while header.
510 // C99 6.8.5p2/p4: The first substatement is executed if the expression
511 // compares unequal to 0. The condition must be a scalar type.
512 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
Devang Patel05f6e6b2007-10-09 20:33:39 +0000513
514 // "do {} while (0)" is common in macros, avoid extra blocks. Be sure
515 // to correctly handle break/continue though.
516 bool EmitBoolCondBranch = true;
Mike Stump1eb44332009-09-09 15:08:12 +0000517 if (llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal))
Devang Patel05f6e6b2007-10-09 20:33:39 +0000518 if (C->isZero())
519 EmitBoolCondBranch = false;
520
Reid Spencer5f016e22007-07-11 17:01:13 +0000521 // As long as the condition is true, iterate the loop.
Devang Patel05f6e6b2007-10-09 20:33:39 +0000522 if (EmitBoolCondBranch)
John McCallff8e1152010-07-23 21:56:41 +0000523 Builder.CreateCondBr(BoolCondVal, LoopBody, LoopExit.getBlock());
Mike Stump1eb44332009-09-09 15:08:12 +0000524
Reid Spencer5f016e22007-07-11 17:01:13 +0000525 // Emit the exit block.
John McCallff8e1152010-07-23 21:56:41 +0000526 EmitBlock(LoopExit.getBlock());
Devang Patel05f6e6b2007-10-09 20:33:39 +0000527
Daniel Dunbaraa5bd872009-04-01 04:37:47 +0000528 // The DoCond block typically is just a branch if we skipped
529 // emitting a branch, try to erase it.
530 if (!EmitBoolCondBranch)
John McCallff8e1152010-07-23 21:56:41 +0000531 SimplifyForwardingBlocks(LoopCond.getBlock());
Reid Spencer5f016e22007-07-11 17:01:13 +0000532}
533
534void CodeGenFunction::EmitForStmt(const ForStmt &S) {
John McCallf1549f62010-07-06 01:34:17 +0000535 JumpDest LoopExit = getJumpDestInCurrentScope("for.end");
536
537 RunCleanupsScope ForScope(*this);
Chris Lattnerda138702007-07-16 21:28:45 +0000538
Devang Patel0554e0e2010-08-25 00:28:56 +0000539 CGDebugInfo *DI = getDebugInfo();
540 if (DI) {
541 DI->setLocation(S.getSourceRange().getBegin());
542 DI->EmitRegionStart(Builder);
543 }
544
Reid Spencer5f016e22007-07-11 17:01:13 +0000545 // Evaluate the first part before the loop.
546 if (S.getInit())
547 EmitStmt(S.getInit());
548
549 // Start the loop with a block that tests the condition.
John McCallf1549f62010-07-06 01:34:17 +0000550 // If there's an increment, the continue scope will be overwritten
551 // later.
552 JumpDest Continue = getJumpDestInCurrentScope("for.cond");
John McCallff8e1152010-07-23 21:56:41 +0000553 llvm::BasicBlock *CondBlock = Continue.getBlock();
Reid Spencer5f016e22007-07-11 17:01:13 +0000554 EmitBlock(CondBlock);
555
Douglas Gregord9752062009-11-25 01:51:31 +0000556 // Create a cleanup scope for the condition variable cleanups.
John McCallf1549f62010-07-06 01:34:17 +0000557 RunCleanupsScope ConditionScope(*this);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000558
Douglas Gregord9752062009-11-25 01:51:31 +0000559 llvm::Value *BoolCondVal = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000560 if (S.getCond()) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000561 // If the for statement has a condition scope, emit the local variable
562 // declaration.
John McCallff8e1152010-07-23 21:56:41 +0000563 llvm::BasicBlock *ExitBlock = LoopExit.getBlock();
Douglas Gregord9752062009-11-25 01:51:31 +0000564 if (S.getConditionVariable()) {
John McCallb6bbcc92010-10-15 04:57:14 +0000565 EmitAutoVarDecl(*S.getConditionVariable());
Douglas Gregord9752062009-11-25 01:51:31 +0000566 }
John McCallf1549f62010-07-06 01:34:17 +0000567
568 // If there are any cleanups between here and the loop-exit scope,
569 // create a block to stage a loop exit along.
570 if (ForScope.requiresCleanups())
571 ExitBlock = createBasicBlock("for.cond.cleanup");
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000572
Reid Spencer5f016e22007-07-11 17:01:13 +0000573 // As long as the condition is true, iterate the loop.
Daniel Dunbar9615ecb2008-11-13 01:38:36 +0000574 llvm::BasicBlock *ForBody = createBasicBlock("for.body");
Mike Stump1eb44332009-09-09 15:08:12 +0000575
Chris Lattner31a09842008-11-12 08:04:58 +0000576 // C99 6.8.5p2/p4: The first substatement is executed if the expression
577 // compares unequal to 0. The condition must be a scalar type.
Douglas Gregord9752062009-11-25 01:51:31 +0000578 BoolCondVal = EvaluateExprAsBool(S.getCond());
John McCallf1549f62010-07-06 01:34:17 +0000579 Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock);
580
John McCallff8e1152010-07-23 21:56:41 +0000581 if (ExitBlock != LoopExit.getBlock()) {
John McCallf1549f62010-07-06 01:34:17 +0000582 EmitBlock(ExitBlock);
583 EmitBranchThroughCleanup(LoopExit);
584 }
Mike Stump1eb44332009-09-09 15:08:12 +0000585
586 EmitBlock(ForBody);
Reid Spencer5f016e22007-07-11 17:01:13 +0000587 } else {
588 // Treat it as a non-zero constant. Don't even create a new block for the
589 // body, just fall into it.
590 }
591
Mike Stump1eb44332009-09-09 15:08:12 +0000592 // If the for loop doesn't have an increment we can just use the
John McCallf1549f62010-07-06 01:34:17 +0000593 // condition as the continue block. Otherwise we'll need to create
594 // a block for it (in the current scope, i.e. in the scope of the
595 // condition), and that we will become our continue block.
Chris Lattnerda138702007-07-16 21:28:45 +0000596 if (S.getInc())
John McCallf1549f62010-07-06 01:34:17 +0000597 Continue = getJumpDestInCurrentScope("for.inc");
Mike Stump1eb44332009-09-09 15:08:12 +0000598
Chris Lattnerda138702007-07-16 21:28:45 +0000599 // Store the blocks to use for break and continue.
John McCallf1549f62010-07-06 01:34:17 +0000600 BreakContinueStack.push_back(BreakContinue(LoopExit, Continue));
Mike Stump3e9da662009-02-07 23:02:10 +0000601
Douglas Gregord9752062009-11-25 01:51:31 +0000602 {
603 // Create a separate cleanup scope for the body, in case it is not
604 // a compound statement.
John McCallf1549f62010-07-06 01:34:17 +0000605 RunCleanupsScope BodyScope(*this);
Douglas Gregord9752062009-11-25 01:51:31 +0000606 EmitStmt(S.getBody());
607 }
Chris Lattnerda138702007-07-16 21:28:45 +0000608
Reid Spencer5f016e22007-07-11 17:01:13 +0000609 // If there is an increment, emit it next.
Daniel Dunbarad12b6d2008-09-28 00:19:22 +0000610 if (S.getInc()) {
John McCallff8e1152010-07-23 21:56:41 +0000611 EmitBlock(Continue.getBlock());
Chris Lattner883f6a72007-08-11 00:04:45 +0000612 EmitStmt(S.getInc());
Daniel Dunbarad12b6d2008-09-28 00:19:22 +0000613 }
Mike Stump1eb44332009-09-09 15:08:12 +0000614
Douglas Gregor45d3fe12010-05-21 18:36:48 +0000615 BreakContinueStack.pop_back();
Douglas Gregord9752062009-11-25 01:51:31 +0000616
John McCallf1549f62010-07-06 01:34:17 +0000617 ConditionScope.ForceCleanup();
618 EmitBranch(CondBlock);
619
620 ForScope.ForceCleanup();
621
Devang Patelbbd9fa42009-10-06 18:36:08 +0000622 if (DI) {
623 DI->setLocation(S.getSourceRange().getEnd());
Devang Patel4d939e62010-07-20 22:20:10 +0000624 DI->EmitRegionEnd(Builder);
Devang Patelbbd9fa42009-10-06 18:36:08 +0000625 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000626
Chris Lattnerda138702007-07-16 21:28:45 +0000627 // Emit the fall-through block.
John McCallff8e1152010-07-23 21:56:41 +0000628 EmitBlock(LoopExit.getBlock(), true);
Reid Spencer5f016e22007-07-11 17:01:13 +0000629}
630
Daniel Dunbar29e0bcc2008-09-24 04:00:38 +0000631void CodeGenFunction::EmitReturnOfRValue(RValue RV, QualType Ty) {
632 if (RV.isScalar()) {
633 Builder.CreateStore(RV.getScalarVal(), ReturnValue);
634 } else if (RV.isAggregate()) {
635 EmitAggregateCopy(ReturnValue, RV.getAggregateAddr(), Ty);
636 } else {
637 StoreComplexToAddr(RV.getComplexVal(), ReturnValue, false);
638 }
Anders Carlsson82d8ef02009-02-09 20:31:03 +0000639 EmitBranchThroughCleanup(ReturnBlock);
Daniel Dunbar29e0bcc2008-09-24 04:00:38 +0000640}
641
Reid Spencer5f016e22007-07-11 17:01:13 +0000642/// EmitReturnStmt - Note that due to GCC extensions, this can have an operand
643/// if the function returns void, or may be missing one if the function returns
644/// non-void. Fun stuff :).
645void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000646 // Emit the result value, even if unused, to evalute the side effects.
647 const Expr *RV = S.getRetValue();
Mike Stump1eb44332009-09-09 15:08:12 +0000648
Daniel Dunbar5ca20842008-09-09 21:00:17 +0000649 // FIXME: Clean this up by using an LValue for ReturnTemp,
650 // EmitStoreThroughLValue, and EmitAnyExpr.
Douglas Gregord86c4772010-05-15 06:46:45 +0000651 if (S.getNRVOCandidate() && S.getNRVOCandidate()->isNRVOVariable() &&
652 !Target.useGlobalsForAutomaticVariables()) {
653 // Apply the named return value optimization for this return statement,
654 // which means doing nothing: the appropriate result has already been
655 // constructed into the NRVO variable.
Douglas Gregor3d91bbc2010-05-17 15:52:46 +0000656
657 // If there is an NRVO flag for this variable, set it to 1 into indicate
658 // that the cleanup code should not destroy the variable.
John McCalld16c2cf2011-02-08 08:22:06 +0000659 if (llvm::Value *NRVOFlag = NRVOFlags[S.getNRVOCandidate()])
660 Builder.CreateStore(Builder.getTrue(), NRVOFlag);
Douglas Gregord86c4772010-05-15 06:46:45 +0000661 } else if (!ReturnValue) {
Daniel Dunbar5ca20842008-09-09 21:00:17 +0000662 // Make sure not to return anything, but evaluate the expression
663 // for side effects.
664 if (RV)
Eli Friedman144ac612008-05-22 01:22:33 +0000665 EmitAnyExpr(RV);
Reid Spencer5f016e22007-07-11 17:01:13 +0000666 } else if (RV == 0) {
Daniel Dunbar5ca20842008-09-09 21:00:17 +0000667 // Do nothing (return value is left uninitialized)
Eli Friedmand54b6ac2009-05-27 04:56:12 +0000668 } else if (FnRetTy->isReferenceType()) {
669 // If this function returns a reference, take the address of the expression
670 // rather than the value.
Anders Carlsson32f36ba2010-06-26 16:35:32 +0000671 RValue Result = EmitReferenceBindingToExpr(RV, /*InitializedDecl=*/0);
Douglas Gregor33fd1fc2010-03-24 23:14:04 +0000672 Builder.CreateStore(Result.getScalarVal(), ReturnValue);
Chris Lattner4b0029d2007-08-26 07:14:44 +0000673 } else if (!hasAggregateLLVMType(RV->getType())) {
Daniel Dunbar5ca20842008-09-09 21:00:17 +0000674 Builder.CreateStore(EmitScalarExpr(RV), ReturnValue);
Chris Lattner9b2dc282008-04-04 16:54:41 +0000675 } else if (RV->getType()->isAnyComplexType()) {
Daniel Dunbar5ca20842008-09-09 21:00:17 +0000676 EmitComplexExprIntoAddr(RV, ReturnValue, false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000677 } else {
John McCall558d2ab2010-09-15 10:14:12 +0000678 EmitAggExpr(RV, AggValueSlot::forAddr(ReturnValue, false, true));
Reid Spencer5f016e22007-07-11 17:01:13 +0000679 }
Eli Friedman144ac612008-05-22 01:22:33 +0000680
Anders Carlsson82d8ef02009-02-09 20:31:03 +0000681 EmitBranchThroughCleanup(ReturnBlock);
Reid Spencer5f016e22007-07-11 17:01:13 +0000682}
683
684void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) {
Daniel Dunbar25b6ebf2009-07-19 07:03:11 +0000685 // As long as debug info is modeled with instructions, we have to ensure we
686 // have a place to insert here and write the stop point here.
687 if (getDebugInfo()) {
688 EnsureInsertPoint();
689 EmitStopPoint(&S);
690 }
691
Ted Kremeneke4ea1f42008-10-06 18:42:27 +0000692 for (DeclStmt::const_decl_iterator I = S.decl_begin(), E = S.decl_end();
693 I != E; ++I)
694 EmitDecl(**I);
Chris Lattner6fa5f092007-07-12 15:43:07 +0000695}
Chris Lattnerda138702007-07-16 21:28:45 +0000696
Daniel Dunbar09124252008-11-12 08:21:33 +0000697void CodeGenFunction::EmitBreakStmt(const BreakStmt &S) {
Chris Lattnerda138702007-07-16 21:28:45 +0000698 assert(!BreakContinueStack.empty() && "break stmt not in a loop or switch!");
699
Daniel Dunbar09124252008-11-12 08:21:33 +0000700 // If this code is reachable then emit a stop point (if generating
701 // debug info). We have to do this ourselves because we are on the
702 // "simple" statement path.
703 if (HaveInsertPoint())
704 EmitStopPoint(&S);
Mike Stumpec9771d2009-02-08 09:22:19 +0000705
John McCallf1549f62010-07-06 01:34:17 +0000706 JumpDest Block = BreakContinueStack.back().BreakBlock;
Anders Carlsson82d8ef02009-02-09 20:31:03 +0000707 EmitBranchThroughCleanup(Block);
Chris Lattnerda138702007-07-16 21:28:45 +0000708}
709
Daniel Dunbar09124252008-11-12 08:21:33 +0000710void CodeGenFunction::EmitContinueStmt(const ContinueStmt &S) {
Chris Lattnerda138702007-07-16 21:28:45 +0000711 assert(!BreakContinueStack.empty() && "continue stmt not in a loop!");
712
Daniel Dunbar09124252008-11-12 08:21:33 +0000713 // If this code is reachable then emit a stop point (if generating
714 // debug info). We have to do this ourselves because we are on the
715 // "simple" statement path.
716 if (HaveInsertPoint())
717 EmitStopPoint(&S);
Mike Stumpec9771d2009-02-08 09:22:19 +0000718
John McCallf1549f62010-07-06 01:34:17 +0000719 JumpDest Block = BreakContinueStack.back().ContinueBlock;
Anders Carlsson82d8ef02009-02-09 20:31:03 +0000720 EmitBranchThroughCleanup(Block);
Chris Lattnerda138702007-07-16 21:28:45 +0000721}
Devang Patel51b09f22007-10-04 23:45:31 +0000722
Devang Patelc049e4f2007-10-08 20:57:48 +0000723/// EmitCaseStmtRange - If case statement range is not too big then
724/// add multiple cases to switch instruction, one for each value within
725/// the range. If range is too big then emit "if" condition check.
726void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S) {
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000727 assert(S.getRHS() && "Expected RHS value in CaseStmt");
Devang Patelc049e4f2007-10-08 20:57:48 +0000728
Anders Carlsson51fe9962008-11-22 21:04:56 +0000729 llvm::APSInt LHS = S.getLHS()->EvaluateAsInt(getContext());
730 llvm::APSInt RHS = S.getRHS()->EvaluateAsInt(getContext());
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000731
Daniel Dunbar16f23572008-07-25 01:11:38 +0000732 // Emit the code for this case. We do this first to make sure it is
733 // properly chained from our predecessor before generating the
734 // switch machinery to enter this block.
Daniel Dunbarf84dcda2008-11-11 04:12:31 +0000735 EmitBlock(createBasicBlock("sw.bb"));
Daniel Dunbar16f23572008-07-25 01:11:38 +0000736 llvm::BasicBlock *CaseDest = Builder.GetInsertBlock();
737 EmitStmt(S.getSubStmt());
738
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000739 // If range is empty, do nothing.
740 if (LHS.isSigned() ? RHS.slt(LHS) : RHS.ult(LHS))
741 return;
Devang Patelc049e4f2007-10-08 20:57:48 +0000742
743 llvm::APInt Range = RHS - LHS;
Daniel Dunbar16f23572008-07-25 01:11:38 +0000744 // FIXME: parameters such as this should not be hardcoded.
Devang Patelc049e4f2007-10-08 20:57:48 +0000745 if (Range.ult(llvm::APInt(Range.getBitWidth(), 64))) {
746 // Range is small enough to add multiple switch instruction cases.
Daniel Dunbar4efde8d2008-07-24 01:18:41 +0000747 for (unsigned i = 0, e = Range.getZExtValue() + 1; i != e; ++i) {
John McCalld16c2cf2011-02-08 08:22:06 +0000748 SwitchInsn->addCase(llvm::ConstantInt::get(getLLVMContext(), LHS),
749 CaseDest);
Devang Patel2d79d0f2007-10-05 20:54:07 +0000750 LHS++;
751 }
Devang Patelc049e4f2007-10-08 20:57:48 +0000752 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000753 }
754
Daniel Dunbar16f23572008-07-25 01:11:38 +0000755 // The range is too big. Emit "if" condition into a new block,
756 // making sure to save and restore the current insertion point.
757 llvm::BasicBlock *RestoreBB = Builder.GetInsertBlock();
Devang Patel2d79d0f2007-10-05 20:54:07 +0000758
Daniel Dunbar16f23572008-07-25 01:11:38 +0000759 // Push this test onto the chain of range checks (which terminates
760 // in the default basic block). The switch's default will be changed
761 // to the top of this chain after switch emission is complete.
762 llvm::BasicBlock *FalseDest = CaseRangeBlock;
Daniel Dunbar55e87422008-11-11 02:29:29 +0000763 CaseRangeBlock = createBasicBlock("sw.caserange");
Devang Patelc049e4f2007-10-08 20:57:48 +0000764
Daniel Dunbar16f23572008-07-25 01:11:38 +0000765 CurFn->getBasicBlockList().push_back(CaseRangeBlock);
766 Builder.SetInsertPoint(CaseRangeBlock);
Devang Patelc049e4f2007-10-08 20:57:48 +0000767
768 // Emit range check.
Mike Stump1eb44332009-09-09 15:08:12 +0000769 llvm::Value *Diff =
770 Builder.CreateSub(SwitchInsn->getCondition(),
John McCalld16c2cf2011-02-08 08:22:06 +0000771 llvm::ConstantInt::get(getLLVMContext(), LHS), "tmp");
Mike Stump1eb44332009-09-09 15:08:12 +0000772 llvm::Value *Cond =
John McCalld16c2cf2011-02-08 08:22:06 +0000773 Builder.CreateICmpULE(Diff, llvm::ConstantInt::get(getLLVMContext(), Range),
774 "inbounds");
Devang Patelc049e4f2007-10-08 20:57:48 +0000775 Builder.CreateCondBr(Cond, CaseDest, FalseDest);
776
Daniel Dunbar16f23572008-07-25 01:11:38 +0000777 // Restore the appropriate insertion point.
Daniel Dunbara448fb22008-11-11 23:11:34 +0000778 if (RestoreBB)
779 Builder.SetInsertPoint(RestoreBB);
780 else
781 Builder.ClearInsertionPoint();
Devang Patelc049e4f2007-10-08 20:57:48 +0000782}
783
784void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) {
785 if (S.getRHS()) {
786 EmitCaseStmtRange(S);
787 return;
788 }
Mike Stump1eb44332009-09-09 15:08:12 +0000789
Daniel Dunbarf84dcda2008-11-11 04:12:31 +0000790 EmitBlock(createBasicBlock("sw.bb"));
Devang Patelc049e4f2007-10-08 20:57:48 +0000791 llvm::BasicBlock *CaseDest = Builder.GetInsertBlock();
Anders Carlsson51fe9962008-11-22 21:04:56 +0000792 llvm::APSInt CaseVal = S.getLHS()->EvaluateAsInt(getContext());
John McCalld16c2cf2011-02-08 08:22:06 +0000793 SwitchInsn->addCase(llvm::ConstantInt::get(getLLVMContext(), CaseVal),
794 CaseDest);
Mike Stump1eb44332009-09-09 15:08:12 +0000795
Chris Lattner5512f282009-03-04 04:46:18 +0000796 // Recursively emitting the statement is acceptable, but is not wonderful for
797 // code where we have many case statements nested together, i.e.:
798 // case 1:
799 // case 2:
800 // case 3: etc.
801 // Handling this recursively will create a new block for each case statement
802 // that falls through to the next case which is IR intensive. It also causes
803 // deep recursion which can run into stack depth limitations. Handle
804 // sequential non-range case statements specially.
805 const CaseStmt *CurCase = &S;
806 const CaseStmt *NextCase = dyn_cast<CaseStmt>(S.getSubStmt());
807
808 // Otherwise, iteratively add consequtive cases to this switch stmt.
809 while (NextCase && NextCase->getRHS() == 0) {
810 CurCase = NextCase;
811 CaseVal = CurCase->getLHS()->EvaluateAsInt(getContext());
John McCalld16c2cf2011-02-08 08:22:06 +0000812 SwitchInsn->addCase(llvm::ConstantInt::get(getLLVMContext(), CaseVal),
813 CaseDest);
Chris Lattner5512f282009-03-04 04:46:18 +0000814
815 NextCase = dyn_cast<CaseStmt>(CurCase->getSubStmt());
816 }
Mike Stump1eb44332009-09-09 15:08:12 +0000817
Chris Lattner5512f282009-03-04 04:46:18 +0000818 // Normal default recursion for non-cases.
819 EmitStmt(CurCase->getSubStmt());
Devang Patel51b09f22007-10-04 23:45:31 +0000820}
821
822void CodeGenFunction::EmitDefaultStmt(const DefaultStmt &S) {
Daniel Dunbar16f23572008-07-25 01:11:38 +0000823 llvm::BasicBlock *DefaultBlock = SwitchInsn->getDefaultDest();
Mike Stump1eb44332009-09-09 15:08:12 +0000824 assert(DefaultBlock->empty() &&
Daniel Dunbar55e87422008-11-11 02:29:29 +0000825 "EmitDefaultStmt: Default block already defined?");
Daniel Dunbar16f23572008-07-25 01:11:38 +0000826 EmitBlock(DefaultBlock);
Devang Patel51b09f22007-10-04 23:45:31 +0000827 EmitStmt(S.getSubStmt());
828}
829
830void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
John McCallf1549f62010-07-06 01:34:17 +0000831 JumpDest SwitchExit = getJumpDestInCurrentScope("sw.epilog");
832
833 RunCleanupsScope ConditionScope(*this);
Douglas Gregord3d53012009-11-24 17:07:59 +0000834
835 if (S.getConditionVariable())
John McCallb6bbcc92010-10-15 04:57:14 +0000836 EmitAutoVarDecl(*S.getConditionVariable());
Douglas Gregord3d53012009-11-24 17:07:59 +0000837
Devang Patel51b09f22007-10-04 23:45:31 +0000838 llvm::Value *CondV = EmitScalarExpr(S.getCond());
839
840 // Handle nested switch statements.
841 llvm::SwitchInst *SavedSwitchInsn = SwitchInsn;
Devang Patelc049e4f2007-10-08 20:57:48 +0000842 llvm::BasicBlock *SavedCRBlock = CaseRangeBlock;
Devang Patel51b09f22007-10-04 23:45:31 +0000843
Daniel Dunbar16f23572008-07-25 01:11:38 +0000844 // Create basic block to hold stuff that comes after switch
845 // statement. We also need to create a default block now so that
846 // explicit case ranges tests can have a place to jump to on
847 // failure.
Daniel Dunbar55e87422008-11-11 02:29:29 +0000848 llvm::BasicBlock *DefaultBlock = createBasicBlock("sw.default");
Daniel Dunbar16f23572008-07-25 01:11:38 +0000849 SwitchInsn = Builder.CreateSwitch(CondV, DefaultBlock);
850 CaseRangeBlock = DefaultBlock;
Devang Patel51b09f22007-10-04 23:45:31 +0000851
Daniel Dunbar09124252008-11-12 08:21:33 +0000852 // Clear the insertion point to indicate we are in unreachable code.
853 Builder.ClearInsertionPoint();
Eli Friedmand28a80d2008-05-12 16:08:04 +0000854
Devang Patele9b8c0a2007-10-30 20:59:40 +0000855 // All break statements jump to NextBlock. If BreakContinueStack is non empty
856 // then reuse last ContinueBlock.
John McCallf1549f62010-07-06 01:34:17 +0000857 JumpDest OuterContinue;
Anders Carlssone4b6d342009-02-10 05:52:02 +0000858 if (!BreakContinueStack.empty())
John McCallf1549f62010-07-06 01:34:17 +0000859 OuterContinue = BreakContinueStack.back().ContinueBlock;
Anders Carlssone4b6d342009-02-10 05:52:02 +0000860
John McCallf1549f62010-07-06 01:34:17 +0000861 BreakContinueStack.push_back(BreakContinue(SwitchExit, OuterContinue));
Devang Patel51b09f22007-10-04 23:45:31 +0000862
863 // Emit switch body.
864 EmitStmt(S.getBody());
Mike Stump1eb44332009-09-09 15:08:12 +0000865
Anders Carlssone4b6d342009-02-10 05:52:02 +0000866 BreakContinueStack.pop_back();
Devang Patel51b09f22007-10-04 23:45:31 +0000867
Daniel Dunbar16f23572008-07-25 01:11:38 +0000868 // Update the default block in case explicit case range tests have
869 // been chained on top.
870 SwitchInsn->setSuccessor(0, CaseRangeBlock);
Mike Stump1eb44332009-09-09 15:08:12 +0000871
John McCallf1549f62010-07-06 01:34:17 +0000872 // If a default was never emitted:
Daniel Dunbar16f23572008-07-25 01:11:38 +0000873 if (!DefaultBlock->getParent()) {
John McCallf1549f62010-07-06 01:34:17 +0000874 // If we have cleanups, emit the default block so that there's a
875 // place to jump through the cleanups from.
876 if (ConditionScope.requiresCleanups()) {
877 EmitBlock(DefaultBlock);
878
879 // Otherwise, just forward the default block to the switch end.
880 } else {
John McCallff8e1152010-07-23 21:56:41 +0000881 DefaultBlock->replaceAllUsesWith(SwitchExit.getBlock());
John McCallf1549f62010-07-06 01:34:17 +0000882 delete DefaultBlock;
883 }
Daniel Dunbar16f23572008-07-25 01:11:38 +0000884 }
Devang Patel51b09f22007-10-04 23:45:31 +0000885
John McCallff8e1152010-07-23 21:56:41 +0000886 ConditionScope.ForceCleanup();
887
Daniel Dunbar16f23572008-07-25 01:11:38 +0000888 // Emit continuation.
John McCallff8e1152010-07-23 21:56:41 +0000889 EmitBlock(SwitchExit.getBlock(), true);
Daniel Dunbar16f23572008-07-25 01:11:38 +0000890
Devang Patel51b09f22007-10-04 23:45:31 +0000891 SwitchInsn = SavedSwitchInsn;
Devang Patelc049e4f2007-10-08 20:57:48 +0000892 CaseRangeBlock = SavedCRBlock;
Devang Patel51b09f22007-10-04 23:45:31 +0000893}
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000894
Chris Lattner2819fa82009-04-26 17:57:12 +0000895static std::string
Daniel Dunbar444be732009-11-13 05:51:54 +0000896SimplifyConstraint(const char *Constraint, const TargetInfo &Target,
Chris Lattner2819fa82009-04-26 17:57:12 +0000897 llvm::SmallVectorImpl<TargetInfo::ConstraintInfo> *OutCons=0) {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000898 std::string Result;
Mike Stump1eb44332009-09-09 15:08:12 +0000899
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000900 while (*Constraint) {
901 switch (*Constraint) {
902 default:
John Thompson2f474ea2010-09-18 01:15:13 +0000903 Result += Target.convertConstraint(*Constraint);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000904 break;
905 // Ignore these
906 case '*':
907 case '?':
908 case '!':
John Thompsonef44e112010-08-10 19:20:14 +0000909 case '=': // Will see this and the following in mult-alt constraints.
910 case '+':
911 break;
John Thompson2f474ea2010-09-18 01:15:13 +0000912 case ',':
913 Result += "|";
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000914 break;
915 case 'g':
916 Result += "imr";
917 break;
Anders Carlsson300fb5d2009-01-18 02:06:20 +0000918 case '[': {
Chris Lattner2819fa82009-04-26 17:57:12 +0000919 assert(OutCons &&
Anders Carlsson300fb5d2009-01-18 02:06:20 +0000920 "Must pass output names to constraints with a symbolic name");
921 unsigned Index;
Mike Stump1eb44332009-09-09 15:08:12 +0000922 bool result = Target.resolveSymbolicName(Constraint,
Chris Lattner2819fa82009-04-26 17:57:12 +0000923 &(*OutCons)[0],
924 OutCons->size(), Index);
Chris Lattnercbf40f92011-01-05 18:41:53 +0000925 assert(result && "Could not resolve symbolic name"); (void)result;
Anders Carlsson300fb5d2009-01-18 02:06:20 +0000926 Result += llvm::utostr(Index);
927 break;
928 }
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000929 }
Mike Stump1eb44332009-09-09 15:08:12 +0000930
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000931 Constraint++;
932 }
Mike Stump1eb44332009-09-09 15:08:12 +0000933
Anders Carlssonfb1aeb82008-02-05 16:35:33 +0000934 return Result;
935}
936
Rafael Espindola03117d12011-01-01 21:12:33 +0000937/// AddVariableConstraints - Look at AsmExpr and if it is a variable declared
938/// as using a particular register add that as a constraint that will be used
939/// in this asm stmt.
Rafael Espindola0ec89f92010-12-30 22:59:32 +0000940static std::string
Rafael Espindola03117d12011-01-01 21:12:33 +0000941AddVariableConstraints(const std::string &Constraint, const Expr &AsmExpr,
942 const TargetInfo &Target, CodeGenModule &CGM,
943 const AsmStmt &Stmt) {
Rafael Espindola0ec89f92010-12-30 22:59:32 +0000944 const DeclRefExpr *AsmDeclRef = dyn_cast<DeclRefExpr>(&AsmExpr);
945 if (!AsmDeclRef)
946 return Constraint;
947 const ValueDecl &Value = *AsmDeclRef->getDecl();
948 const VarDecl *Variable = dyn_cast<VarDecl>(&Value);
949 if (!Variable)
950 return Constraint;
951 AsmLabelAttr *Attr = Variable->getAttr<AsmLabelAttr>();
952 if (!Attr)
953 return Constraint;
954 llvm::StringRef Register = Attr->getLabel();
Rafael Espindolabaf86952011-01-01 21:47:03 +0000955 assert(Target.isValidGCCRegisterName(Register));
Rafael Espindola33a53442011-01-02 03:59:13 +0000956 // FIXME: We should check which registers are compatible with "r" or "x".
957 if (Constraint != "r" && Constraint != "x") {
Rafael Espindola0ec89f92010-12-30 22:59:32 +0000958 CGM.ErrorUnsupported(&Stmt, "__asm__");
959 return Constraint;
960 }
961 return "{" + Register.str() + "}";
962}
963
Eli Friedman6d7cfd72010-07-16 00:55:21 +0000964llvm::Value*
965CodeGenFunction::EmitAsmInputLValue(const AsmStmt &S,
966 const TargetInfo::ConstraintInfo &Info,
967 LValue InputValue, QualType InputType,
968 std::string &ConstraintStr) {
Anders Carlsson63471722009-01-11 19:32:54 +0000969 llvm::Value *Arg;
Mike Stump1eb44332009-09-09 15:08:12 +0000970 if (Info.allowsRegister() || !Info.allowsMemory()) {
Eli Friedman6d7cfd72010-07-16 00:55:21 +0000971 if (!CodeGenFunction::hasAggregateLLVMType(InputType)) {
972 Arg = EmitLoadOfLValue(InputValue, InputType).getScalarVal();
Anders Carlsson63471722009-01-11 19:32:54 +0000973 } else {
Eli Friedman6d7cfd72010-07-16 00:55:21 +0000974 const llvm::Type *Ty = ConvertType(InputType);
Anders Carlssonebaae2a2009-01-12 02:22:13 +0000975 uint64_t Size = CGM.getTargetData().getTypeSizeInBits(Ty);
976 if (Size <= 64 && llvm::isPowerOf2_64(Size)) {
John McCalld16c2cf2011-02-08 08:22:06 +0000977 Ty = llvm::IntegerType::get(getLLVMContext(), Size);
Anders Carlssonebaae2a2009-01-12 02:22:13 +0000978 Ty = llvm::PointerType::getUnqual(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000979
Eli Friedman6d7cfd72010-07-16 00:55:21 +0000980 Arg = Builder.CreateLoad(Builder.CreateBitCast(InputValue.getAddress(),
981 Ty));
Anders Carlssonebaae2a2009-01-12 02:22:13 +0000982 } else {
Eli Friedman6d7cfd72010-07-16 00:55:21 +0000983 Arg = InputValue.getAddress();
Anders Carlssonebaae2a2009-01-12 02:22:13 +0000984 ConstraintStr += '*';
985 }
Anders Carlsson63471722009-01-11 19:32:54 +0000986 }
987 } else {
Eli Friedman6d7cfd72010-07-16 00:55:21 +0000988 Arg = InputValue.getAddress();
Anders Carlsson63471722009-01-11 19:32:54 +0000989 ConstraintStr += '*';
990 }
Mike Stump1eb44332009-09-09 15:08:12 +0000991
Anders Carlsson63471722009-01-11 19:32:54 +0000992 return Arg;
993}
994
Eli Friedman6d7cfd72010-07-16 00:55:21 +0000995llvm::Value* CodeGenFunction::EmitAsmInput(const AsmStmt &S,
996 const TargetInfo::ConstraintInfo &Info,
997 const Expr *InputExpr,
998 std::string &ConstraintStr) {
999 if (Info.allowsRegister() || !Info.allowsMemory())
1000 if (!CodeGenFunction::hasAggregateLLVMType(InputExpr->getType()))
1001 return EmitScalarExpr(InputExpr);
1002
1003 InputExpr = InputExpr->IgnoreParenNoopCasts(getContext());
1004 LValue Dest = EmitLValue(InputExpr);
1005 return EmitAsmInputLValue(S, Info, Dest, InputExpr->getType(), ConstraintStr);
1006}
1007
Chris Lattner47fc7e92010-11-17 05:58:54 +00001008/// getAsmSrcLocInfo - Return the !srcloc metadata node to attach to an inline
Chris Lattner5d936532010-11-17 08:25:26 +00001009/// asm call instruction. The !srcloc MDNode contains a list of constant
1010/// integers which are the source locations of the start of each line in the
1011/// asm.
Chris Lattner47fc7e92010-11-17 05:58:54 +00001012static llvm::MDNode *getAsmSrcLocInfo(const StringLiteral *Str,
1013 CodeGenFunction &CGF) {
Chris Lattner5d936532010-11-17 08:25:26 +00001014 llvm::SmallVector<llvm::Value *, 8> Locs;
1015 // Add the location of the first line to the MDNode.
1016 Locs.push_back(llvm::ConstantInt::get(CGF.Int32Ty,
1017 Str->getLocStart().getRawEncoding()));
1018 llvm::StringRef StrVal = Str->getString();
1019 if (!StrVal.empty()) {
1020 const SourceManager &SM = CGF.CGM.getContext().getSourceManager();
1021 const LangOptions &LangOpts = CGF.CGM.getLangOptions();
1022
1023 // Add the location of the start of each subsequent line of the asm to the
1024 // MDNode.
1025 for (unsigned i = 0, e = StrVal.size()-1; i != e; ++i) {
1026 if (StrVal[i] != '\n') continue;
1027 SourceLocation LineLoc = Str->getLocationOfByte(i+1, SM, LangOpts,
1028 CGF.Target);
1029 Locs.push_back(llvm::ConstantInt::get(CGF.Int32Ty,
1030 LineLoc.getRawEncoding()));
1031 }
1032 }
1033
1034 return llvm::MDNode::get(CGF.getLLVMContext(), Locs.data(), Locs.size());
Chris Lattner47fc7e92010-11-17 05:58:54 +00001035}
1036
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001037void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
Chris Lattner458cd9c2009-03-10 23:21:44 +00001038 // Analyze the asm string to decompose it into its pieces. We know that Sema
1039 // has already done this, so it is guaranteed to be successful.
1040 llvm::SmallVector<AsmStmt::AsmStringPiece, 4> Pieces;
Chris Lattnerfb5058e2009-03-10 23:41:04 +00001041 unsigned DiagOffs;
1042 S.AnalyzeAsmString(Pieces, getContext(), DiagOffs);
Mike Stump1eb44332009-09-09 15:08:12 +00001043
Chris Lattner458cd9c2009-03-10 23:21:44 +00001044 // Assemble the pieces into the final asm string.
1045 std::string AsmString;
1046 for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
1047 if (Pieces[i].isString())
1048 AsmString += Pieces[i].getString();
1049 else if (Pieces[i].getModifier() == '\0')
1050 AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo());
1051 else
1052 AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' +
1053 Pieces[i].getModifier() + '}';
Daniel Dunbar281f55c2008-10-17 20:58:01 +00001054 }
Mike Stump1eb44332009-09-09 15:08:12 +00001055
Chris Lattner481fef92009-05-03 07:05:00 +00001056 // Get all the output and input constraints together.
1057 llvm::SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos;
1058 llvm::SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos;
1059
Mike Stump1eb44332009-09-09 15:08:12 +00001060 for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) {
Chris Lattner481fef92009-05-03 07:05:00 +00001061 TargetInfo::ConstraintInfo Info(S.getOutputConstraint(i),
1062 S.getOutputName(i));
Chris Lattnerb9922592010-03-03 21:52:23 +00001063 bool IsValid = Target.validateOutputConstraint(Info); (void)IsValid;
1064 assert(IsValid && "Failed to parse output constraint");
Chris Lattner481fef92009-05-03 07:05:00 +00001065 OutputConstraintInfos.push_back(Info);
Mike Stump1eb44332009-09-09 15:08:12 +00001066 }
1067
Chris Lattner481fef92009-05-03 07:05:00 +00001068 for (unsigned i = 0, e = S.getNumInputs(); i != e; i++) {
1069 TargetInfo::ConstraintInfo Info(S.getInputConstraint(i),
1070 S.getInputName(i));
Chris Lattnerb9922592010-03-03 21:52:23 +00001071 bool IsValid = Target.validateInputConstraint(OutputConstraintInfos.data(),
1072 S.getNumOutputs(), Info);
1073 assert(IsValid && "Failed to parse input constraint"); (void)IsValid;
Chris Lattner481fef92009-05-03 07:05:00 +00001074 InputConstraintInfos.push_back(Info);
1075 }
Mike Stump1eb44332009-09-09 15:08:12 +00001076
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001077 std::string Constraints;
Mike Stump1eb44332009-09-09 15:08:12 +00001078
Chris Lattnerede9d902009-05-03 07:53:25 +00001079 std::vector<LValue> ResultRegDests;
1080 std::vector<QualType> ResultRegQualTys;
Chris Lattnera077b5c2009-05-03 08:21:20 +00001081 std::vector<const llvm::Type *> ResultRegTypes;
1082 std::vector<const llvm::Type *> ResultTruncRegTypes;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001083 std::vector<const llvm::Type*> ArgTypes;
1084 std::vector<llvm::Value*> Args;
Anders Carlssonf39a4212008-02-05 20:01:53 +00001085
1086 // Keep track of inout constraints.
1087 std::string InOutConstraints;
1088 std::vector<llvm::Value*> InOutArgs;
1089 std::vector<const llvm::Type*> InOutArgTypes;
Anders Carlsson03eb5432009-01-27 20:38:24 +00001090
Mike Stump1eb44332009-09-09 15:08:12 +00001091 for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) {
Chris Lattner481fef92009-05-03 07:05:00 +00001092 TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i];
Anders Carlsson03eb5432009-01-27 20:38:24 +00001093
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001094 // Simplify the output constraint.
Chris Lattner481fef92009-05-03 07:05:00 +00001095 std::string OutputConstraint(S.getOutputConstraint(i));
Lauro Ramos Venancioa5694b82008-02-26 18:33:46 +00001096 OutputConstraint = SimplifyConstraint(OutputConstraint.c_str() + 1, Target);
Mike Stump1eb44332009-09-09 15:08:12 +00001097
Chris Lattner810f6d52009-03-13 17:38:01 +00001098 const Expr *OutExpr = S.getOutputExpr(i);
1099 OutExpr = OutExpr->IgnoreParenNoopCasts(getContext());
Mike Stump1eb44332009-09-09 15:08:12 +00001100
Rafael Espindola03117d12011-01-01 21:12:33 +00001101 OutputConstraint = AddVariableConstraints(OutputConstraint, *OutExpr, Target,
Rafael Espindola0ec89f92010-12-30 22:59:32 +00001102 CGM, S);
1103
Chris Lattner810f6d52009-03-13 17:38:01 +00001104 LValue Dest = EmitLValue(OutExpr);
Chris Lattnerede9d902009-05-03 07:53:25 +00001105 if (!Constraints.empty())
Anders Carlssonbad3a942009-05-01 00:16:04 +00001106 Constraints += ',';
1107
Chris Lattnera077b5c2009-05-03 08:21:20 +00001108 // If this is a register output, then make the inline asm return it
1109 // by-value. If this is a memory result, return the value by-reference.
Chris Lattnerede9d902009-05-03 07:53:25 +00001110 if (!Info.allowsMemory() && !hasAggregateLLVMType(OutExpr->getType())) {
Chris Lattnera077b5c2009-05-03 08:21:20 +00001111 Constraints += "=" + OutputConstraint;
Chris Lattnerede9d902009-05-03 07:53:25 +00001112 ResultRegQualTys.push_back(OutExpr->getType());
1113 ResultRegDests.push_back(Dest);
Chris Lattnera077b5c2009-05-03 08:21:20 +00001114 ResultRegTypes.push_back(ConvertTypeForMem(OutExpr->getType()));
1115 ResultTruncRegTypes.push_back(ResultRegTypes.back());
Mike Stump1eb44332009-09-09 15:08:12 +00001116
Chris Lattnera077b5c2009-05-03 08:21:20 +00001117 // If this output is tied to an input, and if the input is larger, then
1118 // we need to set the actual result type of the inline asm node to be the
1119 // same as the input type.
1120 if (Info.hasMatchingInput()) {
Chris Lattnerebfc9852009-05-03 08:38:58 +00001121 unsigned InputNo;
1122 for (InputNo = 0; InputNo != S.getNumInputs(); ++InputNo) {
1123 TargetInfo::ConstraintInfo &Input = InputConstraintInfos[InputNo];
Chris Lattneraab64d02010-04-23 17:27:29 +00001124 if (Input.hasTiedOperand() && Input.getTiedOperand() == i)
Chris Lattnera077b5c2009-05-03 08:21:20 +00001125 break;
Chris Lattnerebfc9852009-05-03 08:38:58 +00001126 }
1127 assert(InputNo != S.getNumInputs() && "Didn't find matching input!");
Mike Stump1eb44332009-09-09 15:08:12 +00001128
Chris Lattnera077b5c2009-05-03 08:21:20 +00001129 QualType InputTy = S.getInputExpr(InputNo)->getType();
Chris Lattneraab64d02010-04-23 17:27:29 +00001130 QualType OutputType = OutExpr->getType();
Mike Stump1eb44332009-09-09 15:08:12 +00001131
Chris Lattnera077b5c2009-05-03 08:21:20 +00001132 uint64_t InputSize = getContext().getTypeSize(InputTy);
Chris Lattneraab64d02010-04-23 17:27:29 +00001133 if (getContext().getTypeSize(OutputType) < InputSize) {
1134 // Form the asm to return the value as a larger integer or fp type.
1135 ResultRegTypes.back() = ConvertType(InputTy);
Chris Lattnera077b5c2009-05-03 08:21:20 +00001136 }
1137 }
Dale Johannesenf6e2c202010-10-29 23:12:32 +00001138 if (const llvm::Type* AdjTy =
1139 Target.adjustInlineAsmType(OutputConstraint, ResultRegTypes.back(),
John McCalld16c2cf2011-02-08 08:22:06 +00001140 getLLVMContext()))
Dale Johannesenf6e2c202010-10-29 23:12:32 +00001141 ResultRegTypes.back() = AdjTy;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001142 } else {
1143 ArgTypes.push_back(Dest.getAddress()->getType());
Anders Carlssoncad3ab62008-02-05 16:57:38 +00001144 Args.push_back(Dest.getAddress());
Anders Carlssonf39a4212008-02-05 20:01:53 +00001145 Constraints += "=*";
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001146 Constraints += OutputConstraint;
Anders Carlssonf39a4212008-02-05 20:01:53 +00001147 }
Mike Stump1eb44332009-09-09 15:08:12 +00001148
Chris Lattner44def072009-04-26 07:16:29 +00001149 if (Info.isReadWrite()) {
Anders Carlssonf39a4212008-02-05 20:01:53 +00001150 InOutConstraints += ',';
Anders Carlsson63471722009-01-11 19:32:54 +00001151
Anders Carlssonfca93612009-08-04 18:18:36 +00001152 const Expr *InputExpr = S.getOutputExpr(i);
Eli Friedman6d7cfd72010-07-16 00:55:21 +00001153 llvm::Value *Arg = EmitAsmInputLValue(S, Info, Dest, InputExpr->getType(),
1154 InOutConstraints);
Mike Stump1eb44332009-09-09 15:08:12 +00001155
Chris Lattner44def072009-04-26 07:16:29 +00001156 if (Info.allowsRegister())
Anders Carlsson9f2505b2009-01-11 21:23:27 +00001157 InOutConstraints += llvm::utostr(i);
1158 else
1159 InOutConstraints += OutputConstraint;
Anders Carlsson2763b3a2009-01-11 19:46:50 +00001160
Anders Carlssonfca93612009-08-04 18:18:36 +00001161 InOutArgTypes.push_back(Arg->getType());
1162 InOutArgs.push_back(Arg);
Anders Carlssonf39a4212008-02-05 20:01:53 +00001163 }
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001164 }
Mike Stump1eb44332009-09-09 15:08:12 +00001165
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001166 unsigned NumConstraints = S.getNumOutputs() + S.getNumInputs();
Mike Stump1eb44332009-09-09 15:08:12 +00001167
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001168 for (unsigned i = 0, e = S.getNumInputs(); i != e; i++) {
1169 const Expr *InputExpr = S.getInputExpr(i);
1170
Chris Lattner481fef92009-05-03 07:05:00 +00001171 TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
1172
Chris Lattnerede9d902009-05-03 07:53:25 +00001173 if (!Constraints.empty())
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001174 Constraints += ',';
Mike Stump1eb44332009-09-09 15:08:12 +00001175
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001176 // Simplify the input constraint.
Chris Lattner481fef92009-05-03 07:05:00 +00001177 std::string InputConstraint(S.getInputConstraint(i));
Anders Carlsson300fb5d2009-01-18 02:06:20 +00001178 InputConstraint = SimplifyConstraint(InputConstraint.c_str(), Target,
Chris Lattner2819fa82009-04-26 17:57:12 +00001179 &OutputConstraintInfos);
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001180
Rafael Espindola0ec89f92010-12-30 22:59:32 +00001181 InputConstraint =
Rafael Espindola03117d12011-01-01 21:12:33 +00001182 AddVariableConstraints(InputConstraint,
Rafael Espindola0ec89f92010-12-30 22:59:32 +00001183 *InputExpr->IgnoreParenNoopCasts(getContext()),
1184 Target, CGM, S);
1185
Anders Carlsson63471722009-01-11 19:32:54 +00001186 llvm::Value *Arg = EmitAsmInput(S, Info, InputExpr, Constraints);
Mike Stump1eb44332009-09-09 15:08:12 +00001187
Chris Lattner4df4ee02009-05-03 07:27:51 +00001188 // If this input argument is tied to a larger output result, extend the
1189 // input to be the same size as the output. The LLVM backend wants to see
1190 // the input and output of a matching constraint be the same size. Note
1191 // that GCC does not define what the top bits are here. We use zext because
1192 // that is usually cheaper, but LLVM IR should really get an anyext someday.
1193 if (Info.hasTiedOperand()) {
1194 unsigned Output = Info.getTiedOperand();
Chris Lattneraab64d02010-04-23 17:27:29 +00001195 QualType OutputType = S.getOutputExpr(Output)->getType();
Chris Lattner4df4ee02009-05-03 07:27:51 +00001196 QualType InputTy = InputExpr->getType();
Mike Stump1eb44332009-09-09 15:08:12 +00001197
Chris Lattneraab64d02010-04-23 17:27:29 +00001198 if (getContext().getTypeSize(OutputType) >
Chris Lattner4df4ee02009-05-03 07:27:51 +00001199 getContext().getTypeSize(InputTy)) {
1200 // Use ptrtoint as appropriate so that we can do our extension.
1201 if (isa<llvm::PointerType>(Arg->getType()))
Chris Lattner77b89b82010-06-27 07:15:29 +00001202 Arg = Builder.CreatePtrToInt(Arg, IntPtrTy);
Chris Lattneraab64d02010-04-23 17:27:29 +00001203 const llvm::Type *OutputTy = ConvertType(OutputType);
1204 if (isa<llvm::IntegerType>(OutputTy))
1205 Arg = Builder.CreateZExt(Arg, OutputTy);
1206 else
1207 Arg = Builder.CreateFPExt(Arg, OutputTy);
Chris Lattner4df4ee02009-05-03 07:27:51 +00001208 }
1209 }
Dale Johannesenf6e2c202010-10-29 23:12:32 +00001210 if (const llvm::Type* AdjTy =
1211 Target.adjustInlineAsmType(InputConstraint, Arg->getType(),
John McCalld16c2cf2011-02-08 08:22:06 +00001212 getLLVMContext()))
Dale Johannesenf6e2c202010-10-29 23:12:32 +00001213 Arg = Builder.CreateBitCast(Arg, AdjTy);
Mike Stump1eb44332009-09-09 15:08:12 +00001214
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001215 ArgTypes.push_back(Arg->getType());
1216 Args.push_back(Arg);
1217 Constraints += InputConstraint;
1218 }
Mike Stump1eb44332009-09-09 15:08:12 +00001219
Anders Carlssonf39a4212008-02-05 20:01:53 +00001220 // Append the "input" part of inout constraints last.
1221 for (unsigned i = 0, e = InOutArgs.size(); i != e; i++) {
1222 ArgTypes.push_back(InOutArgTypes[i]);
1223 Args.push_back(InOutArgs[i]);
1224 }
1225 Constraints += InOutConstraints;
Mike Stump1eb44332009-09-09 15:08:12 +00001226
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001227 // Clobbers
1228 for (unsigned i = 0, e = S.getNumClobbers(); i != e; i++) {
Anders Carlsson83c021c2010-01-30 19:12:25 +00001229 llvm::StringRef Clobber = S.getClobber(i)->getString();
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001230
Anders Carlsson83c021c2010-01-30 19:12:25 +00001231 Clobber = Target.getNormalizedGCCRegisterName(Clobber);
Mike Stump1eb44332009-09-09 15:08:12 +00001232
Anders Carlssonea041752008-02-06 00:11:32 +00001233 if (i != 0 || NumConstraints != 0)
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001234 Constraints += ',';
Mike Stump1eb44332009-09-09 15:08:12 +00001235
Anders Carlssonea041752008-02-06 00:11:32 +00001236 Constraints += "~{";
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001237 Constraints += Clobber;
Anders Carlssonea041752008-02-06 00:11:32 +00001238 Constraints += '}';
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001239 }
Mike Stump1eb44332009-09-09 15:08:12 +00001240
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001241 // Add machine specific clobbers
Eli Friedmanccf614c2008-12-21 01:15:32 +00001242 std::string MachineClobbers = Target.getClobbers();
1243 if (!MachineClobbers.empty()) {
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001244 if (!Constraints.empty())
1245 Constraints += ',';
Eli Friedmanccf614c2008-12-21 01:15:32 +00001246 Constraints += MachineClobbers;
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001247 }
Anders Carlssonbad3a942009-05-01 00:16:04 +00001248
1249 const llvm::Type *ResultType;
Chris Lattnera077b5c2009-05-03 08:21:20 +00001250 if (ResultRegTypes.empty())
John McCalld16c2cf2011-02-08 08:22:06 +00001251 ResultType = llvm::Type::getVoidTy(getLLVMContext());
Chris Lattnera077b5c2009-05-03 08:21:20 +00001252 else if (ResultRegTypes.size() == 1)
1253 ResultType = ResultRegTypes[0];
Anders Carlssonbad3a942009-05-01 00:16:04 +00001254 else
John McCalld16c2cf2011-02-08 08:22:06 +00001255 ResultType = llvm::StructType::get(getLLVMContext(), ResultRegTypes);
Mike Stump1eb44332009-09-09 15:08:12 +00001256
1257 const llvm::FunctionType *FTy =
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001258 llvm::FunctionType::get(ResultType, ArgTypes, false);
Mike Stump1eb44332009-09-09 15:08:12 +00001259
1260 llvm::InlineAsm *IA =
1261 llvm::InlineAsm::get(FTy, AsmString, Constraints,
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001262 S.isVolatile() || S.getNumOutputs() == 0);
Anders Carlssonbad3a942009-05-01 00:16:04 +00001263 llvm::CallInst *Result = Builder.CreateCall(IA, Args.begin(), Args.end());
Anders Carlssonbc0822b2009-03-02 19:58:15 +00001264 Result->addAttribute(~0, llvm::Attribute::NoUnwind);
Mike Stump1eb44332009-09-09 15:08:12 +00001265
Chris Lattnerfc1a9c32010-04-07 05:46:54 +00001266 // Slap the source location of the inline asm into a !srcloc metadata on the
1267 // call.
Chris Lattner47fc7e92010-11-17 05:58:54 +00001268 Result->setMetadata("srcloc", getAsmSrcLocInfo(S.getAsmString(), *this));
Mike Stump1eb44332009-09-09 15:08:12 +00001269
Chris Lattnera077b5c2009-05-03 08:21:20 +00001270 // Extract all of the register value results from the asm.
1271 std::vector<llvm::Value*> RegResults;
1272 if (ResultRegTypes.size() == 1) {
1273 RegResults.push_back(Result);
Anders Carlssonbad3a942009-05-01 00:16:04 +00001274 } else {
Chris Lattnera077b5c2009-05-03 08:21:20 +00001275 for (unsigned i = 0, e = ResultRegTypes.size(); i != e; ++i) {
Anders Carlssonbad3a942009-05-01 00:16:04 +00001276 llvm::Value *Tmp = Builder.CreateExtractValue(Result, i, "asmresult");
Chris Lattnera077b5c2009-05-03 08:21:20 +00001277 RegResults.push_back(Tmp);
Anders Carlssonbad3a942009-05-01 00:16:04 +00001278 }
1279 }
Mike Stump1eb44332009-09-09 15:08:12 +00001280
Chris Lattnera077b5c2009-05-03 08:21:20 +00001281 for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
1282 llvm::Value *Tmp = RegResults[i];
Mike Stump1eb44332009-09-09 15:08:12 +00001283
Chris Lattnera077b5c2009-05-03 08:21:20 +00001284 // If the result type of the LLVM IR asm doesn't match the result type of
1285 // the expression, do the conversion.
1286 if (ResultRegTypes[i] != ResultTruncRegTypes[i]) {
1287 const llvm::Type *TruncTy = ResultTruncRegTypes[i];
Chris Lattneraab64d02010-04-23 17:27:29 +00001288
1289 // Truncate the integer result to the right size, note that TruncTy can be
1290 // a pointer.
1291 if (TruncTy->isFloatingPointTy())
1292 Tmp = Builder.CreateFPTrunc(Tmp, TruncTy);
Dan Gohman2dca88f2010-04-24 04:55:02 +00001293 else if (TruncTy->isPointerTy() && Tmp->getType()->isIntegerTy()) {
Chris Lattneraab64d02010-04-23 17:27:29 +00001294 uint64_t ResSize = CGM.getTargetData().getTypeSizeInBits(TruncTy);
John McCalld16c2cf2011-02-08 08:22:06 +00001295 Tmp = Builder.CreateTrunc(Tmp,
1296 llvm::IntegerType::get(getLLVMContext(), (unsigned)ResSize));
Chris Lattnera077b5c2009-05-03 08:21:20 +00001297 Tmp = Builder.CreateIntToPtr(Tmp, TruncTy);
Dan Gohman2dca88f2010-04-24 04:55:02 +00001298 } else if (Tmp->getType()->isPointerTy() && TruncTy->isIntegerTy()) {
1299 uint64_t TmpSize =CGM.getTargetData().getTypeSizeInBits(Tmp->getType());
John McCalld16c2cf2011-02-08 08:22:06 +00001300 Tmp = Builder.CreatePtrToInt(Tmp,
1301 llvm::IntegerType::get(getLLVMContext(), (unsigned)TmpSize));
Dan Gohman2dca88f2010-04-24 04:55:02 +00001302 Tmp = Builder.CreateTrunc(Tmp, TruncTy);
1303 } else if (TruncTy->isIntegerTy()) {
1304 Tmp = Builder.CreateTrunc(Tmp, TruncTy);
Dale Johannesenf6e2c202010-10-29 23:12:32 +00001305 } else if (TruncTy->isVectorTy()) {
1306 Tmp = Builder.CreateBitCast(Tmp, TruncTy);
Chris Lattnera077b5c2009-05-03 08:21:20 +00001307 }
1308 }
Mike Stump1eb44332009-09-09 15:08:12 +00001309
Chris Lattnera077b5c2009-05-03 08:21:20 +00001310 EmitStoreThroughLValue(RValue::get(Tmp), ResultRegDests[i],
1311 ResultRegQualTys[i]);
1312 }
Anders Carlssonfb1aeb82008-02-05 16:35:33 +00001313}