CGStmt.cpp revision 92b9bd96ce25630f73717965fcaf4b5a761e49e5
1//===--- CGStmt.cpp - Emit LLVM Code from Statements ----------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This contains code to emit Stmt nodes as LLVM code. 11// 12//===----------------------------------------------------------------------===// 13 14#include "CGDebugInfo.h" 15#include "CodeGenModule.h" 16#include "CodeGenFunction.h" 17#include "clang/AST/StmtVisitor.h" 18#include "clang/Basic/PrettyStackTrace.h" 19#include "clang/Basic/TargetInfo.h" 20#include "llvm/ADT/StringExtras.h" 21#include "llvm/InlineAsm.h" 22#include "llvm/Intrinsics.h" 23#include "llvm/Target/TargetData.h" 24using namespace clang; 25using namespace CodeGen; 26 27//===----------------------------------------------------------------------===// 28// Statement Emission 29//===----------------------------------------------------------------------===// 30 31void CodeGenFunction::EmitStopPoint(const Stmt *S) { 32 if (CGDebugInfo *DI = getDebugInfo()) { 33 if (isa<DeclStmt>(S)) 34 DI->setLocation(S->getLocEnd()); 35 else 36 DI->setLocation(S->getLocStart()); 37 DI->EmitStopPoint(CurFn, Builder); 38 } 39} 40 41void CodeGenFunction::EmitStmt(const Stmt *S) { 42 assert(S && "Null statement?"); 43 44 // Check if we can handle this without bothering to generate an 45 // insert point or debug info. 46 if (EmitSimpleStmt(S)) 47 return; 48 49 // Check if we are generating unreachable code. 50 if (!HaveInsertPoint()) { 51 // If so, and the statement doesn't contain a label, then we do not need to 52 // generate actual code. This is safe because (1) the current point is 53 // unreachable, so we don't need to execute the code, and (2) we've already 54 // handled the statements which update internal data structures (like the 55 // local variable map) which could be used by subsequent statements. 56 if (!ContainsLabel(S)) { 57 // Verify that any decl statements were handled as simple, they may be in 58 // scope of subsequent reachable statements. 59 assert(!isa<DeclStmt>(*S) && "Unexpected DeclStmt!"); 60 return; 61 } 62 63 // Otherwise, make a new block to hold the code. 64 EnsureInsertPoint(); 65 } 66 67 // Generate a stoppoint if we are emitting debug info. 68 EmitStopPoint(S); 69 70 switch (S->getStmtClass()) { 71 default: 72 // Must be an expression in a stmt context. Emit the value (to get 73 // side-effects) and ignore the result. 74 if (!isa<Expr>(S)) 75 ErrorUnsupported(S, "statement"); 76 77 EmitAnyExpr(cast<Expr>(S), 0, false, true); 78 79 // Expression emitters don't handle unreachable blocks yet, so look for one 80 // explicitly here. This handles the common case of a call to a noreturn 81 // function. 82 if (llvm::BasicBlock *CurBB = Builder.GetInsertBlock()) { 83 if (CurBB->empty() && CurBB->use_empty() && !BlockScopes.count(CurBB)) { 84 CurBB->eraseFromParent(); 85 Builder.ClearInsertionPoint(); 86 } 87 } 88 break; 89 case Stmt::IndirectGotoStmtClass: 90 EmitIndirectGotoStmt(cast<IndirectGotoStmt>(*S)); break; 91 92 case Stmt::IfStmtClass: EmitIfStmt(cast<IfStmt>(*S)); break; 93 case Stmt::WhileStmtClass: EmitWhileStmt(cast<WhileStmt>(*S)); break; 94 case Stmt::DoStmtClass: EmitDoStmt(cast<DoStmt>(*S)); break; 95 case Stmt::ForStmtClass: EmitForStmt(cast<ForStmt>(*S)); break; 96 97 case Stmt::ReturnStmtClass: EmitReturnStmt(cast<ReturnStmt>(*S)); break; 98 99 case Stmt::SwitchStmtClass: EmitSwitchStmt(cast<SwitchStmt>(*S)); break; 100 case Stmt::AsmStmtClass: EmitAsmStmt(cast<AsmStmt>(*S)); break; 101 102 case Stmt::ObjCAtTryStmtClass: 103 EmitObjCAtTryStmt(cast<ObjCAtTryStmt>(*S)); 104 break; 105 case Stmt::ObjCAtCatchStmtClass: 106 assert(0 && "@catch statements should be handled by EmitObjCAtTryStmt"); 107 break; 108 case Stmt::ObjCAtFinallyStmtClass: 109 assert(0 && "@finally statements should be handled by EmitObjCAtTryStmt"); 110 break; 111 case Stmt::ObjCAtThrowStmtClass: 112 EmitObjCAtThrowStmt(cast<ObjCAtThrowStmt>(*S)); 113 break; 114 case Stmt::ObjCAtSynchronizedStmtClass: 115 EmitObjCAtSynchronizedStmt(cast<ObjCAtSynchronizedStmt>(*S)); 116 break; 117 case Stmt::ObjCForCollectionStmtClass: 118 EmitObjCForCollectionStmt(cast<ObjCForCollectionStmt>(*S)); 119 break; 120 121 case Stmt::CXXTryStmtClass: 122 EmitCXXTryStmt(cast<CXXTryStmt>(*S)); 123 break; 124 } 125} 126 127bool CodeGenFunction::EmitSimpleStmt(const Stmt *S) { 128 switch (S->getStmtClass()) { 129 default: return false; 130 case Stmt::NullStmtClass: break; 131 case Stmt::CompoundStmtClass: EmitCompoundStmt(cast<CompoundStmt>(*S)); break; 132 case Stmt::DeclStmtClass: EmitDeclStmt(cast<DeclStmt>(*S)); break; 133 case Stmt::LabelStmtClass: EmitLabelStmt(cast<LabelStmt>(*S)); break; 134 case Stmt::GotoStmtClass: EmitGotoStmt(cast<GotoStmt>(*S)); break; 135 case Stmt::BreakStmtClass: EmitBreakStmt(cast<BreakStmt>(*S)); break; 136 case Stmt::ContinueStmtClass: EmitContinueStmt(cast<ContinueStmt>(*S)); break; 137 case Stmt::DefaultStmtClass: EmitDefaultStmt(cast<DefaultStmt>(*S)); break; 138 case Stmt::CaseStmtClass: EmitCaseStmt(cast<CaseStmt>(*S)); break; 139 } 140 141 return true; 142} 143 144/// EmitCompoundStmt - Emit a compound statement {..} node. If GetLast is true, 145/// this captures the expression result of the last sub-statement and returns it 146/// (for use by the statement expression extension). 147RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast, 148 llvm::Value *AggLoc, bool isAggVol) { 149 PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),S.getLBracLoc(), 150 "LLVM IR generation of compound statement ('{}')"); 151 152 CGDebugInfo *DI = getDebugInfo(); 153 if (DI) { 154 DI->setLocation(S.getLBracLoc()); 155 DI->EmitRegionStart(CurFn, Builder); 156 } 157 158 // Keep track of the current cleanup stack depth. 159 CleanupScope Scope(*this); 160 161 for (CompoundStmt::const_body_iterator I = S.body_begin(), 162 E = S.body_end()-GetLast; I != E; ++I) 163 EmitStmt(*I); 164 165 if (DI) { 166 DI->setLocation(S.getRBracLoc()); 167 DI->EmitRegionEnd(CurFn, Builder); 168 } 169 170 RValue RV; 171 if (!GetLast) 172 RV = RValue::get(0); 173 else { 174 // We have to special case labels here. They are statements, but when put 175 // at the end of a statement expression, they yield the value of their 176 // subexpression. Handle this by walking through all labels we encounter, 177 // emitting them before we evaluate the subexpr. 178 const Stmt *LastStmt = S.body_back(); 179 while (const LabelStmt *LS = dyn_cast<LabelStmt>(LastStmt)) { 180 EmitLabel(*LS); 181 LastStmt = LS->getSubStmt(); 182 } 183 184 EnsureInsertPoint(); 185 186 RV = EmitAnyExpr(cast<Expr>(LastStmt), AggLoc); 187 } 188 189 return RV; 190} 191 192void CodeGenFunction::SimplifyForwardingBlocks(llvm::BasicBlock *BB) { 193 llvm::BranchInst *BI = dyn_cast<llvm::BranchInst>(BB->getTerminator()); 194 195 // If there is a cleanup stack, then we it isn't worth trying to 196 // simplify this block (we would need to remove it from the scope map 197 // and cleanup entry). 198 if (!CleanupEntries.empty()) 199 return; 200 201 // Can only simplify direct branches. 202 if (!BI || !BI->isUnconditional()) 203 return; 204 205 BB->replaceAllUsesWith(BI->getSuccessor(0)); 206 BI->eraseFromParent(); 207 BB->eraseFromParent(); 208} 209 210void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB, bool IsFinished) { 211 llvm::BasicBlock *CurBB = Builder.GetInsertBlock(); 212 213 // Fall out of the current block (if necessary). 214 EmitBranch(BB); 215 216 if (IsFinished && BB->use_empty()) { 217 delete BB; 218 return; 219 } 220 221 // If necessary, associate the block with the cleanup stack size. 222 if (!CleanupEntries.empty()) { 223 // Check if the basic block has already been inserted. 224 BlockScopeMap::iterator I = BlockScopes.find(BB); 225 if (I != BlockScopes.end()) { 226 assert(I->second == CleanupEntries.size() - 1); 227 } else { 228 BlockScopes[BB] = CleanupEntries.size() - 1; 229 CleanupEntries.back().Blocks.push_back(BB); 230 } 231 } 232 233 // Place the block after the current block, if possible, or else at 234 // the end of the function. 235 if (CurBB && CurBB->getParent()) 236 CurFn->getBasicBlockList().insertAfter(CurBB, BB); 237 else 238 CurFn->getBasicBlockList().push_back(BB); 239 Builder.SetInsertPoint(BB); 240} 241 242void CodeGenFunction::EmitBranch(llvm::BasicBlock *Target) { 243 // Emit a branch from the current block to the target one if this 244 // was a real block. If this was just a fall-through block after a 245 // terminator, don't emit it. 246 llvm::BasicBlock *CurBB = Builder.GetInsertBlock(); 247 248 if (!CurBB || CurBB->getTerminator()) { 249 // If there is no insert point or the previous block is already 250 // terminated, don't touch it. 251 } else { 252 // Otherwise, create a fall-through branch. 253 Builder.CreateBr(Target); 254 } 255 256 Builder.ClearInsertionPoint(); 257} 258 259void CodeGenFunction::EmitLabel(const LabelStmt &S) { 260 EmitBlock(getBasicBlockForLabel(&S)); 261} 262 263 264void CodeGenFunction::EmitLabelStmt(const LabelStmt &S) { 265 EmitLabel(S); 266 EmitStmt(S.getSubStmt()); 267} 268 269void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) { 270 // If this code is reachable then emit a stop point (if generating 271 // debug info). We have to do this ourselves because we are on the 272 // "simple" statement path. 273 if (HaveInsertPoint()) 274 EmitStopPoint(&S); 275 276 EmitBranchThroughCleanup(getBasicBlockForLabel(S.getLabel())); 277} 278 279 280void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) { 281 // Ensure that we have an i8* for our PHI node. 282 llvm::Value *V = Builder.CreateBitCast(EmitScalarExpr(S.getTarget()), 283 llvm::Type::getInt8PtrTy(VMContext), 284 "addr"); 285 llvm::BasicBlock *CurBB = Builder.GetInsertBlock(); 286 287 288 // Get the basic block for the indirect goto. 289 llvm::BasicBlock *IndGotoBB = GetIndirectGotoBlock(); 290 291 // The first instruction in the block has to be the PHI for the switch dest, 292 // add an entry for this branch. 293 cast<llvm::PHINode>(IndGotoBB->begin())->addIncoming(V, CurBB); 294 295 EmitBranch(IndGotoBB); 296} 297 298void CodeGenFunction::EmitIfStmt(const IfStmt &S) { 299 // C99 6.8.4.1: The first substatement is executed if the expression compares 300 // unequal to 0. The condition must be a scalar type. 301 CleanupScope ConditionScope(*this); 302 303 if (S.getConditionVariable()) 304 EmitLocalBlockVarDecl(*S.getConditionVariable()); 305 306 // If the condition constant folds and can be elided, try to avoid emitting 307 // the condition and the dead arm of the if/else. 308 if (int Cond = ConstantFoldsToSimpleInteger(S.getCond())) { 309 // Figure out which block (then or else) is executed. 310 const Stmt *Executed = S.getThen(), *Skipped = S.getElse(); 311 if (Cond == -1) // Condition false? 312 std::swap(Executed, Skipped); 313 314 // If the skipped block has no labels in it, just emit the executed block. 315 // This avoids emitting dead code and simplifies the CFG substantially. 316 if (!ContainsLabel(Skipped)) { 317 if (Executed) { 318 CleanupScope ExecutedScope(*this); 319 EmitStmt(Executed); 320 } 321 return; 322 } 323 } 324 325 // Otherwise, the condition did not fold, or we couldn't elide it. Just emit 326 // the conditional branch. 327 llvm::BasicBlock *ThenBlock = createBasicBlock("if.then"); 328 llvm::BasicBlock *ContBlock = createBasicBlock("if.end"); 329 llvm::BasicBlock *ElseBlock = ContBlock; 330 if (S.getElse()) 331 ElseBlock = createBasicBlock("if.else"); 332 EmitBranchOnBoolExpr(S.getCond(), ThenBlock, ElseBlock); 333 334 // Emit the 'then' code. 335 EmitBlock(ThenBlock); 336 { 337 CleanupScope ThenScope(*this); 338 EmitStmt(S.getThen()); 339 } 340 EmitBranch(ContBlock); 341 342 // Emit the 'else' code if present. 343 if (const Stmt *Else = S.getElse()) { 344 EmitBlock(ElseBlock); 345 { 346 CleanupScope ElseScope(*this); 347 EmitStmt(Else); 348 } 349 EmitBranch(ContBlock); 350 } 351 352 // Emit the continuation block for code after the if. 353 EmitBlock(ContBlock, true); 354} 355 356void CodeGenFunction::EmitWhileStmt(const WhileStmt &S) { 357 // Emit the header for the loop, insert it, which will create an uncond br to 358 // it. 359 llvm::BasicBlock *LoopHeader = createBasicBlock("while.cond"); 360 EmitBlock(LoopHeader); 361 362 // Create an exit block for when the condition fails, create a block for the 363 // body of the loop. 364 llvm::BasicBlock *ExitBlock = createBasicBlock("while.end"); 365 llvm::BasicBlock *LoopBody = createBasicBlock("while.body"); 366 llvm::BasicBlock *CleanupBlock = 0; 367 llvm::BasicBlock *EffectiveExitBlock = ExitBlock; 368 369 // Store the blocks to use for break and continue. 370 BreakContinueStack.push_back(BreakContinue(ExitBlock, LoopHeader)); 371 372 // C++ [stmt.while]p2: 373 // When the condition of a while statement is a declaration, the 374 // scope of the variable that is declared extends from its point 375 // of declaration (3.3.2) to the end of the while statement. 376 // [...] 377 // The object created in a condition is destroyed and created 378 // with each iteration of the loop. 379 CleanupScope ConditionScope(*this); 380 381 if (S.getConditionVariable()) { 382 EmitLocalBlockVarDecl(*S.getConditionVariable()); 383 384 // If this condition variable requires cleanups, create a basic 385 // block to handle those cleanups. 386 if (ConditionScope.requiresCleanups()) { 387 CleanupBlock = createBasicBlock("while.cleanup"); 388 EffectiveExitBlock = CleanupBlock; 389 } 390 } 391 392 // Evaluate the conditional in the while header. C99 6.8.5.1: The 393 // evaluation of the controlling expression takes place before each 394 // execution of the loop body. 395 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond()); 396 397 // while(1) is common, avoid extra exit blocks. Be sure 398 // to correctly handle break/continue though. 399 bool EmitBoolCondBranch = true; 400 if (llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal)) 401 if (C->isOne()) 402 EmitBoolCondBranch = false; 403 404 // As long as the condition is true, go to the loop body. 405 if (EmitBoolCondBranch) 406 Builder.CreateCondBr(BoolCondVal, LoopBody, EffectiveExitBlock); 407 408 // Emit the loop body. 409 { 410 CleanupScope BodyScope(*this); 411 EmitBlock(LoopBody); 412 EmitStmt(S.getBody()); 413 } 414 415 BreakContinueStack.pop_back(); 416 417 if (CleanupBlock) { 418 // If we have a cleanup block, jump there to perform cleanups 419 // before looping. 420 EmitBranch(CleanupBlock); 421 422 // Emit the cleanup block, performing cleanups for the condition 423 // and then jumping to either the loop header or the exit block. 424 EmitBlock(CleanupBlock); 425 ConditionScope.ForceCleanup(); 426 Builder.CreateCondBr(BoolCondVal, LoopHeader, ExitBlock); 427 } else { 428 // Cycle to the condition. 429 EmitBranch(LoopHeader); 430 } 431 432 // Emit the exit block. 433 EmitBlock(ExitBlock, true); 434 435 436 // The LoopHeader typically is just a branch if we skipped emitting 437 // a branch, try to erase it. 438 if (!EmitBoolCondBranch && !CleanupBlock) 439 SimplifyForwardingBlocks(LoopHeader); 440} 441 442void CodeGenFunction::EmitDoStmt(const DoStmt &S) { 443 // Emit the body for the loop, insert it, which will create an uncond br to 444 // it. 445 llvm::BasicBlock *LoopBody = createBasicBlock("do.body"); 446 llvm::BasicBlock *AfterDo = createBasicBlock("do.end"); 447 EmitBlock(LoopBody); 448 449 llvm::BasicBlock *DoCond = createBasicBlock("do.cond"); 450 451 // Store the blocks to use for break and continue. 452 BreakContinueStack.push_back(BreakContinue(AfterDo, DoCond)); 453 454 // Emit the body of the loop into the block. 455 EmitStmt(S.getBody()); 456 457 BreakContinueStack.pop_back(); 458 459 EmitBlock(DoCond); 460 461 // C99 6.8.5.2: "The evaluation of the controlling expression takes place 462 // after each execution of the loop body." 463 464 // Evaluate the conditional in the while header. 465 // C99 6.8.5p2/p4: The first substatement is executed if the expression 466 // compares unequal to 0. The condition must be a scalar type. 467 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond()); 468 469 // "do {} while (0)" is common in macros, avoid extra blocks. Be sure 470 // to correctly handle break/continue though. 471 bool EmitBoolCondBranch = true; 472 if (llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal)) 473 if (C->isZero()) 474 EmitBoolCondBranch = false; 475 476 // As long as the condition is true, iterate the loop. 477 if (EmitBoolCondBranch) 478 Builder.CreateCondBr(BoolCondVal, LoopBody, AfterDo); 479 480 // Emit the exit block. 481 EmitBlock(AfterDo); 482 483 // The DoCond block typically is just a branch if we skipped 484 // emitting a branch, try to erase it. 485 if (!EmitBoolCondBranch) 486 SimplifyForwardingBlocks(DoCond); 487} 488 489void CodeGenFunction::EmitForStmt(const ForStmt &S) { 490 CleanupScope ForScope(*this); 491 492 // Evaluate the first part before the loop. 493 if (S.getInit()) 494 EmitStmt(S.getInit()); 495 496 // Start the loop with a block that tests the condition. 497 llvm::BasicBlock *CondBlock = createBasicBlock("for.cond"); 498 llvm::BasicBlock *AfterFor = createBasicBlock("for.end"); 499 llvm::BasicBlock *IncBlock = 0; 500 llvm::BasicBlock *CondCleanup = 0; 501 llvm::BasicBlock *EffectiveExitBlock = AfterFor; 502 EmitBlock(CondBlock); 503 504 // Create a cleanup scope for the condition variable cleanups. 505 CleanupScope ConditionScope(*this); 506 507 llvm::Value *BoolCondVal = 0; 508 if (S.getCond()) { 509 // If the for statement has a condition scope, emit the local variable 510 // declaration. 511 if (S.getConditionVariable()) { 512 EmitLocalBlockVarDecl(*S.getConditionVariable()); 513 514 if (ConditionScope.requiresCleanups()) { 515 CondCleanup = createBasicBlock("for.cond.cleanup"); 516 EffectiveExitBlock = CondCleanup; 517 } 518 } 519 520 // As long as the condition is true, iterate the loop. 521 llvm::BasicBlock *ForBody = createBasicBlock("for.body"); 522 523 // C99 6.8.5p2/p4: The first substatement is executed if the expression 524 // compares unequal to 0. The condition must be a scalar type. 525 BoolCondVal = EvaluateExprAsBool(S.getCond()); 526 Builder.CreateCondBr(BoolCondVal, ForBody, EffectiveExitBlock); 527 528 EmitBlock(ForBody); 529 } else { 530 // Treat it as a non-zero constant. Don't even create a new block for the 531 // body, just fall into it. 532 } 533 534 // If the for loop doesn't have an increment we can just use the 535 // condition as the continue block. 536 llvm::BasicBlock *ContinueBlock; 537 if (S.getInc()) 538 ContinueBlock = IncBlock = createBasicBlock("for.inc"); 539 else 540 ContinueBlock = CondBlock; 541 542 // Store the blocks to use for break and continue. 543 BreakContinueStack.push_back(BreakContinue(AfterFor, ContinueBlock)); 544 545 // If the condition is true, execute the body of the for stmt. 546 CGDebugInfo *DI = getDebugInfo(); 547 if (DI) { 548 DI->setLocation(S.getSourceRange().getBegin()); 549 DI->EmitRegionStart(CurFn, Builder); 550 } 551 552 { 553 // Create a separate cleanup scope for the body, in case it is not 554 // a compound statement. 555 CleanupScope BodyScope(*this); 556 EmitStmt(S.getBody()); 557 } 558 559 // If there is an increment, emit it next. 560 if (S.getInc()) { 561 EmitBlock(IncBlock); 562 EmitStmt(S.getInc()); 563 } 564 565 BreakContinueStack.pop_back(); 566 567 // Finally, branch back up to the condition for the next iteration. 568 if (CondCleanup) { 569 // Branch to the cleanup block. 570 EmitBranch(CondCleanup); 571 572 // Emit the cleanup block, which branches back to the loop body or 573 // outside of the for statement once it is done. 574 EmitBlock(CondCleanup); 575 ConditionScope.ForceCleanup(); 576 Builder.CreateCondBr(BoolCondVal, CondBlock, AfterFor); 577 } else 578 EmitBranch(CondBlock); 579 if (DI) { 580 DI->setLocation(S.getSourceRange().getEnd()); 581 DI->EmitRegionEnd(CurFn, Builder); 582 } 583 584 // Emit the fall-through block. 585 EmitBlock(AfterFor, true); 586} 587 588void CodeGenFunction::EmitReturnOfRValue(RValue RV, QualType Ty) { 589 if (RV.isScalar()) { 590 Builder.CreateStore(RV.getScalarVal(), ReturnValue); 591 } else if (RV.isAggregate()) { 592 EmitAggregateCopy(ReturnValue, RV.getAggregateAddr(), Ty); 593 } else { 594 StoreComplexToAddr(RV.getComplexVal(), ReturnValue, false); 595 } 596 EmitBranchThroughCleanup(ReturnBlock); 597} 598 599/// EmitReturnStmt - Note that due to GCC extensions, this can have an operand 600/// if the function returns void, or may be missing one if the function returns 601/// non-void. Fun stuff :). 602void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { 603 // Emit the result value, even if unused, to evalute the side effects. 604 const Expr *RV = S.getRetValue(); 605 606 // FIXME: Clean this up by using an LValue for ReturnTemp, 607 // EmitStoreThroughLValue, and EmitAnyExpr. 608 if (S.getNRVOCandidate() && S.getNRVOCandidate()->isNRVOVariable() && 609 !Target.useGlobalsForAutomaticVariables()) { 610 // Apply the named return value optimization for this return statement, 611 // which means doing nothing: the appropriate result has already been 612 // constructed into the NRVO variable. 613 614 // If there is an NRVO flag for this variable, set it to 1 into indicate 615 // that the cleanup code should not destroy the variable. 616 if (llvm::Value *NRVOFlag = NRVOFlags[S.getNRVOCandidate()]) { 617 const llvm::Type *BoolTy = llvm::Type::getInt1Ty(VMContext); 618 llvm::Value *One = llvm::ConstantInt::get(BoolTy, 1); 619 Builder.CreateStore(One, NRVOFlag); 620 } 621 } else if (!ReturnValue) { 622 // Make sure not to return anything, but evaluate the expression 623 // for side effects. 624 if (RV) 625 EmitAnyExpr(RV); 626 } else if (RV == 0) { 627 // Do nothing (return value is left uninitialized) 628 } else if (FnRetTy->isReferenceType()) { 629 // If this function returns a reference, take the address of the expression 630 // rather than the value. 631 RValue Result = EmitReferenceBindingToExpr(RV, false); 632 Builder.CreateStore(Result.getScalarVal(), ReturnValue); 633 } else if (!hasAggregateLLVMType(RV->getType())) { 634 Builder.CreateStore(EmitScalarExpr(RV), ReturnValue); 635 } else if (RV->getType()->isAnyComplexType()) { 636 EmitComplexExprIntoAddr(RV, ReturnValue, false); 637 } else { 638 EmitAggExpr(RV, ReturnValue, false); 639 } 640 641 EmitBranchThroughCleanup(ReturnBlock); 642} 643 644void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) { 645 // As long as debug info is modeled with instructions, we have to ensure we 646 // have a place to insert here and write the stop point here. 647 if (getDebugInfo()) { 648 EnsureInsertPoint(); 649 EmitStopPoint(&S); 650 } 651 652 for (DeclStmt::const_decl_iterator I = S.decl_begin(), E = S.decl_end(); 653 I != E; ++I) 654 EmitDecl(**I); 655} 656 657void CodeGenFunction::EmitBreakStmt(const BreakStmt &S) { 658 assert(!BreakContinueStack.empty() && "break stmt not in a loop or switch!"); 659 660 // If this code is reachable then emit a stop point (if generating 661 // debug info). We have to do this ourselves because we are on the 662 // "simple" statement path. 663 if (HaveInsertPoint()) 664 EmitStopPoint(&S); 665 666 llvm::BasicBlock *Block = BreakContinueStack.back().BreakBlock; 667 EmitBranchThroughCleanup(Block); 668} 669 670void CodeGenFunction::EmitContinueStmt(const ContinueStmt &S) { 671 assert(!BreakContinueStack.empty() && "continue stmt not in a loop!"); 672 673 // If this code is reachable then emit a stop point (if generating 674 // debug info). We have to do this ourselves because we are on the 675 // "simple" statement path. 676 if (HaveInsertPoint()) 677 EmitStopPoint(&S); 678 679 llvm::BasicBlock *Block = BreakContinueStack.back().ContinueBlock; 680 EmitBranchThroughCleanup(Block); 681} 682 683/// EmitCaseStmtRange - If case statement range is not too big then 684/// add multiple cases to switch instruction, one for each value within 685/// the range. If range is too big then emit "if" condition check. 686void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S) { 687 assert(S.getRHS() && "Expected RHS value in CaseStmt"); 688 689 llvm::APSInt LHS = S.getLHS()->EvaluateAsInt(getContext()); 690 llvm::APSInt RHS = S.getRHS()->EvaluateAsInt(getContext()); 691 692 // Emit the code for this case. We do this first to make sure it is 693 // properly chained from our predecessor before generating the 694 // switch machinery to enter this block. 695 EmitBlock(createBasicBlock("sw.bb")); 696 llvm::BasicBlock *CaseDest = Builder.GetInsertBlock(); 697 EmitStmt(S.getSubStmt()); 698 699 // If range is empty, do nothing. 700 if (LHS.isSigned() ? RHS.slt(LHS) : RHS.ult(LHS)) 701 return; 702 703 llvm::APInt Range = RHS - LHS; 704 // FIXME: parameters such as this should not be hardcoded. 705 if (Range.ult(llvm::APInt(Range.getBitWidth(), 64))) { 706 // Range is small enough to add multiple switch instruction cases. 707 for (unsigned i = 0, e = Range.getZExtValue() + 1; i != e; ++i) { 708 SwitchInsn->addCase(llvm::ConstantInt::get(VMContext, LHS), CaseDest); 709 LHS++; 710 } 711 return; 712 } 713 714 // The range is too big. Emit "if" condition into a new block, 715 // making sure to save and restore the current insertion point. 716 llvm::BasicBlock *RestoreBB = Builder.GetInsertBlock(); 717 718 // Push this test onto the chain of range checks (which terminates 719 // in the default basic block). The switch's default will be changed 720 // to the top of this chain after switch emission is complete. 721 llvm::BasicBlock *FalseDest = CaseRangeBlock; 722 CaseRangeBlock = createBasicBlock("sw.caserange"); 723 724 CurFn->getBasicBlockList().push_back(CaseRangeBlock); 725 Builder.SetInsertPoint(CaseRangeBlock); 726 727 // Emit range check. 728 llvm::Value *Diff = 729 Builder.CreateSub(SwitchInsn->getCondition(), 730 llvm::ConstantInt::get(VMContext, LHS), "tmp"); 731 llvm::Value *Cond = 732 Builder.CreateICmpULE(Diff, 733 llvm::ConstantInt::get(VMContext, Range), "tmp"); 734 Builder.CreateCondBr(Cond, CaseDest, FalseDest); 735 736 // Restore the appropriate insertion point. 737 if (RestoreBB) 738 Builder.SetInsertPoint(RestoreBB); 739 else 740 Builder.ClearInsertionPoint(); 741} 742 743void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) { 744 if (S.getRHS()) { 745 EmitCaseStmtRange(S); 746 return; 747 } 748 749 EmitBlock(createBasicBlock("sw.bb")); 750 llvm::BasicBlock *CaseDest = Builder.GetInsertBlock(); 751 llvm::APSInt CaseVal = S.getLHS()->EvaluateAsInt(getContext()); 752 SwitchInsn->addCase(llvm::ConstantInt::get(VMContext, CaseVal), CaseDest); 753 754 // Recursively emitting the statement is acceptable, but is not wonderful for 755 // code where we have many case statements nested together, i.e.: 756 // case 1: 757 // case 2: 758 // case 3: etc. 759 // Handling this recursively will create a new block for each case statement 760 // that falls through to the next case which is IR intensive. It also causes 761 // deep recursion which can run into stack depth limitations. Handle 762 // sequential non-range case statements specially. 763 const CaseStmt *CurCase = &S; 764 const CaseStmt *NextCase = dyn_cast<CaseStmt>(S.getSubStmt()); 765 766 // Otherwise, iteratively add consequtive cases to this switch stmt. 767 while (NextCase && NextCase->getRHS() == 0) { 768 CurCase = NextCase; 769 CaseVal = CurCase->getLHS()->EvaluateAsInt(getContext()); 770 SwitchInsn->addCase(llvm::ConstantInt::get(VMContext, CaseVal), CaseDest); 771 772 NextCase = dyn_cast<CaseStmt>(CurCase->getSubStmt()); 773 } 774 775 // Normal default recursion for non-cases. 776 EmitStmt(CurCase->getSubStmt()); 777} 778 779void CodeGenFunction::EmitDefaultStmt(const DefaultStmt &S) { 780 llvm::BasicBlock *DefaultBlock = SwitchInsn->getDefaultDest(); 781 assert(DefaultBlock->empty() && 782 "EmitDefaultStmt: Default block already defined?"); 783 EmitBlock(DefaultBlock); 784 EmitStmt(S.getSubStmt()); 785} 786 787void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) { 788 CleanupScope ConditionScope(*this); 789 790 if (S.getConditionVariable()) 791 EmitLocalBlockVarDecl(*S.getConditionVariable()); 792 793 llvm::Value *CondV = EmitScalarExpr(S.getCond()); 794 795 // Handle nested switch statements. 796 llvm::SwitchInst *SavedSwitchInsn = SwitchInsn; 797 llvm::BasicBlock *SavedCRBlock = CaseRangeBlock; 798 799 // Create basic block to hold stuff that comes after switch 800 // statement. We also need to create a default block now so that 801 // explicit case ranges tests can have a place to jump to on 802 // failure. 803 llvm::BasicBlock *NextBlock = createBasicBlock("sw.epilog"); 804 llvm::BasicBlock *DefaultBlock = createBasicBlock("sw.default"); 805 SwitchInsn = Builder.CreateSwitch(CondV, DefaultBlock); 806 CaseRangeBlock = DefaultBlock; 807 808 // Clear the insertion point to indicate we are in unreachable code. 809 Builder.ClearInsertionPoint(); 810 811 // All break statements jump to NextBlock. If BreakContinueStack is non empty 812 // then reuse last ContinueBlock. 813 llvm::BasicBlock *ContinueBlock = 0; 814 if (!BreakContinueStack.empty()) 815 ContinueBlock = BreakContinueStack.back().ContinueBlock; 816 817 // Ensure any vlas created between there and here, are undone 818 BreakContinueStack.push_back(BreakContinue(NextBlock, ContinueBlock)); 819 820 // Emit switch body. 821 EmitStmt(S.getBody()); 822 823 BreakContinueStack.pop_back(); 824 825 // Update the default block in case explicit case range tests have 826 // been chained on top. 827 SwitchInsn->setSuccessor(0, CaseRangeBlock); 828 829 // If a default was never emitted then reroute any jumps to it and 830 // discard. 831 if (!DefaultBlock->getParent()) { 832 DefaultBlock->replaceAllUsesWith(NextBlock); 833 delete DefaultBlock; 834 } 835 836 // Emit continuation. 837 EmitBlock(NextBlock, true); 838 839 SwitchInsn = SavedSwitchInsn; 840 CaseRangeBlock = SavedCRBlock; 841} 842 843static std::string 844SimplifyConstraint(const char *Constraint, const TargetInfo &Target, 845 llvm::SmallVectorImpl<TargetInfo::ConstraintInfo> *OutCons=0) { 846 std::string Result; 847 848 while (*Constraint) { 849 switch (*Constraint) { 850 default: 851 Result += Target.convertConstraint(*Constraint); 852 break; 853 // Ignore these 854 case '*': 855 case '?': 856 case '!': 857 break; 858 case 'g': 859 Result += "imr"; 860 break; 861 case '[': { 862 assert(OutCons && 863 "Must pass output names to constraints with a symbolic name"); 864 unsigned Index; 865 bool result = Target.resolveSymbolicName(Constraint, 866 &(*OutCons)[0], 867 OutCons->size(), Index); 868 assert(result && "Could not resolve symbolic name"); result=result; 869 Result += llvm::utostr(Index); 870 break; 871 } 872 } 873 874 Constraint++; 875 } 876 877 return Result; 878} 879 880llvm::Value* CodeGenFunction::EmitAsmInput(const AsmStmt &S, 881 const TargetInfo::ConstraintInfo &Info, 882 const Expr *InputExpr, 883 std::string &ConstraintStr) { 884 llvm::Value *Arg; 885 if (Info.allowsRegister() || !Info.allowsMemory()) { 886 if (!CodeGenFunction::hasAggregateLLVMType(InputExpr->getType())) { 887 Arg = EmitScalarExpr(InputExpr); 888 } else { 889 InputExpr = InputExpr->IgnoreParenNoopCasts(getContext()); 890 LValue Dest = EmitLValue(InputExpr); 891 892 const llvm::Type *Ty = ConvertType(InputExpr->getType()); 893 uint64_t Size = CGM.getTargetData().getTypeSizeInBits(Ty); 894 if (Size <= 64 && llvm::isPowerOf2_64(Size)) { 895 Ty = llvm::IntegerType::get(VMContext, Size); 896 Ty = llvm::PointerType::getUnqual(Ty); 897 898 Arg = Builder.CreateLoad(Builder.CreateBitCast(Dest.getAddress(), Ty)); 899 } else { 900 Arg = Dest.getAddress(); 901 ConstraintStr += '*'; 902 } 903 } 904 } else { 905 InputExpr = InputExpr->IgnoreParenNoopCasts(getContext()); 906 LValue Dest = EmitLValue(InputExpr); 907 Arg = Dest.getAddress(); 908 ConstraintStr += '*'; 909 } 910 911 return Arg; 912} 913 914void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { 915 // Analyze the asm string to decompose it into its pieces. We know that Sema 916 // has already done this, so it is guaranteed to be successful. 917 llvm::SmallVector<AsmStmt::AsmStringPiece, 4> Pieces; 918 unsigned DiagOffs; 919 S.AnalyzeAsmString(Pieces, getContext(), DiagOffs); 920 921 // Assemble the pieces into the final asm string. 922 std::string AsmString; 923 for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { 924 if (Pieces[i].isString()) 925 AsmString += Pieces[i].getString(); 926 else if (Pieces[i].getModifier() == '\0') 927 AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo()); 928 else 929 AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' + 930 Pieces[i].getModifier() + '}'; 931 } 932 933 // Get all the output and input constraints together. 934 llvm::SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos; 935 llvm::SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos; 936 937 for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) { 938 TargetInfo::ConstraintInfo Info(S.getOutputConstraint(i), 939 S.getOutputName(i)); 940 bool IsValid = Target.validateOutputConstraint(Info); (void)IsValid; 941 assert(IsValid && "Failed to parse output constraint"); 942 OutputConstraintInfos.push_back(Info); 943 } 944 945 for (unsigned i = 0, e = S.getNumInputs(); i != e; i++) { 946 TargetInfo::ConstraintInfo Info(S.getInputConstraint(i), 947 S.getInputName(i)); 948 bool IsValid = Target.validateInputConstraint(OutputConstraintInfos.data(), 949 S.getNumOutputs(), Info); 950 assert(IsValid && "Failed to parse input constraint"); (void)IsValid; 951 InputConstraintInfos.push_back(Info); 952 } 953 954 std::string Constraints; 955 956 std::vector<LValue> ResultRegDests; 957 std::vector<QualType> ResultRegQualTys; 958 std::vector<const llvm::Type *> ResultRegTypes; 959 std::vector<const llvm::Type *> ResultTruncRegTypes; 960 std::vector<const llvm::Type*> ArgTypes; 961 std::vector<llvm::Value*> Args; 962 963 // Keep track of inout constraints. 964 std::string InOutConstraints; 965 std::vector<llvm::Value*> InOutArgs; 966 std::vector<const llvm::Type*> InOutArgTypes; 967 968 for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) { 969 TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i]; 970 971 // Simplify the output constraint. 972 std::string OutputConstraint(S.getOutputConstraint(i)); 973 OutputConstraint = SimplifyConstraint(OutputConstraint.c_str() + 1, Target); 974 975 const Expr *OutExpr = S.getOutputExpr(i); 976 OutExpr = OutExpr->IgnoreParenNoopCasts(getContext()); 977 978 LValue Dest = EmitLValue(OutExpr); 979 if (!Constraints.empty()) 980 Constraints += ','; 981 982 // If this is a register output, then make the inline asm return it 983 // by-value. If this is a memory result, return the value by-reference. 984 if (!Info.allowsMemory() && !hasAggregateLLVMType(OutExpr->getType())) { 985 Constraints += "=" + OutputConstraint; 986 ResultRegQualTys.push_back(OutExpr->getType()); 987 ResultRegDests.push_back(Dest); 988 ResultRegTypes.push_back(ConvertTypeForMem(OutExpr->getType())); 989 ResultTruncRegTypes.push_back(ResultRegTypes.back()); 990 991 // If this output is tied to an input, and if the input is larger, then 992 // we need to set the actual result type of the inline asm node to be the 993 // same as the input type. 994 if (Info.hasMatchingInput()) { 995 unsigned InputNo; 996 for (InputNo = 0; InputNo != S.getNumInputs(); ++InputNo) { 997 TargetInfo::ConstraintInfo &Input = InputConstraintInfos[InputNo]; 998 if (Input.hasTiedOperand() && Input.getTiedOperand() == i) 999 break; 1000 } 1001 assert(InputNo != S.getNumInputs() && "Didn't find matching input!"); 1002 1003 QualType InputTy = S.getInputExpr(InputNo)->getType(); 1004 QualType OutputType = OutExpr->getType(); 1005 1006 uint64_t InputSize = getContext().getTypeSize(InputTy); 1007 if (getContext().getTypeSize(OutputType) < InputSize) { 1008 // Form the asm to return the value as a larger integer or fp type. 1009 ResultRegTypes.back() = ConvertType(InputTy); 1010 } 1011 } 1012 } else { 1013 ArgTypes.push_back(Dest.getAddress()->getType()); 1014 Args.push_back(Dest.getAddress()); 1015 Constraints += "=*"; 1016 Constraints += OutputConstraint; 1017 } 1018 1019 if (Info.isReadWrite()) { 1020 InOutConstraints += ','; 1021 1022 const Expr *InputExpr = S.getOutputExpr(i); 1023 llvm::Value *Arg = EmitAsmInput(S, Info, InputExpr, InOutConstraints); 1024 1025 if (Info.allowsRegister()) 1026 InOutConstraints += llvm::utostr(i); 1027 else 1028 InOutConstraints += OutputConstraint; 1029 1030 InOutArgTypes.push_back(Arg->getType()); 1031 InOutArgs.push_back(Arg); 1032 } 1033 } 1034 1035 unsigned NumConstraints = S.getNumOutputs() + S.getNumInputs(); 1036 1037 for (unsigned i = 0, e = S.getNumInputs(); i != e; i++) { 1038 const Expr *InputExpr = S.getInputExpr(i); 1039 1040 TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i]; 1041 1042 if (!Constraints.empty()) 1043 Constraints += ','; 1044 1045 // Simplify the input constraint. 1046 std::string InputConstraint(S.getInputConstraint(i)); 1047 InputConstraint = SimplifyConstraint(InputConstraint.c_str(), Target, 1048 &OutputConstraintInfos); 1049 1050 llvm::Value *Arg = EmitAsmInput(S, Info, InputExpr, Constraints); 1051 1052 // If this input argument is tied to a larger output result, extend the 1053 // input to be the same size as the output. The LLVM backend wants to see 1054 // the input and output of a matching constraint be the same size. Note 1055 // that GCC does not define what the top bits are here. We use zext because 1056 // that is usually cheaper, but LLVM IR should really get an anyext someday. 1057 if (Info.hasTiedOperand()) { 1058 unsigned Output = Info.getTiedOperand(); 1059 QualType OutputType = S.getOutputExpr(Output)->getType(); 1060 QualType InputTy = InputExpr->getType(); 1061 1062 if (getContext().getTypeSize(OutputType) > 1063 getContext().getTypeSize(InputTy)) { 1064 // Use ptrtoint as appropriate so that we can do our extension. 1065 if (isa<llvm::PointerType>(Arg->getType())) 1066 Arg = Builder.CreatePtrToInt(Arg, 1067 llvm::IntegerType::get(VMContext, LLVMPointerWidth)); 1068 const llvm::Type *OutputTy = ConvertType(OutputType); 1069 if (isa<llvm::IntegerType>(OutputTy)) 1070 Arg = Builder.CreateZExt(Arg, OutputTy); 1071 else 1072 Arg = Builder.CreateFPExt(Arg, OutputTy); 1073 } 1074 } 1075 1076 1077 ArgTypes.push_back(Arg->getType()); 1078 Args.push_back(Arg); 1079 Constraints += InputConstraint; 1080 } 1081 1082 // Append the "input" part of inout constraints last. 1083 for (unsigned i = 0, e = InOutArgs.size(); i != e; i++) { 1084 ArgTypes.push_back(InOutArgTypes[i]); 1085 Args.push_back(InOutArgs[i]); 1086 } 1087 Constraints += InOutConstraints; 1088 1089 // Clobbers 1090 for (unsigned i = 0, e = S.getNumClobbers(); i != e; i++) { 1091 llvm::StringRef Clobber = S.getClobber(i)->getString(); 1092 1093 Clobber = Target.getNormalizedGCCRegisterName(Clobber); 1094 1095 if (i != 0 || NumConstraints != 0) 1096 Constraints += ','; 1097 1098 Constraints += "~{"; 1099 Constraints += Clobber; 1100 Constraints += '}'; 1101 } 1102 1103 // Add machine specific clobbers 1104 std::string MachineClobbers = Target.getClobbers(); 1105 if (!MachineClobbers.empty()) { 1106 if (!Constraints.empty()) 1107 Constraints += ','; 1108 Constraints += MachineClobbers; 1109 } 1110 1111 const llvm::Type *ResultType; 1112 if (ResultRegTypes.empty()) 1113 ResultType = llvm::Type::getVoidTy(VMContext); 1114 else if (ResultRegTypes.size() == 1) 1115 ResultType = ResultRegTypes[0]; 1116 else 1117 ResultType = llvm::StructType::get(VMContext, ResultRegTypes); 1118 1119 const llvm::FunctionType *FTy = 1120 llvm::FunctionType::get(ResultType, ArgTypes, false); 1121 1122 llvm::InlineAsm *IA = 1123 llvm::InlineAsm::get(FTy, AsmString, Constraints, 1124 S.isVolatile() || S.getNumOutputs() == 0); 1125 llvm::CallInst *Result = Builder.CreateCall(IA, Args.begin(), Args.end()); 1126 Result->addAttribute(~0, llvm::Attribute::NoUnwind); 1127 1128 // Slap the source location of the inline asm into a !srcloc metadata on the 1129 // call. 1130 unsigned LocID = S.getAsmString()->getLocStart().getRawEncoding(); 1131 llvm::Value *LocIDC = 1132 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LocID); 1133 Result->setMetadata("srcloc", llvm::MDNode::get(VMContext, &LocIDC, 1)); 1134 1135 // Extract all of the register value results from the asm. 1136 std::vector<llvm::Value*> RegResults; 1137 if (ResultRegTypes.size() == 1) { 1138 RegResults.push_back(Result); 1139 } else { 1140 for (unsigned i = 0, e = ResultRegTypes.size(); i != e; ++i) { 1141 llvm::Value *Tmp = Builder.CreateExtractValue(Result, i, "asmresult"); 1142 RegResults.push_back(Tmp); 1143 } 1144 } 1145 1146 for (unsigned i = 0, e = RegResults.size(); i != e; ++i) { 1147 llvm::Value *Tmp = RegResults[i]; 1148 1149 // If the result type of the LLVM IR asm doesn't match the result type of 1150 // the expression, do the conversion. 1151 if (ResultRegTypes[i] != ResultTruncRegTypes[i]) { 1152 const llvm::Type *TruncTy = ResultTruncRegTypes[i]; 1153 1154 // Truncate the integer result to the right size, note that TruncTy can be 1155 // a pointer. 1156 if (TruncTy->isFloatingPointTy()) 1157 Tmp = Builder.CreateFPTrunc(Tmp, TruncTy); 1158 else if (TruncTy->isPointerTy() && Tmp->getType()->isIntegerTy()) { 1159 uint64_t ResSize = CGM.getTargetData().getTypeSizeInBits(TruncTy); 1160 Tmp = Builder.CreateTrunc(Tmp, llvm::IntegerType::get(VMContext, 1161 (unsigned)ResSize)); 1162 Tmp = Builder.CreateIntToPtr(Tmp, TruncTy); 1163 } else if (Tmp->getType()->isPointerTy() && TruncTy->isIntegerTy()) { 1164 uint64_t TmpSize =CGM.getTargetData().getTypeSizeInBits(Tmp->getType()); 1165 Tmp = Builder.CreatePtrToInt(Tmp, llvm::IntegerType::get(VMContext, 1166 (unsigned)TmpSize)); 1167 Tmp = Builder.CreateTrunc(Tmp, TruncTy); 1168 } else if (TruncTy->isIntegerTy()) { 1169 Tmp = Builder.CreateTrunc(Tmp, TruncTy); 1170 } 1171 } 1172 1173 EmitStoreThroughLValue(RValue::get(Tmp), ResultRegDests[i], 1174 ResultRegQualTys[i]); 1175 } 1176} 1177