CodeGenFunction.h revision 6815e941998659a55c20c147861b0f437928c3d8
1//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===// 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 is the internal per-function state used for llvm translation. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H 15#define CLANG_CODEGEN_CODEGENFUNCTION_H 16 17#include "clang/AST/Type.h" 18#include "clang/AST/ExprCXX.h" 19#include "clang/AST/ExprObjC.h" 20#include "clang/Basic/TargetInfo.h" 21#include "llvm/ADT/DenseMap.h" 22#include "llvm/ADT/SmallVector.h" 23#include "llvm/Support/ValueHandle.h" 24#include <map> 25#include "CodeGenModule.h" 26#include "CGBlocks.h" 27#include "CGBuilder.h" 28#include "CGCall.h" 29#include "CGCXX.h" 30#include "CGValue.h" 31 32namespace llvm { 33 class BasicBlock; 34 class LLVMContext; 35 class Module; 36 class SwitchInst; 37 class Value; 38} 39 40namespace clang { 41 class ASTContext; 42 class CXXDestructorDecl; 43 class CXXTryStmt; 44 class Decl; 45 class EnumConstantDecl; 46 class FunctionDecl; 47 class FunctionProtoType; 48 class LabelStmt; 49 class ObjCContainerDecl; 50 class ObjCInterfaceDecl; 51 class ObjCIvarDecl; 52 class ObjCMethodDecl; 53 class ObjCImplementationDecl; 54 class ObjCPropertyImplDecl; 55 class TargetInfo; 56 class VarDecl; 57 class ObjCForCollectionStmt; 58 class ObjCAtTryStmt; 59 class ObjCAtThrowStmt; 60 class ObjCAtSynchronizedStmt; 61 62namespace CodeGen { 63 class CodeGenModule; 64 class CodeGenTypes; 65 class CGDebugInfo; 66 class CGFunctionInfo; 67 class CGRecordLayout; 68 69/// CodeGenFunction - This class organizes the per-function state that is used 70/// while generating LLVM code. 71class CodeGenFunction : public BlockFunction { 72 CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT 73 void operator=(const CodeGenFunction&); // DO NOT IMPLEMENT 74public: 75 CodeGenModule &CGM; // Per-module state. 76 TargetInfo &Target; 77 78 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; 79 CGBuilderTy Builder; 80 81 /// CurFuncDecl - Holds the Decl for the current function or ObjC method. 82 /// This excludes BlockDecls. 83 const Decl *CurFuncDecl; 84 /// CurCodeDecl - This is the inner-most code context, which includes blocks. 85 const Decl *CurCodeDecl; 86 const CGFunctionInfo *CurFnInfo; 87 QualType FnRetTy; 88 llvm::Function *CurFn; 89 90 /// ReturnBlock - Unified return block. 91 llvm::BasicBlock *ReturnBlock; 92 /// ReturnValue - The temporary alloca to hold the return value. This is null 93 /// iff the function has no return value. 94 llvm::Instruction *ReturnValue; 95 96 /// AllocaInsertPoint - This is an instruction in the entry block before which 97 /// we prefer to insert allocas. 98 llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; 99 100 const llvm::Type *LLVMIntTy; 101 uint32_t LLVMPointerWidth; 102 103public: 104 /// ObjCEHValueStack - Stack of Objective-C exception values, used for 105 /// rethrows. 106 llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack; 107 108 /// PushCleanupBlock - Push a new cleanup entry on the stack and set the 109 /// passed in block as the cleanup block. 110 void PushCleanupBlock(llvm::BasicBlock *CleanupBlock); 111 112 /// CleanupBlockInfo - A struct representing a popped cleanup block. 113 struct CleanupBlockInfo { 114 /// CleanupBlock - the cleanup block 115 llvm::BasicBlock *CleanupBlock; 116 117 /// SwitchBlock - the block (if any) containing the switch instruction used 118 /// for jumping to the final destination. 119 llvm::BasicBlock *SwitchBlock; 120 121 /// EndBlock - the default destination for the switch instruction. 122 llvm::BasicBlock *EndBlock; 123 124 CleanupBlockInfo(llvm::BasicBlock *cb, llvm::BasicBlock *sb, 125 llvm::BasicBlock *eb) 126 : CleanupBlock(cb), SwitchBlock(sb), EndBlock(eb) {} 127 }; 128 129 /// PopCleanupBlock - Will pop the cleanup entry on the stack, process all 130 /// branch fixups and return a block info struct with the switch block and end 131 /// block. 132 CleanupBlockInfo PopCleanupBlock(); 133 134 /// CleanupScope - RAII object that will create a cleanup block and set the 135 /// insert point to that block. When destructed, it sets the insert point to 136 /// the previous block and pushes a new cleanup entry on the stack. 137 class CleanupScope { 138 CodeGenFunction& CGF; 139 llvm::BasicBlock *CurBB; 140 llvm::BasicBlock *CleanupBB; 141 142 public: 143 CleanupScope(CodeGenFunction &cgf) 144 : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()) { 145 CleanupBB = CGF.createBasicBlock("cleanup"); 146 CGF.Builder.SetInsertPoint(CleanupBB); 147 } 148 149 ~CleanupScope() { 150 CGF.PushCleanupBlock(CleanupBB); 151 // FIXME: This is silly, move this into the builder. 152 if (CurBB) 153 CGF.Builder.SetInsertPoint(CurBB); 154 else 155 CGF.Builder.ClearInsertionPoint(); 156 } 157 }; 158 159 /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup 160 /// blocks that have been added. 161 void EmitCleanupBlocks(size_t OldCleanupStackSize); 162 163 /// EmitBranchThroughCleanup - Emit a branch from the current insert block 164 /// through the cleanup handling code (if any) and then on to \arg Dest. 165 /// 166 /// FIXME: Maybe this should really be in EmitBranch? Don't we always want 167 /// this behavior for branches? 168 void EmitBranchThroughCleanup(llvm::BasicBlock *Dest); 169 170 /// PushConditionalTempDestruction - Should be called before a conditional 171 /// part of an expression is emitted. For example, before the RHS of the 172 /// expression below is emitted: 173 /// 174 /// b && f(T()); 175 /// 176 /// This is used to make sure that any temporaryes created in the conditional 177 /// branch are only destroyed if the branch is taken. 178 void PushConditionalTempDestruction(); 179 180 /// PopConditionalTempDestruction - Should be called after a conditional 181 /// part of an expression has been emitted. 182 void PopConditionalTempDestruction(); 183 184private: 185 CGDebugInfo* DebugInfo; 186 187 /// LabelIDs - Track arbitrary ids assigned to labels for use in implementing 188 /// the GCC address-of-label extension and indirect goto. IDs are assigned to 189 /// labels inside getIDForAddrOfLabel(). 190 std::map<const LabelStmt*, unsigned> LabelIDs; 191 192 /// IndirectSwitches - Record the list of switches for indirect 193 /// gotos. Emission of the actual switching code needs to be delayed until all 194 /// AddrLabelExprs have been seen. 195 std::vector<llvm::SwitchInst*> IndirectSwitches; 196 197 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C 198 /// decls. 199 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; 200 201 /// LabelMap - This keeps track of the LLVM basic block for each C label. 202 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap; 203 204 // BreakContinueStack - This keeps track of where break and continue 205 // statements should jump to. 206 struct BreakContinue { 207 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb) 208 : BreakBlock(bb), ContinueBlock(cb) {} 209 210 llvm::BasicBlock *BreakBlock; 211 llvm::BasicBlock *ContinueBlock; 212 }; 213 llvm::SmallVector<BreakContinue, 8> BreakContinueStack; 214 215 /// SwitchInsn - This is nearest current switch instruction. It is null if if 216 /// current context is not in a switch. 217 llvm::SwitchInst *SwitchInsn; 218 219 /// CaseRangeBlock - This block holds if condition check for last case 220 /// statement range in current switch instruction. 221 llvm::BasicBlock *CaseRangeBlock; 222 223 /// InvokeDest - This is the nearest exception target for calls 224 /// which can unwind, when exceptions are being used. 225 llvm::BasicBlock *InvokeDest; 226 227 // VLASizeMap - This keeps track of the associated size for each VLA type. 228 // We track this by the size expression rather than the type itself because 229 // in certain situations, like a const qualifier applied to an VLA typedef, 230 // multiple VLA types can share the same size expression. 231 // FIXME: Maybe this could be a stack of maps that is pushed/popped as we 232 // enter/leave scopes. 233 llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; 234 235 /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid 236 /// calling llvm.stacksave for multiple VLAs in the same scope. 237 bool DidCallStackSave; 238 239 struct CleanupEntry { 240 /// CleanupBlock - The block of code that does the actual cleanup. 241 llvm::BasicBlock *CleanupBlock; 242 243 /// Blocks - Basic blocks that were emitted in the current cleanup scope. 244 std::vector<llvm::BasicBlock *> Blocks; 245 246 /// BranchFixups - Branch instructions to basic blocks that haven't been 247 /// inserted into the current function yet. 248 std::vector<llvm::BranchInst *> BranchFixups; 249 250 explicit CleanupEntry(llvm::BasicBlock *cb) 251 : CleanupBlock(cb) {} 252 }; 253 254 /// CleanupEntries - Stack of cleanup entries. 255 llvm::SmallVector<CleanupEntry, 8> CleanupEntries; 256 257 typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap; 258 259 /// BlockScopes - Map of which "cleanup scope" scope basic blocks have. 260 BlockScopeMap BlockScopes; 261 262 /// CXXThisDecl - When parsing an C++ function, this will hold the implicit 263 /// 'this' declaration. 264 ImplicitParamDecl *CXXThisDecl; 265 266 /// CXXLiveTemporaryInfo - Holds information about a live C++ temporary. 267 struct CXXLiveTemporaryInfo { 268 /// Temporary - The live temporary. 269 const CXXTemporary *Temporary; 270 271 /// ThisPtr - The pointer to the temporary. 272 llvm::Value *ThisPtr; 273 274 /// DtorBlock - The destructor block. 275 llvm::BasicBlock *DtorBlock; 276 277 /// CondPtr - If this is a conditional temporary, this is the pointer to 278 /// the condition variable that states whether the destructor should be 279 /// called or not. 280 llvm::Value *CondPtr; 281 282 CXXLiveTemporaryInfo(const CXXTemporary *temporary, 283 llvm::Value *thisptr, llvm::BasicBlock *dtorblock, 284 llvm::Value *condptr) 285 : Temporary(temporary), ThisPtr(thisptr), DtorBlock(dtorblock), 286 CondPtr(condptr) { } 287 }; 288 289 llvm::SmallVector<CXXLiveTemporaryInfo, 4> LiveTemporaries; 290 291 /// ConditionalTempDestructionStack - Contains the number of live temporaries 292 /// when PushConditionalTempDestruction was called. This is used so that 293 /// we know how many temporaries were created by a certain expression. 294 llvm::SmallVector<size_t, 4> ConditionalTempDestructionStack; 295 296 297 /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM 298 /// type as well as the field number that contains the actual data. 299 llvm::DenseMap<const ValueDecl *, std::pair<const llvm::Type *, 300 unsigned> > ByRefValueInfo; 301 302 /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field 303 /// number that holds the value. 304 unsigned getByRefValueLLVMField(const ValueDecl *VD) const; 305 306public: 307 CodeGenFunction(CodeGenModule &cgm); 308 309 ASTContext &getContext() const; 310 CGDebugInfo *getDebugInfo() { return DebugInfo; } 311 312 llvm::BasicBlock *getInvokeDest() { return InvokeDest; } 313 void setInvokeDest(llvm::BasicBlock *B) { InvokeDest = B; } 314 315 llvm::LLVMContext &getLLVMContext() { return VMContext; } 316 317 //===--------------------------------------------------------------------===// 318 // Objective-C 319 //===--------------------------------------------------------------------===// 320 321 void GenerateObjCMethod(const ObjCMethodDecl *OMD); 322 323 void StartObjCMethod(const ObjCMethodDecl *MD, 324 const ObjCContainerDecl *CD); 325 326 /// GenerateObjCGetter - Synthesize an Objective-C property getter function. 327 void GenerateObjCGetter(ObjCImplementationDecl *IMP, 328 const ObjCPropertyImplDecl *PID); 329 330 /// GenerateObjCSetter - Synthesize an Objective-C property setter function 331 /// for the given property. 332 void GenerateObjCSetter(ObjCImplementationDecl *IMP, 333 const ObjCPropertyImplDecl *PID); 334 335 //===--------------------------------------------------------------------===// 336 // Block Bits 337 //===--------------------------------------------------------------------===// 338 339 llvm::Value *BuildBlockLiteralTmp(const BlockExpr *); 340 llvm::Constant *BuildDescriptorBlockDecl(bool BlockHasCopyDispose, 341 uint64_t Size, 342 const llvm::StructType *, 343 std::vector<HelperInfo> *); 344 345 llvm::Function *GenerateBlockFunction(const BlockExpr *BExpr, 346 const BlockInfo& Info, 347 const Decl *OuterFuncDecl, 348 llvm::DenseMap<const Decl*, llvm::Value*> ldm, 349 uint64_t &Size, uint64_t &Align, 350 llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls, 351 bool &subBlockHasCopyDispose); 352 353 void BlockForwardSelf(); 354 llvm::Value *LoadBlockStruct(); 355 356 llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E); 357 const llvm::Type *BuildByRefType(const ValueDecl *D); 358 359 void GenerateCode(GlobalDecl GD, llvm::Function *Fn); 360 void StartFunction(GlobalDecl GD, QualType RetTy, 361 llvm::Function *Fn, 362 const FunctionArgList &Args, 363 SourceLocation StartLoc); 364 365 /// EmitReturnBlock - Emit the unified return block, trying to avoid its 366 /// emission when possible. 367 void EmitReturnBlock(); 368 369 /// FinishFunction - Complete IR generation of the current function. It is 370 /// legal to call this function even if there is no current insertion point. 371 void FinishFunction(SourceLocation EndLoc=SourceLocation()); 372 373 /// GenerateVtable - Generate the vtable for the given type. 374 llvm::Value *GenerateVtable(const CXXRecordDecl *RD); 375 376 /// GenerateThunk - Generate a thunk for the given method 377 llvm::Constant *GenerateThunk(llvm::Function *Fn, const CXXMethodDecl *MD, 378 bool Extern, int64_t nv, int64_t v); 379 llvm::Constant *GenerateCovariantThunk(llvm::Function *Fn, 380 const CXXMethodDecl *MD, bool Extern, 381 int64_t nv_t, int64_t v_t, 382 int64_t nv_r, int64_t v_r); 383 384 void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type); 385 386 void SynthesizeCXXCopyConstructor(const CXXConstructorDecl *Ctor, 387 CXXCtorType Type, 388 llvm::Function *Fn, 389 const FunctionArgList &Args); 390 391 void SynthesizeCXXCopyAssignment(const CXXMethodDecl *CD, 392 llvm::Function *Fn, 393 const FunctionArgList &Args); 394 395 void SynthesizeDefaultConstructor(const CXXConstructorDecl *Ctor, 396 CXXCtorType Type, 397 llvm::Function *Fn, 398 const FunctionArgList &Args); 399 400 void SynthesizeDefaultDestructor(const CXXDestructorDecl *Dtor, 401 CXXDtorType Type, 402 llvm::Function *Fn, 403 const FunctionArgList &Args); 404 405 /// EmitDtorEpilogue - Emit all code that comes at the end of class's 406 /// destructor. This is to call destructors on members and base classes 407 /// in reverse order of their construction. 408 void EmitDtorEpilogue(const CXXDestructorDecl *Dtor, 409 CXXDtorType Type); 410 411 /// EmitFunctionProlog - Emit the target specific LLVM code to load the 412 /// arguments for the given function. This is also responsible for naming the 413 /// LLVM function arguments. 414 void EmitFunctionProlog(const CGFunctionInfo &FI, 415 llvm::Function *Fn, 416 const FunctionArgList &Args); 417 418 /// EmitFunctionEpilog - Emit the target specific LLVM code to return the 419 /// given temporary. 420 void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue); 421 422 const llvm::Type *ConvertTypeForMem(QualType T); 423 const llvm::Type *ConvertType(QualType T); 424 425 /// LoadObjCSelf - Load the value of self. This function is only valid while 426 /// generating code for an Objective-C method. 427 llvm::Value *LoadObjCSelf(); 428 429 /// TypeOfSelfObject - Return type of object that this self represents. 430 QualType TypeOfSelfObject(); 431 432 /// hasAggregateLLVMType - Return true if the specified AST type will map into 433 /// an aggregate LLVM type or is void. 434 static bool hasAggregateLLVMType(QualType T); 435 436 /// createBasicBlock - Create an LLVM basic block. 437 llvm::BasicBlock *createBasicBlock(const char *Name="", 438 llvm::Function *Parent=0, 439 llvm::BasicBlock *InsertBefore=0) { 440#ifdef NDEBUG 441 return llvm::BasicBlock::Create(VMContext, "", Parent, InsertBefore); 442#else 443 return llvm::BasicBlock::Create(VMContext, Name, Parent, InsertBefore); 444#endif 445 } 446 447 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified 448 /// label maps to. 449 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S); 450 451 /// SimplifyForwardingBlocks - If the given basic block is only a 452 /// branch to another basic block, simplify it. This assumes that no 453 /// other code could potentially reference the basic block. 454 void SimplifyForwardingBlocks(llvm::BasicBlock *BB); 455 456 /// EmitBlock - Emit the given block \arg BB and set it as the insert point, 457 /// adding a fall-through branch from the current insert block if 458 /// necessary. It is legal to call this function even if there is no current 459 /// insertion point. 460 /// 461 /// IsFinished - If true, indicates that the caller has finished emitting 462 /// branches to the given block and does not expect to emit code into it. This 463 /// means the block can be ignored if it is unreachable. 464 void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); 465 466 /// EmitBranch - Emit a branch to the specified basic block from the current 467 /// insert block, taking care to avoid creation of branches from dummy 468 /// blocks. It is legal to call this function even if there is no current 469 /// insertion point. 470 /// 471 /// This function clears the current insertion point. The caller should follow 472 /// calls to this function with calls to Emit*Block prior to generation new 473 /// code. 474 void EmitBranch(llvm::BasicBlock *Block); 475 476 /// HaveInsertPoint - True if an insertion point is defined. If not, this 477 /// indicates that the current code being emitted is unreachable. 478 bool HaveInsertPoint() const { 479 return Builder.GetInsertBlock() != 0; 480 } 481 482 /// EnsureInsertPoint - Ensure that an insertion point is defined so that 483 /// emitted IR has a place to go. Note that by definition, if this function 484 /// creates a block then that block is unreachable; callers may do better to 485 /// detect when no insertion point is defined and simply skip IR generation. 486 void EnsureInsertPoint() { 487 if (!HaveInsertPoint()) 488 EmitBlock(createBasicBlock()); 489 } 490 491 /// ErrorUnsupported - Print out an error that codegen doesn't support the 492 /// specified stmt yet. 493 void ErrorUnsupported(const Stmt *S, const char *Type, 494 bool OmitOnError=false); 495 496 //===--------------------------------------------------------------------===// 497 // Helpers 498 //===--------------------------------------------------------------------===// 499 500 Qualifiers MakeQualifiers(QualType T) { 501 Qualifiers Quals = T.getQualifiers(); 502 Quals.setObjCGCAttr(getContext().getObjCGCAttrKind(T)); 503 return Quals; 504 } 505 506 /// CreateTempAlloca - This creates a alloca and inserts it into the entry 507 /// block. 508 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, 509 const char *Name = "tmp"); 510 511 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified 512 /// expression and compare the result against zero, returning an Int1Ty value. 513 llvm::Value *EvaluateExprAsBool(const Expr *E); 514 515 /// EmitAnyExpr - Emit code to compute the specified expression which can have 516 /// any type. The result is returned as an RValue struct. If this is an 517 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where 518 /// the result should be returned. 519 /// 520 /// \param IgnoreResult - True if the resulting value isn't used. 521 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, 522 bool IsAggLocVolatile = false, bool IgnoreResult = false, 523 bool IsInitializer = false); 524 525 // EmitVAListRef - Emit a "reference" to a va_list; this is either the address 526 // or the value of the expression, depending on how va_list is defined. 527 llvm::Value *EmitVAListRef(const Expr *E); 528 529 /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will 530 /// always be accessible even if no aggregate location is provided. 531 RValue EmitAnyExprToTemp(const Expr *E, bool IsAggLocVolatile = false, 532 bool IsInitializer = false); 533 534 /// EmitAggregateCopy - Emit an aggrate copy. 535 /// 536 /// \param isVolatile - True iff either the source or the destination is 537 /// volatile. 538 void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, 539 QualType EltTy, bool isVolatile=false); 540 541 void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty); 542 543 /// StartBlock - Start new block named N. If insert block is a dummy block 544 /// then reuse it. 545 void StartBlock(const char *N); 546 547 /// GetAddrOfStaticLocalVar - Return the address of a static local variable. 548 llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD); 549 550 /// GetAddrOfLocalVar - Return the address of a local variable. 551 llvm::Value *GetAddrOfLocalVar(const VarDecl *VD); 552 553 /// getAccessedFieldNo - Given an encoded value and a result number, return 554 /// the input field number being accessed. 555 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); 556 557 unsigned GetIDForAddrOfLabel(const LabelStmt *L); 558 559 /// EmitMemSetToZero - Generate code to memset a value of the given type to 0. 560 void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty); 561 562 // EmitVAArg - Generate code to get an argument from the passed in pointer 563 // and update it accordingly. The return value is a pointer to the argument. 564 // FIXME: We should be able to get rid of this method and use the va_arg 565 // instruction in LLVM instead once it works well enough. 566 llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty); 567 568 // EmitVLASize - Generate code for any VLA size expressions that might occur 569 // in a variably modified type. If Ty is a VLA, will return the value that 570 // corresponds to the size in bytes of the VLA type. Will return 0 otherwise. 571 /// 572 /// This function can be called with a null (unreachable) insert point. 573 llvm::Value *EmitVLASize(QualType Ty); 574 575 // GetVLASize - Returns an LLVM value that corresponds to the size in bytes 576 // of a variable length array type. 577 llvm::Value *GetVLASize(const VariableArrayType *); 578 579 /// LoadCXXThis - Load the value of 'this'. This function is only valid while 580 /// generating code for an C++ member function. 581 llvm::Value *LoadCXXThis(); 582 583 /// GetAddressCXXOfBaseClass - This function will add the necessary delta 584 /// to the load of 'this' and returns address of the base class. 585 // FIXME. This currently only does a derived to non-virtual base conversion. 586 // Other kinds of conversions will come later. 587 llvm::Value *GetAddressCXXOfBaseClass(llvm::Value *BaseValue, 588 const CXXRecordDecl *ClassDecl, 589 const CXXRecordDecl *BaseClassDecl, 590 bool NullCheckValue); 591 592 void EmitClassAggrMemberwiseCopy(llvm::Value *DestValue, 593 llvm::Value *SrcValue, 594 const ArrayType *Array, 595 const CXXRecordDecl *BaseClassDecl, 596 QualType Ty); 597 598 void EmitClassAggrCopyAssignment(llvm::Value *DestValue, 599 llvm::Value *SrcValue, 600 const ArrayType *Array, 601 const CXXRecordDecl *BaseClassDecl, 602 QualType Ty); 603 604 void EmitClassMemberwiseCopy(llvm::Value *DestValue, llvm::Value *SrcValue, 605 const CXXRecordDecl *ClassDecl, 606 const CXXRecordDecl *BaseClassDecl, 607 QualType Ty); 608 609 void EmitClassCopyAssignment(llvm::Value *DestValue, llvm::Value *SrcValue, 610 const CXXRecordDecl *ClassDecl, 611 const CXXRecordDecl *BaseClassDecl, 612 QualType Ty); 613 614 void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, 615 llvm::Value *This, 616 CallExpr::const_arg_iterator ArgBeg, 617 CallExpr::const_arg_iterator ArgEnd); 618 619 void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 620 const ConstantArrayType *ArrayTy, 621 llvm::Value *ArrayPtr); 622 void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 623 llvm::Value *NumElements, 624 llvm::Value *ArrayPtr); 625 626 void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D, 627 const ArrayType *Array, 628 llvm::Value *This); 629 630 void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, 631 llvm::Value *This); 632 633 void PushCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr); 634 void PopCXXTemporary(); 635 636 llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); 637 void EmitCXXDeleteExpr(const CXXDeleteExpr *E); 638 639 //===--------------------------------------------------------------------===// 640 // Declaration Emission 641 //===--------------------------------------------------------------------===// 642 643 /// EmitDecl - Emit a declaration. 644 /// 645 /// This function can be called with a null (unreachable) insert point. 646 void EmitDecl(const Decl &D); 647 648 /// EmitBlockVarDecl - Emit a block variable declaration. 649 /// 650 /// This function can be called with a null (unreachable) insert point. 651 void EmitBlockVarDecl(const VarDecl &D); 652 653 /// EmitLocalBlockVarDecl - Emit a local block variable declaration. 654 /// 655 /// This function can be called with a null (unreachable) insert point. 656 void EmitLocalBlockVarDecl(const VarDecl &D); 657 658 void EmitStaticBlockVarDecl(const VarDecl &D); 659 660 /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. 661 void EmitParmDecl(const VarDecl &D, llvm::Value *Arg); 662 663 //===--------------------------------------------------------------------===// 664 // Statement Emission 665 //===--------------------------------------------------------------------===// 666 667 /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. 668 void EmitStopPoint(const Stmt *S); 669 670 /// EmitStmt - Emit the code for the statement \arg S. It is legal to call 671 /// this function even if there is no current insertion point. 672 /// 673 /// This function may clear the current insertion point; callers should use 674 /// EnsureInsertPoint if they wish to subsequently generate code without first 675 /// calling EmitBlock, EmitBranch, or EmitStmt. 676 void EmitStmt(const Stmt *S); 677 678 /// EmitSimpleStmt - Try to emit a "simple" statement which does not 679 /// necessarily require an insertion point or debug information; typically 680 /// because the statement amounts to a jump or a container of other 681 /// statements. 682 /// 683 /// \return True if the statement was handled. 684 bool EmitSimpleStmt(const Stmt *S); 685 686 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, 687 llvm::Value *AggLoc = 0, bool isAggVol = false); 688 689 /// EmitLabel - Emit the block for the given label. It is legal to call this 690 /// function even if there is no current insertion point. 691 void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt. 692 693 void EmitLabelStmt(const LabelStmt &S); 694 void EmitGotoStmt(const GotoStmt &S); 695 void EmitIndirectGotoStmt(const IndirectGotoStmt &S); 696 void EmitIfStmt(const IfStmt &S); 697 void EmitWhileStmt(const WhileStmt &S); 698 void EmitDoStmt(const DoStmt &S); 699 void EmitForStmt(const ForStmt &S); 700 void EmitReturnStmt(const ReturnStmt &S); 701 void EmitDeclStmt(const DeclStmt &S); 702 void EmitBreakStmt(const BreakStmt &S); 703 void EmitContinueStmt(const ContinueStmt &S); 704 void EmitSwitchStmt(const SwitchStmt &S); 705 void EmitDefaultStmt(const DefaultStmt &S); 706 void EmitCaseStmt(const CaseStmt &S); 707 void EmitCaseStmtRange(const CaseStmt &S); 708 void EmitAsmStmt(const AsmStmt &S); 709 710 void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); 711 void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); 712 void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); 713 void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); 714 715 void EmitCXXTryStmt(const CXXTryStmt &S); 716 717 //===--------------------------------------------------------------------===// 718 // LValue Expression Emission 719 //===--------------------------------------------------------------------===// 720 721 /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. 722 RValue GetUndefRValue(QualType Ty); 723 724 /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E 725 /// and issue an ErrorUnsupported style diagnostic (using the 726 /// provided Name). 727 RValue EmitUnsupportedRValue(const Expr *E, 728 const char *Name); 729 730 /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue 731 /// an ErrorUnsupported style diagnostic (using the provided Name). 732 LValue EmitUnsupportedLValue(const Expr *E, 733 const char *Name); 734 735 /// EmitLValue - Emit code to compute a designator that specifies the location 736 /// of the expression. 737 /// 738 /// This can return one of two things: a simple address or a bitfield 739 /// reference. In either case, the LLVM Value* in the LValue structure is 740 /// guaranteed to be an LLVM pointer type. 741 /// 742 /// If this returns a bitfield reference, nothing about the pointee type of 743 /// the LLVM value is known: For example, it may not be a pointer to an 744 /// integer. 745 /// 746 /// If this returns a normal address, and if the lvalue's C type is fixed 747 /// size, this method guarantees that the returned pointer type will point to 748 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a 749 /// variable length type, this is not possible. 750 /// 751 LValue EmitLValue(const Expr *E); 752 753 /// EmitLoadOfScalar - Load a scalar value from an address, taking 754 /// care to appropriately convert from the memory representation to 755 /// the LLVM value representation. 756 llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, 757 QualType Ty); 758 759 /// EmitStoreOfScalar - Store a scalar value to an address, taking 760 /// care to appropriately convert from the memory representation to 761 /// the LLVM value representation. 762 void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, 763 bool Volatile, QualType Ty); 764 765 /// EmitLoadOfLValue - Given an expression that represents a value lvalue, 766 /// this method emits the address of the lvalue, then loads the result as an 767 /// rvalue, returning the rvalue. 768 RValue EmitLoadOfLValue(LValue V, QualType LVType); 769 RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType); 770 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType); 771 RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType); 772 RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType); 773 774 775 /// EmitStoreThroughLValue - Store the specified rvalue into the specified 776 /// lvalue, where both are guaranteed to the have the same type, and that type 777 /// is 'Ty'. 778 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); 779 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst, 780 QualType Ty); 781 void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty); 782 void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty); 783 784 /// EmitStoreThroughLValue - Store Src into Dst with same constraints as 785 /// EmitStoreThroughLValue. 786 /// 787 /// \param Result [out] - If non-null, this will be set to a Value* for the 788 /// bit-field contents after the store, appropriate for use as the result of 789 /// an assignment to the bit-field. 790 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty, 791 llvm::Value **Result=0); 792 793 // Note: only availabe for agg return types 794 LValue EmitBinaryOperatorLValue(const BinaryOperator *E); 795 // Note: only available for agg return types 796 LValue EmitCallExprLValue(const CallExpr *E); 797 // Note: only available for agg return types 798 LValue EmitVAArgExprLValue(const VAArgExpr *E); 799 LValue EmitDeclRefLValue(const DeclRefExpr *E); 800 LValue EmitStringLiteralLValue(const StringLiteral *E); 801 LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); 802 LValue EmitPredefinedFunctionName(unsigned Type); 803 LValue EmitPredefinedLValue(const PredefinedExpr *E); 804 LValue EmitUnaryOpLValue(const UnaryOperator *E); 805 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); 806 LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); 807 LValue EmitMemberExpr(const MemberExpr *E); 808 LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); 809 LValue EmitConditionalOperatorLValue(const ConditionalOperator *E); 810 LValue EmitCastLValue(const CastExpr *E); 811 812 llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, 813 const ObjCIvarDecl *Ivar); 814 LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field, 815 bool isUnion, unsigned CVRQualifiers); 816 LValue EmitLValueForIvar(QualType ObjectTy, 817 llvm::Value* Base, const ObjCIvarDecl *Ivar, 818 unsigned CVRQualifiers); 819 820 LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field, 821 unsigned CVRQualifiers); 822 823 LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E); 824 825 LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E); 826 LValue EmitCXXConstructLValue(const CXXConstructExpr *E); 827 LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); 828 LValue EmitCXXExprWithTemporariesLValue(const CXXExprWithTemporaries *E); 829 830 LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); 831 LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); 832 LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E); 833 LValue EmitObjCKVCRefLValue(const ObjCImplicitSetterGetterRefExpr *E); 834 LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E); 835 LValue EmitStmtExprLValue(const StmtExpr *E); 836 837 //===--------------------------------------------------------------------===// 838 // Scalar Expression Emission 839 //===--------------------------------------------------------------------===// 840 841 /// EmitCall - Generate a call of the given function, expecting the given 842 /// result type, and using the given argument list which specifies both the 843 /// LLVM arguments and the types they were derived from. 844 /// 845 /// \param TargetDecl - If given, the decl of the function in a 846 /// direct call; used to set attributes on the call (noreturn, 847 /// etc.). 848 RValue EmitCall(const CGFunctionInfo &FnInfo, 849 llvm::Value *Callee, 850 const CallArgList &Args, 851 const Decl *TargetDecl = 0); 852 853 RValue EmitCall(llvm::Value *Callee, QualType FnType, 854 CallExpr::const_arg_iterator ArgBeg, 855 CallExpr::const_arg_iterator ArgEnd, 856 const Decl *TargetDecl = 0); 857 RValue EmitCallExpr(const CallExpr *E); 858 859 llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *&This, 860 const llvm::Type *Ty); 861 RValue EmitCXXMemberCall(const CXXMethodDecl *MD, 862 llvm::Value *Callee, 863 llvm::Value *This, 864 CallExpr::const_arg_iterator ArgBeg, 865 CallExpr::const_arg_iterator ArgEnd); 866 RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E); 867 868 RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, 869 const CXXMethodDecl *MD); 870 871 RValue EmitBuiltinExpr(const FunctionDecl *FD, 872 unsigned BuiltinID, const CallExpr *E); 873 874 RValue EmitBlockCallExpr(const CallExpr *E); 875 876 /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call 877 /// is unhandled by the current target. 878 llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 879 880 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); 881 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 882 883 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...); 884 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals, 885 bool isSplat = false); 886 887 llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); 888 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); 889 llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); 890 RValue EmitObjCMessageExpr(const ObjCMessageExpr *E); 891 RValue EmitObjCPropertyGet(const Expr *E); 892 RValue EmitObjCSuperPropertyGet(const Expr *Exp, const Selector &S); 893 void EmitObjCPropertySet(const Expr *E, RValue Src); 894 void EmitObjCSuperPropertySet(const Expr *E, const Selector &S, RValue Src); 895 896 897 /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in 898 /// expression. Will emit a temporary variable if E is not an LValue. 899 RValue EmitReferenceBindingToExpr(const Expr* E, QualType DestType, 900 bool IsInitializer = false); 901 902 //===--------------------------------------------------------------------===// 903 // Expression Emission 904 //===--------------------------------------------------------------------===// 905 906 // Expressions are broken into three classes: scalar, complex, aggregate. 907 908 /// EmitScalarExpr - Emit the computation of the specified expression of LLVM 909 /// scalar type, returning the result. 910 llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); 911 912 /// EmitScalarConversion - Emit a conversion from the specified type to the 913 /// specified destination type, both of which are LLVM scalar types. 914 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, 915 QualType DstTy); 916 917 /// EmitComplexToScalarConversion - Emit a conversion from the specified 918 /// complex type to the specified destination type, where the destination type 919 /// is an LLVM scalar type. 920 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, 921 QualType DstTy); 922 923 924 /// EmitAggExpr - Emit the computation of the specified expression of 925 /// aggregate type. The result is computed into DestPtr. Note that if 926 /// DestPtr is null, the value of the aggregate expression is not needed. 927 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest, 928 bool IgnoreResult = false, bool IsInitializer = false, 929 bool RequiresGCollection = false); 930 931 /// EmitGCMemmoveCollectable - Emit special API for structs with object 932 /// pointers. 933 void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr, 934 QualType Ty); 935 936 /// EmitComplexExpr - Emit the computation of the specified expression of 937 /// complex type, returning the result. 938 ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false, 939 bool IgnoreImag = false, 940 bool IgnoreRealAssign = false, 941 bool IgnoreImagAssign = false); 942 943 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression 944 /// of complex type, storing into the specified Value*. 945 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, 946 bool DestIsVolatile); 947 948 /// StoreComplexToAddr - Store a complex number into the specified address. 949 void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr, 950 bool DestIsVolatile); 951 /// LoadComplexFromAddr - Load a complex number from the specified address. 952 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); 953 954 /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global 955 /// for a static block var decl. 956 llvm::GlobalVariable * CreateStaticBlockVarDecl(const VarDecl &D, 957 const char *Separator, 958 llvm::GlobalValue::LinkageTypes 959 Linkage); 960 961 /// EmitStaticCXXBlockVarDeclInit - Create the initializer for a C++ 962 /// runtime initialized static block var decl. 963 void EmitStaticCXXBlockVarDeclInit(const VarDecl &D, 964 llvm::GlobalVariable *GV); 965 966 /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ 967 /// variable with global storage. 968 void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr); 969 970 /// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr 971 /// with the C++ runtime so that its destructor will be called at exit. 972 void EmitCXXGlobalDtorRegistration(const CXXDestructorDecl *Dtor, 973 llvm::Constant *DeclPtr); 974 975 /// GenerateCXXGlobalInitFunc - Generates code for initializing global 976 /// variables. 977 void GenerateCXXGlobalInitFunc(llvm::Function *Fn, 978 const VarDecl **Decls, 979 unsigned NumDecls); 980 981 void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E); 982 983 RValue EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, 984 llvm::Value *AggLoc = 0, 985 bool IsAggLocVolatile = false, 986 bool IsInitializer = false); 987 988 //===--------------------------------------------------------------------===// 989 // Internal Helpers 990 //===--------------------------------------------------------------------===// 991 992 /// ContainsLabel - Return true if the statement contains a label in it. If 993 /// this statement is not executed normally, it not containing a label means 994 /// that we can just remove the code. 995 static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); 996 997 /// ConstantFoldsToSimpleInteger - If the specified expression does not fold 998 /// to a constant, or if it does but contains a label, return 0. If it 999 /// constant folds to 'true' and does not contain a label, return 1, if it 1000 /// constant folds to 'false' and does not contain a label, return -1. 1001 int ConstantFoldsToSimpleInteger(const Expr *Cond); 1002 1003 /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an 1004 /// if statement) to the specified blocks. Based on the condition, this might 1005 /// try to simplify the codegen of the conditional based on the branch. 1006 void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, 1007 llvm::BasicBlock *FalseBlock); 1008private: 1009 1010 /// EmitIndirectSwitches - Emit code for all of the switch 1011 /// instructions in IndirectSwitches. 1012 void EmitIndirectSwitches(); 1013 1014 void EmitReturnOfRValue(RValue RV, QualType Ty); 1015 1016 /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty 1017 /// from function arguments into \arg Dst. See ABIArgInfo::Expand. 1018 /// 1019 /// \param AI - The first function argument of the expansion. 1020 /// \return The argument following the last expanded function 1021 /// argument. 1022 llvm::Function::arg_iterator 1023 ExpandTypeFromArgs(QualType Ty, LValue Dst, 1024 llvm::Function::arg_iterator AI); 1025 1026 /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg 1027 /// Ty, into individual arguments on the provided vector \arg Args. See 1028 /// ABIArgInfo::Expand. 1029 void ExpandTypeToArgs(QualType Ty, RValue Src, 1030 llvm::SmallVector<llvm::Value*, 16> &Args); 1031 1032 llvm::Value* EmitAsmInput(const AsmStmt &S, 1033 const TargetInfo::ConstraintInfo &Info, 1034 const Expr *InputExpr, std::string &ConstraintStr); 1035 1036 /// EmitCleanupBlock - emits a single cleanup block. 1037 void EmitCleanupBlock(); 1038 1039 /// AddBranchFixup - adds a branch instruction to the list of fixups for the 1040 /// current cleanup scope. 1041 void AddBranchFixup(llvm::BranchInst *BI); 1042 1043 /// EmitCallArg - Emit a single call argument. 1044 RValue EmitCallArg(const Expr *E, QualType ArgType); 1045 1046 /// EmitCallArgs - Emit call arguments for a function. 1047 /// The CallArgTypeInfo parameter is used for iterating over the known 1048 /// argument types of the function being called. 1049 template<typename T> 1050 void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo, 1051 CallExpr::const_arg_iterator ArgBeg, 1052 CallExpr::const_arg_iterator ArgEnd) { 1053 CallExpr::const_arg_iterator Arg = ArgBeg; 1054 1055 // First, use the argument types that the type info knows about 1056 if (CallArgTypeInfo) { 1057 for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(), 1058 E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) { 1059 QualType ArgType = *I; 1060 1061 assert(getContext().getCanonicalType(ArgType.getNonReferenceType()). 1062 getTypePtr() == 1063 getContext().getCanonicalType(Arg->getType()).getTypePtr() && 1064 "type mismatch in call argument!"); 1065 1066 Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), 1067 ArgType)); 1068 } 1069 1070 // Either we've emitted all the call args, or we have a call to a 1071 // variadic function. 1072 assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) && 1073 "Extra arguments in non-variadic function!"); 1074 1075 } 1076 1077 // If we still have any arguments, emit them using the type of the argument. 1078 for (; Arg != ArgEnd; ++Arg) { 1079 QualType ArgType = Arg->getType(); 1080 Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), 1081 ArgType)); 1082 } 1083 } 1084}; 1085 1086 1087} // end namespace CodeGen 1088} // end namespace clang 1089 1090#endif 1091